Skip to content

Commit 9e128c8

Browse files
ic-27FintasticMan
andauthored
ShakeWake: Fixed instant wake after sleep issue in certain positions (#1691)
* ShakeWake: Fixed instant wake after sleep issue in certain positions Add lastX var to track the previous x acceleration for correct calculation of speed. Reorder axes for clarity. --------- Co-authored-by: Isaac <114504394+isaacc27@users.noreply.github.com> Co-authored-by: FintasticMan <52415484+FintasticMan@users.noreply.github.com>
1 parent f057894 commit 9e128c8

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

src/components/motion/MotionController.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
1616
lastTime = time;
1717
time = xTaskGetTickCount();
1818

19+
lastX = this->x;
1920
this->x = x;
2021
lastY = this->y;
2122
this->y = y;
@@ -53,7 +54,7 @@ bool MotionController::ShouldRaiseWake(bool isSleeping) {
5354

5455
bool MotionController::ShouldShakeWake(uint16_t thresh) {
5556
/* Currently Polling at 10hz, If this ever goes faster scalar and EMA might need adjusting */
56-
int32_t speed = std::abs(z + (y / 2) + (x / 4) - lastY / 2 - lastZ) / (time - lastTime) * 100;
57+
int32_t speed = std::abs(z - lastZ + (y / 2) - (lastY / 2) + (x / 4) - (lastX / 4)) / (time - lastTime) * 100;
5758
//(.2 * speed) + ((1 - .2) * accumulatedSpeed);
5859
// implemented without floats as .25Alpha
5960
accumulatedSpeed = (speed / 5) + ((accumulatedSpeed / 5) * 4);

src/components/motion/MotionController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ namespace Pinetime {
6767
TickType_t lastTime = 0;
6868
TickType_t time = 0;
6969

70+
int16_t lastX = 0;
7071
int16_t x = 0;
7172
int16_t lastYForRaiseWake = 0;
7273
int16_t lastY = 0;

0 commit comments

Comments
 (0)