* 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.

Dependencies:   DHT22

Revision:
0:ee08053aaf57
Child:
1:8db3d642a94f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/bike_service.h	Thu Nov 02 16:13:17 2017 +0000
@@ -0,0 +1,50 @@
+#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__ */