From 13a2126240a9e421d91436423d19e3c1c2908619 Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 7 Jul 2017 08:10:06 -0400 Subject: [PATCH] RPM refactoring --- firmware/controllers/trigger/rpm_calculator.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 8b8a1f712d..c5f9cac2c4 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -61,7 +61,7 @@ RpmCalculator::RpmCalculator() { } bool RpmCalculator::isStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - return rpmValue == 0; + return state == STOPPED; } bool RpmCalculator::isCranking(DECLARE_ENGINE_PARAMETER_SIGNATURE) { @@ -72,7 +72,7 @@ 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) { - return rpmValue >= CONFIG(cranking.rpm); + return state == RUNNING; } bool RpmCalculator::checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) { @@ -122,6 +122,13 @@ void RpmCalculator::setRpmValue(int value DECLARE_ENGINE_PARAMETER_SUFFIX) { */ ENGINE(periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE)); } + if (rpmValue == 0) { + state = STOPPED; + } else if (rpmValue < CONFIG(cranking.rpm)) { + state = CRANKING; + } else { + state = RUNNING; + } } void RpmCalculator::onNewEngineCycle() {