auto-sync

This commit is contained in:
rusEfi 2016-12-23 14:01:45 -05:00
parent 9283b1f39a
commit a73141f687
4 changed files with 12 additions and 7 deletions

View File

@ -58,6 +58,7 @@ public:
ThermistorMath(); ThermistorMath();
void setConfig(thermistor_conf_s *config); void setConfig(thermistor_conf_s *config);
void prepareThermistorCurve(thermistor_conf_s *tc); void prepareThermistorCurve(thermistor_conf_s *tc);
bool isLinearSensor();
float s_h_a; float s_h_a;
float s_h_b; float s_h_b;
float s_h_c; float s_h_c;

View File

@ -49,8 +49,7 @@ float getVoutInVoltageDividor(float Vin, float r1, float r2) {
return r2 * Vin / (r1 + r2); return r2 * Vin / (r1 + r2);
} }
float getKelvinTemperature(ThermistorConf *config, float resistance, ThermistorMath *tm) { float getKelvinTemperature(float resistance, ThermistorMath *tm) {
tm->setConfig(&config->config); // implementation checks if config has changed or not
if (resistance <= 0) { if (resistance <= 0) {
//warning("Invalid resistance in getKelvinTemperature=", resistance); //warning("Invalid resistance in getKelvinTemperature=", resistance);
@ -86,10 +85,12 @@ float getTemperatureC(ThermistorConf *config, ThermistorMath *tm) {
firmwareError(CUSTOM_ERR_THERM, "thermstr not initialized"); firmwareError(CUSTOM_ERR_THERM, "thermstr not initialized");
return NAN; return NAN;
} }
tm->setConfig(&config->config); // implementation checks if configuration has changed or not
float voltage = getVoltageDivided("term", config->adcChannel); float voltage = getVoltageDivided("term", config->adcChannel);
float resistance = getResistance(config, voltage); float resistance = getResistance(config, voltage);
float kelvinTemperature = getKelvinTemperature(config, resistance, tm); float kelvinTemperature = getKelvinTemperature(resistance, tm);
return convertKelvinToCelcius(kelvinTemperature); return convertKelvinToCelcius(kelvinTemperature);
} }
@ -214,7 +215,8 @@ void setCommonNTCSensor(ThermistorConf *thermistorConf) {
#if EFI_PROD_CODE #if EFI_PROD_CODE
static void testCltByR(float resistance) { 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)); scheduleMsg(logger, "for R=%f we have %f", resistance, (kTemp - KELV));
} }
#endif #endif

View File

@ -30,7 +30,7 @@ float getTempK(float resistance);
float convertCelciustoF(float tempC); float convertCelciustoF(float tempC);
float convertFtoCelcius(float tempF); 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 getResistance(ThermistorConf *config, float voltage);
float getTemperatureC(ThermistorConf *config, ThermistorMath *tm); float getTemperatureC(ThermistorConf *config, ThermistorMath *tm);
float getCoolantTemperature(DECLARE_ENGINE_PARAMETER_F); float getCoolantTemperature(DECLARE_ENGINE_PARAMETER_F);

View File

@ -91,7 +91,8 @@ void testSensors(void) {
ThermistorMath tm; ThermistorMath tm;
{ {
setThermistorConfiguration(&tc, 32, 9500, 75, 2100, 120, 1000); 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(75 + KELV, t);
assertEquals(-0.003, tm.s_h_a); assertEquals(-0.003, tm.s_h_a);
@ -103,8 +104,9 @@ void testSensors(void) {
{ {
// 2003 Neon sensor // 2003 Neon sensor
setThermistorConfiguration(&tc, 0, 32500, 30, 7550, 100, 700); 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); assertEquals(-2.7983, t - KELV);
assertEqualsM("A", 0.0009, tm.s_h_a); assertEqualsM("A", 0.0009, tm.s_h_a);