* This is the code for "BLE Device for motorbike". The device is attached on any bike at will. * User can control 2 switches and these switches can control anything that user wants ie: turn on * the bike, turn on the alarm system of the bike, turn on the light... * Temperature sensor is also included in the device. User can view the temperature when he/she gets * near the bike. * For the next version, humidity and air quality sensor are also added.
source/bike_service.h@1:8db3d642a94f, 2017-11-02 (annotated)
- Committer:
- DuyLionTran
- Date:
- Thu Nov 02 17:44:51 2017 +0000
- Revision:
- 1:8db3d642a94f
- Parent:
- 0:ee08053aaf57
- Child:
- 2:65ed7cd0480c
Roll back to no Temperature measurement
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DuyLionTran | 0:ee08053aaf57 | 1 | #ifndef __BLE_BIKE_SERVICE_H__ |
DuyLionTran | 0:ee08053aaf57 | 2 | #define __BLE_BIKE_SERVICE_H__ |
DuyLionTran | 0:ee08053aaf57 | 3 | |
DuyLionTran | 0:ee08053aaf57 | 4 | #include "ble/BLE.h" |
DuyLionTran | 0:ee08053aaf57 | 5 | |
DuyLionTran | 0:ee08053aaf57 | 6 | /** |
DuyLionTran | 0:ee08053aaf57 | 7 | * @class bikeService |
DuyLionTran | 0:ee08053aaf57 | 8 | * @brief This is a customized service for a device controlling the bike via BLE |
DuyLionTran | 0:ee08053aaf57 | 9 | */ |
DuyLionTran | 0:ee08053aaf57 | 10 | class bikeService { |
DuyLionTran | 1:8db3d642a94f | 11 | public: |
DuyLionTran | 0:ee08053aaf57 | 12 | const static uint16_t BIKE_SERVICE_UUID = 0xA580; |
DuyLionTran | 0:ee08053aaf57 | 13 | const static uint16_t SWITCH_CONTROL_UUID = 0xA581; |
DuyLionTran | 1:8db3d642a94f | 14 | const static uint16_t TEMPERATURE_MEASURE_UUID = 0xA582; |
DuyLionTran | 1:8db3d642a94f | 15 | |
DuyLionTran | 1:8db3d642a94f | 16 | // void updateTemperatureState(uint16_t newTemperature); |
DuyLionTran | 0:ee08053aaf57 | 17 | |
DuyLionTran | 0:ee08053aaf57 | 18 | /** |
DuyLionTran | 0:ee08053aaf57 | 19 | * @param[in] _ble BLE object for the underlying controller. |
DuyLionTran | 0:ee08053aaf57 | 20 | * @param[in] currentTemperature The temperature measured from the sensor. |
DuyLionTran | 0:ee08053aaf57 | 21 | */ |
DuyLionTran | 0:ee08053aaf57 | 22 | |
DuyLionTran | 1:8db3d642a94f | 23 | bikeService(BLEDevice &_ble, bool initialSwitchState) : |
DuyLionTran | 0:ee08053aaf57 | 24 | ble(_ble), |
DuyLionTran | 1:8db3d642a94f | 25 | switchState(SWITCH_CONTROL_UUID, &initialSwitchState) |
DuyLionTran | 1:8db3d642a94f | 26 | // temperatureState(TEMPERATURE_MEASURE_UUID, ¤tTemperature) |
DuyLionTran | 0:ee08053aaf57 | 27 | { |
DuyLionTran | 0:ee08053aaf57 | 28 | /* Create and add the service */ |
DuyLionTran | 1:8db3d642a94f | 29 | GattCharacteristic *charTable[] = {&switchState}; |
DuyLionTran | 0:ee08053aaf57 | 30 | GattService bikeService(BIKE_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
DuyLionTran | 1:8db3d642a94f | 31 | ble.addService(bikeService); |
DuyLionTran | 0:ee08053aaf57 | 32 | } |
DuyLionTran | 0:ee08053aaf57 | 33 | |
DuyLionTran | 0:ee08053aaf57 | 34 | GattAttribute::Handle_t getValueHandle() const { |
DuyLionTran | 1:8db3d642a94f | 35 | return switchState.getValueHandle(); |
DuyLionTran | 0:ee08053aaf57 | 36 | } |
DuyLionTran | 0:ee08053aaf57 | 37 | |
DuyLionTran | 1:8db3d642a94f | 38 | void updateTemperatureState(uint16_t newTemperature) { |
DuyLionTran | 1:8db3d642a94f | 39 | currentTemperature = newTemperature; |
DuyLionTran | 1:8db3d642a94f | 40 | |
DuyLionTran | 1:8db3d642a94f | 41 | /* An error occured here, need to create a new GattServer class? */ |
DuyLionTran | 1:8db3d642a94f | 42 | // ble.gattServer().write(temperatureState.getValueHandle(), (uint16_t *) ¤tTemperature, sizeof(uint16_t)); |
DuyLionTran | 1:8db3d642a94f | 43 | } |
DuyLionTran | 0:ee08053aaf57 | 44 | private: |
DuyLionTran | 1:8db3d642a94f | 45 | int16_t currentTemperature; |
DuyLionTran | 0:ee08053aaf57 | 46 | |
DuyLionTran | 1:8db3d642a94f | 47 | BLEDevice &ble; |
DuyLionTran | 1:8db3d642a94f | 48 | ReadWriteGattCharacteristic<bool> switchState; |
DuyLionTran | 1:8db3d642a94f | 49 | // ReadOnlyGattCharacteristic<int16_t> temperatureState; |
DuyLionTran | 0:ee08053aaf57 | 50 | }; |
DuyLionTran | 0:ee08053aaf57 | 51 | |
DuyLionTran | 0:ee08053aaf57 | 52 | #endif /* __BLE_BIKE_SERVICE_H__ */ |