* 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.
Diff: source/bike_service.h
- Revision:
- 1:8db3d642a94f
- Parent:
- 0:ee08053aaf57
- Child:
- 2:65ed7cd0480c
diff -r ee08053aaf57 -r 8db3d642a94f source/bike_service.h --- a/source/bike_service.h Thu Nov 02 16:13:17 2017 +0000 +++ b/source/bike_service.h Thu Nov 02 17:44:51 2017 +0000 @@ -8,43 +8,45 @@ * @brief This is a customized service for a device controlling the bike via BLE */ class bikeService { -public: +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, uint16_t temperature) : + bikeService(BLEDevice &_ble, bool initialSwitchState) : ble(_ble), - switchCharacteristic(SWITCH_CONTROL_UUID, &initialSwitchState), - temperatureCharacteristic(GattCharacteristic::UUID_TEMPERATURE_MEASUREMENT_CHAR, &temperature, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) + switchState(SWITCH_CONTROL_UUID, &initialSwitchState) +// temperatureState(TEMPERATURE_MEASURE_UUID, ¤tTemperature) { /* Create and add the service */ - GattCharacteristic *charTable[] = {&switchCharacteristic, &temperatureCharacteristic}; + GattCharacteristic *charTable[] = {&switchState}; GattService bikeService(BIKE_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); - ble.gattServer().addService(bikeService); + ble.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)); + 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: - uint16_t temperature; + int16_t currentTemperature; - BLE &ble; - ReadWriteGattCharacteristic<bool> switchCharacteristic; - ReadOnlyGattCharacteristic<uint16_t> temperatureCharacteristic; + BLEDevice &ble; + ReadWriteGattCharacteristic<bool> switchState; +// ReadOnlyGattCharacteristic<int16_t> temperatureState; }; #endif /* __BLE_BIKE_SERVICE_H__ */