From 1381c814fa81e11352cf6e7ab473077c9e0d0af7 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 4 Mar 2017 20:19:14 -0500 Subject: [PATCH] progress #363 - refactoring, less confusing code and a step towards a bug fix --- .../controllers/trigger/trigger_decoder.cpp | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 47c10d4dae..7a693b3579 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -208,18 +208,23 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no bool isSynchronizationPoint; if (TRIGGER_SHAPE(isSynchronizationNeeded)) { + // this is getting a little out of hand, any ideas? + + bool primaryGap = currentDuration > toothed_previous_duration * TRIGGER_SHAPE(syncRatioFrom) + && currentDuration < toothed_previous_duration * TRIGGER_SHAPE(syncRatioTo); + + bool secondaryGap = cisnan(TRIGGER_SHAPE(secondSyncRatioFrom)) || (toothed_previous_duration > durationBeforePrevious * TRIGGER_SHAPE(secondSyncRatioFrom) + && toothed_previous_duration < durationBeforePrevious * TRIGGER_SHAPE(secondSyncRatioTo)); + + bool thirdGap = cisnan(TRIGGER_SHAPE(thirdSyncRatioFrom)) || (durationBeforePrevious > thirdPreviousDuration * TRIGGER_SHAPE(thirdSyncRatioFrom) + && durationBeforePrevious < thirdPreviousDuration * TRIGGER_SHAPE(thirdSyncRatioTo)); + /** * Here I prefer to have two multiplications instead of one division, that's a micro-optimization */ - isSynchronizationPoint = - currentDuration > toothed_previous_duration * TRIGGER_SHAPE(syncRatioFrom) - && currentDuration < toothed_previous_duration * TRIGGER_SHAPE(syncRatioTo) - && toothed_previous_duration > durationBeforePrevious * TRIGGER_SHAPE(secondSyncRatioFrom) - && toothed_previous_duration < durationBeforePrevious * TRIGGER_SHAPE(secondSyncRatioTo) -// this is getting a little out of hand, any ideas? - && durationBeforePrevious > thirdPreviousDuration * TRIGGER_SHAPE(thirdSyncRatioFrom) - && durationBeforePrevious < thirdPreviousDuration * TRIGGER_SHAPE(thirdSyncRatioTo) -; + isSynchronizationPoint = primaryGap + && secondaryGap + && thirdGap; #if EFI_PROD_CODE || defined(__DOXYGEN__) if (engineConfiguration->isPrintTriggerSynchDetails || someSortOfTriggerError) {