BTLE example for a CJMCU-8223 (NRF51822+Lis3dh). Also includes an OLED display. Further details on ioprog.com
Dependencies: mbed BLE_API nRF51822
LEDService.h@0:8fa1c7356f71, 2020-06-24 (annotated)
- Committer:
- f3d
- Date:
- Wed Jun 24 11:37:11 2020 +0000
- Revision:
- 0:8fa1c7356f71
Initial commit for CJMCU-8223 offering an LED service and an accelerometer service. Also includes an Oled display
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
f3d | 0:8fa1c7356f71 | 1 | /* mbed Microcontroller Library |
f3d | 0:8fa1c7356f71 | 2 | * Copyright (c) 2006-2013 ARM Limited |
f3d | 0:8fa1c7356f71 | 3 | * |
f3d | 0:8fa1c7356f71 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
f3d | 0:8fa1c7356f71 | 5 | * you may not use this file except in compliance with the License. |
f3d | 0:8fa1c7356f71 | 6 | * You may obtain a copy of the License at |
f3d | 0:8fa1c7356f71 | 7 | * |
f3d | 0:8fa1c7356f71 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
f3d | 0:8fa1c7356f71 | 9 | * |
f3d | 0:8fa1c7356f71 | 10 | * Unless required by applicable law or agreed to in writing, software |
f3d | 0:8fa1c7356f71 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
f3d | 0:8fa1c7356f71 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
f3d | 0:8fa1c7356f71 | 13 | * See the License for the specific language governing permissions and |
f3d | 0:8fa1c7356f71 | 14 | * limitations under the License. |
f3d | 0:8fa1c7356f71 | 15 | */ |
f3d | 0:8fa1c7356f71 | 16 | |
f3d | 0:8fa1c7356f71 | 17 | #ifndef __BLE_LED_SERVICE_H__ |
f3d | 0:8fa1c7356f71 | 18 | #define __BLE_LED_SERVICE_H__ |
f3d | 0:8fa1c7356f71 | 19 | |
f3d | 0:8fa1c7356f71 | 20 | class LEDService { |
f3d | 0:8fa1c7356f71 | 21 | public: |
f3d | 0:8fa1c7356f71 | 22 | const static uint16_t LED_SERVICE_UUID = 0xA000; |
f3d | 0:8fa1c7356f71 | 23 | const static uint16_t LED_STATE_CHARACTERISTIC_UUID = 0xA001; |
f3d | 0:8fa1c7356f71 | 24 | |
f3d | 0:8fa1c7356f71 | 25 | LEDService(BLEDevice &_ble, bool initialValueForLEDCharacteristic) : |
f3d | 0:8fa1c7356f71 | 26 | ble(_ble), ledState(LED_STATE_CHARACTERISTIC_UUID, &initialValueForLEDCharacteristic) |
f3d | 0:8fa1c7356f71 | 27 | { |
f3d | 0:8fa1c7356f71 | 28 | GattCharacteristic *charTable[] = {&ledState}; |
f3d | 0:8fa1c7356f71 | 29 | GattService ledService(LED_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
f3d | 0:8fa1c7356f71 | 30 | ble.addService(ledService); |
f3d | 0:8fa1c7356f71 | 31 | } |
f3d | 0:8fa1c7356f71 | 32 | |
f3d | 0:8fa1c7356f71 | 33 | GattAttribute::Handle_t getValueHandle() const { |
f3d | 0:8fa1c7356f71 | 34 | return ledState.getValueHandle(); |
f3d | 0:8fa1c7356f71 | 35 | } |
f3d | 0:8fa1c7356f71 | 36 | |
f3d | 0:8fa1c7356f71 | 37 | private: |
f3d | 0:8fa1c7356f71 | 38 | BLEDevice &ble; |
f3d | 0:8fa1c7356f71 | 39 | ReadWriteGattCharacteristic<bool> ledState; |
f3d | 0:8fa1c7356f71 | 40 | }; |
f3d | 0:8fa1c7356f71 | 41 | |
f3d | 0:8fa1c7356f71 | 42 | #endif /* #ifndef __BLE_LED_SERVICE_H__ */ |