Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: CCS811
Fork of MtConnect04S_MtSense02 by
source/AirQualityService.h
- Committer:
- johnathanlyu
- Date:
- 2018-04-27
- Revision:
- 2:f3768a226561
- Parent:
- 0:4d76c0bc0f78
File content as of revision 2:f3768a226561:
#ifndef AIRQUALITYSERVICE_H
#define AIRQUALITYSERVICE_H
#include "ble/BLE.h"
class AirQualityService {
public:
typedef uint16_t CO2Type_t;
typedef uint16_t TVOCType_t;
AirQualityService(BLE& _ble, UUID co2CID, UUID tvocCID) :
ble(_ble),
co2Characteristic (co2CID, &co2, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
tvocCharacteristic(tvocCID, &tvoc, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {
uint8_t AQSID[16] = { '@', 'M', 'T', 'M',
'C', 'O', '2', 'A',
'N', 'D', 'T', 'V',
'O', 'C', '@', '@',
};
static bool serviceAdded = false; /* We should only ever need to add the information service once. */
UUID customUUID(AQSID);
if (serviceAdded) {
return;
}
GattCharacteristic *charTable[] = { &co2Characteristic, &tvocCharacteristic };
GattService customAQService(customUUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
ble.gattServer().addService(customAQService);
serviceAdded = true;
}
void updateCO2(uint16_t co2ppm) {
co2 = (CO2Type_t) co2ppm;
ble.gattServer().write(co2Characteristic.getValueHandle(), (uint8_t *) &co2, sizeof(CO2Type_t));
}
void updateTVOC(uint16_t tvocppb) {
tvoc = (TVOCType_t) tvocppb;
ble.gattServer().write(tvocCharacteristic.getValueHandle(), (uint8_t *) &tvoc, sizeof(TVOCType_t));
}
private:
BLE& ble;
CO2Type_t co2;
TVOCType_t tvoc;
ReadOnlyGattCharacteristic<CO2Type_t> co2Characteristic;
ReadOnlyGattCharacteristic<TVOCType_t> tvocCharacteristic;
};
#endif
