From 1735529a6b826ca5d008d7705875ed2e19f8d35a Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 31 Jan 2020 01:21:56 -0500 Subject: [PATCH] refactoring: extracting DEEP_IN_THE_PAST_SECONDS contant --- firmware/controllers/algo/engine2.cpp | 2 +- firmware/controllers/engine_cycle/rpm_calculator.cpp | 2 +- firmware/controllers/trigger/trigger_central.h | 2 +- firmware/util/efitime.h | 6 ++++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index 33d4464cc0..ead3ac910d 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -41,7 +41,7 @@ WarningCodeState::WarningCodeState() { void WarningCodeState::clear() { warningCounter = 0; lastErrorCode = 0; - timeOfPreviousWarning = -10; + timeOfPreviousWarning = DEEP_IN_THE_PAST_SECONDS; recentWarnings.clear(); } diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index 042b90ac8a..06068e4027 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -96,7 +96,7 @@ RpmCalculator::RpmCalculator() { // which we cannot provide inside this parameter-less constructor. need a solution for this minor mess // we need this initial to have not_running at first invocation - lastRpmEventTimeNt = (efitick_t) -10 * NT_PER_SECOND; + lastRpmEventTimeNt = (efitick_t) DEEP_IN_THE_PAST_SECONDS * NT_PER_SECOND; } /** diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index 0e6b5cf9bb..5bad20e69d 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -54,7 +54,7 @@ public: TriggerWaveform triggerShape; - efitick_t previousVvtCamTime = 0; + efitick_t previousVvtCamTime = DEEP_IN_THE_PAST_SECONDS * NT_PER_SECOND; efitick_t previousVvtCamDuration = 0; private: diff --git a/firmware/util/efitime.h b/firmware/util/efitime.h index 48e7ccb6f6..449de1d0ee 100644 --- a/firmware/util/efitime.h +++ b/firmware/util/efitime.h @@ -22,6 +22,12 @@ // milliseconds to ticks #define MS2NT(msTime) US2NT(MS2US(msTime)) +/** + * We use this 'deep in past, before ECU has ever started' value as a way to unify + * handling of first ever event and an event which has happened after a large pause in engine activity + */ +#define DEEP_IN_THE_PAST_SECONDS -10 + // todo: implement a function to work with times considering counter overflow #define overflowDiff(now, time) ((now) - (time))