Trigger: warning code on normal engine start up #669

making more code unit-testable
This commit is contained in:
Andrey 2021-06-25 11:50:23 -04:00
parent 28a27367e5
commit 266e50f4ca
4 changed files with 15 additions and 9 deletions

View File

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

View File

@ -107,7 +107,7 @@ void setTriggerEmulatorRPM(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
efiPrintf("Emulating position sensor(s). RPM=%d", rpm); efiPrintf("Emulating position sensor(s). RPM=%d", rpm);
} }
static void updateTriggerWaveformIfNeeded(PwmConfig *state) { static void updateTriggerWaveformIfNeeded(PwmConfig *state DECLARE_ENGINE_PARAMETER_SUFFIX) {
if (atTriggerVersion < engine->triggerCentral.triggerShape.version) { if (atTriggerVersion < engine->triggerCentral.triggerShape.version) {
atTriggerVersion = engine->triggerCentral.triggerShape.version; atTriggerVersion = engine->triggerCentral.triggerShape.version;
efiPrintf("Stimulator: updating trigger shape: %d/%d %d", atTriggerVersion, efiPrintf("Stimulator: updating trigger shape: %d/%d %d", atTriggerVersion,
@ -127,6 +127,10 @@ static void updateTriggerWaveformIfNeeded(PwmConfig *state) {
static TriggerEmulatorHelper helper; static TriggerEmulatorHelper helper;
static bool hasStimPins = false; static bool hasStimPins = false;
static bool hasInitTriggerEmulator = false;
# if !EFI_UNIT_TEST
static void emulatorApplyPinState(int stateIndex, PwmConfig *state) /* pwm_gen_callback */ { static void emulatorApplyPinState(int stateIndex, PwmConfig *state) /* pwm_gen_callback */ {
if (engine->directSelfStimulation) { if (engine->directSelfStimulation) {
/** /**
@ -143,9 +147,7 @@ static void emulatorApplyPinState(int stateIndex, PwmConfig *state) /* pwm_gen_c
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
} }
static bool hasInitTriggerEmulator = false; static void initTriggerPwm(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
static void initTriggerPwm() {
// No need to start more than once // No need to start more than once
if (hasInitTriggerEmulator) { if (hasInitTriggerEmulator) {
return; return;
@ -195,15 +197,17 @@ void onConfigurationChangeRpmEmulatorCallback(engine_configuration_s *previousCo
setTriggerEmulatorRPM(engineConfiguration->triggerSimulatorFrequency); setTriggerEmulatorRPM(engineConfiguration->triggerSimulatorFrequency);
} }
#endif /* EFI_UNIT_TEST */
void initTriggerEmulator(DECLARE_ENGINE_PARAMETER_SIGNATURE) { void initTriggerEmulator(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
efiPrintf("Emulating %s", getConfigurationName(engineConfiguration->engineType)); efiPrintf("Emulating %s", getConfigurationName(engineConfiguration->engineType));
startTriggerEmulatorPins(); startTriggerEmulatorPins(PASS_ENGINE_PARAMETER_SIGNATURE);
initTriggerEmulatorLogic(); initTriggerEmulatorLogic(PASS_ENGINE_PARAMETER_SIGNATURE);
} }
void startTriggerEmulatorPins() { void startTriggerEmulatorPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
hasStimPins = false; hasStimPins = false;
for (size_t i = 0; i < efi::size(emulatorOutputs); i++) { for (size_t i = 0; i < efi::size(emulatorOutputs); i++) {
triggerSignal.outputPins[i] = &emulatorOutputs[i]; triggerSignal.outputPins[i] = &emulatorOutputs[i];

View File

@ -13,7 +13,7 @@ class PwmConfig;
class MultiChannelStateSequence; class MultiChannelStateSequence;
void initTriggerEmulator(DECLARE_ENGINE_PARAMETER_SIGNATURE); void initTriggerEmulator(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void startTriggerEmulatorPins(); void startTriggerEmulatorPins(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void stopTriggerEmulatorPins(); void stopTriggerEmulatorPins();
void setTriggerEmulatorRPM(int value DECLARE_ENGINE_PARAMETER_SUFFIX); void setTriggerEmulatorRPM(int value DECLARE_ENGINE_PARAMETER_SUFFIX);
void onConfigurationChangeRpmEmulatorCallback(engine_configuration_s *previousConfiguration); void onConfigurationChangeRpmEmulatorCallback(engine_configuration_s *previousConfiguration);

View File

@ -11,6 +11,8 @@
#define EFI_ENABLE_ASSERTS TRUE #define EFI_ENABLE_ASSERTS TRUE
#define EFI_EMULATE_POSITION_SENSORS TRUE
#define EFI_ENGINE_SNIFFER TRUE #define EFI_ENGINE_SNIFFER TRUE
#define EFI_PRINTF_FUEL_DETAILS TRUE #define EFI_PRINTF_FUEL_DETAILS TRUE