Refactor Trigger System #635

reducing global state magic
This commit is contained in:
rusefi 2019-02-03 02:33:33 -05:00
parent 8fee275f53
commit 4fa48c0ca7
4 changed files with 15 additions and 21 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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_ */

View File

@ -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();
}