51 52 with same code

Dependencies:   CM3592

Fork of MtConnect04S_MtSense05 by MtM+

Committer:
johnathanlyu
Date:
Fri Apr 27 09:58:41 2018 +0000
Revision:
1:6881d24f8efe
Parent:
0:6d6708b58601
51 52 with same code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnathanlyu 0:6d6708b58601 1 #ifndef ENVIRONMENTALUVSERVICE_H
johnathanlyu 0:6d6708b58601 2 #define ENVIRONMENTALUVSERVICE_H
johnathanlyu 0:6d6708b58601 3
johnathanlyu 0:6d6708b58601 4 #include "ble/BLE.h"
johnathanlyu 0:6d6708b58601 5
johnathanlyu 0:6d6708b58601 6 class EnvironmentUVService {
johnathanlyu 0:6d6708b58601 7 public:
johnathanlyu 0:6d6708b58601 8
johnathanlyu 0:6d6708b58601 9 typedef int UVType_t;
johnathanlyu 0:6d6708b58601 10 EnvironmentUVService(BLE& _ble) :
johnathanlyu 0:6d6708b58601 11 ble(_ble),
johnathanlyu 0:6d6708b58601 12 uvCharacteristic(0x2A76, &uv ) {
johnathanlyu 0:6d6708b58601 13
johnathanlyu 0:6d6708b58601 14 static bool serviceAdded = false; /* We should only ever need to add the information service once. */
johnathanlyu 0:6d6708b58601 15 if (serviceAdded) {
johnathanlyu 0:6d6708b58601 16 return;
johnathanlyu 0:6d6708b58601 17 }
johnathanlyu 0:6d6708b58601 18
johnathanlyu 0:6d6708b58601 19 GattCharacteristic *charTable[] = { &uvCharacteristic };
johnathanlyu 0:6d6708b58601 20
johnathanlyu 0:6d6708b58601 21 GattService environmentalService(GattService::UUID_ENVIRONMENTAL_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
johnathanlyu 0:6d6708b58601 22
johnathanlyu 0:6d6708b58601 23 ble.gattServer().addService(environmentalService);
johnathanlyu 0:6d6708b58601 24 serviceAdded = true;
johnathanlyu 0:6d6708b58601 25 }
johnathanlyu 0:6d6708b58601 26
johnathanlyu 0:6d6708b58601 27 void updateTemperature(int uvIndex) {
johnathanlyu 0:6d6708b58601 28 uv = (UVType_t) uvIndex;
johnathanlyu 0:6d6708b58601 29 ble.gattServer().write(uvCharacteristic.getValueHandle(), (uint8_t *) &uv, sizeof(UVType_t));
johnathanlyu 0:6d6708b58601 30 }
johnathanlyu 0:6d6708b58601 31
johnathanlyu 0:6d6708b58601 32 private:
johnathanlyu 0:6d6708b58601 33
johnathanlyu 0:6d6708b58601 34 BLE& ble;
johnathanlyu 0:6d6708b58601 35 UVType_t uv;
johnathanlyu 0:6d6708b58601 36 ReadOnlyGattCharacteristic<UVType_t> uvCharacteristic;
johnathanlyu 0:6d6708b58601 37 };
johnathanlyu 0:6d6708b58601 38
johnathanlyu 0:6d6708b58601 39
johnathanlyu 0:6d6708b58601 40 #endif