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