From 0c01c3d0132f39bade9b82f7244fabc536b8a66e Mon Sep 17 00:00:00 2001 From: Martin Jaeger <17674105+martinjaeger@users.noreply.github.com> Date: Thu, 16 Jan 2020 20:21:08 +0100 Subject: [PATCH] Fixed wrong initialization of static Wh counters --- src/device_status.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/device_status.cpp b/src/device_status.cpp index 84b7914..a945a24 100644 --- a/src/device_status.cpp +++ b/src/device_status.cpp @@ -9,6 +9,7 @@ #include "pcb.h" #include "main.h" +#include "helper.h" #include // for fabs function #include @@ -22,10 +23,20 @@ void DeviceStatus::update_energy() // stores the input/output energy status of previous day and to add // xxx_day_Wh only once per day and increase accuracy - static uint32_t solar_in_total_Wh_prev = solar_in_total_Wh; - static uint32_t load_out_total_Wh_prev = load_out_total_Wh; - static uint32_t bat_chg_total_Wh_prev = bat_chg_total_Wh; - static uint32_t bat_dis_total_Wh_prev = bat_dis_total_Wh; + static uint32_t solar_in_total_Wh_prev; + static uint32_t load_out_total_Wh_prev; + static uint32_t bat_chg_total_Wh_prev; + static uint32_t bat_dis_total_Wh_prev; + + static bool first_call = true; + if (first_call) { + // initialize values with values we got from EEPROM + solar_in_total_Wh_prev = solar_in_total_Wh; + load_out_total_Wh_prev = load_out_total_Wh; + bat_chg_total_Wh_prev = bat_chg_total_Wh; + bat_dis_total_Wh_prev = bat_dis_total_Wh; + first_call = false; + } #if CONFIG_HV_TERMINAL_SOLAR || CONFIG_LV_TERMINAL_SOLAR || CONFIG_PWM_TERMINAL_SOLAR if (solar_terminal.voltage < bat_terminal.voltage) {