BLE Library with custom services for the tortuga bike

Dependents:   TORTUGA_BLE

Fork of BLE_API by aapje monkey

Revision:
1202:a31d51d9fba8
Parent:
1131:5cc818415e2b
Child:
1203:3bc52a68543f
Child:
1204:c87f50212c84
--- a/ble/services/BikeService.h	Sat Apr 16 14:55:58 2016 +0000
+++ b/ble/services/BikeService.h	Sat Apr 30 13:29:42 2016 +0000
@@ -7,8 +7,13 @@
     const static uint16_t BIKE_DISTANCE_CHARACTERISTIC_UUID = 0x696A;
     const static uint16_t BIKE_AVERAGE_CHARACTERISTIC_UUID = 0x696B;
     const static uint16_t BIKE_PULSE_CHARACTERISTIC_UUID = 0x696C;
- 
+    const static uint16_t BIKE_START_CHARACTERISTIC_UUID = 0x696D;
+    
+    uint8_t *start;
+    
+    //CONSTRUCTOR
     BikeService(BLE &_ble,
+                uint8_t *startBool,
                 uint32_t initialDistance = 0,
                 uint32_t initialAverage = 0) : 
         ble(_ble), 
@@ -16,11 +21,20 @@
         bikeAverage(initialAverage),
         bikeDistanceChar(BIKE_DISTANCE_CHARACTERISTIC_UUID, 0, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
         bikeAverageChar(BIKE_AVERAGE_CHARACTERISTIC_UUID, 0, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
-        bikePulseChar(BIKE_PULSE_CHARACTERISTIC_UUID, 0, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
+        bikePulseChar(BIKE_PULSE_CHARACTERISTIC_UUID, 0, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+        bikeStartChar(BIKE_START_CHARACTERISTIC_UUID, startBool, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
     {
-        GattCharacteristic *charTable[] = {&bikeDistanceChar, &bikeAverageChar, &bikePulseChar};
+        GattCharacteristic *charTable[] = {&bikeDistanceChar, &bikeAverageChar, &bikePulseChar, &bikeStartChar};
         GattService         bikeService(BikeService::BIKE_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
         ble.gattServer().addService(bikeService);
+        ble.onDataWritten(this, &BikeService::onDataWrittenCallback);
+        start = startBool;
+    }
+    
+    void onDataWrittenCallback(const GattWriteCallbackParams *writeParams) {
+        if (writeParams->handle == bikeStartChar.getValueHandle()) {
+                *start = *(writeParams->data);
+            }
     }
     
  
@@ -47,6 +61,7 @@
     ReadOnlyGattCharacteristic<uint32_t>  bikePulseChar;
     ReadOnlyGattCharacteristic<uint32_t>  bikeDistanceChar;
     ReadOnlyGattCharacteristic<uint32_t>  bikeAverageChar;
+    ReadWriteGattCharacteristic<uint8_t>  bikeStartChar;
 };
  
-#endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */
\ No newline at end of file
+#endif
\ No newline at end of file