Run a K30 CO2 sensor on a Nordic nRF52DK Board

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

Committer:
davidgsIoT
Date:
Wed May 02 12:14:43 2018 +0000
Revision:
63:8ec90c81ff7d
Parent:
61:a5d14d0a94a1
Updated Readme

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davidgsIoT 61:a5d14d0a94a1 1 #ifndef __K30_SERVICE_H__
davidgsIoT 61:a5d14d0a94a1 2 #define __K30_SERVICE_H__
davidgsIoT 61:a5d14d0a94a1 3
davidgsIoT 61:a5d14d0a94a1 4 class K30Service {
davidgsIoT 61:a5d14d0a94a1 5 public:
davidgsIoT 61:a5d14d0a94a1 6 const static uint16_t K30_SERVICE_UUID = 0xA000;
davidgsIoT 61:a5d14d0a94a1 7 const static uint16_t K30_VALUE_CHARACTERISTIC_UUID = 0xA001;
davidgsIoT 61:a5d14d0a94a1 8
davidgsIoT 61:a5d14d0a94a1 9 K30Service(BLEDevice &_ble, float k30Initial) :
davidgsIoT 61:a5d14d0a94a1 10 ble(_ble), k30Value(K30_VALUE_CHARACTERISTIC_UUID, &k30Initial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
davidgsIoT 61:a5d14d0a94a1 11 {
davidgsIoT 61:a5d14d0a94a1 12 GattCharacteristic *charTable[] = {&k30Value};
davidgsIoT 61:a5d14d0a94a1 13 GattService k30Service(K30Service::K30_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
davidgsIoT 61:a5d14d0a94a1 14 ble.addService(k30Service);
davidgsIoT 61:a5d14d0a94a1 15 }
davidgsIoT 61:a5d14d0a94a1 16
davidgsIoT 61:a5d14d0a94a1 17 void updateK30Value(float newValue) {
davidgsIoT 61:a5d14d0a94a1 18 ble.updateCharacteristicValue(k30Value.getValueHandle(), (uint8_t *)&newValue, sizeof(float));
davidgsIoT 61:a5d14d0a94a1 19 }
davidgsIoT 61:a5d14d0a94a1 20
davidgsIoT 61:a5d14d0a94a1 21 private:
davidgsIoT 61:a5d14d0a94a1 22 BLEDevice &ble;
davidgsIoT 61:a5d14d0a94a1 23 ReadOnlyGattCharacteristic<float> k30Value;
davidgsIoT 61:a5d14d0a94a1 24 };
davidgsIoT 61:a5d14d0a94a1 25
davidgsIoT 61:a5d14d0a94a1 26 #endif /* #ifndef __K30_SERVICE_H__ */