Add balancing start/end event

This commit is contained in:
Daniel Öster 2025-01-07 16:01:17 +02:00
parent 54db0a2216
commit a60a1c3b5c
3 changed files with 15 additions and 3 deletions

View file

@ -244,14 +244,18 @@ void update_machineryprotection() {
// If this is the start of the balancing period, capture the current time // If this is the start of the balancing period, capture the current time
if (datalayer.battery.settings.balancing_start_time_ms == 0) { if (datalayer.battery.settings.balancing_start_time_ms == 0) {
datalayer.battery.settings.balancing_start_time_ms = millis(); datalayer.battery.settings.balancing_start_time_ms = millis();
//TODO, raise info event? Forced balancing starting! set_event(EVENT_BALANCING_START, 0);
} else {
clear_event(EVENT_BALANCING_START);
} }
// Check if the elapsed time exceeds the balancing time // Check if the elapsed time exceeds the balancing time
if (millis() - datalayer.battery.settings.balancing_start_time_ms >= datalayer.battery.settings.balancing_time_ms) { if (millis() - datalayer.battery.settings.balancing_start_time_ms >= datalayer.battery.settings.balancing_time_ms) {
datalayer.battery.settings.user_requests_balancing = false; datalayer.battery.settings.user_requests_balancing = false;
datalayer.battery.settings.balancing_start_time_ms = 0; // Reset the start time datalayer.battery.settings.balancing_start_time_ms = 0; // Reset the start time
//TODO, raise info event? Balancing time elapsed. Turning off... set_event(EVENT_BALANCING_END, 0);
} else {
clear_event(EVENT_BALANCING_END);
} }
} }
} }

View file

@ -159,6 +159,8 @@ void init_events(void) {
events.entries[EVENT_SOC_PLAUSIBILITY_ERROR].level = EVENT_LEVEL_WARNING; events.entries[EVENT_SOC_PLAUSIBILITY_ERROR].level = EVENT_LEVEL_WARNING;
events.entries[EVENT_SOC_UNAVAILABLE].level = EVENT_LEVEL_WARNING; events.entries[EVENT_SOC_UNAVAILABLE].level = EVENT_LEVEL_WARNING;
events.entries[EVENT_KWH_PLAUSIBILITY_ERROR].level = EVENT_LEVEL_INFO; events.entries[EVENT_KWH_PLAUSIBILITY_ERROR].level = EVENT_LEVEL_INFO;
events.entries[EVENT_BALANCING_START].level = EVENT_LEVEL_INFO;
events.entries[EVENT_BALANCING_END].level = EVENT_LEVEL_INFO;
events.entries[EVENT_BATTERY_EMPTY].level = EVENT_LEVEL_INFO; events.entries[EVENT_BATTERY_EMPTY].level = EVENT_LEVEL_INFO;
events.entries[EVENT_BATTERY_FULL].level = EVENT_LEVEL_INFO; events.entries[EVENT_BATTERY_FULL].level = EVENT_LEVEL_INFO;
events.entries[EVENT_BATTERY_FROZEN].level = EVENT_LEVEL_INFO; events.entries[EVENT_BATTERY_FROZEN].level = EVENT_LEVEL_INFO;
@ -302,6 +304,10 @@ const char* get_event_message_string(EVENTS_ENUM_TYPE event) {
return "Warning: SOC not sent by BMS. Calibrate BMS via app."; return "Warning: SOC not sent by BMS. Calibrate BMS via app.";
case EVENT_KWH_PLAUSIBILITY_ERROR: case EVENT_KWH_PLAUSIBILITY_ERROR:
return "Info: kWh remaining reported by battery not plausible. Battery needs cycling."; return "Info: kWh remaining reported by battery not plausible. Battery needs cycling.";
case EVENT_BALANCING_START:
return "Info: Balancing has started";
case EVENT_BALANCING_END:
return "Info: Balancing has ended";
case EVENT_BATTERY_EMPTY: case EVENT_BATTERY_EMPTY:
return "Info: Battery is completely discharged"; return "Info: Battery is completely discharged";
case EVENT_BATTERY_FULL: case EVENT_BATTERY_FULL:

View file

@ -6,7 +6,7 @@
// #define INCLUDE_EVENTS_TEST // Enable to run an event test loop, see events_test_on_target.cpp // #define INCLUDE_EVENTS_TEST // Enable to run an event test loop, see events_test_on_target.cpp
#define EE_MAGIC_HEADER_VALUE 0x0018 // 0x0000 to 0xFFFF #define EE_MAGIC_HEADER_VALUE 0x0019 // 0x0000 to 0xFFFF
#define GENERATE_ENUM(ENUM) ENUM, #define GENERATE_ENUM(ENUM) ENUM,
#define GENERATE_STRING(STRING) #STRING, #define GENERATE_STRING(STRING) #STRING,
@ -45,6 +45,8 @@
XX(EVENT_SOC_PLAUSIBILITY_ERROR) \ XX(EVENT_SOC_PLAUSIBILITY_ERROR) \
XX(EVENT_SOC_UNAVAILABLE) \ XX(EVENT_SOC_UNAVAILABLE) \
XX(EVENT_KWH_PLAUSIBILITY_ERROR) \ XX(EVENT_KWH_PLAUSIBILITY_ERROR) \
XX(EVENT_BALANCING_START) \
XX(EVENT_BALANCING_END) \
XX(EVENT_BATTERY_EMPTY) \ XX(EVENT_BATTERY_EMPTY) \
XX(EVENT_BATTERY_FULL) \ XX(EVENT_BATTERY_FULL) \
XX(EVENT_BATTERY_FROZEN) \ XX(EVENT_BATTERY_FROZEN) \