Legacy BLE LED example repackaged with Mbed OS 5.9.1

Committer:
RalphF
Date:
Tue Aug 07 16:49:34 2018 +0000
Revision:
0:1129cbb9e3c9
Standard BLE LED example built for Mbed OS 5.9.1.  Tested with nRF52840-DK.

Who changed what in which revision?

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