Kris Scholte Lubberink
/
SSS_Ble
Ble for smart sOlutions
Diff: source/ColorService.h
- Revision:
- 1:9fc54848a198
- Child:
- 3:f594022fe519
diff -r fe5389573740 -r 9fc54848a198 source/ColorService.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/ColorService.h Mon Mar 25 18:14:12 2019 +0000 @@ -0,0 +1,51 @@ +#ifndef __BLE_TEMPHUM_SERVICE_H__ +#define __BLE_COLOR_SERVICE_H__ + +#include "ble/BLE.h" +#include "CustomUUIDs.h" +class ColorService { +public: + typedef int16_t ColorType_t; + /** + * @brief ColorService constructor. + * @param ble Reference to BLE device. + */ + ColorService(BLE& _ble) : + ble(_ble), + colorCharacteristic(CustomUUIDs::UUID_COLOR_CHAR, &color) + { + static bool serviceAdded = false; /* We should only ever need to add the information service once. */ + if (serviceAdded) { + return; + } + + GattCharacteristic *charTable[] = { &colorCharacteristic }; + + GattService tempHumService( + CustomUUIDs::UUID_COLOR_SERVICE, + charTable, + sizeof(charTable) / sizeof(GattCharacteristic *)); + + ble.gattServer().addService(tempHumService); + serviceAdded = true; + } + + + /** + * @brief Update temperature characteristic. + * @param newTemperatureVal New temperature measurement. + */ + void updateColor(ColorType_t newColorVal) + { + color = newColorVal; + ble.gattServer().write(colorCharacteristic.getValueHandle(), (uint8_t *) &color, sizeof(ColorType_t)); + } + +private: + BLE& ble; + + ColorType_t color; + + ReadWriteGattCharacteristic<ColorType_t> colorCharacteristic; +}; +#endif /* #ifndef __BLE_COLOR_SERVICE_H__*/ \ No newline at end of file