commit
9c001d2772
@ -0,0 +1,7 @@
|
||||
# Hello!
|
||||
We are an open source project of [ARM mbed](www.mbed.com). Contributions via [pull request](https://github.com/armmbed/yotta/pulls), and [bug reports](https://github.com/armmbed/yotta/issues) are welcome!
|
||||
|
||||
Please submit your pull request to the 'develop' branch of this module. Commits to develop will merge into master at the time of the next release.
|
||||
|
||||
# Contributor agreement
|
||||
For your pull request to be accepted, we will need you to agree to our [contributor agreement](http://developer.mbed.org/contributor_agreement/) to give us the necessary rights to use and distribute your contributions. (To click through the agreement create an account on mbed.com and log in.)
|
@ -0,0 +1,106 @@
|
||||
/* 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:
|
||||
typedef int16_t TemperatureType_t;
|
||||
typedef uint16_t HumidityType_t;
|
||||
typedef uint32_t PressureType_t;
|
||||
|
||||
/**
|
||||
* @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) :
|
||||
ble(_ble),
|
||||
temperatureCharacteristic(GattCharacteristic::UUID_TEMPERATURE_CHAR, &temperature),
|
||||
humidityCharacteristic(GattCharacteristic::UUID_HUMIDITY_CHAR, &humidity),
|
||||
pressureCharacteristic(GattCharacteristic::UUID_PRESSURE_CHAR, &pressure)
|
||||
{
|
||||
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(HumidityType_t newHumidityVal)
|
||||
{
|
||||
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(PressureType_t newPressureVal)
|
||||
{
|
||||
pressure = (PressureType_t) (newPressureVal * 10);
|
||||
ble.gattServer().write(pressureCharacteristic.getValueHandle(), (uint8_t *) &pressure, sizeof(PressureType_t));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update temperature characteristic.
|
||||
* @param newTemperatureVal New temperature measurement.
|
||||
*/
|
||||
void updateTemperature(float newTemperatureVal)
|
||||
{
|
||||
temperature = (TemperatureType_t) (newTemperatureVal * 100);
|
||||
ble.gattServer().write(temperatureCharacteristic.getValueHandle(), (uint8_t *) &temperature, sizeof(TemperatureType_t));
|
||||
}
|
||||
|
||||
private:
|
||||
BLE& ble;
|
||||
|
||||
TemperatureType_t temperature;
|
||||
HumidityType_t humidity;
|
||||
PressureType_t pressure;
|
||||
|
||||
ReadOnlyGattCharacteristic<TemperatureType_t> temperatureCharacteristic;
|
||||
ReadOnlyGattCharacteristic<HumidityType_t> humidityCharacteristic;
|
||||
ReadOnlyGattCharacteristic<PressureType_t> pressureCharacteristic;
|
||||
};
|
||||
|
||||
#endif /* #ifndef __BLE_ENVIRONMENTAL_SERVICE_H__*/
|
Loading…
Reference in new issue