test
Dependencies: BLE_API mbed nRF51822
ButtonService.h@0:b5b89fa49f16, 2018-04-13 (annotated)
- Committer:
- dmorris
- Date:
- Fri Apr 13 01:29:15 2018 +0000
- Revision:
- 0:b5b89fa49f16
test;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dmorris | 0:b5b89fa49f16 | 1 | /* mbed Microcontroller Library |
dmorris | 0:b5b89fa49f16 | 2 | * Copyright (c) 2006-2013 ARM Limited |
dmorris | 0:b5b89fa49f16 | 3 | * |
dmorris | 0:b5b89fa49f16 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
dmorris | 0:b5b89fa49f16 | 5 | * you may not use this file except in compliance with the License. |
dmorris | 0:b5b89fa49f16 | 6 | * You may obtain a copy of the License at |
dmorris | 0:b5b89fa49f16 | 7 | * |
dmorris | 0:b5b89fa49f16 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
dmorris | 0:b5b89fa49f16 | 9 | * |
dmorris | 0:b5b89fa49f16 | 10 | * Unless required by applicable law or agreed to in writing, software |
dmorris | 0:b5b89fa49f16 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
dmorris | 0:b5b89fa49f16 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dmorris | 0:b5b89fa49f16 | 13 | * See the License for the specific language governing permissions and |
dmorris | 0:b5b89fa49f16 | 14 | * limitations under the License. |
dmorris | 0:b5b89fa49f16 | 15 | */ |
dmorris | 0:b5b89fa49f16 | 16 | |
dmorris | 0:b5b89fa49f16 | 17 | #ifndef __BLE_BUTTON_SERVICE_H__ |
dmorris | 0:b5b89fa49f16 | 18 | #define __BLE_BUTTON_SERVICE_H__ |
dmorris | 0:b5b89fa49f16 | 19 | |
dmorris | 0:b5b89fa49f16 | 20 | class ButtonService { |
dmorris | 0:b5b89fa49f16 | 21 | public: |
dmorris | 0:b5b89fa49f16 | 22 | const static uint16_t BUTTON_SERVICE_UUID = 0xA000; |
dmorris | 0:b5b89fa49f16 | 23 | const static uint16_t BUTTON_STATE_CHARACTERISTIC_UUID = 0xA001; |
dmorris | 0:b5b89fa49f16 | 24 | |
dmorris | 0:b5b89fa49f16 | 25 | ButtonService(BLE &_ble, bool buttonPressedInitial) : |
dmorris | 0:b5b89fa49f16 | 26 | ble(_ble), buttonState(BUTTON_STATE_CHARACTERISTIC_UUID, &buttonPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
dmorris | 0:b5b89fa49f16 | 27 | { |
dmorris | 0:b5b89fa49f16 | 28 | GattCharacteristic *charTable[] = {&buttonState}; |
dmorris | 0:b5b89fa49f16 | 29 | GattService buttonService(ButtonService::BUTTON_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
dmorris | 0:b5b89fa49f16 | 30 | ble.gattServer().addService(buttonService); |
dmorris | 0:b5b89fa49f16 | 31 | } |
dmorris | 0:b5b89fa49f16 | 32 | |
dmorris | 0:b5b89fa49f16 | 33 | void updateButtonState(bool newState) { |
dmorris | 0:b5b89fa49f16 | 34 | ble.gattServer().write(buttonState.getValueHandle(), (uint8_t *)&newState, sizeof(bool)); |
dmorris | 0:b5b89fa49f16 | 35 | } |
dmorris | 0:b5b89fa49f16 | 36 | |
dmorris | 0:b5b89fa49f16 | 37 | private: |
dmorris | 0:b5b89fa49f16 | 38 | BLE &ble; |
dmorris | 0:b5b89fa49f16 | 39 | ReadOnlyGattCharacteristic<bool> buttonState; |
dmorris | 0:b5b89fa49f16 | 40 | }; |
dmorris | 0:b5b89fa49f16 | 41 | |
dmorris | 0:b5b89fa49f16 | 42 | #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */ |