From 4ac4d8b8a147fabe614e87a7e41bf59f21462eaf Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 7 Jul 2017 07:20:04 -0400 Subject: [PATCH] RPM refactoring --- firmware/controllers/trigger/rpm_calculator.cpp | 4 ++-- firmware/controllers/trigger/rpm_calculator.h | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index ccc9747ccf..8b8a1f712d 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -103,7 +103,6 @@ bool RpmCalculator::checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) { return true; } -// private method void RpmCalculator::assignRpmValue(int value) { previousRpmValue = rpmValue; rpmValue = value; @@ -148,9 +147,10 @@ float RpmCalculator::getRpmAcceleration() { void RpmCalculator::setStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE) { revolutionCounterSinceStart = 0; if (rpmValue != 0) { - rpmValue = 0; + assignRpmValue(0); scheduleMsg(logger, "engine stopped"); } + state = STOPPED; } /** diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index c09122f511..45f7573484 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -44,7 +44,7 @@ typedef enum { * The engine is running (RPM >= cranking.rpm) */ RUNNING, -} engine_state_e; +} spinning_state_e; class Engine; @@ -67,11 +67,6 @@ public: */ 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); @@ -95,6 +90,11 @@ public: volatile floatus_t oneDegreeUs; volatile efitime_t lastRpmEventTimeNt; private: + /** + * Should be called once we've realized engine is not spinning any more. + */ + void setStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE); + void assignRpmValue(int value); /** * This counter is incremented with each revolution of one of the shafts. Could be @@ -105,6 +105,8 @@ private: * Same as the above, but since the engine started spinning */ volatile uint32_t revolutionCounterSinceStart; + + spinning_state_e state; }; /**