20 #warning "These services are deprecated and will be removed. Please see services.md for details about replacement services." 22 #ifndef __BLE_HEALTH_THERMOMETER_SERVICE_H__ 23 #define __BLE_HEALTH_THERMOMETER_SERVICE_H__ 27 #include "ble/GattServer.h" 29 #if BLE_FEATURE_GATT_SERVER 64 valueBytes(initialTemp),
71 ble.gattServer().addService(hrmService);
82 valueBytes.updateTemperature(temperature);
83 ble.gattServer().write(tempMeasurement.
getValueHandle(), valueBytes.getPointer(),
sizeof(TemperatureValueBytes));
92 ble.gattServer().write(tempLocation.
getValueHandle(),
reinterpret_cast<uint8_t *
>(&loc),
sizeof(uint8_t));
97 struct TemperatureValueBytes {
98 static const unsigned OFFSET_OF_FLAGS = 0;
99 static const unsigned OFFSET_OF_VALUE = OFFSET_OF_FLAGS +
sizeof(uint8_t);
100 static const unsigned SIZEOF_VALUE_BYTES =
sizeof(uint8_t) +
sizeof(
float);
102 static const unsigned TEMPERATURE_UNITS_FLAG_POS = 0;
103 static const unsigned TIMESTAMP_FLAG_POS = 1;
104 static const unsigned TEMPERATURE_TYPE_FLAG_POS = 2;
106 static const uint8_t TEMPERATURE_UNITS_CELSIUS = 0;
107 static const uint8_t TEMPERATURE_UNITS_FAHRENHEIT = 1;
109 TemperatureValueBytes(
float initialTemperature) : bytes() {
111 bytes[OFFSET_OF_FLAGS] = (TEMPERATURE_UNITS_CELSIUS << TEMPERATURE_UNITS_FLAG_POS) |
112 (
false << TIMESTAMP_FLAG_POS) |
113 (
false << TEMPERATURE_TYPE_FLAG_POS);
118 uint32_t temp_ieee11073 = quick_ieee11073_from_float(temp);
119 memcpy(&bytes[OFFSET_OF_VALUE], &temp_ieee11073,
sizeof(
float));
122 uint8_t *getPointer() {
126 const uint8_t *getPointer()
const {
136 static uint32_t quick_ieee11073_from_float(
float temperature) {
137 uint8_t exponent = 0xFE;
138 uint32_t mantissa = (uint32_t)(temperature * 100);
140 return (((uint32_t)exponent) << 24) | mantissa;
146 uint8_t bytes[SIZEOF_VALUE_BYTES];
151 TemperatureValueBytes valueBytes;
156 #endif // BLE_FEATURE_GATT_SERVER void updateTemperature(float temperature)
Update the temperature being broadcast.
GattAttribute::Handle_t getValueHandle() const
Get the characteristic's value attribute handle in the ATT table.
SensorLocation_t
Location of sensor on the body.
UUID of the health thermometer.
BLE Health Thermometer Service.
Representation of a GattServer characteristic.
void updateLocation(SensorLocation_t loc)
Update the location.
Representation of a GattServer service.
Entry namespace for all BLE API definitions.
Abstract away BLE-capable radio transceivers or SOCs.
HealthThermometerService(BLE &_ble, float initialTemp, uint8_t _location)
Add the Health Thermometer Service to an existing BLE object, initialize with temperature and locatio...