LED and Button for BLE workshop (TinyBLE)

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_LED by Bluetooth Low Energy

Committer:
rgrover1
Date:
Wed Feb 18 10:22:43 2015 +0000
Revision:
0:ed5c53845de7
a simple demo driving an LED through a BLE service

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 0:ed5c53845de7 1 /* mbed Microcontroller Library
rgrover1 0:ed5c53845de7 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 0:ed5c53845de7 3 *
rgrover1 0:ed5c53845de7 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 0:ed5c53845de7 5 * you may not use this file except in compliance with the License.
rgrover1 0:ed5c53845de7 6 * You may obtain a copy of the License at
rgrover1 0:ed5c53845de7 7 *
rgrover1 0:ed5c53845de7 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 0:ed5c53845de7 9 *
rgrover1 0:ed5c53845de7 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 0:ed5c53845de7 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 0:ed5c53845de7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 0:ed5c53845de7 13 * See the License for the specific language governing permissions and
rgrover1 0:ed5c53845de7 14 * limitations under the License.
rgrover1 0:ed5c53845de7 15 */
rgrover1 0:ed5c53845de7 16
rgrover1 0:ed5c53845de7 17 #ifndef __BLE_LED_SERVICE_H__
rgrover1 0:ed5c53845de7 18 #define __BLE_LED_SERVICE_H__
rgrover1 0:ed5c53845de7 19
rgrover1 0:ed5c53845de7 20 class LEDService {
rgrover1 0:ed5c53845de7 21 public:
rgrover1 0:ed5c53845de7 22 const static uint16_t LED_SERVICE_UUID = 0xA000;
rgrover1 0:ed5c53845de7 23 const static uint16_t LED_STATE_CHARACTERISTIC_UUID = 0xA001;
rgrover1 0:ed5c53845de7 24
rgrover1 0:ed5c53845de7 25 LEDService(BLEDevice &_ble, bool initialValueForLEDCharacteristic) :
rgrover1 0:ed5c53845de7 26 ble(_ble), ledState(LED_STATE_CHARACTERISTIC_UUID, &initialValueForLEDCharacteristic)
rgrover1 0:ed5c53845de7 27 {
rgrover1 0:ed5c53845de7 28 GattCharacteristic *charTable[] = {&ledState};
rgrover1 0:ed5c53845de7 29 GattService ledService(LED_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
rgrover1 0:ed5c53845de7 30 ble.addService(ledService);
rgrover1 0:ed5c53845de7 31 }
rgrover1 0:ed5c53845de7 32
rgrover1 0:ed5c53845de7 33 GattAttribute::Handle_t getValueHandle() const {
rgrover1 0:ed5c53845de7 34 return ledState.getValueHandle();
rgrover1 0:ed5c53845de7 35 }
rgrover1 0:ed5c53845de7 36
rgrover1 0:ed5c53845de7 37 private:
rgrover1 0:ed5c53845de7 38 BLEDevice &ble;
rgrover1 0:ed5c53845de7 39 ReadWriteGattCharacteristic<bool> ledState;
rgrover1 0:ed5c53845de7 40 };
rgrover1 0:ed5c53845de7 41
rgrover1 0:ed5c53845de7 42 #endif /* #ifndef __BLE_LED_SERVICE_H__ */