MtM+ / Mbed OS Mt05_MtSense05

Dependencies:   CM3592

Fork of MtConnect04S_MtSense05 by MtM+

Revision:
0:6d6708b58601
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/EnvironmentalUVService.h	Tue Jun 06 02:02:38 2017 +0000
@@ -0,0 +1,40 @@
+#ifndef ENVIRONMENTALUVSERVICE_H
+#define ENVIRONMENTALUVSERVICE_H
+
+#include "ble/BLE.h"
+
+class EnvironmentUVService {
+     public:
+     
+        typedef int UVType_t;
+        EnvironmentUVService(BLE& _ble) : 
+            ble(_ble),
+            uvCharacteristic(0x2A76, &uv ) {
+                
+                static bool serviceAdded = false; /* We should only ever need to add the information service once. */
+                if (serviceAdded) {
+                    return;
+                }
+        
+                GattCharacteristic *charTable[] = { &uvCharacteristic };
+        
+                GattService environmentalService(GattService::UUID_ENVIRONMENTAL_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
+        
+                ble.gattServer().addService(environmentalService);
+                serviceAdded = true;     
+            }
+            
+        void updateTemperature(int uvIndex) {
+            uv = (UVType_t) uvIndex;
+            ble.gattServer().write(uvCharacteristic.getValueHandle(), (uint8_t *) &uv, sizeof(UVType_t));
+        }
+        
+    private:
+    
+        BLE& ble;
+        UVType_t uv;
+        ReadOnlyGattCharacteristic<UVType_t> uvCharacteristic;
+};
+
+
+#endif
\ No newline at end of file