From a98b5d87cd960d6b4a690d530fc85456d20e93d4 Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 6 Jul 2017 19:33:25 -0400 Subject: [PATCH] RPM refactoring --- firmware/controllers/engine_controller.cpp | 5 ++++ .../controllers/trigger/rpm_calculator.cpp | 23 ++++++++++++------- firmware/controllers/trigger/rpm_calculator.h | 8 +++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index fbb7e4c945..900fdb48c6 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -259,6 +259,11 @@ static void periodicSlowCallback(Engine *engine) { } #endif + /** + * Update engine RPM state if needed (check timeouts). + */ + engine->rpmCalculator.checkIfSpinning(PASS_ENGINE_PARAMETER_SIGNATURE); + if (engine->rpmCalculator.isStopped(PASS_ENGINE_PARAMETER_SIGNATURE)) { #if (EFI_PROD_CODE && EFI_ENGINE_CONTROL && EFI_INTERNAL_FLASH) || defined(__DOXYGEN__) writeToFlashIfPending(); diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index e2ae3a4eb3..fc4ddb4cb8 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -100,6 +100,9 @@ bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_SIGNATURE) { return result; } +bool RpmCalculator::checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + return false; +} // private method void RpmCalculator::assignRpmValue(int value) { @@ -143,6 +146,17 @@ float RpmCalculator::getRpmAcceleration() { return 1.0 * previousRpmValue / rpmValue; } +void RpmCalculator::setStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + revolutionCounterSinceStart = 0; + if (rpmValue != 0) { + rpmValue = 0; + scheduleMsg(logger, + "templog rpm=0 since not running [%x][%x] [%x][%x]", + (int) (notRunnintNow >> 32), (int) notRunnintNow, + (int) (notRunningPrev >> 32), (int) notRunningPrev); + } +} + /** * WARNING: this is a heavy method because 'getRpm()' is relatively heavy * @@ -156,14 +170,7 @@ int RpmCalculator::getRpm(DECLARE_ENGINE_PARAMETER_SIGNATURE) { return mockRpm; #endif if (!isRunning(PASS_ENGINE_PARAMETER_SIGNATURE)) { - revolutionCounterSinceStart = 0; - if (rpmValue != 0) { - rpmValue = 0; - scheduleMsg(logger, - "templog rpm=0 since not running [%x][%x] [%x][%x]", - (int) (notRunnintNow >> 32), (int) notRunnintNow, - (int) (notRunningPrev >> 32), (int) notRunningPrev); - } + setStopped(PASS_ENGINE_PARAMETER_SIGNATURE); } return rpmValue; } diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index d904a75755..ae2f2806ce 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -70,6 +70,14 @@ public: * Please note that this is a relatively heavy method due to getTimeNowNt() usage */ bool isRunning(DECLARE_ENGINE_PARAMETER_SIGNATURE); + + /** + * Should be called once we've realized engine is not spinning any more. + */ + void setStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE); + + bool checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE); + int getRpm(DECLARE_ENGINE_PARAMETER_SIGNATURE); /** * This method is invoked once per engine cycle right after we calculate new RPM value