From 1a7e5b20d952becf90c7d39225b13bd00b9d38e7 Mon Sep 17 00:00:00 2001 From: andreika-git Date: Mon, 26 Jun 2017 21:31:10 +0300 Subject: [PATCH] onConfigurationChangeTriggerCallback() (#448) * onConfigurationChangeTriggerCallback() * conform isTriggerConfigChanged * #if EFI_EMULATE_POSITION_SENSORS * Now it works! * svnversion --- .../controllers/algo/engine_configuration.cpp | 3 +++ .../trigger/main_trigger_callback.cpp | 2 +- .../controllers/trigger/trigger_central.cpp | 27 +++++++++++++++++++ .../controllers/trigger/trigger_central.h | 3 +++ .../trigger/trigger_emulator_algo.cpp | 2 +- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 189f2f7903..dfb5b22e2f 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -170,6 +170,9 @@ void incrementGlobalConfigurationVersion(DECLARE_ENGINE_PARAMETER_SIGNATURE) { onConfigurationChangeIdleCallback(&activeConfiguration); #endif /* EFI_IDLE_CONTROL */ +#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__) + onConfigurationChangeTriggerCallback(&activeConfiguration); +#endif /* EFI_SHAFT_POSITION_INPUT */ rememberCurrentConfiguration(); } diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 2cab270609..88bc8c02b4 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -465,7 +465,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D if (trgEventIndex == 0) { - if (triggerVersion.isOld()) { + if (checkIfTriggerConfigChanged()) { engine->ignitionEvents.isReady = false; // we need to rebuild ignition schedule engine->injectionEvents.isReady = false; // todo: move 'triggerIndexByAngle' change into trigger initialization, why is it invoked from here if it's only about trigger shape & optimization? diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index dde4b72c4e..473a512971 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -78,6 +78,7 @@ uint32_t triggerMaxDuration = 0; static bool isInsideTriggerHandler = false; +static bool isTriggerConfigChanged = false; efitick_t previousVvtCamTime = 0; efitick_t previousVvtCamDuration = 0; @@ -541,6 +542,32 @@ static void resetRunningTriggerCounters() { #endif } +#define COMPARE_CONFIG_PARAMS(param) (engineConfiguration->param != previousConfiguration->param) + +void onConfigurationChangeTriggerCallback(engine_configuration_s *previousConfiguration) { + isTriggerConfigChanged = COMPARE_CONFIG_PARAMS(trigger.type) || + COMPARE_CONFIG_PARAMS(operationMode) || + COMPARE_CONFIG_PARAMS(useOnlyRisingEdgeForTrigger) || + COMPARE_CONFIG_PARAMS(globalTriggerAngleOffset) || + COMPARE_CONFIG_PARAMS(trigger.customTotalToothCount) || + COMPARE_CONFIG_PARAMS(trigger.customSkippedToothCount) || + COMPARE_CONFIG_PARAMS(bc.triggerInputPins[0]) || + COMPARE_CONFIG_PARAMS(bc.triggerInputPins[1]) || + COMPARE_CONFIG_PARAMS(bc.triggerInputPins[2]) || + COMPARE_CONFIG_PARAMS(camInput) || + COMPARE_CONFIG_PARAMS(vvtMode) || + COMPARE_CONFIG_PARAMS(bc.vvtCamSensorUseRise) || + COMPARE_CONFIG_PARAMS(vvtOffset) || + COMPARE_CONFIG_PARAMS(vvtDisplayInverted) || + COMPARE_CONFIG_PARAMS(bc.nb2ratioFrom) || + COMPARE_CONFIG_PARAMS(bc.nb2ratioTo) || + COMPARE_CONFIG_PARAMS(nbVvtIndex); +} + +bool checkIfTriggerConfigChanged(void) { + return isTriggerConfigChanged; +} + void initTriggerCentral(Logging *sharedLogger) { logger = sharedLogger; strcpy((char*) shaft_signal_msg_index, "x_"); diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index f3afebd828..70094c396d 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -63,4 +63,7 @@ void addTriggerEventListener(ShaftPositionListener handler, const char *name, En int isSignalDecoderError(void); void resetMaxValues(); +void onConfigurationChangeTriggerCallback(engine_configuration_s *previousConfiguration); +bool checkIfTriggerConfigChanged(void); + #endif /* TRIGGER_CENTRAL_H_ */ diff --git a/firmware/controllers/trigger/trigger_emulator_algo.cpp b/firmware/controllers/trigger/trigger_emulator_algo.cpp index e6289ae74f..3b3ab416ab 100644 --- a/firmware/controllers/trigger/trigger_emulator_algo.cpp +++ b/firmware/controllers/trigger/trigger_emulator_algo.cpp @@ -121,7 +121,7 @@ void setTriggerEmulatorRPM(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { } static void updateTriggerShapeIfNeeded(PwmConfig *state) { - if (emulatorConfigVersion.isOld()) { + if (checkIfTriggerConfigChanged()) { scheduleMsg(logger, "Stimulator: updating trigger shape: %d/%d %d", emulatorConfigVersion.getVersion(), getGlobalConfigurationVersion(), currentTimeMillis());