Eugene Mwangi
/
mbed-os-example-ble-WEIGHT-public
test code
source/WEIGHTService.h@76:a3df66cb69e6, 2019-02-11 (annotated)
- Committer:
- Eugene0469
- Date:
- Mon Feb 11 15:05:13 2019 +0000
- Revision:
- 76:a3df66cb69e6
- Child:
- 80:167f8aabffca
any help will be greatly appreciated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Eugene0469 | 76:a3df66cb69e6 | 1 | /* mbed Microcontroller Library |
Eugene0469 | 76:a3df66cb69e6 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Eugene0469 | 76:a3df66cb69e6 | 3 | * |
Eugene0469 | 76:a3df66cb69e6 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Eugene0469 | 76:a3df66cb69e6 | 5 | * you may not use this file except in compliance with the License. |
Eugene0469 | 76:a3df66cb69e6 | 6 | * You may obtain a copy of the License at |
Eugene0469 | 76:a3df66cb69e6 | 7 | * |
Eugene0469 | 76:a3df66cb69e6 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Eugene0469 | 76:a3df66cb69e6 | 9 | * |
Eugene0469 | 76:a3df66cb69e6 | 10 | * Unless required by applicable law or agreed to in writing, software |
Eugene0469 | 76:a3df66cb69e6 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Eugene0469 | 76:a3df66cb69e6 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Eugene0469 | 76:a3df66cb69e6 | 13 | * See the License for the specific language governing permissions and |
Eugene0469 | 76:a3df66cb69e6 | 14 | * limitations under the License. |
Eugene0469 | 76:a3df66cb69e6 | 15 | */ |
Eugene0469 | 76:a3df66cb69e6 | 16 | |
Eugene0469 | 76:a3df66cb69e6 | 17 | #ifndef __BLE_WEIGHT_SERVICE_H__ |
Eugene0469 | 76:a3df66cb69e6 | 18 | #define __BLE_WEIGHT_SERVICE_H__ |
Eugene0469 | 76:a3df66cb69e6 | 19 | |
Eugene0469 | 76:a3df66cb69e6 | 20 | class WEIGHTService { |
Eugene0469 | 76:a3df66cb69e6 | 21 | public: |
Eugene0469 | 76:a3df66cb69e6 | 22 | const static uint16_t WEIGHT_SERVICE_UUID = 0xA000; |
Eugene0469 | 76:a3df66cb69e6 | 23 | const static uint16_t WEIGHT_STATE_CHARACTERISTIC_UUID = 0xA001; |
Eugene0469 | 76:a3df66cb69e6 | 24 | |
Eugene0469 | 76:a3df66cb69e6 | 25 | WEIGHTService(BLEDevice &_ble, float initialValueForWEIGHTCharacteristic) : |
Eugene0469 | 76:a3df66cb69e6 | 26 | ble(_ble), weightState(WEIGHT_STATE_CHARACTERISTIC_UUID, &initialValueForWEIGHTCharacteristic) |
Eugene0469 | 76:a3df66cb69e6 | 27 | { |
Eugene0469 | 76:a3df66cb69e6 | 28 | GattCharacteristic *charTable[] = {&weightState}; |
Eugene0469 | 76:a3df66cb69e6 | 29 | GattService weightService(WEIGHT_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
Eugene0469 | 76:a3df66cb69e6 | 30 | |
Eugene0469 | 76:a3df66cb69e6 | 31 | ble.gattServer().addService(weightService); |
Eugene0469 | 76:a3df66cb69e6 | 32 | } |
Eugene0469 | 76:a3df66cb69e6 | 33 | |
Eugene0469 | 76:a3df66cb69e6 | 34 | //GattAttribute::Handle_t getValueHandle() const |
Eugene0469 | 76:a3df66cb69e6 | 35 | // { |
Eugene0469 | 76:a3df66cb69e6 | 36 | // return weightState.getValueHandle(); |
Eugene0469 | 76:a3df66cb69e6 | 37 | // } |
Eugene0469 | 76:a3df66cb69e6 | 38 | void updateWeight(float newValue) |
Eugene0469 | 76:a3df66cb69e6 | 39 | { |
Eugene0469 | 76:a3df66cb69e6 | 40 | float newWeight = (float) newValue; |
Eugene0469 | 76:a3df66cb69e6 | 41 | ble.gattServer().write(weightState.getValueHandle(), |
Eugene0469 | 76:a3df66cb69e6 | 42 | (uint8_t *)&newWeight, sizeof(float)); |
Eugene0469 | 76:a3df66cb69e6 | 43 | } |
Eugene0469 | 76:a3df66cb69e6 | 44 | |
Eugene0469 | 76:a3df66cb69e6 | 45 | private: |
Eugene0469 | 76:a3df66cb69e6 | 46 | BLEDevice &ble; |
Eugene0469 | 76:a3df66cb69e6 | 47 | ReadOnlyGattCharacteristic<float> weightState; |
Eugene0469 | 76:a3df66cb69e6 | 48 | }; |
Eugene0469 | 76:a3df66cb69e6 | 49 | |
Eugene0469 | 76:a3df66cb69e6 | 50 | #endif /* #ifndef __BLE_WEIGHT_SERVICE_H__ */ |