Test code for a generic nrf51822
Dependencies: mbed AES BLE_API nRF51822 smallAES
TemperatureService.h@0:df3f7838f957, 2020-02-18 (annotated)
- Committer:
- f3d
- Date:
- Tue Feb 18 11:41:19 2020 +0000
- Revision:
- 0:df3f7838f957
Generic NRF51822 example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
f3d | 0:df3f7838f957 | 1 | /* mbed Microcontroller Library |
f3d | 0:df3f7838f957 | 2 | * Copyright (c) 2006-2013 ARM Limited |
f3d | 0:df3f7838f957 | 3 | * |
f3d | 0:df3f7838f957 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
f3d | 0:df3f7838f957 | 5 | * you may not use this file except in compliance with the License. |
f3d | 0:df3f7838f957 | 6 | * You may obtain a copy of the License at |
f3d | 0:df3f7838f957 | 7 | * |
f3d | 0:df3f7838f957 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
f3d | 0:df3f7838f957 | 9 | * |
f3d | 0:df3f7838f957 | 10 | * Unless required by applicable law or agreed to in writing, software |
f3d | 0:df3f7838f957 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
f3d | 0:df3f7838f957 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
f3d | 0:df3f7838f957 | 13 | * See the License for the specific language governing permissions and |
f3d | 0:df3f7838f957 | 14 | * limitations under the License. |
f3d | 0:df3f7838f957 | 15 | */ |
f3d | 0:df3f7838f957 | 16 | |
f3d | 0:df3f7838f957 | 17 | #ifndef __BLE_TEMP_SERVICE_H__ |
f3d | 0:df3f7838f957 | 18 | #define __BLE_TEMP_SERVICE_H__ |
f3d | 0:df3f7838f957 | 19 | |
f3d | 0:df3f7838f957 | 20 | class TempService { |
f3d | 0:df3f7838f957 | 21 | public: |
f3d | 0:df3f7838f957 | 22 | const static uint16_t TEMP_SERVICE_UUID = 0xA002; |
f3d | 0:df3f7838f957 | 23 | const static uint16_t TEMP_VALUE_CHARACTERISTIC_UUID = 0xA003; |
f3d | 0:df3f7838f957 | 24 | |
f3d | 0:df3f7838f957 | 25 | TempService(BLEDevice &_ble) : |
f3d | 0:df3f7838f957 | 26 | ble(_ble), Temperature(TEMP_VALUE_CHARACTERISTIC_UUID, 0) |
f3d | 0:df3f7838f957 | 27 | { |
f3d | 0:df3f7838f957 | 28 | GattCharacteristic *charTable[] = {&Temperature}; |
f3d | 0:df3f7838f957 | 29 | GattService TempService(TEMP_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
f3d | 0:df3f7838f957 | 30 | ble.addService(TempService); |
f3d | 0:df3f7838f957 | 31 | } |
f3d | 0:df3f7838f957 | 32 | |
f3d | 0:df3f7838f957 | 33 | GattAttribute::Handle_t getValueHandle() const { |
f3d | 0:df3f7838f957 | 34 | return Temperature.getValueHandle(); |
f3d | 0:df3f7838f957 | 35 | } |
f3d | 0:df3f7838f957 | 36 | void updateValue(uint16_t newValue) { |
f3d | 0:df3f7838f957 | 37 | ble.gattServer().write(this->getValueHandle(), (uint8_t *)&newValue, sizeof(uint16_t)); |
f3d | 0:df3f7838f957 | 38 | } |
f3d | 0:df3f7838f957 | 39 | private: |
f3d | 0:df3f7838f957 | 40 | BLEDevice &ble; |
f3d | 0:df3f7838f957 | 41 | ReadWriteGattCharacteristic<int> Temperature; |
f3d | 0:df3f7838f957 | 42 | }; |
f3d | 0:df3f7838f957 | 43 | |
f3d | 0:df3f7838f957 | 44 | #endif /* #ifndef __BLE_LED_SERVICE_H__ */ |