From 749282c80717d8f1fd7ea7d7d1aa22f660b54a1f Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 15 Oct 2020 19:04:42 -0700 Subject: [PATCH] more safe parts probably (#1883) --- .../actuators/electronic_throttle.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 71b15ce7ff..f8df471807 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -829,14 +829,15 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #endif /* EFI_PROD_CODE */ // If you don't have a pedal we have no business here. - if (!Sensor::hasSensor(SensorType::AcceleratorPedalPrimary)) { - return; + if (Sensor::hasSensor(SensorType::AcceleratorPedalPrimary)) { + engine->etbActualCount = Sensor::hasSensor(SensorType::Tps2) ? 2 : 1; + } else { + engine->etbActualCount = 0; } pedal2tpsMap.init(config->pedalToTpsTable, config->pedalToTpsPedalBins, config->pedalToTpsRpmBins); - engine->etbActualCount = Sensor::hasSensor(SensorType::Tps2) ? 2 : 1; - + bool mustHaveEtbConfigured = Sensor::hasSensor(SensorType::AcceleratorPedalPrimary); bool anyEtbConfigured = false; for (int i = 0 ; i < engine->etbActualCount; i++) { @@ -858,6 +859,16 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } } + if (!anyEtbConfigured) { + // It's not valid to have a PPS without any ETBs - check that at least one ETB was enabled along with the pedal + if (mustHaveEtbConfigured) { + firmwareError(OBD_PCM_Processor_Fault, "A pedal position sensor was configured, but no electronic throttles are configured."); + } + + // Don't start the thread if no throttles are in use. + return; + } + #if 0 && ! EFI_UNIT_TEST percent_t startupThrottlePosition = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE); if (absF(startupThrottlePosition - engineConfiguration->etbNeutralPosition) > STARTUP_NEUTRAL_POSITION_ERROR_THRESHOLD) {