From 1cc71ef8ecef038775f5e2a1066f96212fdfa0e6 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Tue, 10 Dec 2019 00:07:46 -0500 Subject: [PATCH] dual-ETB progress --- firmware/controllers/engine_controller.cpp | 2 +- firmware/controllers/sensors/tps.cpp | 25 +++++++++++++++------- firmware/controllers/sensors/tps.h | 2 +- unit_tests/tests/test_sensors.cpp | 4 ++-- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 202abfe541..e8d29a4086 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -819,6 +819,6 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20191206; + return 20191209; } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/sensors/tps.cpp b/firmware/controllers/sensors/tps.cpp index 4ded0610bc..594464ae12 100644 --- a/firmware/controllers/sensors/tps.cpp +++ b/firmware/controllers/sensors/tps.cpp @@ -1,5 +1,5 @@ /** - * @author Andrey Belomutskiy, (c) 2012-2018 + * @author Andrey Belomutskiy, (c) 2012-2019 */ #include "engine.h" #include "tps.h" @@ -78,7 +78,7 @@ float getTpsRateOfChange(void) { * Return current TPS position based on configured ADC levels, and adc * * */ -percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_SUFFIX) { +percent_t getTpsValue(int index, int adc DECLARE_ENGINE_PARAMETER_SUFFIX) { DISPLAY_STATE(Engine) DISPLAY_TAG(TPS_SECTION); @@ -109,9 +109,16 @@ percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_SUFFIX) { DISPLAY_TEXT(Current_ADC) DISPLAY(DISPLAY_FIELD(currentTpsAdc)) DISPLAY_TEXT(interpolate_between) - float result = interpolateMsg("TPS", TPS_TS_CONVERSION * CONFIG(DISPLAY_CONFIG(tpsMax)), 100, - DISPLAY_TEXT(and) - TPS_TS_CONVERSION * CONFIG(DISPLAY_CONFIG(tpsMin)), 0, adc); + + DISPLAY(DISPLAY_CONFIG(tpsMax)) + DISPLAY_TEXT(and) + DISPLAY(DISPLAY_CONFIG(tpsMin)) + + int tpsMax = index == 0 ? CONFIG(tpsMax) : CONFIG(tps2Max); + int tpsMin = index == 0 ? CONFIG(tpsMin) : CONFIG(tps2Min); + + float result = interpolateMsg("TPS", TPS_TS_CONVERSION * tpsMax, 100, + TPS_TS_CONVERSION * tpsMin, 0, adc); if (result < engineConfiguration->tpsErrorDetectionTooLow) { #if EFI_PROD_CODE // too much noise with simulator @@ -140,6 +147,7 @@ float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE) { * Return TPS ADC readings. * We need ADC value because TunerStudio has a nice TPS configuration wizard, and this wizard * wants a TPS value. + * @param index [0, ETB_COUNT) */ int getTPS12bitAdc(int index DECLARE_ENGINE_PARAMETER_SUFFIX) { #if !EFI_PROD_CODE @@ -197,8 +205,9 @@ void grabPedalIsWideOpen() { /** * @brief Position on physical primary TPS */ -static percent_t getPrimatyRawTPS(int index DECLARE_ENGINE_PARAMETER_SUFFIX) { - percent_t tpsValue = getTpsValue(getTPS12bitAdc(index PASS_ENGINE_PARAMETER_SUFFIX) PASS_ENGINE_PARAMETER_SUFFIX); +static percent_t getPrimaryRawTPS(int index DECLARE_ENGINE_PARAMETER_SUFFIX) { + int adcValue = getTPS12bitAdc(index PASS_ENGINE_PARAMETER_SUFFIX); + percent_t tpsValue = getTpsValue(index, adcValue PASS_ENGINE_PARAMETER_SUFFIX); return tpsValue; } @@ -238,7 +247,7 @@ percent_t getTPSWithIndex(int index DECLARE_ENGINE_PARAMETER_SUFFIX) { // todo: blah blah // todo: if two TPS do not match - show OBD code via malfunction_central.c - return getPrimatyRawTPS(index PASS_ENGINE_PARAMETER_SUFFIX); + return getPrimaryRawTPS(index PASS_ENGINE_PARAMETER_SUFFIX); } percent_t getTPS(DECLARE_ENGINE_PARAMETER_SIGNATURE) { diff --git a/firmware/controllers/sensors/tps.h b/firmware/controllers/sensors/tps.h index cd12176012..7d23e5a103 100644 --- a/firmware/controllers/sensors/tps.h +++ b/firmware/controllers/sensors/tps.h @@ -30,7 +30,7 @@ int convertVoltageTo10bitADC(float voltage); int getTPS12bitAdc(int index DECLARE_ENGINE_PARAMETER_SUFFIX); #define getTPS10bitAdc() (getTPS12bitAdc(0 PASS_ENGINE_PARAMETER_SUFFIX) / TPS_TS_CONVERSION) float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE); -percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_SUFFIX); +percent_t getTpsValue(int index, int adc DECLARE_ENGINE_PARAMETER_SUFFIX); void setBosch0280750009(DECLARE_ENGINE_PARAMETER_SIGNATURE); void setMockTpsAdc(percent_t tpsPosition DECLARE_ENGINE_PARAMETER_SUFFIX); void setMockTpsValue(percent_t tpsPosition DECLARE_ENGINE_PARAMETER_SUFFIX); diff --git a/unit_tests/tests/test_sensors.cpp b/unit_tests/tests/test_sensors.cpp index 4bfb6994b3..8852c2e21e 100644 --- a/unit_tests/tests/test_sensors.cpp +++ b/unit_tests/tests/test_sensors.cpp @@ -34,12 +34,12 @@ TEST(sensors, tps) { engineConfiguration->tpsMax = 193; engineConfiguration->tpsMin = 43; - ASSERT_NEAR(49.3333, getTpsValue(4 * 117 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); + ASSERT_NEAR(49.3333, getTpsValue(0, 4 * 117 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); engineConfiguration->tpsMax = 43; engineConfiguration->tpsMin = 193; - assertEqualsM("test#2", 50.6667, getTpsValue(4 * 117 PASS_ENGINE_PARAMETER_SUFFIX)); + assertEqualsM("test#2", 50.6667, getTpsValue(0, 4 * 117 PASS_ENGINE_PARAMETER_SUFFIX)); } TEST(sensors, testTpsRateOfChange) {