refactoring: reducing code duplication

This commit is contained in:
rusefi 2019-10-21 23:47:40 -04:00
parent 2ee280be5b
commit 88348ebd09
6 changed files with 25 additions and 25 deletions

View File

@ -184,7 +184,7 @@ void incrementGlobalConfigurationVersion(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#endif /* EFI_IDLE_CONTROL */
#if EFI_SHAFT_POSITION_INPUT
onConfigurationChangeTriggerCallback(&activeConfiguration PASS_ENGINE_PARAMETER_SUFFIX);
onConfigurationChangeTriggerCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif /* EFI_SHAFT_POSITION_INPUT */
#if EFI_EMULATE_POSITION_SENSORS
onConfigurationChangeRpmEmulatorCallback(&activeConfiguration);

View File

@ -78,4 +78,6 @@
x.config = config; \
x.boardConfiguration = boardConfiguration;
#define isConfigurationChanged(x) (engineConfiguration->x != activeConfiguration.x)
#endif /* CONTROLLERS_CORE_COMMON_HEADERS_H_ */

View File

@ -32,8 +32,6 @@
extern persistent_config_container_s persistentState; \
extern persistent_config_s *config; \
#define isConfigurationChanged(x) (engineConfiguration->x != activeConfiguration.x)
#define EXTERN_ENGINE \
extern Engine ___engine; \
extern Engine *engine; \

View File

@ -667,31 +667,29 @@ static void resetRunningTriggerCounters() {
#endif
}
#define COMPARE_CONFIG_PARAMS(param) (engineConfiguration->param != previousConfiguration->param)
void onConfigurationChangeTriggerCallback(engine_configuration_s *previousConfiguration DECLARE_ENGINE_PARAMETER_SUFFIX) {
void onConfigurationChangeTriggerCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
bool changed = false;
for (int i = 0; i < CAM_INPUTS_COUNT; i++) {
changed |= COMPARE_CONFIG_PARAMS(camInputs[i]);
changed |= isConfigurationChanged(camInputs[i]);
}
changed |=
COMPARE_CONFIG_PARAMS(trigger.type) ||
COMPARE_CONFIG_PARAMS(ambiguousOperationMode) ||
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(vvtMode) ||
COMPARE_CONFIG_PARAMS(bc.vvtCamSensorUseRise) ||
COMPARE_CONFIG_PARAMS(vvtOffset) ||
COMPARE_CONFIG_PARAMS(vvtDisplayInverted) ||
COMPARE_CONFIG_PARAMS(bc.miataNb2VVTRatioFrom) ||
COMPARE_CONFIG_PARAMS(bc.miataNb2VVTRatioTo) ||
COMPARE_CONFIG_PARAMS(nbVvtIndex);
isConfigurationChanged(trigger.type) ||
isConfigurationChanged(ambiguousOperationMode) ||
isConfigurationChanged(useOnlyRisingEdgeForTrigger) ||
isConfigurationChanged(globalTriggerAngleOffset) ||
isConfigurationChanged(trigger.customTotalToothCount) ||
isConfigurationChanged(trigger.customSkippedToothCount) ||
isConfigurationChanged(bc.triggerInputPins[0]) ||
isConfigurationChanged(bc.triggerInputPins[1]) ||
isConfigurationChanged(bc.triggerInputPins[2]) ||
isConfigurationChanged(vvtMode) ||
isConfigurationChanged(bc.vvtCamSensorUseRise) ||
isConfigurationChanged(vvtOffset) ||
isConfigurationChanged(vvtDisplayInverted) ||
isConfigurationChanged(bc.miataNb2VVTRatioFrom) ||
isConfigurationChanged(bc.miataNb2VVTRatioTo) ||
isConfigurationChanged(nbVvtIndex);
if (changed) {
assertEngineReference();

View File

@ -69,7 +69,7 @@ void addTriggerEventListener(ShaftPositionListener handler, const char *name, En
int isSignalDecoderError(void);
void resetMaxValues();
void onConfigurationChangeTriggerCallback(engine_configuration_s *previousConfiguration DECLARE_ENGINE_PARAMETER_SUFFIX);
void onConfigurationChangeTriggerCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE);
bool checkIfTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE);
bool isTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE);

View File

@ -72,7 +72,9 @@ void print(const char *fmt, ...);
#define CCM_OPTIONAL
#define EXTERN_ENGINE extern EnginePins enginePins
#define EXTERN_ENGINE extern EnginePins enginePins; \
extern engine_configuration_s activeConfiguration
#define EXTERN_CONFIG