From f6f4d520d7a38466373fe156025fc6e507a75d4c Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 6 Feb 2024 15:00:20 +0200 Subject: [PATCH] Fix average temperature calculation --- Software/src/inverter/BYD-CAN.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Software/src/inverter/BYD-CAN.cpp b/Software/src/inverter/BYD-CAN.cpp index 1b0cc036d..3909cc2b7 100644 --- a/Software/src/inverter/BYD-CAN.cpp +++ b/Software/src/inverter/BYD-CAN.cpp @@ -109,8 +109,9 @@ CAN_frame_t BYD_210 = {.FIR = {.B = static int discharge_current = 0; static int charge_current = 0; static int initialDataSent = 0; -static int temperature_average = 0; - +static int16_t temperature_average = 0; +static int16_t temp_min = 0; +static int16_t temp_max = 0; static int inverter_voltage = 0; static int inverter_SOC = 0; static long inverter_timestamp = 0; @@ -134,7 +135,9 @@ void update_values_can_byd() { //This function maps all the values fetched from MAXDISCHARGEAMP; //Cap the value to the max allowed Amp. Some inverters cannot handle large values. } - temperature_average = ((temperature_max + temperature_min) / 2); + temp_min = temperature_min; //Convert from unsigned to signed + temp_max = temperature_max; + temperature_average = ((temp_max + temp_min) / 2); //Map values to CAN messages //Maxvoltage (eg 400.0V = 4000 , 16bits long)