From 17b044d941b00cf8a692b0a44671f241b41f933a Mon Sep 17 00:00:00 2001 From: Martin Jaeger <17674105+martinjaeger@users.noreply.github.com> Date: Thu, 11 Jul 2019 17:50:40 +0200 Subject: [PATCH] Improve SOC and load LED behavior at low SOC This commit prevents that the SOC bar shows 2 LEDs already even though the load is still switched of because of low voltage. --- src/leds.cpp | 6 +++--- src/leds.h | 5 ++++- src/main.cpp | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/leds.cpp b/src/leds.cpp index 3196840..f42c10c 100644 --- a/src/leds.cpp +++ b/src/leds.cpp @@ -228,7 +228,7 @@ void leds_toggle_error() } //---------------------------------------------------------------------------- -void leds_update_soc(int soc) +void leds_update_soc(int soc, bool load_off_low_soc) { #ifndef LED_DCDC // if there is no dedicated LED for the DC/DC converter status, blink SOC @@ -246,12 +246,12 @@ void leds_update_soc(int soc) trigger_timeout[LED_SOC_1] = -1; trigger_timeout[LED_SOC_2] = -1; trigger_timeout[LED_SOC_3] = -1; - if (soc > 80) { + if (soc > 80 && !load_off_low_soc) { led_states[LED_SOC_1] = blink_chg; led_states[LED_SOC_2] = LED_STATE_ON; led_states[LED_SOC_3] = LED_STATE_ON; } - else if (soc > 20) { + else if (soc > 20 && !load_off_low_soc) { led_states[LED_SOC_1] = LED_STATE_OFF; led_states[LED_SOC_2] = blink_chg; led_states[LED_SOC_3] = LED_STATE_ON; diff --git a/src/leds.h b/src/leds.h index 633c3a3..28cc0c1 100644 --- a/src/leds.h +++ b/src/leds.h @@ -81,8 +81,11 @@ void leds_flicker(int led, int timeout = -1); void leds_update_1s(); /** Updates SOC LED bar (if existing) + * + * @param soc SOC in percent + * @param load_off_low_soc Prevents showing two SOC LEDs if load is switched off because of low SOC */ -void leds_update_soc(int soc); +void leds_update_soc(int soc, bool load_off_low_soc = false); /** Toggles between even and uneven LEDs switched on/off to create * annoying flashing in case of an error. diff --git a/src/main.cpp b/src/main.cpp index 133f4ef..498462f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -186,7 +186,7 @@ int main() eeprom_update(); leds_update_1s(); - leds_update_soc(charger.soc); + leds_update_soc(charger.soc, load.switch_state == LOAD_STATE_OFF_LOW_SOC); uext_process_1s(); thingset_serial_process_1s();