From 85976ed63dd78d6c02a58d5b0d8c6fd838f216e6 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sat, 17 Dec 2022 15:23:32 -0500 Subject: [PATCH] guards --- firmware/console/status_loop.cpp | 6 +-- .../engine_cycle/rpm_calculator.cpp | 49 ++++++++++--------- firmware/development/engine_emulator.cpp | 2 + firmware/hw_layer/mmc_card.cpp | 2 + 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 122e9933ca..d90adce09d 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -765,15 +765,15 @@ void updateTunerStudioState() { tsOutputChannels->revolutionCounterSinceStart = engine->rpmCalculator.getRevolutionCounterSinceStart(); #if EFI_CAN_SUPPORT - postCanState(); + postCanState(); #endif /* EFI_CAN_SUPPORT */ #if EFI_CLOCK_LOCKS - tsOutputChannels->maxLockedDuration = NT2US(maxLockedDuration); - tsOutputChannels->maxTriggerReentrant = maxTriggerReentrant; + tsOutputChannels->maxLockedDuration = NT2US(maxLockedDuration); #endif /* EFI_CLOCK_LOCKS */ #if EFI_SHAFT_POSITION_INPUT + tsOutputChannels->maxTriggerReentrant = maxTriggerReentrant; tsOutputChannels->triggerPrimaryFall = engine->triggerCentral.getHwEventCounter((int)SHAFT_PRIMARY_FALLING); tsOutputChannels->triggerPrimaryRise = engine->triggerCentral.getHwEventCounter((int)SHAFT_PRIMARY_RISING); diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index 20d74d76b1..bbd695c78d 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -19,12 +19,9 @@ #include "trigger_central.h" #include "tooth_logger.h" -#if EFI_PROD_CODE -#endif /* EFI_PROD_CODE */ - #if EFI_SENSOR_CHART #include "sensor_chart.h" -#endif +#endif // EFI_SENSOR_CHART #include "engine_sniffer.h" @@ -63,6 +60,30 @@ float RpmCalculator::getCachedRpm() const { return cachedRpmValue; } +operation_mode_e lookupOperationMode() { + if (engineConfiguration->twoStroke) { + return TWO_STROKE; + } else { + return engineConfiguration->skippedWheelOnCam ? FOUR_STROKE_CAM_SENSOR : FOUR_STROKE_CRANK_SENSOR; + } +} + +// todo: move to triggerCentral/triggerShape since has nothing to do with rotation state! +operation_mode_e RpmCalculator::getOperationMode() const { +#if EFI_SHAFT_POSITION_INPUT + // Ignore user-provided setting for well known triggers. + if (doesTriggerImplyOperationMode(engineConfiguration->trigger.type)) { + // For example for Miata NA, there is no reason to allow user to set FOUR_STROKE_CRANK_SENSOR + return engine->triggerCentral.triggerShape.getWheelOperationMode(); + } else +#endif // EFI_SHAFT_POSITION_INPUT + { + // For example 36-1, could be on either cam or crank, so we have to ask the user + return lookupOperationMode(); + } +} + + #if EFI_SHAFT_POSITION_INPUT RpmCalculator::RpmCalculator() : @@ -118,26 +139,6 @@ static bool doesTriggerImplyOperationMode(trigger_type_e type) { } } -operation_mode_e lookupOperationMode() { - if (engineConfiguration->twoStroke) { - return TWO_STROKE; - } else { - return engineConfiguration->skippedWheelOnCam ? FOUR_STROKE_CAM_SENSOR : FOUR_STROKE_CRANK_SENSOR; - } -} - -// todo: move to triggerCentral/triggerShape since has nothing to do with rotation state! -operation_mode_e RpmCalculator::getOperationMode() const { - // Ignore user-provided setting for well known triggers. - if (doesTriggerImplyOperationMode(engineConfiguration->trigger.type)) { - // For example for Miata NA, there is no reason to allow user to set FOUR_STROKE_CRANK_SENSOR - return engine->triggerCentral.triggerShape.getWheelOperationMode(); - } else { - // For example 36-1, could be on either cam or crank, so we have to ask the user - return lookupOperationMode(); - } -} - void RpmCalculator::assignRpmValue(float floatRpmValue) { previousRpmValue = cachedRpmValue; diff --git a/firmware/development/engine_emulator.cpp b/firmware/development/engine_emulator.cpp index 3481477a83..e4966ae90f 100644 --- a/firmware/development/engine_emulator.cpp +++ b/firmware/development/engine_emulator.cpp @@ -22,5 +22,7 @@ void initEngineEmulator() { initPotentiometers(); #endif /* EFI_POTENTIOMETER && HAL_USE_SPI*/ +#if EFI_EMULATE_POSITION_SENSORS initTriggerEmulator(); +#endif // EFI_EMULATE_POSITION_SENSORS } diff --git a/firmware/hw_layer/mmc_card.cpp b/firmware/hw_layer/mmc_card.cpp index 78d2173652..9b8b1a9f9a 100644 --- a/firmware/hw_layer/mmc_card.cpp +++ b/firmware/hw_layer/mmc_card.cpp @@ -575,6 +575,7 @@ void mlgLogger() { } static void sdTriggerLogger() { +#if EFI_TOOTH_LOGGER EnableToothLogger(); while (true) { @@ -584,6 +585,7 @@ static void sdTriggerLogger() { ReturnToothLoggerBuffer(buffer); } +#endif /* EFI_TOOTH_LOGGER */ } bool isSdCardAlive(void) {