Merge branch 'master' of https://github.com/xcrespo/ble into xcrespo-master
This commit is contained in:
commit
e1bce4e5a3
4 changed files with 125 additions and 4 deletions
|
@ -57,6 +57,7 @@ public:
|
|||
UUID_HEART_RATE_MEASUREMENT_CHAR = 0x2A37,
|
||||
UUID_HID_CONTROL_POINT_CHAR = 0x2A4C,
|
||||
UUID_HID_INFORMATION_CHAR = 0x2A4A,
|
||||
UUID_HUMIDITY_CHAR = 0x2A6F,
|
||||
UUID_IEEE_REGULATORY_CERTIFICATION_DATA_LIST_CHAR = 0x2A2A,
|
||||
UUID_INTERMEDIATE_CUFF_PRESSURE_CHAR = 0x2A36,
|
||||
UUID_INTERMEDIATE_TEMPERATURE_CHAR = 0x2A1E,
|
||||
|
@ -67,6 +68,7 @@ public:
|
|||
UUID_UNREAD_ALERT_CHAR = 0x2A45,
|
||||
UUID_NEW_ALERT_CHAR = 0x2A46,
|
||||
UUID_PNP_ID_CHAR = 0x2A50,
|
||||
UUID_PRESSURE_CHAR = 0x2A6D,
|
||||
UUID_PROTOCOL_MODE_CHAR = 0x2A4E,
|
||||
UUID_RECORD_ACCESS_CONTROL_POINT_CHAR = 0x2A52,
|
||||
UUID_REFERENCE_TIME_INFORMATION_CHAR = 0x2A14,
|
||||
|
@ -81,6 +83,7 @@ public:
|
|||
UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR = 0x2A47,
|
||||
UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR = 0x2A48,
|
||||
UUID_SYSTEM_ID_CHAR = 0x2A23,
|
||||
UUID_TEMPERATURE_CHAR = 0x2A6E,
|
||||
UUID_TEMPERATURE_MEASUREMENT_CHAR = 0x2A1C,
|
||||
UUID_TEMPERATURE_TYPE_CHAR = 0x2A1D,
|
||||
UUID_TIME_ACCURACY_CHAR = 0x2A12,
|
||||
|
@ -93,7 +96,7 @@ public:
|
|||
UUID_CSC_FEATURE_CHAR = 0x2A5C,
|
||||
UUID_CSC_MEASUREMENT_CHAR = 0x2A5B,
|
||||
UUID_RSC_FEATURE_CHAR = 0x2A54,
|
||||
UUID_RSC_MEASUREMENT_CHAR = 0x2A53,
|
||||
UUID_RSC_MEASUREMENT_CHAR = 0x2A53
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
UUID_CURRENT_TIME_SERVICE = 0x1805,
|
||||
UUID_CYCLING_SPEED_AND_CADENCE = 0x1816,
|
||||
UUID_DEVICE_INFORMATION_SERVICE = 0x180A,
|
||||
UUID_ENVIRONMENTAL_SERVICE = 0x181A,
|
||||
UUID_GLUCOSE_SERVICE = 0x1808,
|
||||
UUID_HEALTH_THERMOMETER_SERVICE = 0x1809,
|
||||
UUID_HEART_RATE_SERVICE = 0x180D,
|
||||
|
|
117
ble/services/EnvironmentalService.h
Normal file
117
ble/services/EnvironmentalService.h
Normal file
|
@ -0,0 +1,117 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __BLE_ENVIRONMENTAL_SERVICE_H__
|
||||
#define __BLE_ENVIRONMENTAL_SERVICE_H__
|
||||
|
||||
#include "ble/BLE.h"
|
||||
|
||||
/**
|
||||
* @class EnvironmentalService
|
||||
* @brief BLE Environmental Service. This service provides the location of the thermometer and the temperature. <br>
|
||||
* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.environmental_sensing.xml <br>
|
||||
* Temperature: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature.xml <br>
|
||||
* Humidity: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.humidity.xml <br>
|
||||
* Pressure: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.pressure.xml
|
||||
*/
|
||||
class EnvironmentalService {
|
||||
public:
|
||||
/**
|
||||
* @brief EnvironmentalService constructor.
|
||||
* @param ble Reference to BLE device.
|
||||
* @param temperature_en Enable this characteristic.
|
||||
* @param humidity_en Enable this characteristic.
|
||||
* @param pressure_en Enable this characteristic.
|
||||
*/
|
||||
EnvironmentalService(BLE &_ble,
|
||||
bool temperature_en = false,
|
||||
bool humidity_en = false,
|
||||
bool pressure_en = false) :
|
||||
ble(_ble),
|
||||
temperatureCharacteristic(GattCharacteristic::UUID_TEMPERATURE_CHAR,
|
||||
(uint8_t *) &temperature,
|
||||
(temperature_en) ? 2 : 0, // minLength
|
||||
(temperature_en) ? 2 : 0, // maxLength
|
||||
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
|
||||
humidityCharacteristic(GattCharacteristic::UUID_HUMIDITY_CHAR,
|
||||
(uint8_t *) &humidity,
|
||||
(humidity_en) ? 2 : 0, // minLength
|
||||
(humidity_en) ? 2 : 0, // maxLength
|
||||
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
|
||||
pressureCharacteristic(GattCharacteristic::UUID_PRESSURE_CHAR,
|
||||
(uint8_t *) &pressure,
|
||||
(pressure_en) ? 4 : 0, // minLength
|
||||
(pressure_en) ? 4 : 0, // maxLength
|
||||
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)
|
||||
{
|
||||
static bool serviceAdded = false; /* We should only ever need to add the information service once. */
|
||||
if (serviceAdded) {
|
||||
return;
|
||||
}
|
||||
|
||||
GattCharacteristic *charTable[] = { &humidityCharacteristic,
|
||||
&pressureCharacteristic,
|
||||
&temperatureCharacteristic };
|
||||
|
||||
GattService environmentalService(GattService::UUID_ENVIRONMENTAL_SERVICE, charTable,
|
||||
sizeof(charTable) / sizeof(GattCharacteristic *));
|
||||
|
||||
ble.gattServer().addService(environmentalService);
|
||||
serviceAdded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update humidity characteristic.
|
||||
* @param newHumidityVal New humidity measurement.
|
||||
*/
|
||||
void updateHumidity(uint16_t newHumidityVal)
|
||||
{
|
||||
humidity = (uint32_t) (newHumidityVal*100);
|
||||
ble.gattServer().write(humidityCharacteristic.getValueHandle(), (uint8_t *) &humidity, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update pressure characteristic.
|
||||
* @param newPressureVal New pressure measurement.
|
||||
*/
|
||||
void updatePressure(uint32_t newPressureVal)
|
||||
{
|
||||
pressure = (uint32_t) (newPressureVal*10);
|
||||
ble.gattServer().write(pressureCharacteristic.getValueHandle(), (uint8_t *) &pressure, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update temperature characteristic.
|
||||
* @param newTemperatureVal New temperature measurement.
|
||||
*/
|
||||
void updateTemperature(float newTemperatureVal)
|
||||
{
|
||||
temperature = (int16_t) (newTemperatureVal*100);
|
||||
ble.gattServer().write(temperatureCharacteristic.getValueHandle(), (uint8_t *) &temperature, 2);
|
||||
}
|
||||
|
||||
private:
|
||||
BLE &ble;
|
||||
|
||||
int16_t temperature;
|
||||
GattCharacteristic temperatureCharacteristic;
|
||||
uint16_t humidity;
|
||||
GattCharacteristic humidityCharacteristic;
|
||||
uint32_t pressure;
|
||||
GattCharacteristic pressureCharacteristic;
|
||||
};
|
||||
|
||||
#endif /* #ifndef __BLE_ENVIRONMENTAL_SERVICE_H__*/
|
|
@ -52,11 +52,11 @@ public:
|
|||
GattCharacteristic *charTable[] = {&alertLevelChar};
|
||||
GattService linkLossService(GattService::UUID_LINK_LOSS_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
|
||||
|
||||
ble.addService(linkLossService);
|
||||
ble.gattServer().addService(linkLossService);
|
||||
serviceAdded = true;
|
||||
|
||||
ble.onDisconnection(this, &LinkLossService::onDisconnectionFilter);
|
||||
ble.onDataWritten(this, &LinkLossService::onDataWritten);
|
||||
ble.gap().onDisconnection(this, &LinkLossService::onDisconnectionFilter);
|
||||
ble.gattServer().onDataWritten(this, &LinkLossService::onDataWritten);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue