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@15:aac1b3950a9e, 2019-04-16 (annotated)
- Committer:
- loicguibert
- Date:
- Tue Apr 16 07:22:47 2019 +0000
- Revision:
- 15:aac1b3950a9e
- Parent:
- 14:c5578b5edabe
- Child:
- 16:eed9a9ba319c
TP.04 part. 3 done
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| loicguibert | 14:c5578b5edabe | 1 | #include "EnvironmentalService.h" |
| loicguibert | 14:c5578b5edabe | 2 | |
| loicguibert | 14:c5578b5edabe | 3 | #include "mbed.h" |
| loicguibert | 14:c5578b5edabe | 4 | |
| loicguibert | 14:c5578b5edabe | 5 | EnvironmentalService::EnvironmentalService(BLE& ble, Logger& logger) |
| loicguibert | 14:c5578b5edabe | 6 | : m_ble(ble), |
| loicguibert | 14:c5578b5edabe | 7 | m_serviceAdded(false), |
| loicguibert | 15:aac1b3950a9e | 8 | m_pressureCharacteristic(GattCharacteristic::UUID_PRESSURE_CHAR, &m_pressure), |
| loicguibert | 15:aac1b3950a9e | 9 | m_temperatureCharacteristic(GattCharacteristic::UUID_TEMPERATURE_CHAR, &m_temperature), |
| loicguibert | 15:aac1b3950a9e | 10 | m_humidityCharacteristic(GattCharacteristic::UUID_HUMIDITY_CHAR, &m_humidity), |
| loicguibert | 14:c5578b5edabe | 11 | m_logger(logger) { |
| loicguibert | 14:c5578b5edabe | 12 | } |
| loicguibert | 14:c5578b5edabe | 13 | |
| loicguibert | 14:c5578b5edabe | 14 | void EnvironmentalService::addServiceToGattServer(void) { |
| loicguibert | 14:c5578b5edabe | 15 | // We should only ever need to add the information service once |
| loicguibert | 14:c5578b5edabe | 16 | if (m_serviceAdded) { |
| loicguibert | 14:c5578b5edabe | 17 | return; |
| loicguibert | 14:c5578b5edabe | 18 | } |
| loicguibert | 14:c5578b5edabe | 19 | |
| loicguibert | 15:aac1b3950a9e | 20 | GattCharacteristic *charTable[] = { |
| loicguibert | 15:aac1b3950a9e | 21 | &m_pressureCharacteristic, |
| loicguibert | 15:aac1b3950a9e | 22 | &m_temperatureCharacteristic, |
| loicguibert | 15:aac1b3950a9e | 23 | &m_humidityCharacteristic |
| loicguibert | 15:aac1b3950a9e | 24 | }; |
| loicguibert | 14:c5578b5edabe | 25 | |
| loicguibert | 15:aac1b3950a9e | 26 | GattService environmentalService(GattService::UUID_ENVIRONMENTAL_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
| loicguibert | 15:aac1b3950a9e | 27 | m_ble.gattServer().addService(environmentalService); |
| loicguibert | 14:c5578b5edabe | 28 | |
| loicguibert | 14:c5578b5edabe | 29 | m_serviceAdded = true; |
| loicguibert | 14:c5578b5edabe | 30 | |
| loicguibert | 14:c5578b5edabe | 31 | m_logger.log("Environmental service added\r\n"); |
| loicguibert | 14:c5578b5edabe | 32 | } |
| loicguibert | 14:c5578b5edabe | 33 | |
| loicguibert | 15:aac1b3950a9e | 34 | void EnvironmentalService::updateEnvironmentalService(PressureType_t newPressure, TemperatureType_t newTemperature, HumidityType_t newHumidity) { |
| loicguibert | 15:aac1b3950a9e | 35 | m_pressure = newPressure; |
| loicguibert | 15:aac1b3950a9e | 36 | m_temperature = newTemperature; |
| loicguibert | 15:aac1b3950a9e | 37 | m_humidity = newHumidity; |
| loicguibert | 15:aac1b3950a9e | 38 | m_ble.gattServer().write(m_pressureCharacteristic.getValueHandle(), (uint8_t *) &m_pressure, sizeof(PressureType_t)); |
| loicguibert | 15:aac1b3950a9e | 39 | m_ble.gattServer().write(m_temperatureCharacteristic.getValueHandle(), (uint8_t *) &m_temperature, sizeof(m_temperature)); |
| loicguibert | 15:aac1b3950a9e | 40 | m_ble.gattServer().write(m_humidityCharacteristic.getValueHandle(), (uint8_t *) &m_humidity, sizeof(m_humidity)); |
| loicguibert | 14:c5578b5edabe | 41 | } |