![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
No changes
Dependencies: BLE_API mbed nRF51822
Fork of SDP_Version3_Abdul by
ReedSwitchService.h@5:fd83a2ac378e, 2017-02-26 (annotated)
- Committer:
- galism
- Date:
- Sun Feb 26 03:24:30 2017 +0000
- Revision:
- 5:fd83a2ac378e
- Parent:
- 4:caab577334f0
No changes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
galism | 4:caab577334f0 | 1 | /* Senior Project Bluetooth bicycle speedometer |
galism | 4:caab577334f0 | 2 | Author: Michael Galis |
galism | 4:caab577334f0 | 3 | This header file describes the Reed Switch Service that I created to be able |
galism | 4:caab577334f0 | 4 | to send the state of the reed switch as a magnet passes by. |
galism | 4:caab577334f0 | 5 | */ |
galism | 4:caab577334f0 | 6 | |
galism | 4:caab577334f0 | 7 | #ifndef __BLE_BUTTON_SERVICE_H__ |
galism | 4:caab577334f0 | 8 | #define __BLE_BUTTON_SERVICE_H__ |
galism | 4:caab577334f0 | 9 | |
galism | 4:caab577334f0 | 10 | class ReedSwitchService { |
galism | 4:caab577334f0 | 11 | public: |
galism | 4:caab577334f0 | 12 | const static uint16_t REED_SWITCH_SERVICE_UUID = 0xA006; |
galism | 4:caab577334f0 | 13 | const static uint16_t REED_SWITCH_STATE_CHARACTERISTIC_UUID = 0xA007; |
galism | 4:caab577334f0 | 14 | |
galism | 4:caab577334f0 | 15 | ReedSwitchService(BLE &_ble, uint8_t reedSwitchPressedInitial) : |
galism | 4:caab577334f0 | 16 | ble(_ble), |
galism | 4:caab577334f0 | 17 | reedSwitchState(REED_SWITCH_STATE_CHARACTERISTIC_UUID, &reedSwitchPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
galism | 4:caab577334f0 | 18 | { |
galism | 4:caab577334f0 | 19 | GattCharacteristic *charTable[] = {&reedSwitchState}; |
galism | 4:caab577334f0 | 20 | GattService reedSwitchService(ReedSwitchService::REED_SWITCH_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
galism | 4:caab577334f0 | 21 | ble.gattServer().addService(reedSwitchService); |
galism | 4:caab577334f0 | 22 | } |
galism | 4:caab577334f0 | 23 | |
galism | 4:caab577334f0 | 24 | void updateReedSwitchState(uint8_t newState) |
galism | 4:caab577334f0 | 25 | { |
galism | 4:caab577334f0 | 26 | ble.gattServer().write(reedSwitchState.getValueHandle(), (uint8_t *)&newState, sizeof(uint8_t)); |
galism | 4:caab577334f0 | 27 | } |
galism | 4:caab577334f0 | 28 | |
galism | 4:caab577334f0 | 29 | private: |
galism | 4:caab577334f0 | 30 | BLE &ble; |
galism | 4:caab577334f0 | 31 | ReadOnlyGattCharacteristic<uint8_t> reedSwitchState; |
galism | 4:caab577334f0 | 32 | }; |
galism | 4:caab577334f0 | 33 | |
galism | 4:caab577334f0 | 34 | #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */ |