just a fork

Fork of BLE_API by Bluetooth Low Energy

Committer:
vcoubard
Date:
Wed Apr 06 19:13:46 2016 +0100
Revision:
1131:692ddf04fc42
Parent:
1056:ce2fb3d09929
Child:
1134:d540a48f650d
Synchronized with git rev 13bf70b6
Author: Rohit Grover
Release 2.1.5
=============

A minor release to separate the concept of minlen and len in
GattCharacteristic. Also contains some improvements to documentation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 1131:692ddf04fc42 1 /* mbed Microcontroller Library
vcoubard 1131:692ddf04fc42 2 * Copyright (c) 2006-2013 ARM Limited
vcoubard 1131:692ddf04fc42 3 *
vcoubard 1131:692ddf04fc42 4 * Licensed under the Apache License, Version 2.0 (the "License");
vcoubard 1131:692ddf04fc42 5 * you may not use this file except in compliance with the License.
vcoubard 1131:692ddf04fc42 6 * You may obtain a copy of the License at
vcoubard 1131:692ddf04fc42 7 *
vcoubard 1131:692ddf04fc42 8 * http://www.apache.org/licenses/LICENSE-2.0
vcoubard 1131:692ddf04fc42 9 *
vcoubard 1131:692ddf04fc42 10 * Unless required by applicable law or agreed to in writing, software
vcoubard 1131:692ddf04fc42 11 * distributed under the License is distributed on an "AS IS" BASIS,
vcoubard 1131:692ddf04fc42 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
vcoubard 1131:692ddf04fc42 13 * See the License for the specific language governing permissions and
vcoubard 1131:692ddf04fc42 14 * limitations under the License.
vcoubard 1131:692ddf04fc42 15 */
vcoubard 1131:692ddf04fc42 16
vcoubard 1131:692ddf04fc42 17 #ifndef __BLE_ENVIRONMENTAL_SERVICE_H__
vcoubard 1131:692ddf04fc42 18 #define __BLE_ENVIRONMENTAL_SERVICE_H__
vcoubard 1131:692ddf04fc42 19
vcoubard 1131:692ddf04fc42 20 #include "ble/BLE.h"
vcoubard 1131:692ddf04fc42 21
vcoubard 1131:692ddf04fc42 22 /**
vcoubard 1131:692ddf04fc42 23 * @class EnvironmentalService
vcoubard 1131:692ddf04fc42 24 * @brief BLE Environmental Service. This service provides the location of the thermometer and the temperature. <br>
vcoubard 1131:692ddf04fc42 25 * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.environmental_sensing.xml <br>
vcoubard 1131:692ddf04fc42 26 * Temperature: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature.xml <br>
vcoubard 1131:692ddf04fc42 27 * Humidity: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.humidity.xml <br>
vcoubard 1131:692ddf04fc42 28 * Pressure: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.pressure.xml
vcoubard 1131:692ddf04fc42 29 */
vcoubard 1131:692ddf04fc42 30 class EnvironmentalService {
vcoubard 1131:692ddf04fc42 31 public:
vcoubard 1131:692ddf04fc42 32 typedef int16_t TemperatureType_t;
vcoubard 1131:692ddf04fc42 33 typedef uint16_t HumidityType_t;
vcoubard 1131:692ddf04fc42 34 typedef uint32_t PressureType_t;
vcoubard 1131:692ddf04fc42 35
vcoubard 1131:692ddf04fc42 36 /**
vcoubard 1131:692ddf04fc42 37 * @brief EnvironmentalService constructor.
vcoubard 1131:692ddf04fc42 38 * @param ble Reference to BLE device.
vcoubard 1131:692ddf04fc42 39 * @param temperature_en Enable this characteristic.
vcoubard 1131:692ddf04fc42 40 * @param humidity_en Enable this characteristic.
vcoubard 1131:692ddf04fc42 41 * @param pressure_en Enable this characteristic.
vcoubard 1131:692ddf04fc42 42 */
vcoubard 1131:692ddf04fc42 43 EnvironmentalService(BLE& _ble) :
vcoubard 1131:692ddf04fc42 44 ble(_ble),
vcoubard 1131:692ddf04fc42 45 temperatureCharacteristic(GattCharacteristic::UUID_TEMPERATURE_CHAR, &temperature),
vcoubard 1131:692ddf04fc42 46 humidityCharacteristic(GattCharacteristic::UUID_HUMIDITY_CHAR, &humidity),
vcoubard 1131:692ddf04fc42 47 pressureCharacteristic(GattCharacteristic::UUID_PRESSURE_CHAR, &pressure)
vcoubard 1131:692ddf04fc42 48 {
vcoubard 1131:692ddf04fc42 49 static bool serviceAdded = false; /* We should only ever need to add the information service once. */
vcoubard 1131:692ddf04fc42 50 if (serviceAdded) {
vcoubard 1131:692ddf04fc42 51 return;
vcoubard 1131:692ddf04fc42 52 }
vcoubard 1131:692ddf04fc42 53
vcoubard 1131:692ddf04fc42 54 GattCharacteristic *charTable[] = { &humidityCharacteristic,
vcoubard 1131:692ddf04fc42 55 &pressureCharacteristic,
vcoubard 1131:692ddf04fc42 56 &temperatureCharacteristic };
vcoubard 1131:692ddf04fc42 57
vcoubard 1131:692ddf04fc42 58 GattService environmentalService(GattService::UUID_ENVIRONMENTAL_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
vcoubard 1131:692ddf04fc42 59
vcoubard 1131:692ddf04fc42 60 ble.gattServer().addService(environmentalService);
vcoubard 1131:692ddf04fc42 61 serviceAdded = true;
vcoubard 1131:692ddf04fc42 62 }
vcoubard 1131:692ddf04fc42 63
vcoubard 1131:692ddf04fc42 64 /**
vcoubard 1131:692ddf04fc42 65 * @brief Update humidity characteristic.
vcoubard 1131:692ddf04fc42 66 * @param newHumidityVal New humidity measurement.
vcoubard 1131:692ddf04fc42 67 */
vcoubard 1131:692ddf04fc42 68 void updateHumidity(HumidityType_t newHumidityVal)
vcoubard 1131:692ddf04fc42 69 {
vcoubard 1131:692ddf04fc42 70 humidity = (HumidityType_t) (newHumidityVal * 100);
vcoubard 1131:692ddf04fc42 71 ble.gattServer().write(humidityCharacteristic.getValueHandle(), (uint8_t *) &humidity, sizeof(HumidityType_t));
vcoubard 1131:692ddf04fc42 72 }
vcoubard 1131:692ddf04fc42 73
vcoubard 1131:692ddf04fc42 74 /**
vcoubard 1131:692ddf04fc42 75 * @brief Update pressure characteristic.
vcoubard 1131:692ddf04fc42 76 * @param newPressureVal New pressure measurement.
vcoubard 1131:692ddf04fc42 77 */
vcoubard 1131:692ddf04fc42 78 void updatePressure(PressureType_t newPressureVal)
vcoubard 1131:692ddf04fc42 79 {
vcoubard 1131:692ddf04fc42 80 pressure = (PressureType_t) (newPressureVal * 10);
vcoubard 1131:692ddf04fc42 81 ble.gattServer().write(pressureCharacteristic.getValueHandle(), (uint8_t *) &pressure, sizeof(PressureType_t));
vcoubard 1131:692ddf04fc42 82 }
vcoubard 1131:692ddf04fc42 83
vcoubard 1131:692ddf04fc42 84 /**
vcoubard 1131:692ddf04fc42 85 * @brief Update temperature characteristic.
vcoubard 1131:692ddf04fc42 86 * @param newTemperatureVal New temperature measurement.
vcoubard 1131:692ddf04fc42 87 */
vcoubard 1131:692ddf04fc42 88 void updateTemperature(float newTemperatureVal)
vcoubard 1131:692ddf04fc42 89 {
vcoubard 1131:692ddf04fc42 90 temperature = (TemperatureType_t) (newTemperatureVal * 100);
vcoubard 1131:692ddf04fc42 91 ble.gattServer().write(temperatureCharacteristic.getValueHandle(), (uint8_t *) &temperature, sizeof(TemperatureType_t));
vcoubard 1131:692ddf04fc42 92 }
vcoubard 1131:692ddf04fc42 93
vcoubard 1131:692ddf04fc42 94 private:
vcoubard 1131:692ddf04fc42 95 BLE& ble;
vcoubard 1131:692ddf04fc42 96
vcoubard 1131:692ddf04fc42 97 TemperatureType_t temperature;
vcoubard 1131:692ddf04fc42 98 HumidityType_t humidity;
vcoubard 1131:692ddf04fc42 99 PressureType_t pressure;
vcoubard 1131:692ddf04fc42 100
vcoubard 1131:692ddf04fc42 101 ReadOnlyGattCharacteristic<TemperatureType_t> temperatureCharacteristic;
vcoubard 1131:692ddf04fc42 102 ReadOnlyGattCharacteristic<HumidityType_t> humidityCharacteristic;
vcoubard 1131:692ddf04fc42 103 ReadOnlyGattCharacteristic<PressureType_t> pressureCharacteristic;
vcoubard 1131:692ddf04fc42 104 };
vcoubard 1131:692ddf04fc42 105
rgrover1 906:8ddab3271c2f 106 #endif /* #ifndef __BLE_ENVIRONMENTAL_SERVICE_H__*/