just a fork

Fork of BLE_API by Bluetooth Low Energy

Committer:
vcoubard
Date:
Wed Apr 06 19:15:30 2016 +0100
Revision:
1179:4ab722f8dca0
Parent:
1156:e1ea38b576c6
Child:
1183:1589830dbdb7
Synchronized with git rev ca632aaf
Author: Andres Amaya Garcia
Update Gap state after advertising times out

The BLE API was not updating the Gap internal state when the advertising stops
because of a user timeout. This commit fixes the issue by updating the internal
state structure in Gap just before the registered callbacks are notified of the
advertising timeout.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 1139:911c42364719 1 /* mbed Microcontroller Library
vcoubard 1139:911c42364719 2 * Copyright (c) 2006-2013 ARM Limited
vcoubard 1139:911c42364719 3 *
vcoubard 1139:911c42364719 4 * Licensed under the Apache License, Version 2.0 (the "License");
vcoubard 1139:911c42364719 5 * you may not use this file except in compliance with the License.
vcoubard 1139:911c42364719 6 * You may obtain a copy of the License at
vcoubard 1139:911c42364719 7 *
vcoubard 1139:911c42364719 8 * http://www.apache.org/licenses/LICENSE-2.0
vcoubard 1139:911c42364719 9 *
vcoubard 1139:911c42364719 10 * Unless required by applicable law or agreed to in writing, software
vcoubard 1139:911c42364719 11 * distributed under the License is distributed on an "AS IS" BASIS,
vcoubard 1139:911c42364719 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
vcoubard 1139:911c42364719 13 * See the License for the specific language governing permissions and
vcoubard 1139:911c42364719 14 * limitations under the License.
vcoubard 1139:911c42364719 15 */
vcoubard 1139:911c42364719 16
vcoubard 1139:911c42364719 17 #ifndef __BLE_BATTERY_SERVICE_H__
vcoubard 1139:911c42364719 18 #define __BLE_BATTERY_SERVICE_H__
vcoubard 1139:911c42364719 19
vcoubard 1139:911c42364719 20 #include "ble/BLE.h"
vcoubard 1139:911c42364719 21
vcoubard 1139:911c42364719 22 /**
vcoubard 1139:911c42364719 23 * @class BatteryService
vcoubard 1139:911c42364719 24 * @brief BLE Battery Service. This service displays the battery level from 0% to 100%, represented as an 8bit number.
vcoubard 1139:911c42364719 25 * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.battery_service.xml
vcoubard 1139:911c42364719 26 * Battery Level Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.battery_level.xml
vcoubard 1139:911c42364719 27 */
vcoubard 1139:911c42364719 28 class BatteryService {
vcoubard 1139:911c42364719 29 public:
vcoubard 1139:911c42364719 30 /**
vcoubard 1179:4ab722f8dca0 31 * @param[ref] _ble
vcoubard 1139:911c42364719 32 * BLE object for the underlying controller.
vcoubard 1139:911c42364719 33 * @param[in] level
vcoubard 1139:911c42364719 34 * 8bit batterly level. Usually used to represent percentage of batterly charge remaining.
vcoubard 1139:911c42364719 35 */
vcoubard 1139:911c42364719 36 BatteryService(BLE &_ble, uint8_t level = 100) :
vcoubard 1139:911c42364719 37 ble(_ble),
vcoubard 1139:911c42364719 38 batteryLevel(level),
vcoubard 1139:911c42364719 39 batteryLevelCharacteristic(GattCharacteristic::UUID_BATTERY_LEVEL_CHAR, &batteryLevel, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {
vcoubard 1139:911c42364719 40
vcoubard 1139:911c42364719 41 GattCharacteristic *charTable[] = {&batteryLevelCharacteristic};
vcoubard 1139:911c42364719 42 GattService batteryService(GattService::UUID_BATTERY_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
vcoubard 1139:911c42364719 43
vcoubard 1139:911c42364719 44 ble.addService(batteryService);
vcoubard 1139:911c42364719 45 }
vcoubard 1139:911c42364719 46
vcoubard 1139:911c42364719 47 /**
vcoubard 1179:4ab722f8dca0 48 * @brief Update the battery level with a new value. [Valid values lie between 0 and 100];
vcoubard 1139:911c42364719 49 * anything outside this range will be ignored.
vcoubard 1139:911c42364719 50 *
vcoubard 1139:911c42364719 51 * @param newLevel
vcoubard 1139:911c42364719 52 * Update to battery level.
vcoubard 1139:911c42364719 53 */
vcoubard 1139:911c42364719 54 void updateBatteryLevel(uint8_t newLevel) {
vcoubard 1139:911c42364719 55 batteryLevel = newLevel;
vcoubard 1139:911c42364719 56 ble.gattServer().write(batteryLevelCharacteristic.getValueHandle(), &batteryLevel, 1);
vcoubard 1139:911c42364719 57 }
vcoubard 1139:911c42364719 58
vcoubard 1139:911c42364719 59 protected:
vcoubard 1139:911c42364719 60 BLE &ble;
vcoubard 1139:911c42364719 61
vcoubard 1139:911c42364719 62 uint8_t batteryLevel;
vcoubard 1139:911c42364719 63 ReadOnlyGattCharacteristic<uint8_t> batteryLevelCharacteristic;
vcoubard 1139:911c42364719 64 };
vcoubard 1139:911c42364719 65
rgrover1 712:b04b5db36865 66 #endif /* #ifndef __BLE_BATTERY_SERVICE_H__*/