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

Revision:
9:40874a5c5ad0
Parent:
8:1735fddd5491
Child:
10:8cf4069d064a
diff -r 1735fddd5491 -r 40874a5c5ad0 source/main.cpp
--- a/source/main.cpp	Mon Nov 05 16:08:00 2018 +0000
+++ b/source/main.cpp	Wed Nov 07 10:55:00 2018 +0000
@@ -29,9 +29,9 @@
 static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE};
 
 int16_t destination[3];
-//uint8_t hrmCounter = 0;
 short hrmCounter = 0;
-short test_var = 0;
+double step_threshold = 14.45;
+double oldAcceleration = 0.0;
 static HeartRateService* hrService;
 MPU9250 mpu = MPU9250(P0_26, P0_27);
 
@@ -44,33 +44,33 @@
 
 void updateSensorValue() {
     mpu.readAccelData(destination);
-//    test_var++;
     
     double acc_x = destination[0] / 1000.0;
     double acc_y = destination[1] / 1000.0;
     double acc_z = destination[2] / 1000.0;
-//    printf("acc_x: " );
-//    printf("%f\n", acc_x);
     
     double sqr_acc_x = acc_x*acc_x;
     double sqr_acc_y = acc_y*acc_y;
     double sqr_acc_z = acc_z*acc_z;
-//    printf("sqr_acc_x: " );
-//    printf("%f\n", sqr_acc_x);
     
     double sum_acc = sqr_acc_x + sqr_acc_y + sqr_acc_z;
-    printf("sum_acc: " );
-    printf("%f\n", sum_acc);
+
+    double accel = sqrt(sum_acc);
     
-    double value = sqrt(sum_acc);
-    hrmCounter = (short) value;
-//    hrmCounter = test_var;
-    printf("SEND_VALUE: " );
+    int step = 0;
+ 
+    if (accel < step_threshold && oldAcceleration >= step_threshold) {
+        // && (timeCurrent - lastStepTime > STEP_DELAY)) {
+            step = 1;
+            // lastStepTime = timeCurrent;
+        }
+    
+    oldAcceleration = accel;
+    
+    hrmCounter = (short) step;
+    printf("STEP: " );
     printf("%hu\n", hrmCounter);  
-//    printf("value: " );
-//    printf("%f\n", value);
-    /* printf("%u\n", (unsigned int)acc_x);*/
-
+    
     hrService->updateHeartRate(hrmCounter);
 }
 
@@ -149,7 +149,7 @@
 int main()
 {    
     mpu.initMPU9250();
-    eventQueue.call_every(400, blinkCallback);
+    eventQueue.call_every(100, blinkCallback);
 
     BLE &ble = BLE::Instance();
     ble.onEventsToProcess(scheduleBleEventsProcessing);