BLE Library with custom services for the tortuga bike

Dependents:   TORTUGA_BLE

Fork of BLE_API by aapje monkey

Files at this revision

API Documentation at this revision

Comitter:
ptuytsch
Date:
Mon Jul 18 09:25:32 2016 +0000
Parent:
1206:8afbec0520f5
Commit message:
make it working with tortuga itself

Changed in this revision

ble/services/BikeBatteryService.h Show annotated file Show diff for this revision Revisions of this file
ble/services/BikeService.h Show annotated file Show diff for this revision Revisions of this file
diff -r 8afbec0520f5 -r da7745688342 ble/services/BikeBatteryService.h
--- a/ble/services/BikeBatteryService.h	Fri Jul 15 12:49:23 2016 +0000
+++ b/ble/services/BikeBatteryService.h	Mon Jul 18 09:25:32 2016 +0000
@@ -47,12 +47,15 @@
         batteryLevel3(level3),
         batteryLevelCharacteristic1(BATTERY_LEVEL_1_CHARACTERISTIC_UUID, &batteryLevel1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
         batteryLevelCharacteristic2(BATTERY_LEVEL_2_CHARACTERISTIC_UUID, &batteryLevel2, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
-        batteryLevelCharacteristic3(BATTERY_LEVEL_3_CHARACTERISTIC_UUID, &batteryLevel3, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {
+        batteryLevelCharacteristic3(BATTERY_LEVEL_3_CHARACTERISTIC_UUID, &batteryLevel3, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
+    {
 
         GattCharacteristic *charTable[] = {&batteryLevelCharacteristic1, &batteryLevelCharacteristic2, &batteryLevelCharacteristic3};
         GattService         batteryService(BATTERY_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
 
         ble.gattServer().addService(batteryService);
+        //printf("adress of _ble: %#x\n", &_ble);
+        //printf("adress of ble: %#x\n", &ble);
     }
 
     /**
@@ -63,11 +66,15 @@
      *              Update to battery level.
      */
     void updateBatteryLevel1(uint8_t newLevel) {
+        //printf("try to update batlevel 1\n");
         if (newLevel != batteryLevel1)
         {
             batteryLevel1 = newLevel;
             ble.gattServer().write(batteryLevelCharacteristic1.getValueHandle(), &batteryLevel1, 1);
+            //printf("BLE battery Level 1 update : %i\n", batteryLevel1);
+            //printf("adress of ble: %#x\n", &ble);
         }
+        
     }
     void updateBatteryLevel2(uint8_t newLevel) {
         if (newLevel != batteryLevel2)
@@ -81,6 +88,7 @@
         {
             batteryLevel3 = newLevel;
             ble.gattServer().write(batteryLevelCharacteristic3.getValueHandle(), &batteryLevel3, 1);
+            //printf("battery level updated\n");
         }
     }
 
diff -r 8afbec0520f5 -r da7745688342 ble/services/BikeService.h
--- a/ble/services/BikeService.h	Fri Jul 15 12:49:23 2016 +0000
+++ b/ble/services/BikeService.h	Mon Jul 18 09:25:32 2016 +0000
@@ -157,59 +157,70 @@
         if (tmp != tripDistance){
             tripDistance = tmp;
             ble.gattServer().write(tripDistanceChar.getValueHandle(),(uint8_t *)&tripDistance,sizeof(uint32_t));
+            for (uint64_t i = 0; i<0x2760; i++);
         }    
         tmp = ((bd->getDataSet(BikeData::TRIP))->getAverage()) * 100;
         if (tmp != tripAverage){
             tripAverage = tmp;
             ble.gattServer().write(tripAverageChar.getValueHandle(),(uint8_t *)&tripAverage,sizeof(uint32_t));
+            for (uint64_t i = 0; i<0x2760; i++);
             }
         tmp = ((bd->getDataSet(BikeData::TRIP))->getTime());
         if (tmp != tripTime){
             tripTime = tmp;
             ble.gattServer().write(tripTimeChar.getValueHandle(),(uint8_t *)&tripTime,sizeof(uint32_t));
+            for (uint64_t i = 0; i<0x2760; i++);
             }
         //OverallData
         tmp = (bd->getDataSet(BikeData::OVERALL))->getDistance()*100;
         if (tmp != overallDistance){
             overallDistance = tmp;
             ble.gattServer().write(overallDistanceChar.getValueHandle(),(uint8_t *)&overallDistance,sizeof(uint32_t));
+            for (uint64_t i = 0; i<0x2760; i++);
             }
         tmp = (bd->getDataSet(BikeData::OVERALL))->getAverage()*100;
         if (tmp != overallAverage){
             overallAverage = tmp;
             ble.gattServer().write(overallAverageChar.getValueHandle(),(uint8_t *)&overallAverage,sizeof(uint32_t));
+            for (uint64_t i = 0; i<0x2760; i++);
             }
         tmp = (bd->getDataSet(BikeData::OVERALL))->getTime();
         if (tmp != overallTime){
             overallTime = tmp;
             ble.gattServer().write(overallTimeChar.getValueHandle(),(uint8_t *)&overallTime,sizeof(uint32_t));
+            for (uint64_t i = 0; i<0x2760; i++);
             }
         //Since Battery Change
         tmp = (bd->getDataSet(BikeData::BATCHANGE))->getDistance() *100;
         if (tmp != batChangeDistance){
             batChangeDistance = tmp;
             ble.gattServer().write(batChangeDistanceChar.getValueHandle(),(uint8_t *)&batChangeDistance,sizeof(uint32_t));
+            for (uint64_t i = 0; i<0x2760; i++);
             }
         tmp = (bd->getDataSet(BikeData::BATCHANGE))->getAverage() *100;
         if (tmp != batChangeAverage){
             batChangeAverage = tmp;
             ble.gattServer().write(batChangeAverageChar.getValueHandle(),(uint8_t *)&batChangeAverage,sizeof(uint32_t));
+            for (uint64_t i = 0; i<0x2760; i++);
             }
         tmp = (bd->getDataSet(BikeData::BATCHANGE))->getTime();
         if (tmp != batChangeTime){
             batChangeTime = tmp;
             ble.gattServer().write(batChangeTimeChar.getValueHandle(),(uint8_t *)&batChangeTime,sizeof(uint32_t));
+            for (uint64_t i = 0; i<0x2760; i++);
             }
         // Continious Data
         tmp = bd->getLastCount();
         if (tmp != pulse){
             pulse = tmp;
             ble.gattServer().write(pulseChar.getValueHandle(),&pulse,sizeof(uint8_t));
+            for (uint64_t i = 0; i<0x2760; i++);
             }
         tmp = bd->getSpeed()*100;
         if (tmp != speed){
             speed = tmp;
             ble.gattServer().write(speedChar.getValueHandle(),(uint8_t *)&speed,sizeof(uint32_t));
+            for (uint64_t i = 0; i<0x2760; i++);
             }
         tmp = bd->isLogging()*'5';
         if (tmp != control){