diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 2e618c3dd9..d626adb50e 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -145,7 +145,7 @@ void printSensors(void) { reportSensorF(getCaption(LP_THROTTLE), getTPS(), 2); if (engineConfiguration->hasCltSensor) { - reportSensorF(getCaption(LP_ECT), getCoolantTemperature(), 2); + reportSensorF(getCaption(LP_ECT), getCoolantTemperature(engineConfiguration2), 2); } reportSensorF(getCaption(LP_IAT), getIntakeAirTemperature(), 2); @@ -310,11 +310,11 @@ static void showFuelInfo2(float rpm, float engineLoad) { scheduleMsg(&logger2, "algo=%s/pump=%s", algorithmToString(engineConfiguration->algorithm), boolToString(getOutputPinValue(FUEL_PUMP_RELAY))); - scheduleMsg(&logger2, "cranking fuel: %f", getCrankingFuel()); + scheduleMsg(&logger2, "cranking fuel: %f", getCrankingFuel(&engine)); if (engine.rpmCalculator->isRunning()) { float iatCorrection = getIatCorrection(getIntakeAirTemperature()); - float cltCorrection = getCltCorrection(getCoolantTemperature()); + float cltCorrection = getCltCorrection(getCoolantTemperature(engineConfiguration2)); float injectorLag = getInjectorLag(getVBatt()); scheduleMsg(&logger2, "rpm=%f engineLoad=%f", rpm, engineLoad); scheduleMsg(&logger2, "baseFuel=%f", baseFuel); @@ -357,7 +357,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels) { #endif float tps = getTPS(); - float coolant = getCoolantTemperature(); + float coolant = getCoolantTemperature(engineConfiguration2); float intake = getIntakeAirTemperature(); float engineLoad = getEngineLoad(); @@ -388,13 +388,13 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels) { tsOutputChannels->cylinder_cleanup_enabled = engineConfiguration->isCylinderCleanupEnabled; tsOutputChannels->secondTriggerChannelEnabled = engineConfiguration->secondTriggerChannelEnabled; - tsOutputChannels->isCltError = !isValidCoolantTemperature(getCoolantTemperature()); + tsOutputChannels->isCltError = !isValidCoolantTemperature(getCoolantTemperature(engineConfiguration2)); tsOutputChannels->isIatError = !isValidIntakeAirTemperature(getIntakeAirTemperature()); #endif tsOutputChannels->tCharge = getTCharge(rpm, tps, coolant, intake); tsOutputChannels->sparkDwell = getSparkDwellMs(rpm); tsOutputChannels->pulseWidth = getRunningFuel(baseFuel, &engine, rpm); - tsOutputChannels->crankingFuel = getCrankingFuel(); + tsOutputChannels->crankingFuel = getCrankingFuel(&engine); } extern TunerStudioOutputChannels tsOutputChannels; diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index b512e321a9..538b815928 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -23,7 +23,7 @@ static Logging logger; */ void Engine::updateSlowSensors() { engineState.iat = getIntakeAirTemperature(); - engineState.clt = getCoolantTemperature(); + engineState.clt = getCoolantTemperature(engineConfiguration2); } void Engine::onTriggerEvent(uint64_t nowUs) { diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 9872dd3f7e..ec4d3ab6a9 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -73,7 +73,7 @@ static int getNumberOfInjections(engine_configuration_s const *engineConfigurati */ float getFuelMs(int rpm, Engine *engine) { if (isCranking()) { - return getCrankingFuel() / getNumberOfInjections(engine->engineConfiguration, engine->engineConfiguration->crankingInjectionMode); + return getCrankingFuel(engine) / getNumberOfInjections(engine->engineConfiguration, engine->engineConfiguration->crankingInjectionMode); } else { float baseFuel = getBaseFuel(engine, rpm); float fuelPerCycle = getRunningFuel(baseFuel, engine, rpm); @@ -84,7 +84,7 @@ float getFuelMs(int rpm, Engine *engine) { // todo: start using 'engine' parameter and not 'extern' float getRunningFuel(float baseFuel, Engine *engine, int rpm) { float iatCorrection = getIatCorrection(getIntakeAirTemperature()); - float cltCorrection = getCltCorrection(getCoolantTemperature()); + float cltCorrection = getCltCorrection(getCoolantTemperature(engine->engineConfiguration2)); float injectorLag = getInjectorLag(getVBatt()); #if EFI_ACCEL_ENRICHMENT @@ -154,8 +154,8 @@ float getBaseTableFuel(int rpm, float engineLoad) { /** * @return Duration of fuel injection while craning, in milliseconds */ -float getCrankingFuel(void) { - return getStartingFuel(getCoolantTemperature()); +float getCrankingFuel(Engine *engine) { + return getStartingFuel(getCoolantTemperature(engine->engineConfiguration2)); } float getStartingFuel(float coolantTemperature) { diff --git a/firmware/controllers/algo/fuel_math.h b/firmware/controllers/algo/fuel_math.h index d8288d89f0..11b9b38cf4 100644 --- a/firmware/controllers/algo/fuel_math.h +++ b/firmware/controllers/algo/fuel_math.h @@ -18,7 +18,7 @@ float getIatCorrection(float iat); float getInjectorLag(float vBatt); float getCltCorrection(float clt); float getRunningFuel(float baseFuel, Engine *engine, int rpm); -float getCrankingFuel(void); +float getCrankingFuel(Engine *engine); float getStartingFuel(float coolantTemperature); float getFuelMs(int rpm, Engine *engine); diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index ff6425bd2b..8b3c198417 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -117,7 +117,7 @@ static void updateErrorCodes(void) { * technically we can set error codes right inside the getMethods, but I a bit on a fence about it */ setError(isValidIntakeAirTemperature(getIntakeAirTemperature()), OBD_Intake_Air_Temperature_Circuit_Malfunction); - setError(isValidCoolantTemperature(getCoolantTemperature()), OBD_Engine_Coolant_Temperature_Circuit_Malfunction); + setError(isValidCoolantTemperature(getCoolantTemperature(engineConfiguration2)), OBD_Engine_Coolant_Temperature_Circuit_Malfunction); } static void fanRelayControl(void) { @@ -128,9 +128,9 @@ static void fanRelayControl(void) { int newValue; if (isCurrentlyOn) { // if the fan is already on, we keep it on till the 'fanOff' temperature - newValue = getCoolantTemperature() > engineConfiguration->fanOffTemperature; + newValue = getCoolantTemperature(engineConfiguration2) > engineConfiguration->fanOffTemperature; } else { - newValue = getCoolantTemperature() > engineConfiguration->fanOnTemperature; + newValue = getCoolantTemperature(engineConfiguration2) > engineConfiguration->fanOnTemperature; } if (isCurrentlyOn != newValue) { diff --git a/firmware/controllers/lcd_controller.cpp b/firmware/controllers/lcd_controller.cpp index 6dca705391..af29e6a11b 100644 --- a/firmware/controllers/lcd_controller.cpp +++ b/firmware/controllers/lcd_controller.cpp @@ -43,7 +43,7 @@ static char * prepareVBattMapLine(char *buffer) { static char * prepareCltIatTpsLine(char *buffer) { char *ptr = buffer; *ptr++ = 'C'; - ptr = ftoa(ptr, getCoolantTemperature(), 10.0f); + ptr = ftoa(ptr, getCoolantTemperature(engine.engineConfiguration2), 10.0f); ptr = appendStr(ptr, " C"); ptr = ftoa(ptr, getIntakeAirTemperature(), 10.0f); diff --git a/firmware/controllers/math/speed_density.cpp b/firmware/controllers/math/speed_density.cpp index 1aecf8a828..ef717d2e79 100644 --- a/firmware/controllers/math/speed_density.cpp +++ b/firmware/controllers/math/speed_density.cpp @@ -67,7 +67,7 @@ float getSpeedDensityFuel(Engine *engine, int rpm) { engine_configuration_s *engineConfiguration = engine->engineConfiguration; float tps = getTPS(); - float coolantC = getCoolantTemperature(); + float coolantC = getCoolantTemperature(engine->engineConfiguration2); float intakeC = getIntakeAirTemperature(); float tChargeK = convertCelsiusToKelvin(getTCharge(rpm, tps, coolantC, intakeC)); float map = getMap(); diff --git a/firmware/controllers/sensors/allsensors.c b/firmware/controllers/sensors/allsensors.cpp similarity index 85% rename from firmware/controllers/sensors/allsensors.c rename to firmware/controllers/sensors/allsensors.cpp index 2a43759510..29a103f07b 100644 --- a/firmware/controllers/sensors/allsensors.c +++ b/firmware/controllers/sensors/allsensors.cpp @@ -1,5 +1,5 @@ /** - * @file allsensors.h + * @file allsensors.cpp * @brief * * diff --git a/firmware/controllers/sensors/allsensors.h b/firmware/controllers/sensors/allsensors.h index 9d9a41ed2d..c0c4c9f0e1 100644 --- a/firmware/controllers/sensors/allsensors.h +++ b/firmware/controllers/sensors/allsensors.h @@ -25,16 +25,6 @@ #include "adc_math.h" #endif - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - void initSensors(void); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - #endif /*SENSORS_H_*/ diff --git a/firmware/controllers/sensors/sensors.mk b/firmware/controllers/sensors/sensors.mk index 39d5397340..3b2fb1fa92 100644 --- a/firmware/controllers/sensors/sensors.mk +++ b/firmware/controllers/sensors/sensors.mk @@ -1,9 +1,10 @@ -CONTROLLERS_SENSORS_SRC = $(PROJECT_DIR)/controllers/sensors/allsensors.c \ +CONTROLLERS_SENSORS_SRC = \ $(PROJECT_DIR)/controllers/sensors/maf.c \ $(PROJECT_DIR)/controllers/sensors/voltage.c CONTROLLERS_SENSORS_SRC_CPP = $(PROJECT_DIR)/controllers/sensors/thermistors.cpp \ + $(PROJECT_DIR)/controllers/sensors/allsensors.cpp \ $(PROJECT_DIR)/controllers/sensors/map.cpp \ $(PROJECT_DIR)/controllers/sensors/tps.cpp \ $(PROJECT_DIR)/controllers/sensors/ego.cpp diff --git a/firmware/controllers/sensors/thermistors.cpp b/firmware/controllers/sensors/thermistors.cpp index 1ee176e9ac..b192d7a2eb 100644 --- a/firmware/controllers/sensors/thermistors.cpp +++ b/firmware/controllers/sensors/thermistors.cpp @@ -107,7 +107,7 @@ bool isValidIntakeAirTemperature(float temperature) { /** * @return coolant temperature, in Celsius */ -float getCoolantTemperature(void) { +float getCoolantTemperature(engine_configuration2_s * engineConfiguration2) { float temperature = getTemperatureC(&engineConfiguration2->clt); if (!isValidCoolantTemperature(temperature)) { warning(OBD_PCM_Processor_Fault, "unrealistic CLT %f", temperature); diff --git a/firmware/controllers/sensors/thermistors.h b/firmware/controllers/sensors/thermistors.h index 1a2521b7ef..cef8e445ad 100644 --- a/firmware/controllers/sensors/thermistors.h +++ b/firmware/controllers/sensors/thermistors.h @@ -14,6 +14,7 @@ #define KELV 273.15 #include "sensor_types.h" +#include "ec2.h" #ifdef __cplusplus extern "C" @@ -37,7 +38,7 @@ float convertFtoCelcius(float tempF); float getKelvinTemperature(float resistance, ThermistorConf *thermistor); float getResistance(Thermistor *thermistor); float getTemperatureC(Thermistor *thermistor); -float getCoolantTemperature(void); +float getCoolantTemperature(engine_configuration2_s * engineConfiguration2); bool isValidCoolantTemperature(float temperature); float getIntakeAirTemperature(void); bool isValidIntakeAirTemperature(float temperature); diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 1405894767..97fe2e135e 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -289,7 +289,7 @@ static void printTPSInfo(void) { static void printTemperatureInfo(void) { printThermistor("CLT", &engineConfiguration2->clt); - if (!isValidCoolantTemperature(getCoolantTemperature())) { + if (!isValidCoolantTemperature(getCoolantTemperature(engineConfiguration2))) { scheduleMsg(&logger, "CLT sensing error"); } printThermistor("IAT", &engineConfiguration2->iat); diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 9cd397cf93..5b440578f1 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -241,5 +241,5 @@ void firmwareError(const char *fmt, ...) { } int getRusEfiVersion(void) { - return 20141001; + return 20141002; } diff --git a/unit_tests/main.h b/unit_tests/main.h index ef508a1912..d3580e2528 100644 --- a/unit_tests/main.h +++ b/unit_tests/main.h @@ -46,8 +46,6 @@ void assertTrueM(const char *msg, float actual); void assertFalse(float actual); void assertFalseM(const char *msg, float actual); -float getIntakeAirTemperature(void); -float getCoolantTemperature(void); float getVBatt(void); float getMaf(void); diff --git a/unit_tests/test_fuel_map.cpp b/unit_tests/test_fuel_map.cpp index 3bdbaa29a1..3d3dee464e 100644 --- a/unit_tests/test_fuel_map.cpp +++ b/unit_tests/test_fuel_map.cpp @@ -79,7 +79,7 @@ void testFuelMap(void) { assertEquals(NAN, getIntakeAirTemperature()); float iatCorrection = getIatCorrection(-KELV); assertEqualsM("IAT", 2, iatCorrection); - float cltCorrection = getCltCorrection(getCoolantTemperature()); + float cltCorrection = getCltCorrection(getCoolantTemperature(engineConfiguration2)); assertEqualsM("CLT", 1, cltCorrection); float injectorLag = getInjectorLag(getVBatt()); assertEquals(0, injectorLag);