Abdul Alf / Mbed 2 deprecated SDP_Version3_Abdul

Dependencies:   BLE_API mbed nRF51822

Fork of SDP_Version3_Abdul by Michael Galis

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ReedSwitchService.h Source File

ReedSwitchService.h

00001 /* Senior Project Bluetooth bicycle speedometer
00002 Author: Michael Galis
00003 This header file describes the Reed Switch Service that I created to be able
00004 to send the state of the reed switch as a magnet passes by.
00005 */
00006 
00007 #ifndef __BLE_BUTTON_SERVICE_H__
00008 #define __BLE_BUTTON_SERVICE_H__
00009 
00010 class ReedSwitchService {
00011 public:
00012     const static uint16_t REED_SWITCH_SERVICE_UUID              = 0xA006;
00013     const static uint16_t REED_SWITCH_STATE_CHARACTERISTIC_UUID = 0xA007;
00014 
00015     ReedSwitchService(BLE &_ble, uint8_t reedSwitchPressedInitial) :
00016         ble(_ble), 
00017         reedSwitchState(REED_SWITCH_STATE_CHARACTERISTIC_UUID, &reedSwitchPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
00018     {
00019         GattCharacteristic *charTable[] = {&reedSwitchState};
00020         GattService         reedSwitchService(ReedSwitchService::REED_SWITCH_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
00021         ble.gattServer().addService(reedSwitchService);
00022     }
00023 
00024     void updateReedSwitchState(uint8_t newState) 
00025     {
00026         ble.gattServer().write(reedSwitchState.getValueHandle(), (uint8_t *)&newState, sizeof(uint8_t));
00027     }
00028 
00029 private:
00030     BLE                              &ble;
00031     ReadOnlyGattCharacteristic<uint8_t>  reedSwitchState;
00032 };
00033 
00034 #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */