BLE Library with custom services for the tortuga bike
Fork of BLE_API by
ble/services/BikeService.h@1131:5cc818415e2b, 2016-04-16 (annotated)
- Committer:
- ptuytsch
- Date:
- Sat Apr 16 14:55:58 2016 +0000
- Revision:
- 1131:5cc818415e2b
- Child:
- 1202:a31d51d9fba8
no change
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ptuytsch | 1131:5cc818415e2b | 1 | #ifndef __BLE_BIKE_SERVICE_H__ |
ptuytsch | 1131:5cc818415e2b | 2 | #define __BLE_BIKE_SERVICE_H__ |
ptuytsch | 1131:5cc818415e2b | 3 | |
ptuytsch | 1131:5cc818415e2b | 4 | class BikeService { |
ptuytsch | 1131:5cc818415e2b | 5 | public: |
ptuytsch | 1131:5cc818415e2b | 6 | const static uint16_t BIKE_SERVICE_UUID = 0x6969; |
ptuytsch | 1131:5cc818415e2b | 7 | const static uint16_t BIKE_DISTANCE_CHARACTERISTIC_UUID = 0x696A; |
ptuytsch | 1131:5cc818415e2b | 8 | const static uint16_t BIKE_AVERAGE_CHARACTERISTIC_UUID = 0x696B; |
ptuytsch | 1131:5cc818415e2b | 9 | const static uint16_t BIKE_PULSE_CHARACTERISTIC_UUID = 0x696C; |
ptuytsch | 1131:5cc818415e2b | 10 | |
ptuytsch | 1131:5cc818415e2b | 11 | BikeService(BLE &_ble, |
ptuytsch | 1131:5cc818415e2b | 12 | uint32_t initialDistance = 0, |
ptuytsch | 1131:5cc818415e2b | 13 | uint32_t initialAverage = 0) : |
ptuytsch | 1131:5cc818415e2b | 14 | ble(_ble), |
ptuytsch | 1131:5cc818415e2b | 15 | bikeDistance(initialDistance), |
ptuytsch | 1131:5cc818415e2b | 16 | bikeAverage(initialAverage), |
ptuytsch | 1131:5cc818415e2b | 17 | bikeDistanceChar(BIKE_DISTANCE_CHARACTERISTIC_UUID, 0, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ptuytsch | 1131:5cc818415e2b | 18 | bikeAverageChar(BIKE_AVERAGE_CHARACTERISTIC_UUID, 0, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ptuytsch | 1131:5cc818415e2b | 19 | bikePulseChar(BIKE_PULSE_CHARACTERISTIC_UUID, 0, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
ptuytsch | 1131:5cc818415e2b | 20 | { |
ptuytsch | 1131:5cc818415e2b | 21 | GattCharacteristic *charTable[] = {&bikeDistanceChar, &bikeAverageChar, &bikePulseChar}; |
ptuytsch | 1131:5cc818415e2b | 22 | GattService bikeService(BikeService::BIKE_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
ptuytsch | 1131:5cc818415e2b | 23 | ble.gattServer().addService(bikeService); |
ptuytsch | 1131:5cc818415e2b | 24 | } |
ptuytsch | 1131:5cc818415e2b | 25 | |
ptuytsch | 1131:5cc818415e2b | 26 | |
ptuytsch | 1131:5cc818415e2b | 27 | void updateBikeDistance(float newDistance) { |
ptuytsch | 1131:5cc818415e2b | 28 | bikeDistance = newDistance*100; |
ptuytsch | 1131:5cc818415e2b | 29 | ble.gattServer().write(bikeDistanceChar.getValueHandle(), (uint8_t *)&bikeDistance, sizeof(uint32_t)); |
ptuytsch | 1131:5cc818415e2b | 30 | } |
ptuytsch | 1131:5cc818415e2b | 31 | |
ptuytsch | 1131:5cc818415e2b | 32 | void updateBikeAverage(float newAverage) { |
ptuytsch | 1131:5cc818415e2b | 33 | bikeAverage = newAverage*100; |
ptuytsch | 1131:5cc818415e2b | 34 | ble.gattServer().write(bikeAverageChar.getValueHandle(), (uint8_t *)&bikeAverage, sizeof(uint32_t)); |
ptuytsch | 1131:5cc818415e2b | 35 | } |
ptuytsch | 1131:5cc818415e2b | 36 | |
ptuytsch | 1131:5cc818415e2b | 37 | void updateBikePulse(uint32_t newPulse) { |
ptuytsch | 1131:5cc818415e2b | 38 | bikePulse = newPulse; |
ptuytsch | 1131:5cc818415e2b | 39 | ble.gattServer().write(bikePulseChar.getValueHandle(), (uint8_t *)&bikePulse, sizeof(uint32_t)); |
ptuytsch | 1131:5cc818415e2b | 40 | } |
ptuytsch | 1131:5cc818415e2b | 41 | |
ptuytsch | 1131:5cc818415e2b | 42 | private: |
ptuytsch | 1131:5cc818415e2b | 43 | BLE &ble; |
ptuytsch | 1131:5cc818415e2b | 44 | uint32_t bikeDistance; |
ptuytsch | 1131:5cc818415e2b | 45 | uint32_t bikeAverage; |
ptuytsch | 1131:5cc818415e2b | 46 | uint32_t bikePulse; |
ptuytsch | 1131:5cc818415e2b | 47 | ReadOnlyGattCharacteristic<uint32_t> bikePulseChar; |
ptuytsch | 1131:5cc818415e2b | 48 | ReadOnlyGattCharacteristic<uint32_t> bikeDistanceChar; |
ptuytsch | 1131:5cc818415e2b | 49 | ReadOnlyGattCharacteristic<uint32_t> bikeAverageChar; |
ptuytsch | 1131:5cc818415e2b | 50 | }; |
ptuytsch | 1131:5cc818415e2b | 51 | |
ptuytsch | 1131:5cc818415e2b | 52 | #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */ |