From da3ef84b5f78d9926ff3cb54c53976d07062a72a Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sun, 9 Mar 2025 12:59:53 -0400 Subject: [PATCH] usability of 3 lobe vs 4 lobe profile curve fix #7583 only:uaefi --- firmware/controllers/engine_controller.cpp | 18 ++++++++++++++++++ unit_tests/tests/test_hpfp.cpp | 2 ++ 2 files changed, 20 insertions(+) diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 5666794a97..9984c00a0f 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -520,11 +520,29 @@ PUBLIC_API_WEAK bool validateBoardConfig() { return true; } +static bool validateGdi() { + auto lobes = engineConfiguration->hpfpCamLobes; + if (!lobes) { + return true; + } + int expectedLastLobeProfileAngle = 360 / lobes; + float actualLastAngle = config->hpfpLobeProfileAngle[HpfpLobeProfile_SIZE - 1]; + if (expectedLastLobeProfileAngle != actualLastAngle) { + criticalError("Last HPFP angle expected %d got %f", expectedLastLobeProfileAngle, actualLastAngle); + return false; + } + + return true; +} + // Returns false if there's an obvious problem with the loaded configuration bool validateConfigOnStartUpOrBurn() { if (!validateBoardConfig()) { return false; } + if (!validateGdi()) { + return false; + } if (config->dynoCarCarMassKg == 0) { setDynoDefaults(); } diff --git a/unit_tests/tests/test_hpfp.cpp b/unit_tests/tests/test_hpfp.cpp index b5e632d726..ffc310c821 100755 --- a/unit_tests/tests/test_hpfp.cpp +++ b/unit_tests/tests/test_hpfp.cpp @@ -13,6 +13,8 @@ TEST(HPFP, Lobe) { engineConfiguration->hpfpPeakPos = 123; engineConfiguration->hpfpCamLobes = 3; + validateConfigOnStartUpOrBurn(); + engine->triggerCentral.vvtPosition[0][0] = 40; // Bank 0 engine->triggerCentral.vvtPosition[0][1] = 80; engine->triggerCentral.vvtPosition[1][0] =120; // Bank 1