diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 478fa9fbd7..0431d81d44 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -297,7 +297,7 @@ static void periodicSlowCallback(Engine *engine) { /** * Update engine RPM state if needed (check timeouts). */ - bool isSpinning = engine->rpmCalculator.checkIfSpinning(PASS_ENGINE_PARAMETER_SIGNATURE); + bool isSpinning = engine->rpmCalculator.checkIfSpinning(getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX); if (!isSpinning) { engine->rpmCalculator.setStopSpinning(PASS_ENGINE_PARAMETER_SIGNATURE); } diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 6d9a4cda43..8e3f1db2d9 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -61,16 +61,16 @@ RpmCalculator::RpmCalculator() { revolutionCounterSinceBootForUnitTest = 0; } -bool RpmCalculator::isStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +bool RpmCalculator::isStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE) const { // Spinning-up with zero RPM means that the engine is not ready yet, and is treated as 'stopped'. return state == STOPPED || (state == SPINNING_UP && rpmValue == 0); } -bool RpmCalculator::isSpinningUp(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +bool RpmCalculator::isSpinningUp(DECLARE_ENGINE_PARAMETER_SIGNATURE) const { return state == SPINNING_UP; } -bool RpmCalculator::isCranking(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +bool RpmCalculator::isCranking(DECLARE_ENGINE_PARAMETER_SIGNATURE) const { // Spinning-up with non-zero RPM is suitable for all engine math, as good as cranking return state == CRANKING || (state == SPINNING_UP && rpmValue > 0); } @@ -78,15 +78,14 @@ bool RpmCalculator::isCranking(DECLARE_ENGINE_PARAMETER_SIGNATURE) { /** * @return true if there was a full shaft revolution within the last second */ -bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_SIGNATURE) const { return state == RUNNING; } /** * @return true if engine is spinning (cranking or running) */ -bool RpmCalculator::checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - efitick_t nowNt = getTimeNowNt(); +bool RpmCalculator::checkIfSpinning(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) const { if (ENGINE(needToStopEngine(nowNt))) { return false; } @@ -148,7 +147,7 @@ void RpmCalculator::setRpmValue(int value DECLARE_ENGINE_PARAMETER_SUFFIX) { #endif } -spinning_state_e RpmCalculator::getState(void) { +spinning_state_e RpmCalculator::getState() const { return state; } @@ -237,7 +236,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, if (index == 0) { ENGINE(m.beforeRpmCb) = GET_TIMESTAMP(); - bool hadRpmRecently = rpmState->checkIfSpinning(PASS_ENGINE_PARAMETER_SIGNATURE); + bool hadRpmRecently = rpmState->checkIfSpinning(nowNt PASS_ENGINE_PARAMETER_SUFFIX); if (hadRpmRecently) { efitime_t diffNt = nowNt - rpmState->lastRpmEventTimeNt; diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index 3123b27344..6f26cc78be 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -62,26 +62,26 @@ public: /** * Returns true if the engine is not spinning (RPM==0) */ - bool isStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE); + bool isStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE) const; /** * Returns true if the engine is spinning up */ - bool isSpinningUp(DECLARE_ENGINE_PARAMETER_SIGNATURE); + bool isSpinningUp(DECLARE_ENGINE_PARAMETER_SIGNATURE) const; /** * Returns true if the engine is cranking OR spinning up */ - bool isCranking(DECLARE_ENGINE_PARAMETER_SIGNATURE); + bool isCranking(DECLARE_ENGINE_PARAMETER_SIGNATURE) const; /** * Returns true if the engine is running and not cranking */ - bool isRunning(DECLARE_ENGINE_PARAMETER_SIGNATURE); + bool isRunning(DECLARE_ENGINE_PARAMETER_SIGNATURE) const; - bool checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE); + bool checkIfSpinning(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) const; /** * This accessor is used in unit-tests. */ - spinning_state_e getState(void); + spinning_state_e getState() const; /** * Should be called on every trigger event when the engine is just starting to spin up.