diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 6d9f9833e0..989da9c523 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -255,6 +255,10 @@ void Engine::OnTriggerStateProperState(efitick_t nowNt) { rpmCalculator.setSpinningUp(nowNt PASS_ENGINE_PARAMETER_SUFFIX); } +void Engine::OnTriggerSyncronization(bool wasSynchronized) { + +} + void Engine::setConfig(persistent_config_s *config) { this->config = config; diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index b07bff7d21..ef8cdfafb6 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -60,6 +60,7 @@ public: void OnTriggerStateDecodingError() override; void OnTriggerStateProperState(efitick_t nowNt) override; + void OnTriggerSyncronization(bool wasSynchronized) override; void setConfig(persistent_config_s *config); injection_mode_e getCurrentInjectionMode(DECLARE_ENGINE_PARAMETER_SIGNATURE); diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index dba5aa38ea..7243e9ad98 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -638,10 +638,15 @@ void TriggerState::decodeTriggerEvent(const TriggerStateCallback triggerCycleCal if (isSynchronizationPoint) { + if (triggerStateListener) { + triggerStateListener->OnTriggerSyncronization(wasSynchronized); + } + // We only care about trigger shape once we have synchronized trigger. Anything could happen // during first revolution and it's fine if (wasSynchronized) { + /** * We can check if things are fine by comparing the number of events in a cycle with the expected number of event. */ @@ -649,9 +654,9 @@ void TriggerState::decodeTriggerEvent(const TriggerStateCallback triggerCycleCal enginePins.triggerDecoderErrorPin.setValue(isDecodingError); - // 'haveListener' means we are running a real engine and now just preparing trigger shape + // 'triggerStateListener is not null' means we are running a real engine and now just preparing trigger shape // that's a bit of a hack, a sweet OOP solution would be a real callback or at least 'needDecodingErrorLogic' method? - if (isDecodingError && haveListener) { + if (isDecodingError && triggerStateListener) { triggerStateListener->OnTriggerStateDecodingError(); } @@ -678,7 +683,7 @@ void TriggerState::decodeTriggerEvent(const TriggerStateCallback triggerCycleCal toothed_previous_time = nowNt; } - if (!isValidIndex(PASS_ENGINE_PARAMETER_SIGNATURE) && haveListener) { + if (!isValidIndex(PASS_ENGINE_PARAMETER_SIGNATURE) && triggerStateListener) { // let's not show a warning if we are just starting to spin if (GET_RPM_VALUE != 0) { warning(CUSTOM_SYNC_ERROR, "sync error: index #%d above total size %d", currentCycle.current_index, getTriggerSize()); @@ -695,7 +700,7 @@ void TriggerState::decodeTriggerEvent(const TriggerStateCallback triggerCycleCal runtimeStatistics(nowNt PASS_ENGINE_PARAMETER_SUFFIX); // Needed for early instant-RPM detection - if (haveListener) { + if (triggerStateListener) { triggerStateListener->OnTriggerStateProperState(nowNt); } } diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 8c83bfec7c..4c5612db22 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -18,6 +18,7 @@ class TriggerStateListener { public: virtual void OnTriggerStateDecodingError() = 0; virtual void OnTriggerStateProperState(efitick_t nowNt) = 0; + virtual void OnTriggerSyncronization(bool wasSynchronized) = 0; }; typedef void (*TriggerStateCallback)(TriggerState *);