Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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