Ble for smart sOlutions

Dependencies:   Adafruit_WS2801

Committer:
krissl
Date:
Mon Mar 25 18:14:12 2019 +0000
Revision:
1:9fc54848a198
Child:
3:f594022fe519
Ble;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
krissl 1:9fc54848a198 1 #ifndef __BLE_TEMPHUM_SERVICE_H__
krissl 1:9fc54848a198 2 #define __BLE_COLOR_SERVICE_H__
krissl 1:9fc54848a198 3
krissl 1:9fc54848a198 4 #include "ble/BLE.h"
krissl 1:9fc54848a198 5 #include "CustomUUIDs.h"
krissl 1:9fc54848a198 6 class ColorService {
krissl 1:9fc54848a198 7 public:
krissl 1:9fc54848a198 8 typedef int16_t ColorType_t;
krissl 1:9fc54848a198 9 /**
krissl 1:9fc54848a198 10 * @brief ColorService constructor.
krissl 1:9fc54848a198 11 * @param ble Reference to BLE device.
krissl 1:9fc54848a198 12 */
krissl 1:9fc54848a198 13 ColorService(BLE& _ble) :
krissl 1:9fc54848a198 14 ble(_ble),
krissl 1:9fc54848a198 15 colorCharacteristic(CustomUUIDs::UUID_COLOR_CHAR, &color)
krissl 1:9fc54848a198 16 {
krissl 1:9fc54848a198 17 static bool serviceAdded = false; /* We should only ever need to add the information service once. */
krissl 1:9fc54848a198 18 if (serviceAdded) {
krissl 1:9fc54848a198 19 return;
krissl 1:9fc54848a198 20 }
krissl 1:9fc54848a198 21
krissl 1:9fc54848a198 22 GattCharacteristic *charTable[] = { &colorCharacteristic };
krissl 1:9fc54848a198 23
krissl 1:9fc54848a198 24 GattService tempHumService(
krissl 1:9fc54848a198 25 CustomUUIDs::UUID_COLOR_SERVICE,
krissl 1:9fc54848a198 26 charTable,
krissl 1:9fc54848a198 27 sizeof(charTable) / sizeof(GattCharacteristic *));
krissl 1:9fc54848a198 28
krissl 1:9fc54848a198 29 ble.gattServer().addService(tempHumService);
krissl 1:9fc54848a198 30 serviceAdded = true;
krissl 1:9fc54848a198 31 }
krissl 1:9fc54848a198 32
krissl 1:9fc54848a198 33
krissl 1:9fc54848a198 34 /**
krissl 1:9fc54848a198 35 * @brief Update temperature characteristic.
krissl 1:9fc54848a198 36 * @param newTemperatureVal New temperature measurement.
krissl 1:9fc54848a198 37 */
krissl 1:9fc54848a198 38 void updateColor(ColorType_t newColorVal)
krissl 1:9fc54848a198 39 {
krissl 1:9fc54848a198 40 color = newColorVal;
krissl 1:9fc54848a198 41 ble.gattServer().write(colorCharacteristic.getValueHandle(), (uint8_t *) &color, sizeof(ColorType_t));
krissl 1:9fc54848a198 42 }
krissl 1:9fc54848a198 43
krissl 1:9fc54848a198 44 private:
krissl 1:9fc54848a198 45 BLE& ble;
krissl 1:9fc54848a198 46
krissl 1:9fc54848a198 47 ColorType_t color;
krissl 1:9fc54848a198 48
krissl 1:9fc54848a198 49 ReadWriteGattCharacteristic<ColorType_t> colorCharacteristic;
krissl 1:9fc54848a198 50 };
krissl 1:9fc54848a198 51 #endif /* #ifndef __BLE_COLOR_SERVICE_H__*/