Skip to content

Commit 7ea36e8

Browse files
committed
Unconditionally calculate shake speed
1 parent 90e458b commit 7ea36e8

3 files changed

Lines changed: 9 additions & 13 deletions

File tree

src/components/motion/MotionController.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
5454
zHistory++;
5555
zHistory[0] = z;
5656

57+
// Update accumulated speed
58+
// Currently polling at 10Hz, if this ever goes faster scalar and EMA might need adjusting
59+
int32_t speed = std::abs(zHistory[0] - zHistory[histSize - 1] + ((yHistory[0] - yHistory[histSize - 1]) / 2) +
60+
((xHistory[0] - xHistory[histSize - 1]) / 4)) *
61+
100 / (time - lastTime);
62+
// integer version of (.2 * speed) + ((1 - .2) * accumulatedSpeed);
63+
accumulatedSpeed = speed / 5 + accumulatedSpeed * 4 / 5;
64+
5765
stats = GetAccelStats();
5866

5967
int32_t deltaSteps = nbSteps - this->nbSteps;
@@ -111,17 +119,6 @@ bool MotionController::ShouldRaiseWake() const {
111119
return DegreesRolled(stats.yMean, stats.zMean, stats.prevYMean, stats.prevZMean) < rollDegreesThresh;
112120
}
113121

114-
bool MotionController::ShouldShakeWake(uint16_t thresh) {
115-
/* Currently Polling at 10hz, If this ever goes faster scalar and EMA might need adjusting */
116-
int32_t speed = std::abs(zHistory[0] - zHistory[histSize - 1] + (yHistory[0] - yHistory[histSize - 1]) / 2 +
117-
(xHistory[0] - xHistory[histSize - 1]) / 4) *
118-
100 / (time - lastTime);
119-
// (.2 * speed) + ((1 - .2) * accumulatedSpeed);
120-
accumulatedSpeed = speed / 5 + accumulatedSpeed * 4 / 5;
121-
122-
return accumulatedSpeed > thresh;
123-
}
124-
125122
bool MotionController::ShouldLowerSleep() const {
126123
if ((stats.xMean > 887 && DegreesRolled(stats.xMean, stats.zMean, stats.prevXMean, stats.prevZMean) > 30) ||
127124
(stats.xMean < -887 && DegreesRolled(stats.xMean, stats.zMean, stats.prevXMean, stats.prevZMean) < -30)) {

src/components/motion/MotionController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ namespace Pinetime {
4444
return currentTripSteps;
4545
}
4646

47-
bool ShouldShakeWake(uint16_t thresh);
4847
bool ShouldRaiseWake() const;
4948
bool ShouldLowerSleep() const;
5049

src/systemtask/SystemTask.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ void SystemTask::UpdateMotion() {
437437
if ((settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) &&
438438
motionController.ShouldRaiseWake()) ||
439439
(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) &&
440-
motionController.ShouldShakeWake(settingsController.GetShakeThreshold()))) {
440+
motionController.CurrentShakeSpeed() > settingsController.GetShakeThreshold())) {
441441
GoToRunning();
442442
}
443443
}

0 commit comments

Comments
 (0)