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