From bab1744d1d4cb7f74d7cb21aad38228d25d1b6fb Mon Sep 17 00:00:00 2001 From: rusefi Date: Mon, 4 Nov 2019 22:44:52 -0500 Subject: [PATCH] progress towards #961 --- firmware/controllers/actuators/idle_thread.cpp | 4 ++-- firmware/controllers/algo/engine_configuration.cpp | 2 +- firmware/controllers/sensors/thermistors.cpp | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/firmware/controllers/actuators/idle_thread.cpp b/firmware/controllers/actuators/idle_thread.cpp index 00a5ca1820..4fcd9d0e5f 100644 --- a/firmware/controllers/actuators/idle_thread.cpp +++ b/firmware/controllers/actuators/idle_thread.cpp @@ -293,7 +293,7 @@ static percent_t automaticIdleController(DECLARE_ENGINE_PARAMETER_SIGNATURE) { int idlePidLowerRpm = targetRpm + CONFIG(idlePidRpmDeadZone); if (CONFIG(idlePidRpmUpperLimit) > 0) { engine->engineState.idle.idleState = PID_UPPER; - if (CONFIGB(useIacTableForCoasting) && !cisnan(engine->sensors.clt)) { + if (CONFIGB(useIacTableForCoasting) && hasCltSensor()) { percent_t iacPosForCoasting = interpolate2d("iacCoasting", getCoolantTemperature(), CONFIG(iacCoastingBins), CONFIG(iacCoasting)); newValue = interpolateClamped(idlePidLowerRpm, newValue, idlePidLowerRpm + CONFIG(idlePidRpmUpperLimit), iacPosForCoasting, rpm); } else { @@ -371,7 +371,7 @@ static percent_t automaticIdleController(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #endif /* EFI_SHAFT_POSITION_INPUT */ // cltCorrection is used only for cranking or running in manual mode float cltCorrection; - if (cisnan(clt)) + if (!hasCltSensor()) cltCorrection = 1.0f; // Use separate CLT correction table for cranking else if (engineConfiguration->overrideCrankingIacSetting && !isRunning) { diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index a8cb6977c1..16f3e42365 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -548,7 +548,7 @@ void setTargetRpmCurve(int rpm DECLARE_CONFIG_PARAMETER_SUFFIX) { int getTargetRpmForIdleCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) { float clt = getCoolantTemperature(); int targetRpm; - if (cisnan(clt)) { + if (!hasCltSensor()) { // error is already reported, let's take first value from the table should be good enough error handing solution targetRpm = CONFIG(cltIdleRpm)[0]; } else { diff --git a/firmware/controllers/sensors/thermistors.cpp b/firmware/controllers/sensors/thermistors.cpp index 29377f60b0..76168ed211 100644 --- a/firmware/controllers/sensors/thermistors.cpp +++ b/firmware/controllers/sensors/thermistors.cpp @@ -129,15 +129,14 @@ bool hasCltSensorM(DECLARE_ENGINE_PARAMETER_SIGNATURE) { if (!haveSensorChannel) { return false; } -// return !cisnan(engine->sensors.clt); todo why would unit tests fail?! - return true; + return !cisnan(engine->sensors.clt); } /** * @return coolant temperature, in Celsius */ temperature_t getCoolantTemperatureM(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - if (!hasCltSensor()) { + if (engineConfiguration->clt.adcChannel == EFI_ADC_NONE) { engine->isCltBroken = false; return NO_CLT_SENSOR_TEMPERATURE; } @@ -212,14 +211,18 @@ void ThermistorMath::prepareThermistorCurve(thermistor_conf_s *tc) { } bool hasIatSensorM(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - return engineConfiguration->iat.adcChannel != EFI_ADC_NONE; + bool haveSensorChannel = engineConfiguration->iat.adcChannel != EFI_ADC_NONE; + if (!haveSensorChannel) { + return false; + } + return !cisnan(engine->sensors.iat); } /** * @return Celsius value */ temperature_t getIntakeAirTemperatureM(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - if (!hasIatSensor()) { + if (engineConfiguration->iat.adcChannel == EFI_ADC_NONE) { return NO_IAT_SENSOR_TEMPERATURE; } float temperature = getTemperatureC(&engineConfiguration->iat, &engine->engineState.iatCurve,