* 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:
- 0:ee08053aaf57
- Child:
- 1:8db3d642a94f
File content as of revision 0:ee08053aaf57:
#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; /** * @param[in] _ble BLE object for the underlying controller. * @param[in] currentTemperature The temperature measured from the sensor. */ bikeService(BLEDevice &_ble, bool initialSwitchState, uint16_t temperature) : ble(_ble), switchCharacteristic(SWITCH_CONTROL_UUID, &initialSwitchState), temperatureCharacteristic(GattCharacteristic::UUID_TEMPERATURE_MEASUREMENT_CHAR, &temperature, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) { /* Create and add the service */ GattCharacteristic *charTable[] = {&switchCharacteristic, &temperatureCharacteristic}; GattService bikeService(BIKE_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); ble.gattServer().addService(bikeService); } GattAttribute::Handle_t getValueHandle() const { return switchCharacteristic.getValueHandle(); } void updateTemperatureCharacteristic(uint16_t newTemperatureVal) { temperature = newTemperatureVal; ble.gattServer().write(temperatureCharacteristic.getValueHandle(), (uint8_t *) &temperature, sizeof(uint16_t)); } private: uint16_t temperature; BLE &ble; ReadWriteGattCharacteristic<bool> switchCharacteristic; ReadOnlyGattCharacteristic<uint16_t> temperatureCharacteristic; }; #endif /* __BLE_BIKE_SERVICE_H__ */