From eba0278fdd3018c037f18be5c897581d6ca57328 Mon Sep 17 00:00:00 2001 From: rusefi Date: Tue, 15 Jan 2019 21:18:44 -0500 Subject: [PATCH] The Big Refactoring of 2019: configuration version should not be a global variable #656 --- firmware/console/status_loop.cpp | 4 +--- firmware/controllers/trigger/trigger_decoder.cpp | 10 ++++++---- firmware/controllers/trigger/trigger_decoder.h | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 49b0320ce2..a6679ec10f 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -594,10 +594,8 @@ static void setBlinkingPeriod(int value) { #if EFI_PROD_CODE || defined(__DOXYGEN__) -extern efitick_t lastDecodingErrorTime; - static bool isTriggerErrorNow() { - bool justHadError = (getTimeNowNt() - lastDecodingErrorTime) < US2NT(2 * 1000 * 3 * blinkingPeriod); + bool justHadError = (getTimeNowNt() - engine->triggerCentral.triggerState.lastDecodingErrorTime) < US2NT(2 * 1000 * 3 * blinkingPeriod); return justHadError || isTriggerDecoderError(); } diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index ea0e74ed87..8919db61de 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -40,6 +40,10 @@ EXTERN_ENGINE ; +// todo: this should become a field on some class +// no reason to make this a field on TriggerState since we have two instances of that one +// and only one needs this data structure. we probably need a virtual method of .addError() and +// only TriggerStateWithRunningStatistics would have the field? static cyclic_buffer errorDetection; #if ! EFI_PROD_CODE || defined(__DOXYGEN__) @@ -53,10 +57,6 @@ extern TunerStudioOutputChannels tsOutputChannels; static Logging * logger; -efitick_t lastDecodingErrorTime = US2NT(-10000000LL); -// the boolean flag is a performance optimization so that complex comparison is avoided if no error -static bool someSortOfTriggerError = false; - /** * @return TRUE is something is wrong with trigger decoding */ @@ -249,6 +249,8 @@ void TriggerState::reset() { totalRevolutionCounter = 0; totalTriggerErrorCounter = 0; orderingErrorCounter = 0; + lastDecodingErrorTime = US2NT(-10000000LL); + someSortOfTriggerError = false; memset(toothDurations, 0, sizeof(toothDurations)); curSignal = SHAFT_PRIMARY_FALLING; diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index c0a458ef49..77970be56d 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -74,6 +74,10 @@ public: */ bool shaft_is_synchronized; + efitick_t lastDecodingErrorTime; + // the boolean flag is a performance optimization so that complex comparison is avoided if no error + bool someSortOfTriggerError; + /** * current duration at index zero and previous durations are following */