LED and ADC service for the BBC Microbit
Dependencies: AES BLE_API mbed nRF51822 smallAES
ADCService.h@0:21352e62003f, 2018-02-14 (annotated)
- Committer:
- f3d
- Date:
- Wed Feb 14 19:18:44 2018 +0000
- Revision:
- 0:21352e62003f
Extension of the BLE ADC program which now includes an ADC service
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
f3d | 0:21352e62003f | 1 | // Additional service to extend the basic LED example for the BBC microbit. |
f3d | 0:21352e62003f | 2 | #ifndef __BLE_ADC_SERVICE_H__ |
f3d | 0:21352e62003f | 3 | #define __BLE_ADC_SERVICE_H__ |
f3d | 0:21352e62003f | 4 | |
f3d | 0:21352e62003f | 5 | class ADCService { |
f3d | 0:21352e62003f | 6 | public: |
f3d | 0:21352e62003f | 7 | const static uint16_t ADC_SERVICE_UUID = 0xA002; |
f3d | 0:21352e62003f | 8 | const static uint16_t ADC_VALUE_CHARACTERISTIC_UUID = 0xA003; |
f3d | 0:21352e62003f | 9 | |
f3d | 0:21352e62003f | 10 | ADCService(BLEDevice &_ble, uint16_t initialValueForADCCharacteristic) : |
f3d | 0:21352e62003f | 11 | ble(_ble), ADCValue(ADC_VALUE_CHARACTERISTIC_UUID, &initialValueForADCCharacteristic) |
f3d | 0:21352e62003f | 12 | { |
f3d | 0:21352e62003f | 13 | GattCharacteristic *charTable[] = {&ADCValue}; |
f3d | 0:21352e62003f | 14 | GattService ADCService(ADC_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
f3d | 0:21352e62003f | 15 | ble.addService(ADCService); |
f3d | 0:21352e62003f | 16 | } |
f3d | 0:21352e62003f | 17 | |
f3d | 0:21352e62003f | 18 | GattAttribute::Handle_t getValueHandle() const { |
f3d | 0:21352e62003f | 19 | return ADCValue.getValueHandle(); |
f3d | 0:21352e62003f | 20 | } |
f3d | 0:21352e62003f | 21 | void updateADCValue(uint16_t newValue) { |
f3d | 0:21352e62003f | 22 | ble.gattServer().write(ADCValue.getValueHandle(), (uint8_t *)&newValue, sizeof(uint16_t)); |
f3d | 0:21352e62003f | 23 | } |
f3d | 0:21352e62003f | 24 | |
f3d | 0:21352e62003f | 25 | private: |
f3d | 0:21352e62003f | 26 | BLEDevice &ble; |
f3d | 0:21352e62003f | 27 | ReadWriteGattCharacteristic<uint16_t> ADCValue; |
f3d | 0:21352e62003f | 28 | }; |
f3d | 0:21352e62003f | 29 | |
f3d | 0:21352e62003f | 30 | #endif /* #ifndef __BLE_ADC_SERVICE_H__ */ |