Improve readability with getHandle inline

Fork of BLE_API by Bluetooth Low Energy

Revision:
257:6be2b4b0cd71
Parent:
245:98f930d14515
diff -r e14bc27b224f -r 6be2b4b0cd71 services/HealthThermometerService.h
--- a/services/HealthThermometerService.h	Tue Dec 02 02:51:52 2014 +0000
+++ b/services/HealthThermometerService.h	Mon Jan 12 14:49:53 2015 -0800
@@ -19,28 +19,35 @@
 
 #include "BLEDevice.h"
 
-/* Health Thermometer Service */
-/* Service:  https://developer.bluetooth.org/gatt/profiles/Pages/ProfileViewer.aspx?u=org.bluetooth.profile.health_thermometer.xml */
-/* Temperature Measurement: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature_measurement.xml */
-/* Temperature Type: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature_type.xml */
+/**
+* @class HealthThermometerService
+* @brief BLE Health Thermometer Service. This service provides the location of the thermometer and the temperature.  <br>
+* Service:  https://developer.bluetooth.org/gatt/profiles/Pages/ProfileViewer.aspx?u=org.bluetooth.profile.health_thermometer.xml <br>
+* Temperature Measurement: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature_measurement.xml <br>
+* Temperature Type: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature_type.xml
+*/
 class HealthThermometerService {
 public:
-    enum {
-        LOCATION_ARMPIT = 1,
-        LOCATION_BODY,
-        LOCATION_EAR,
-        LOCATION_FINGER,
-        LOCATION_GI_TRACT,
-        LOCATION_MOUTH,
-        LOCATION_RECTUM,
-        LOCATION_TOE,
-        LOCATION_EAR_DRUM,
+    /**
+    * @enum Sensor Location
+    * @brief Location of sensor on the body
+    */
+    enum SensorLocation_t {
+        LOCATION_ARMPIT = 1,    /*!< armpit */
+        LOCATION_BODY,          /*!< body */
+        LOCATION_EAR,           /*!< ear */
+        LOCATION_FINGER,        /*!< finger */
+        LOCATION_GI_TRACT,      /*!< GI tract */
+        LOCATION_MOUTH,         /*!< mouth */
+        LOCATION_RECTUM,        /*!< rectum */
+        LOCATION_TOE,           /*!< toe */
+        LOCATION_EAR_DRUM,      /*!< ear drum */
     };
 
 public:
-
     /**
-     * @param[in] _ble         reference to the BLE device
+     * @brief Add the Health Thermometer Service to an existing ble object, initialize with temperature and location.
+     * @param[ref] _ble         reference to the BLE device
      * @param[in] initialTemp  initial value in celsius
      * @param[in] _location
      */
@@ -59,6 +66,13 @@
         ble.addService(hrmService);
     }
 
+    /**
+    * @brief Update the temperature being broadcast
+    *
+    * @param[in] temperature
+    *                   Floating point value of the temperature
+    *
+    */
     void updateTemperature(float temperature) {
         if (ble.getGapState().connected) {
             valueBytes.updateTemperature(temperature);
@@ -66,6 +80,15 @@
         }
     }
 
+    /**
+     * @brief Update the location.
+     * @param loc
+     *        new location value.
+     */
+    void updateLocation(SensorLocation_t loc) {
+        ble.updateCharacteristicValue(tempLocation.getValueHandle(), reinterpret_cast<uint8_t *>(&loc), sizeof(uint8_t));
+    }
+
 private:
     /* Private internal representation for the bytes used to work with the vaulue of the heart-rate characteristic. */
     struct TemperatureValueBytes {
@@ -77,8 +100,8 @@
         static const unsigned TIMESTAMP_FLAG_POS         = 1;
         static const unsigned TEMPERATURE_TYPE_FLAG_POS  = 2;
 
-        static const uint8_t TEMPERATURE_UNITS_CELSIUS    = 0;
-        static const uint8_t TEMPERATURE_UNITS_FAHRENHEIT = 1;
+        static const uint8_t  TEMPERATURE_UNITS_CELSIUS    = 0;
+        static const uint8_t  TEMPERATURE_UNITS_FAHRENHEIT = 1;
 
         TemperatureValueBytes(float initialTemperature) : bytes() {
             /* assumption: temperature values are expressed in Celsius */
@@ -93,7 +116,7 @@
             memcpy(&bytes[OFFSET_OF_VALUE], &temp_ieee11073, sizeof(float));
         }
 
-        uint8_t *getPointer(void) {
+        uint8_t       *getPointer(void) {
             return bytes;
         }
 
@@ -101,7 +124,7 @@
             return bytes;
         }
 
-    private:
+private:
         /**
          * @brief A very quick conversion between a float temperature and 11073-20601 FLOAT-Type.
          * @param temperature The temperature as a float.
@@ -114,8 +137,7 @@
             return (((uint32_t)exponent) << 24) | mantissa;
         }
 
-
-    private:
+private:
         /* First byte = 8-bit flags, Second field is a float holding the temperature value. */
         /* See --> https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature_measurement.xml */
         uint8_t bytes[SIZEOF_VALUE_BYTES];
@@ -128,4 +150,4 @@
     GattCharacteristic     tempLocation;
 };
 
-#endif /* #ifndef __BLE_HEALTH_THERMOMETER_SERVICE_H__*/
+#endif /* #ifndef __BLE_HEALTH_THERMOMETER_SERVICE_H__*/
\ No newline at end of file