diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index c25a1a91cf..913d795d94 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -58,6 +58,7 @@ public: ThermistorMath(); void setConfig(thermistor_conf_s *config); void prepareThermistorCurve(thermistor_conf_s *tc); + bool isLinearSensor(); float s_h_a; float s_h_b; float s_h_c; diff --git a/firmware/controllers/sensors/thermistors.cpp b/firmware/controllers/sensors/thermistors.cpp index db6c693601..5d1b174f8b 100644 --- a/firmware/controllers/sensors/thermistors.cpp +++ b/firmware/controllers/sensors/thermistors.cpp @@ -49,8 +49,7 @@ float getVoutInVoltageDividor(float Vin, float r1, float r2) { return r2 * Vin / (r1 + r2); } -float getKelvinTemperature(ThermistorConf *config, float resistance, ThermistorMath *tm) { - tm->setConfig(&config->config); // implementation checks if config has changed or not +float getKelvinTemperature(float resistance, ThermistorMath *tm) { if (resistance <= 0) { //warning("Invalid resistance in getKelvinTemperature=", resistance); @@ -86,10 +85,12 @@ float getTemperatureC(ThermistorConf *config, ThermistorMath *tm) { firmwareError(CUSTOM_ERR_THERM, "thermstr not initialized"); return NAN; } + tm->setConfig(&config->config); // implementation checks if configuration has changed or not + float voltage = getVoltageDivided("term", config->adcChannel); float resistance = getResistance(config, voltage); - float kelvinTemperature = getKelvinTemperature(config, resistance, tm); + float kelvinTemperature = getKelvinTemperature(resistance, tm); return convertKelvinToCelcius(kelvinTemperature); } @@ -214,7 +215,8 @@ void setCommonNTCSensor(ThermistorConf *thermistorConf) { #if EFI_PROD_CODE static void testCltByR(float resistance) { - float kTemp = getKelvinTemperature(&engineConfiguration->clt, resistance, &engine->engineState.cltCurve); + // we expect slowPeriodicCallback to already update configuration in the curve helper class see setConfig + float kTemp = getKelvinTemperature(resistance, &engine->engineState.cltCurve); scheduleMsg(logger, "for R=%f we have %f", resistance, (kTemp - KELV)); } #endif diff --git a/firmware/controllers/sensors/thermistors.h b/firmware/controllers/sensors/thermistors.h index 254db80d87..4edc9ea85b 100644 --- a/firmware/controllers/sensors/thermistors.h +++ b/firmware/controllers/sensors/thermistors.h @@ -30,7 +30,7 @@ float getTempK(float resistance); float convertCelciustoF(float tempC); float convertFtoCelcius(float tempF); -float getKelvinTemperature(ThermistorConf *config, float resistance, ThermistorMath *tm); +float getKelvinTemperature(float resistance, ThermistorMath *tm); float getResistance(ThermistorConf *config, float voltage); float getTemperatureC(ThermistorConf *config, ThermistorMath *tm); float getCoolantTemperature(DECLARE_ENGINE_PARAMETER_F); diff --git a/unit_tests/test_sensors.cpp b/unit_tests/test_sensors.cpp index 70c5d12c9f..2a177acc88 100644 --- a/unit_tests/test_sensors.cpp +++ b/unit_tests/test_sensors.cpp @@ -91,7 +91,8 @@ void testSensors(void) { ThermistorMath tm; { setThermistorConfiguration(&tc, 32, 9500, 75, 2100, 120, 1000); - float t = getKelvinTemperature(&tc, 2100, &tm); + tm.setConfig(&tc.config); + float t = getKelvinTemperature(2100, &tm); assertEquals(75 + KELV, t); assertEquals(-0.003, tm.s_h_a); @@ -103,8 +104,9 @@ void testSensors(void) { { // 2003 Neon sensor setThermistorConfiguration(&tc, 0, 32500, 30, 7550, 100, 700); + tm.setConfig(&tc.config); - float t = getKelvinTemperature(&tc, 38000, &tm); + float t = getKelvinTemperature(38000, &tm); assertEquals(-2.7983, t - KELV); assertEqualsM("A", 0.0009, tm.s_h_a);