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