From ddf127fff9a8f245f693a887e5c931854260d511 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 24 May 2026 01:15:16 -0700 Subject: [PATCH 1/2] Return actual brake percentage when using BSE off of min/max Signed-off-by: Daniel Hansen --- ECU/Application/Src/StateUtils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ECU/Application/Src/StateUtils.c b/ECU/Application/Src/StateUtils.c index 23ad03c85..13c83920d 100644 --- a/ECU/Application/Src/StateUtils.c +++ b/ECU/Application/Src/StateUtils.c @@ -123,7 +123,7 @@ float CalcBrakePercent(volatile const ECU_StateData *stateData) return 0; #endif - return stateData->bse_signal / 4096.0f; + return (stateData->bse_signal - BSE_MIN) / (float)(BSE_MAX - BSE_MIN); } // TODO: reconsider deadzone From ab0046768cb013198dd40b8e8f0269d432d6639e Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 28 May 2026 21:14:37 -0700 Subject: [PATCH 2/2] Handle under min and over max --- ECU/Application/Src/StateUtils.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ECU/Application/Src/StateUtils.c b/ECU/Application/Src/StateUtils.c index 13c83920d..efef6b4a0 100644 --- a/ECU/Application/Src/StateUtils.c +++ b/ECU/Application/Src/StateUtils.c @@ -123,7 +123,18 @@ float CalcBrakePercent(volatile const ECU_StateData *stateData) return 0; #endif - return (stateData->bse_signal - BSE_MIN) / (float)(BSE_MAX - BSE_MIN); + if (stateData->bse_signal <= BSE_MIN) { + return 0; + } + + const uint16_t numerator = stateData->bse_signal - BSE_MIN; + const uint16_t denominator = BSE_MAX - BSE_MIN; + + if (numerator > denominator) { + return 1.0f; + } + + return (float)numerator / (float)denominator; } // TODO: reconsider deadzone