Run a K30 CO2 sensor on a Nordic nRF52DK Board

Fork of mbed-os-example-ble-BatteryLevel by mbed-os-examples

Revision:
61:a5d14d0a94a1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/k30.h	Tue May 01 17:45:11 2018 +0000
@@ -0,0 +1,26 @@
+#ifndef __K30_SERVICE_H__
+#define __K30_SERVICE_H__
+ 
+class K30Service {
+public:
+    const static uint16_t K30_SERVICE_UUID              = 0xA000;
+    const static uint16_t K30_VALUE_CHARACTERISTIC_UUID = 0xA001;
+ 
+    K30Service(BLEDevice &_ble, float k30Initial) :
+        ble(_ble), k30Value(K30_VALUE_CHARACTERISTIC_UUID, &k30Initial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
+    {
+        GattCharacteristic *charTable[] = {&k30Value};
+        GattService         k30Service(K30Service::K30_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
+        ble.addService(k30Service);
+    }
+ 
+    void updateK30Value(float newValue) {
+        ble.updateCharacteristicValue(k30Value.getValueHandle(), (uint8_t *)&newValue, sizeof(float));
+    }
+ 
+private:
+    BLEDevice                        &ble;
+    ReadOnlyGattCharacteristic<float>  k30Value;
+};
+ 
+#endif /* #ifndef __K30_SERVICE_H__ */
\ No newline at end of file