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.
Fork of BLE_API by
Diff: ble/services/EnvironmentalService.h
- Revision:
- 866:0f44d2aaf201
- Parent:
- 865:2bcdb60b537e
- Child:
- 867:a2a40c69eec0
--- a/ble/services/EnvironmentalService.h	Mon Nov 02 09:09:07 2015 +0000
+++ b/ble/services/EnvironmentalService.h	Mon Nov 02 09:09:07 2015 +0000
@@ -29,6 +29,10 @@
 */
 class EnvironmentalService {
 public:
+    typedef int16_t  TemperatureType_t;
+    typedef uint16_t HumidityType_t;
+    typedef uint32_t PressureType_t;
+
     /**
      * @brief   EnvironmentalService constructor.
      * @param   ble Reference to BLE device.
@@ -77,20 +81,20 @@
      * @brief   Update humidity characteristic.
      * @param   newHumidityVal New humidity measurement.
      */
-    void updateHumidity(uint16_t newHumidityVal)
+    void updateHumidity(HumidityType_t newHumidityVal)
     {
-        humidity = (uint32_t) (newHumidityVal * 100);
-        ble.gattServer().write(humidityCharacteristic.getValueHandle(), (uint8_t *) &humidity, 2);
+        humidity = (HumidityType_t) (newHumidityVal * 100);
+        ble.gattServer().write(humidityCharacteristic.getValueHandle(), (uint8_t *) &humidity, sizeof(HumidityType_t));
     }
 
     /**
      * @brief   Update pressure characteristic.
      * @param   newPressureVal New pressure measurement.
      */
-    void updatePressure(uint32_t newPressureVal)
+    void updatePressure(PressureType_t newPressureVal)
     {
-        pressure = (uint32_t) (newPressureVal * 10);
-        ble.gattServer().write(pressureCharacteristic.getValueHandle(), (uint8_t *) &pressure, 4);
+        pressure = (PressureType_t) (newPressureVal * 10);
+        ble.gattServer().write(pressureCharacteristic.getValueHandle(), (uint8_t *) &pressure, sizeof(PressureType_t));
     }
 
     /**
@@ -99,8 +103,8 @@
      */
     void updateTemperature(float newTemperatureVal)
     {
-        temperature = (int16_t) (newTemperatureVal * 100);
-        ble.gattServer().write(temperatureCharacteristic.getValueHandle(), (uint8_t *) &temperature, 2);
+        temperature = (TemperatureType_t) (newTemperatureVal * 100);
+        ble.gattServer().write(temperatureCharacteristic.getValueHandle(), (uint8_t *) &temperature, sizeof(TemperatureType_t));
     }
 
 private:
    