diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 9c2f6b666b..9d56a0849a 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -343,6 +343,12 @@ public: IgnitionEventList ignitionEvents; int getGlobalConfigurationVersion(void) const; + /** + * true if a recent configuration change has changed any of the trigger settings which + * we have not adjusted for yet + */ + bool isTriggerConfigChanged = false; + // a pointer with interface type would make this code nicer but would carry extra runtime // cost to resolve pointer, we use instances as a micro optimization diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 3cfca07e04..f4ff931fe4 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -63,12 +63,6 @@ WaveChart waveChart; EXTERN_ENGINE; -/** - * true if a recent configuration change has changed any of the trigger settings which - * we have not adjusted for yet - */ -static bool isTriggerConfigChanged = false; - #if EFI_HISTOGRAMS || defined(__DOXYGEN__) static histogram_s triggerCallbackHistogram; #endif /* EFI_HISTOGRAMS */ @@ -678,28 +672,24 @@ void onConfigurationChangeTriggerCallback(engine_configuration_s *previousConfig #endif } #if EFI_DEFAILED_LOGGING - scheduleMsg(logger, "isTriggerConfigChanged=%d", isTriggerConfigChanged); + scheduleMsg(logger, "isTriggerConfigChanged=%d", engine->isTriggerConfigChanged); #endif /* EFI_DEFAILED_LOGGING */ // we do not want to miss two updates in a row - isTriggerConfigChanged = isTriggerConfigChanged || changed; + engine->isTriggerConfigChanged = engine->isTriggerConfigChanged || changed; } /** * @returns true if configuration just changed, and if that change has affected trigger */ bool checkIfTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - bool result = triggerVersion.isOld(engine->getGlobalConfigurationVersion()) && isTriggerConfigChanged; - isTriggerConfigChanged = false; // whoever has called the method is supposed to react to changes + bool result = triggerVersion.isOld(engine->getGlobalConfigurationVersion()) && engine->isTriggerConfigChanged; + engine->isTriggerConfigChanged = false; // whoever has called the method is supposed to react to changes return result; } -bool readIfTriggerConfigChangedForUnitTest(void) { - return isTriggerConfigChanged; -} - -void resetTriggerConfigChangedForUnitTest(void) { - isTriggerConfigChanged = false; +bool readIfTriggerConfigChangedForUnitTest(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + return engine->isTriggerConfigChanged; } void initTriggerCentral(Logging *sharedLogger) { diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index 879fb660d5..813e2d2258 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -68,7 +68,6 @@ void resetMaxValues(); void onConfigurationChangeTriggerCallback(engine_configuration_s *previousConfiguration DECLARE_ENGINE_PARAMETER_SUFFIX); bool checkIfTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE); -bool readIfTriggerConfigChangedForUnitTest(void); -void resetTriggerConfigChangedForUnitTest(void); +bool readIfTriggerConfigChangedForUnitTest(DECLARE_ENGINE_PARAMETER_SIGNATURE); #endif /* TRIGGER_CENTRAL_H_ */ diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index 6e8e0471c6..e7c5e20f41 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -75,7 +75,6 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persiste engine->initializeTriggerShape(NULL PASS_ENGINE_PARAMETER_SUFFIX); engine->triggerCentral.addEventListener(rpmShaftPositionCallback, "rpm reporter", engine); engine->triggerCentral.addEventListener(mainTriggerCallback, "main loop", engine); - resetTriggerConfigChangedForUnitTest(); } /** @@ -213,11 +212,11 @@ void setupSimpleTestEngineWithMaf(EngineTestHelper *eth, injection_mode_e inject engine->updateSlowSensors(PASS_ENGINE_PARAMETER_SIGNATURE); ASSERT_NEAR( 70, engine->sensors.clt, EPS4D) << "CLT"; - ASSERT_EQ( 0, readIfTriggerConfigChangedForUnitTest()) << "trigger #1"; + ASSERT_EQ( 0, readIfTriggerConfigChangedForUnitTest(PASS_ENGINE_PARAMETER_SIGNATURE)) << "trigger #1"; engineConfiguration->trigger.type = trigger; incrementGlobalConfigurationVersion(PASS_ENGINE_PARAMETER_SIGNATURE); - ASSERT_EQ( 1, readIfTriggerConfigChangedForUnitTest()) << "trigger #2"; + ASSERT_EQ( 1, readIfTriggerConfigChangedForUnitTest(PASS_ENGINE_PARAMETER_SIGNATURE)) << "trigger #2"; eth->applyTriggerShape(); }