![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
app critics will say it's money, cash, toes
Diff: source/main.cpp
- Revision:
- 10:8cf4069d064a
- Parent:
- 9:40874a5c5ad0
- Child:
- 11:5023e8c93e4d
--- a/source/main.cpp Wed Nov 07 10:55:00 2018 +0000 +++ b/source/main.cpp Wed Nov 07 19:30:43 2018 +0000 @@ -16,6 +16,8 @@ #include <events/mbed_events.h> #include <math.h> +#include <chrono> +#include <ctime> #include <mbed.h> #include "MPU9250.h" #include "ble/BLE.h" @@ -31,7 +33,11 @@ int16_t destination[3]; short hrmCounter = 0; double step_threshold = 14.45; +long step_delay = 330; double oldAcceleration = 0.0; +long lastStepTime = 0; +long timeCurrent; + static HeartRateService* hrService; MPU9250 mpu = MPU9250(P0_26, P0_27); @@ -58,12 +64,16 @@ double accel = sqrt(sum_acc); int step = 0; - - if (accel < step_threshold && oldAcceleration >= step_threshold) { - // && (timeCurrent - lastStepTime > STEP_DELAY)) { - step = 1; - // lastStepTime = timeCurrent; - } + + namespace sc = std::chrono; + auto time = sc::system_clock::now(); // get the current time + auto millis = sc::duration_cast<sc::milliseconds>(time); + timeCurrent = millis.count(); + + if (accel < step_threshold && oldAcceleration >= step_threshold && (timeCurrent - lastStepTime > STEP_DELAY)) { + step = 1; + lastStepTime = timeCurrent; + } oldAcceleration = accel; @@ -149,6 +159,7 @@ int main() { mpu.initMPU9250(); + eventQueue.call_every(100, blinkCallback); BLE &ble = BLE::Instance();