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:
- spadaaa
- Date:
- 2019-04-17
- Revision:
- 19:e056f98192f2
- Parent:
- 18:7002e66af2e5
- Child:
- 20:dac20b06d457
File content as of revision 19:e056f98192f2:
#include "EnvironmentalService.h"
#include "mbed.h"
#include <stdio.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 (newPressure == newPressureTrend) m_pressureTrend = STEADY;
if (newPressure > newPressureTrend) m_pressureTrend = RISING_CONTINUOUSLY;
if (newPressure < newPressureTrend) 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));
}