MtM+ / Mbed OS Mt05_MtSense05

Dependencies:   CM3592

Fork of MtConnect04S_MtSense05 by MtM+

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EnvironmentalUVService.h Source File

EnvironmentalUVService.h

00001 #ifndef ENVIRONMENTALUVSERVICE_H
00002 #define ENVIRONMENTALUVSERVICE_H
00003 
00004 #include "ble/BLE.h"
00005 
00006 class EnvironmentUVService {
00007      public:
00008      
00009         typedef int UVType_t;
00010         EnvironmentUVService(BLE& _ble) : 
00011             ble(_ble),
00012             uvCharacteristic(0x2A76, &uv ) {
00013                 
00014                 static bool serviceAdded = false; /* We should only ever need to add the information service once. */
00015                 if (serviceAdded) {
00016                     return;
00017                 }
00018         
00019                 GattCharacteristic *charTable[] = { &uvCharacteristic };
00020         
00021                 GattService environmentalService(GattService::UUID_ENVIRONMENTAL_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
00022         
00023                 ble.gattServer().addService(environmentalService);
00024                 serviceAdded = true;     
00025             }
00026             
00027         void updateTemperature(int uvIndex) {
00028             uv = (UVType_t) uvIndex;
00029             ble.gattServer().write(uvCharacteristic.getValueHandle(), (uint8_t *) &uv, sizeof(UVType_t));
00030         }
00031         
00032     private:
00033     
00034         BLE& ble;
00035         UVType_t uv;
00036         ReadOnlyGattCharacteristic<UVType_t> uvCharacteristic;
00037 };
00038 
00039 
00040 #endif