auto-sync

This commit is contained in:
rusEfi 2015-05-23 00:04:54 -04:00
parent 75e22583d2
commit 3c7d9e5b74
5 changed files with 33 additions and 36 deletions

View File

@ -72,9 +72,10 @@ public:
class ThermistorMath {
public:
ThermistorMath();
thermistor_conf_s currentConfig;
thermistor_curve_s curve;
void init(thermistor_conf_s currentConfig);
void init(thermistor_conf_s *config);
private:
thermistor_conf_s currentConfig;
};
class EngineState {

View File

@ -45,7 +45,9 @@ float getVoutInVoltageDividor(float Vin, float r1, float r2) {
return r2 * Vin / (r1 + r2);
}
float getKelvinTemperature(float resistance, thermistor_curve_s * curve) {
float getKelvinTemperature(ThermistorConf *config, float resistance, ThermistorMath *tm) {
tm->init(&config->config); // implementation checks if config has changed or not
thermistor_curve_s * curve = &tm->curve;
efiAssert(curve != NULL, "thermistor pointer is NULL", NAN);
if (resistance <= 0) {
@ -78,14 +80,14 @@ float getResistance(ThermistorConf *config) {
return resistance;
}
float getTemperatureC(ThermistorConf *config, thermistor_curve_s * curve) {
float getTemperatureC(ThermistorConf *config, ThermistorMath *tm) {
if (!initialized) {
firmwareError("thermstr not initialized");
return NAN;
}
float resistance = getResistance(config);
float kelvinTemperature = getKelvinTemperature(resistance, curve);
float kelvinTemperature = getKelvinTemperature(config, resistance, tm);
return convertKelvinToCelcius(kelvinTemperature);
}
@ -103,7 +105,7 @@ bool isValidIntakeAirTemperature(float temperature) {
* @return coolant temperature, in Celsius
*/
float getCoolantTemperature(DECLARE_ENGINE_PARAMETER_F) {
float temperature = getTemperatureC(&engineConfiguration->clt, &engine->engineState.cltCurve.curve);
float temperature = getTemperatureC(&engineConfiguration->clt, &engine->engineState.cltCurve);
if (!isValidCoolantTemperature(temperature)) {
efiAssert(engineConfiguration!=NULL, "NULL engineConfiguration", NAN);
if (engineConfiguration->hasCltSensor) {
@ -127,9 +129,7 @@ void setThermistorConfiguration(ThermistorConf * thermistor, float tempC1, float
tc->resistance_3 = r3;
}
void prepareThermistorCurve(ThermistorConf * config, thermistor_curve_s * curve) {
efiAssertVoid(config!=NULL, "therm config");
thermistor_conf_s *tc = &config->config;
static void prepareThermistorCurve(thermistor_conf_s *tc, thermistor_curve_s * curve) {
float T1 = tc->tempC_1 + KELV;
float T2 = tc->tempC_2 + KELV;
float T3 = tc->tempC_3 + KELV;
@ -168,7 +168,7 @@ void prepareThermistorCurve(ThermistorConf * config, thermistor_curve_s * curve)
* @return Celsius value
*/
float getIntakeAirTemperature(DECLARE_ENGINE_PARAMETER_F) {
float temperature = getTemperatureC(&engineConfiguration->iat, &engine->engineState.iatCurve.curve);
float temperature = getTemperatureC(&engineConfiguration->iat, &engine->engineState.iatCurve);
if (!isValidIntakeAirTemperature(temperature)) {
efiAssert(engineConfiguration!=NULL, "NULL engineConfiguration", NAN);
if (engineConfiguration->hasIatSensor) {
@ -196,11 +196,8 @@ void setCommonNTCSensor(ThermistorConf *thermistorConf) {
#if EFI_PROD_CODE
static void testCltByR(float resistance) {
float kTemp = getKelvinTemperature(resistance, &engine->engineState.cltCurve.curve);
float kTemp = getKelvinTemperature(&engineConfiguration->clt, resistance, &engine->engineState.cltCurve);
scheduleMsg(logger, "for R=%f we have %f", resistance, (kTemp - KELV));
prepareThermistorCurve(&engineConfiguration->clt, &engine->engineState.cltCurve.curve);
}
#endif
@ -208,10 +205,6 @@ void initThermistors(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) {
logger = sharedLogger;
efiAssertVoid(engine!=NULL, "e NULL initThermistors");
efiAssertVoid(engine->engineConfiguration2!=NULL, "e2 NULL initThermistors");
prepareThermistorCurve(&engineConfiguration->clt,
&engine->engineState.cltCurve.curve);
prepareThermistorCurve(&engineConfiguration->iat,
&engine->engineState.iatCurve.curve);
#if EFI_PROD_CODE
addConsoleActionF("test_clt_by_r", testCltByR);
@ -221,9 +214,15 @@ void initThermistors(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) {
}
ThermistorMath::ThermistorMath() {
memset(&currentConfig, 0, sizeof(currentConfig));
}
void ThermistorMath::init(thermistor_conf_s currentConfig) {
void ThermistorMath::init(thermistor_conf_s *config) {
bool_t isSameConfig = memcmp(config, &currentConfig, sizeof(currentConfig)) == 0;
if (isSameConfig) {
return;
}
memcpy(&currentConfig, config, sizeof(currentConfig));
prepareThermistorCurve(config, &curve);
}

View File

@ -31,9 +31,9 @@ float getTempK(float resistance);
float convertCelciustoF(float tempC);
float convertFtoCelcius(float tempF);
float getKelvinTemperature(float resistance, thermistor_curve_s * curve);
float getKelvinTemperature(ThermistorConf *config, float resistance, ThermistorMath *tm);
float getResistance(ThermistorConf *config);
float getTemperatureC(ThermistorConf *config, thermistor_curve_s * curve);
float getTemperatureC(ThermistorConf *config, ThermistorMath *tm);
float getCoolantTemperature(DECLARE_ENGINE_PARAMETER_F);
bool isValidCoolantTemperature(float temperature);
float getIntakeAirTemperature(DECLARE_ENGINE_PARAMETER_F);
@ -41,7 +41,6 @@ bool isValidIntakeAirTemperature(float temperature);
void setThermistorConfiguration(ThermistorConf * tc, float temp1, float r1, float temp2, float r2, float temp3,
float r3);
void prepareThermistorCurve(ThermistorConf * config, thermistor_curve_s * curve);
class Engine;

View File

@ -367,12 +367,13 @@ static void setOM(int value) {
static char pinNameBuffer[16];
static void printThermistor(const char *msg, ThermistorConf *config, thermistor_curve_s * curve) {
static void printThermistor(const char *msg, ThermistorConf *config, ThermistorMath *tm) {
thermistor_curve_s * curve = &tm->curve;
adc_channel_e adcChannel = config->adcChannel;
float voltage = getVoltageDivided("term", adcChannel);
float r = getResistance(config);
float t = getTemperatureC(config, curve);
float t = getTemperatureC(config, tm);
thermistor_conf_s *tc = &config->config;
@ -428,11 +429,11 @@ static void printTPSInfo(void) {
static void printTemperatureInfo(void) {
#if EFI_ANALOG_SENSORS || defined(__DOXYGEN__)
printThermistor("CLT", &engineConfiguration->clt, &engine->engineState.cltCurve.curve);
printThermistor("CLT", &engineConfiguration->clt, &engine->engineState.cltCurve);
if (!isValidCoolantTemperature(getCoolantTemperature(PASS_ENGINE_PARAMETER_F))) {
scheduleMsg(&logger, "CLT sensing error");
}
printThermistor("IAT", &engineConfiguration->iat, &engine->engineState.iatCurve.curve);
printThermistor("IAT", &engineConfiguration->iat, &engine->engineState.iatCurve);
if (!isValidIntakeAirTemperature(getIntakeAirTemperature(PASS_ENGINE_PARAMETER_F))) {
scheduleMsg(&logger, "IAT sensing error");
}

View File

@ -86,32 +86,29 @@ void testSensors(void) {
testTpsRateOfChange();
testHip9011lookup();
thermistor_curve_s c;
thermistor_curve_s *curve = &c;
ThermistorMath tm;
thermistor_curve_s *curve = &tm.curve;
{
setThermistorConfiguration(&tc, 32, 9500, 75, 2100, 120, 1000);
prepareThermistorCurve(&tc, curve);
float t = getKelvinTemperature(&tc, 2100, &tm);
assertEquals(75 + KELV, t);
assertEquals(-0.003, curve->s_h_a);
assertEquals(0.001, curve->s_h_b);
assertEquals(0.0, curve->s_h_c);
float t = getKelvinTemperature(2100, curve);
assertEquals(75 + KELV, t);
}
{
// 2003 Neon sensor
setThermistorConfiguration(&tc, 0, 32500, 30, 7550, 100, 700);
prepareThermistorCurve(&tc, curve);
float t = getKelvinTemperature(&tc, 38000, &tm);
assertEquals(-2.7983, t - KELV);
assertEqualsM("A", 0.0009, curve->s_h_a);
assertEqualsM("B", 0.0003, curve->s_h_b);
assertEquals(0.0, curve->s_h_c);
float t = getKelvinTemperature(38000, curve);
assertEquals(-2.7983, t - KELV);
}
}