diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index dc3fdc0d..39808752 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -7,15 +7,14 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) service->OnNewStepCountValue(nbSteps); } - if (service != nullptr && (this->x != x || this->y != y || this->z != z)) { + if (service != nullptr && (this->x != x || lastYs[lastYIndex] != y || this->z != z)) { service->OnNewMotionValues(x, y, z); } lastYIndex++; lastYIndex %= lastYs.size(); - lastYs.at(lastYIndex) = this->y; + lastYs[lastYIndex] = y; this->x = x; - this->y = y; this->z = z; int32_t deltaSteps = nbSteps - this->nbSteps; this->nbSteps = nbSteps; @@ -27,7 +26,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) bool MotionController::Should_RaiseWake(bool isSleeping) { if ((x + 335) <= 670 && z < 0) { if (not isSleeping) { - if (y <= 0) { + if (lastYs[lastYIndex] <= 0) { return false; } else { lastYForWakeUp = 0; @@ -35,12 +34,12 @@ bool MotionController::Should_RaiseWake(bool isSleeping) { } } - if (y >= 0) { + if (lastYs[lastYIndex] >= 0) { lastYForWakeUp = 0; return false; } - if (y + 230 < lastYForWakeUp) { - lastYForWakeUp = y; + if (lastYs[lastYIndex] + 230 < lastYForWakeUp) { + lastYForWakeUp = lastYs[lastYIndex]; return true; } } @@ -52,7 +51,7 @@ bool MotionController::Should_ShakeWake(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) - lastYForShake - lastZForShake) / diff * 100; + int32_t speed = std::abs(z + (lastYs[lastYIndex] / 2) + (x / 4) - lastYForShake - lastZForShake) / diff * 100; //(.2 * speed) + ((1 - .2) * accumulatedspeed); // implemented without floats as .25Alpha accumulatedspeed = (speed / 5) + ((accumulatedspeed / 5) * 4); @@ -61,7 +60,7 @@ bool MotionController::Should_ShakeWake(uint16_t thresh) { wake = true; } lastXForShake = x / 4; - lastYForShake = y / 2; + lastYForShake = lastYs[lastYIndex] / 2; lastZForShake = z; return wake; } @@ -70,13 +69,13 @@ int32_t MotionController::currentShakeSpeed() { } bool MotionController::ShouldLowerSleep() const { - if (lastYs.at((lastYIndex + 2) % lastYs.size()) < lastYs.at((lastYIndex + 1) % lastYs.size()) + 192 || - lastYs.at((lastYIndex + 2) % lastYs.size()) < 512) { + if (lastYs[(lastYIndex + 2) % lastYs.size()] < lastYs[(lastYIndex + 1) % lastYs.size()] + 192 || + lastYs[(lastYIndex + 2) % lastYs.size()] < 512) { return false; } for (uint8_t i = 3; i < lastYs.size(); i++) { - if (lastYs.at((lastYIndex + i) % lastYs.size()) < 0) { + if (lastYs[(lastYIndex + i) % lastYs.size()] < 0) { return false; } } diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index bef52786..5771e019 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -21,7 +21,7 @@ namespace Pinetime { return x; } int16_t Y() const { - return y; + return lastYs[lastYIndex]; } int16_t Z() const { return z; @@ -57,7 +57,6 @@ namespace Pinetime { uint32_t nbSteps; uint32_t currentTripSteps = 0; int16_t x = 0; - int16_t y = 0; int16_t z = 0; std::array lastYs = {}; uint8_t lastYIndex = 0; diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index c6a324a2..06275c0d 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -11,13 +11,7 @@ namespace Pinetime { enum class ClockType : uint8_t { H24, H12 }; enum class Notification : uint8_t { ON, OFF }; enum class ChimesOption : uint8_t { None, Hours, HalfHours }; - enum class WakeUpMode : uint8_t { - SingleTap = 0, - DoubleTap = 1, - RaiseWrist = 2, - Shake = 3, - LowerWrist = 4 - }; + enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, Shake = 3, LowerWrist = 4 }; enum class Colors : uint8_t { White, Silver, @@ -141,15 +135,14 @@ namespace Pinetime { return settings.screenTimeOut; }; - void SetShakeThreshold(uint16_t thresh){ - if(settings.shakeWakeThreshold != thresh){ - settings.shakeWakeThreshold = thresh; - settingsChanged = true; + void SetShakeThreshold(uint16_t thresh) { + if (settings.shakeWakeThreshold != thresh) { + settings.shakeWakeThreshold = thresh; + settingsChanged = true; } - } - int16_t GetShakeThreshold() const{ + int16_t GetShakeThreshold() const { return settings.shakeWakeThreshold; } @@ -196,20 +189,20 @@ namespace Pinetime { if (goal != settings.stepsGoal) { settingsChanged = true; } - settings.stepsGoal = goal; + settings.stepsGoal = goal; }; - + uint32_t GetStepsGoal() const { return settings.stepsGoal; }; - void SetBleRadioEnabled(bool enabled) { - bleRadioEnabled = enabled; - }; + void SetBleRadioEnabled(bool enabled) { + bleRadioEnabled = enabled; + }; - bool GetBleRadioEnabled() const { - return bleRadioEnabled; - }; + bool GetBleRadioEnabled() const { + return bleRadioEnabled; + }; private: Pinetime::Controllers::FS& fs;