* 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
- Committer:
- DuyLionTran
- Date:
- 2017-11-02
- Revision:
- 1:8db3d642a94f
- Parent:
- 0:ee08053aaf57
- Child:
- 2:65ed7cd0480c
File content as of revision 1:8db3d642a94f:
#ifndef __BLE_BIKE_SERVICE_H__ #define __BLE_BIKE_SERVICE_H__ #include "ble/BLE.h" /** * @class bikeService * @brief This is a customized service for a device controlling the bike via BLE */ class bikeService { public: const static uint16_t BIKE_SERVICE_UUID = 0xA580; const static uint16_t SWITCH_CONTROL_UUID = 0xA581; const static uint16_t TEMPERATURE_MEASURE_UUID = 0xA582; // void updateTemperatureState(uint16_t newTemperature); /** * @param[in] _ble BLE object for the underlying controller. * @param[in] currentTemperature The temperature measured from the sensor. */ bikeService(BLEDevice &_ble, bool initialSwitchState) : ble(_ble), switchState(SWITCH_CONTROL_UUID, &initialSwitchState) // temperatureState(TEMPERATURE_MEASURE_UUID, ¤tTemperature) { /* Create and add the service */ GattCharacteristic *charTable[] = {&switchState}; GattService bikeService(BIKE_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); ble.addService(bikeService); } GattAttribute::Handle_t getValueHandle() const { return switchState.getValueHandle(); } void updateTemperatureState(uint16_t newTemperature) { currentTemperature = newTemperature; /* An error occured here, need to create a new GattServer class? */ // ble.gattServer().write(temperatureState.getValueHandle(), (uint16_t *) ¤tTemperature, sizeof(uint16_t)); } private: int16_t currentTemperature; BLEDevice &ble; ReadWriteGattCharacteristic<bool> switchState; // ReadOnlyGattCharacteristic<int16_t> temperatureState; }; #endif /* __BLE_BIKE_SERVICE_H__ */