From c08e4c3af5315da176271e8ca831a71caa452f32 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 1 Mar 2023 17:20:34 -0500 Subject: [PATCH] only:mre_f4 --- firmware/controllers/sensors/tps.cpp | 21 ++++++++++--------- firmware/controllers/sensors/tps.h | 1 + .../tests/actuators/test_etb_integrated.cpp | 13 ++++++++++++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/firmware/controllers/sensors/tps.cpp b/firmware/controllers/sensors/tps.cpp index 6ca3020ac1..e38684a344 100644 --- a/firmware/controllers/sensors/tps.cpp +++ b/firmware/controllers/sensors/tps.cpp @@ -49,6 +49,15 @@ bool isPedalError() { extern SentTps sentTps; +float decodeTpsSentValue(float sentValue) { + switch (engineConfiguration->sentEtbType) { + case SentEtbType::GM_TYPE_1: + return interpolateMsg("tps", /*x1*/0xE48, /*y1*/0, /*x2*/0x1A0, /*y2*/POSITION_FULLY_OPEN, /*x*/sentValue); + default: + return interpolateMsg("tps", /*x1*/engineConfiguration->customSentTpsMin, /*y1*/0, /*x2*/engineConfiguration->customSentTpsMax, /*y2*/POSITION_FULLY_OPEN, /*x*/sentValue); + } +} + void sentTpsDecode() { #if EFI_SENT_SUPPORT if (!isDigitalTps1()) { @@ -56,16 +65,8 @@ void sentTpsDecode() { } // todo: move away from weird float API float sentValue = getSentValue(0); - float tpsValue; - switch (engineConfiguration->sentEtbType) { - case SentEtbType::GM_TYPE_1: - tpsValue = interpolateClamped(/*x1*/0xE48, /*y1*/0, /*x2*/0x1A0, /*y2*/POSITION_FULLY_OPEN, /*x*/sentValue); - break; - default: - tpsValue = interpolateClamped(/*x1*/engineConfiguration->customSentTpsMin, /*y1*/0, /*x2*/engineConfiguration->customSentTpsMax, /*y2*/POSITION_FULLY_OPEN, /*x*/sentValue); - break; - } + float tpsValue = decodeTpsSentValue(sentValue); sentTps.setValidValue(tpsValue, getTimeNowNt()); #endif // EFI_SENT_SUPPORT -} \ No newline at end of file +} diff --git a/firmware/controllers/sensors/tps.h b/firmware/controllers/sensors/tps.h index 019231fe1f..ace1bb788d 100644 --- a/firmware/controllers/sensors/tps.h +++ b/firmware/controllers/sensors/tps.h @@ -37,6 +37,7 @@ void grabPedalIsUp(); void grabPedalIsWideOpen(); void sentTpsDecode(); +float decodeTpsSentValue(float sentValue); bool isDigitalTps1(); bool isTps1Error(); diff --git a/unit_tests/tests/actuators/test_etb_integrated.cpp b/unit_tests/tests/actuators/test_etb_integrated.cpp index 31b03aabe1..c9e3cdea68 100644 --- a/unit_tests/tests/actuators/test_etb_integrated.cpp +++ b/unit_tests/tests/actuators/test_etb_integrated.cpp @@ -152,3 +152,16 @@ TEST(etb, sentTpsIntegrated) { initTps(); doInitElectronicThrottle(); } + +TEST(etb, sentTpsIntegratedDecode) { + EngineTestHelper eth(TEST_ENGINE); // we have a destructor so cannot move EngineTestHelper into utility method + + engineConfiguration->sentEtbType = SentEtbType::GM_TYPE_1; + + ASSERT_NEAR(20.246, decodeTpsSentValue(3000), EPS2D); + + engineConfiguration->sentEtbType = SentEtbType::CUSTOM; + engineConfiguration->customSentTpsMin = 5000; + engineConfiguration->customSentTpsMax = 1000; + ASSERT_NEAR(75, decodeTpsSentValue(2000), EPS2D); +}