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.
EnvironmentalService.cpp
- Committer:
- loicguibert
- Date:
- 2019-04-16
- Revision:
- 15:aac1b3950a9e
- Parent:
- 14:c5578b5edabe
- Child:
- 16:eed9a9ba319c
File content as of revision 15:aac1b3950a9e:
#include "EnvironmentalService.h" #include "mbed.h" EnvironmentalService::EnvironmentalService(BLE& ble, Logger& logger) : m_ble(ble), m_serviceAdded(false), m_pressureCharacteristic(GattCharacteristic::UUID_PRESSURE_CHAR, &m_pressure), m_temperatureCharacteristic(GattCharacteristic::UUID_TEMPERATURE_CHAR, &m_temperature), m_humidityCharacteristic(GattCharacteristic::UUID_HUMIDITY_CHAR, &m_humidity), m_logger(logger) { } void EnvironmentalService::addServiceToGattServer(void) { // We should only ever need to add the information service once if (m_serviceAdded) { return; } GattCharacteristic *charTable[] = { &m_pressureCharacteristic, &m_temperatureCharacteristic, &m_humidityCharacteristic }; GattService environmentalService(GattService::UUID_ENVIRONMENTAL_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); m_ble.gattServer().addService(environmentalService); m_serviceAdded = true; m_logger.log("Environmental service added\r\n"); } void EnvironmentalService::updateEnvironmentalService(PressureType_t newPressure, TemperatureType_t newTemperature, HumidityType_t newHumidity) { m_pressure = newPressure; m_temperature = newTemperature; m_humidity = newHumidity; m_ble.gattServer().write(m_pressureCharacteristic.getValueHandle(), (uint8_t *) &m_pressure, sizeof(PressureType_t)); m_ble.gattServer().write(m_temperatureCharacteristic.getValueHandle(), (uint8_t *) &m_temperature, sizeof(m_temperature)); m_ble.gattServer().write(m_humidityCharacteristic.getValueHandle(), (uint8_t *) &m_humidity, sizeof(m_humidity)); }