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