From d41fee0cf66c901b638eea05ca24c5f7ea5310ed Mon Sep 17 00:00:00 2001 From: Finlay Davidson Date: Fri, 12 Nov 2021 00:59:03 +0100 Subject: [PATCH] Improve and simplify Raise to Wake algorithm --- src/components/motion/MotionController.cpp | 30 ++++++++-------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index cae4910518..523f02ebdd 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -18,26 +18,18 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) } bool MotionController::ShouldWakeUp(bool isSleeping) { - if ((x + 335) <= 670 && z < 0) { - if (not isSleeping) { - if (y <= 0) { - return false; - } else { - lastYForWakeUp = 0; - return false; - } - } - - if (y >= 0) { - lastYForWakeUp = 0; - return false; - } - if (y + 230 < lastYForWakeUp) { - lastYForWakeUp = y; - return true; - } + bool ret = false; + + if (x >= -384 && x <= 384 && + z <= 0 && + y <= lastYForWakeUp - 192 && + isSleeping) { + ret = true; } - return false; + + lastYForWakeUp = (y < 0) ? y : 0; + + return ret; } void MotionController::IsSensorOk(bool isOk) { isSensorOk = isOk;