From 76e79df375aca1b34a53eedc38bce7a3cda0a8a7 Mon Sep 17 00:00:00 2001 From: Finlay Davidson Date: Sun, 5 Mar 2023 15:19:52 +0100 Subject: shakewake: Switch to more generic timekeeping Could be used for other motion-based algorithms in the future. --- src/components/motion/MotionController.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/components/motion/MotionController.cpp') diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index aab8b9d4..5fc548be 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -1,6 +1,5 @@ #include "components/motion/MotionController.h" -#include #include using namespace Pinetime::Controllers; @@ -14,6 +13,9 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) service->OnNewMotionValues(x, y, z); } + lastTime = time; + time = xTaskGetTickCount(); + this->x = x; lastY = this->y; this->y = y; @@ -50,10 +52,8 @@ bool MotionController::Should_RaiseWake(bool isSleeping) { } bool MotionController::ShouldShakeWake(uint16_t thresh) { - auto diff = xTaskGetTickCount() - lastShakeTime; - lastShakeTime = xTaskGetTickCount(); /* Currently Polling at 10hz, If this ever goes faster scalar and EMA might need adjusting */ - int32_t speed = std::abs(z + (y / 2) + (x / 4) - lastY / 2 - lastZ) / diff * 100; + int32_t speed = std::abs(z + (y / 2) + (x / 4) - lastY / 2 - lastZ) / (time - lastTime) * 100; //(.2 * speed) + ((1 - .2) * accumulatedSpeed); // implemented without floats as .25Alpha accumulatedSpeed = (speed / 5) + ((accumulatedSpeed / 5) * 4); -- cgit v1.2.3-70-g09d2