From 284c32cda89a2c6ffa3d4d57d50d7b4b0debc39c Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 27 Aug 2023 22:03:12 +0300 Subject: [PATCH] Catch polled temp anomalies --- Software/NISSAN-LEAF-BATTERY.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Software/NISSAN-LEAF-BATTERY.cpp b/Software/NISSAN-LEAF-BATTERY.cpp index 0208f369..67b42ff5 100644 --- a/Software/NISSAN-LEAF-BATTERY.cpp +++ b/Software/NISSAN-LEAF-BATTERY.cpp @@ -154,8 +154,14 @@ void update_values_leaf_battery() { temp_polled_min = ((Temp_fromRAW_to_F(temp_raw_min) - 320 ) * 5) / 9; //Convert from F to C temp_polled_max = ((Temp_fromRAW_to_F(temp_raw_max) - 320 ) * 5) / 9; //Convert from F to C - temperature_min = convert2unsignedint16((temp_polled_min)); //add sign if negative - temperature_max = convert2unsignedint16((temp_polled_max)); + if(temp_polled_min < temp_polled_max){ //Catch any edge cases from Temp_fromRAW_to_F function + temperature_min = convert2unsignedint16((temp_polled_min)); + temperature_max = convert2unsignedint16((temp_polled_max)); + } + else{ + temperature_min = convert2unsignedint16((temp_polled_max)); + temperature_max = convert2unsignedint16((temp_polled_min)); + } } }