app critics will say it's money, cash, toes

Revision:
22:50f88b18cfad
Parent:
21:36bd27c83b35
Child:
23:7126ef3503e2
diff -r 36bd27c83b35 -r 50f88b18cfad source/main.cpp
--- a/source/main.cpp	Fri Dec 14 16:22:10 2018 +0000
+++ b/source/main.cpp	Sun Dec 16 13:51:44 2018 +0000
@@ -48,6 +48,7 @@
 double oldAcceleration = 0.0;
 int callback_cycles = 1;
 int step;
+int step_buffer;
 int totalsteps = 0;
 
 int run_threshold = 5;
@@ -87,6 +88,8 @@
         double accel = sqrt(sum_acc);
     
         if (accel < step_threshold && oldAcceleration >= step_threshold && (callback_cycles > 3)) {
+            step_buffer++;
+            //reached running speed
             if (callback_cycles <= run_threshold) {
                 if (run_count >= 2) {
                     step = 2;
@@ -96,6 +99,7 @@
                     run_count++;
                 }
             }
+            //at walking speed
             else {
                 step = 1;
                 run_count = 0;    
@@ -138,8 +142,19 @@
     old_pb = new_pb;    
     
     if (BLE_conn) {
+        step_buffer--;
+        if (step_buffer > 0) {
+            hrService->updateHeartRate(-1);
+            while (step_buffer > 127) {
+                hrService->updateHeartRate(127);
+                step_buffer -= 127;
+            }
+            hrService->updateHeartRate(step_buffer);
+            step_buffer = 0;
+            hrService->updateHeartRate(-1);
+        }
         hrmCounter = (short) step;    
-        hrService->updateHeartRate(hrmCounter);
+        hrService->updateHeartRate(hrmCounter);        
         BLE_conn = false;
     }
 }