Skip to content

Commit 5269885

Browse files
committed
Improve and simplify algorithm
1 parent c925c62 commit 5269885

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/components/motion/MotionController.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,14 @@ bool MotionController::ShouldWakeUp(bool isSleeping) {
4040
return false;
4141
}
4242
bool MotionController::ShouldSleep(bool isSleeping) {
43-
if (not isSleeping) {
44-
if (y <= 0) {
45-
lastYForSleep = 0;
46-
return false;
47-
}
48-
if (y - 230 > lastYForSleep) {
49-
lastYForSleep = y;
50-
return true;
51-
}
52-
}
53-
return false;
43+
bool ret = false;
44+
45+
if (y >= lastYForSleep + 192 && !isSleeping)
46+
ret = true;
47+
48+
lastYForSleep = (y > 320) ? y : 320;
49+
50+
return ret;
5451
}
5552

5653
void MotionController::IsSensorOk(bool isOk) {

0 commit comments

Comments
 (0)