MtM+ / Mbed OS Mt05_MtSense02

Dependencies:   CCS811

Fork of MtConnect04S_MtSense02 by MtM+

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AirQualityService.h Source File

AirQualityService.h

00001 #ifndef AIRQUALITYSERVICE_H
00002 #define AIRQUALITYSERVICE_H
00003 
00004 #include "ble/BLE.h"
00005 
00006 class AirQualityService {
00007     public:
00008         typedef uint16_t CO2Type_t;
00009         typedef uint16_t TVOCType_t;
00010         AirQualityService(BLE& _ble, UUID co2CID, UUID tvocCID) : 
00011             ble(_ble),
00012             co2Characteristic (co2CID, &co2, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00013             tvocCharacteristic(tvocCID, &tvoc, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {
00014                 
00015                 uint8_t AQSID[16] = {   '@', 'M', 'T', 'M',
00016                                         'C', 'O', '2', 'A',
00017                                         'N', 'D', 'T', 'V',
00018                                         'O', 'C',  '@',  '@',
00019                                     };
00020                                         
00021                 static bool serviceAdded = false; /* We should only ever need to add the information service once. */
00022                 UUID customUUID(AQSID);
00023                 
00024                 if (serviceAdded) {
00025                     return;
00026                 }
00027         
00028                 GattCharacteristic *charTable[] = { &co2Characteristic, &tvocCharacteristic };
00029         
00030                 GattService customAQService(customUUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
00031         
00032                 ble.gattServer().addService(customAQService);
00033                 serviceAdded = true;   
00034                 
00035         }
00036         
00037         void updateCO2(uint16_t co2ppm) {
00038             co2 = (CO2Type_t) co2ppm;
00039             ble.gattServer().write(co2Characteristic.getValueHandle(), (uint8_t *) &co2, sizeof(CO2Type_t));
00040         }
00041         
00042         void updateTVOC(uint16_t tvocppb) {
00043             tvoc = (TVOCType_t) tvocppb;
00044             ble.gattServer().write(tvocCharacteristic.getValueHandle(), (uint8_t *) &tvoc, sizeof(TVOCType_t));
00045         }
00046     
00047     private:
00048         BLE&        ble;
00049         CO2Type_t   co2;
00050         TVOCType_t  tvoc;
00051         ReadOnlyGattCharacteristic<CO2Type_t>   co2Characteristic;
00052         ReadOnlyGattCharacteristic<TVOCType_t>  tvocCharacteristic;
00053 };
00054 
00055 #endif