Kris Scholte Lubberink
/
SSS_Ble
Ble for smart sOlutions
source/ColorService.h
- Committer:
- krissl
- Date:
- 2019-03-25
- Revision:
- 1:9fc54848a198
- Child:
- 3:f594022fe519
File content as of revision 1:9fc54848a198:
#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__*/