No changes

Dependencies:   BLE_API mbed nRF51822

Fork of SDP_Version3_Abdul by Michael Galis

ReedSwitchService.h

Committer:
galism
Date:
2017-02-26
Revision:
5:fd83a2ac378e
Parent:
4:caab577334f0

File content as of revision 5:fd83a2ac378e:

/* Senior Project Bluetooth bicycle speedometer
Author: Michael Galis
This header file describes the Reed Switch Service that I created to be able
to send the state of the reed switch as a magnet passes by.
*/

#ifndef __BLE_BUTTON_SERVICE_H__
#define __BLE_BUTTON_SERVICE_H__

class ReedSwitchService {
public:
    const static uint16_t REED_SWITCH_SERVICE_UUID              = 0xA006;
    const static uint16_t REED_SWITCH_STATE_CHARACTERISTIC_UUID = 0xA007;

    ReedSwitchService(BLE &_ble, uint8_t reedSwitchPressedInitial) :
        ble(_ble), 
        reedSwitchState(REED_SWITCH_STATE_CHARACTERISTIC_UUID, &reedSwitchPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
    {
        GattCharacteristic *charTable[] = {&reedSwitchState};
        GattService         reedSwitchService(ReedSwitchService::REED_SWITCH_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
        ble.gattServer().addService(reedSwitchService);
    }

    void updateReedSwitchState(uint8_t newState) 
    {
        ble.gattServer().write(reedSwitchState.getValueHandle(), (uint8_t *)&newState, sizeof(uint8_t));
    }

private:
    BLE                              &ble;
    ReadOnlyGattCharacteristic<uint8_t>  reedSwitchState;
};

#endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */