Luca Mottola
/
IOTAtelier1819-BLELed
BLE example of a write characteristic to control a Led
source/LEDService.h@72:0ec27f82fe6d, 2018-11-16 (annotated)
- Committer:
- lmottola
- Date:
- Fri Nov 16 14:05:43 2018 +0000
- Revision:
- 72:0ec27f82fe6d
- Parent:
- 2:864ddfb70a9c
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 2:864ddfb70a9c | 1 | /* mbed Microcontroller Library |
mbed_official | 2:864ddfb70a9c | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 2:864ddfb70a9c | 3 | * |
mbed_official | 2:864ddfb70a9c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 2:864ddfb70a9c | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 2:864ddfb70a9c | 6 | * You may obtain a copy of the License at |
mbed_official | 2:864ddfb70a9c | 7 | * |
mbed_official | 2:864ddfb70a9c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 2:864ddfb70a9c | 9 | * |
mbed_official | 2:864ddfb70a9c | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 2:864ddfb70a9c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 2:864ddfb70a9c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 2:864ddfb70a9c | 13 | * See the License for the specific language governing permissions and |
mbed_official | 2:864ddfb70a9c | 14 | * limitations under the License. |
mbed_official | 2:864ddfb70a9c | 15 | */ |
mbed_official | 2:864ddfb70a9c | 16 | |
mbed_official | 2:864ddfb70a9c | 17 | #ifndef __BLE_LED_SERVICE_H__ |
mbed_official | 2:864ddfb70a9c | 18 | #define __BLE_LED_SERVICE_H__ |
mbed_official | 2:864ddfb70a9c | 19 | |
mbed_official | 2:864ddfb70a9c | 20 | class LEDService { |
mbed_official | 2:864ddfb70a9c | 21 | public: |
mbed_official | 2:864ddfb70a9c | 22 | const static uint16_t LED_SERVICE_UUID = 0xA000; |
mbed_official | 2:864ddfb70a9c | 23 | const static uint16_t LED_STATE_CHARACTERISTIC_UUID = 0xA001; |
mbed_official | 2:864ddfb70a9c | 24 | |
mbed_official | 2:864ddfb70a9c | 25 | LEDService(BLEDevice &_ble, bool initialValueForLEDCharacteristic) : |
mbed_official | 2:864ddfb70a9c | 26 | ble(_ble), ledState(LED_STATE_CHARACTERISTIC_UUID, &initialValueForLEDCharacteristic) |
mbed_official | 2:864ddfb70a9c | 27 | { |
mbed_official | 2:864ddfb70a9c | 28 | GattCharacteristic *charTable[] = {&ledState}; |
mbed_official | 2:864ddfb70a9c | 29 | GattService ledService(LED_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
mbed_official | 2:864ddfb70a9c | 30 | ble.addService(ledService); |
mbed_official | 2:864ddfb70a9c | 31 | } |
mbed_official | 2:864ddfb70a9c | 32 | |
mbed_official | 2:864ddfb70a9c | 33 | GattAttribute::Handle_t getValueHandle() const |
mbed_official | 2:864ddfb70a9c | 34 | { |
mbed_official | 2:864ddfb70a9c | 35 | return ledState.getValueHandle(); |
mbed_official | 2:864ddfb70a9c | 36 | } |
mbed_official | 2:864ddfb70a9c | 37 | |
mbed_official | 2:864ddfb70a9c | 38 | private: |
mbed_official | 2:864ddfb70a9c | 39 | BLEDevice &ble; |
mbed_official | 2:864ddfb70a9c | 40 | ReadWriteGattCharacteristic<bool> ledState; |
mbed_official | 2:864ddfb70a9c | 41 | }; |
mbed_official | 2:864ddfb70a9c | 42 | |
mbed_official | 2:864ddfb70a9c | 43 | #endif /* #ifndef __BLE_LED_SERVICE_H__ */ |