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:
- 16:eed9a9ba319c
- Parent:
- 15:aac1b3950a9e
- Child:
- 18:7002e66af2e5
File content as of revision 16:eed9a9ba319c:
#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_pressureTrendCharacteristic(0x2AA3, &m_pressureTrend), 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, &m_pressureTrendCharacteristic }; 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, uint32_t newPressureTrend) { m_pressure = newPressure; m_temperature = newTemperature; m_humidity = newHumidity; if (newPressureTrend < newPressure) { m_pressureTrend = RISING_CONTINUOUSLY; } else if (newPressureTrend == newPressure) { m_pressureTrend = STEADY; } else { m_pressureTrend = FALLING_CONTINUOUSLY; } 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)); m_ble.gattServer().write(m_pressureTrendCharacteristic.getValueHandle(), (uint8_t *) &m_pressureTrend, sizeof(m_pressureTrend)); }