Skip to content

Commit 863f826

Browse files
committed
Refactor threshold usage to use monitor_config values
Removed hardcoded temperature and SOC threshold macros from lvgl_main_screen.h and updated lvgl_updates.cpp to use threshold values from monitor_config.h. Also adjusted bmsLowCellVoltageThresholds in monitor_config.h to new warnHigh and critHigh values. This centralizes threshold configuration and improves maintainability.
1 parent 524551b commit 863f826

File tree

3 files changed

+10
-21
lines changed

3 files changed

+10
-21
lines changed

inc/sp140/lvgl/lvgl_main_screen.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@ enum ScreenPage {
2121
#define LVGL_PURPLE lv_color_make(128, 0, 128)
2222
#define LVGL_GRAY lv_color_make(128, 128, 128)
2323

24-
// Temperature thresholds
25-
#define BATT_TEMP_WARNING 45.0f
26-
#define BATT_TEMP_CRITICAL 55.0f
27-
#define ESC_TEMP_WARNING 90.0f
28-
#define ESC_TEMP_CRITICAL 100.0f
29-
#define MOTOR_TEMP_WARNING 90.0f
30-
#define MOTOR_TEMP_CRITICAL 110.0f
31-
32-
#define BATT_CRITICAL_SOC_THRESHOLD 5.0f
33-
#define BATT_WARNING_SOC_THRESHOLD 20.0f
34-
#define CELL_VOLTAGE_WARNING 3.2f
35-
#define CELL_VOLTAGE_CRITICAL 2.95f
3624

3725
// LVGL styles for temperature warnings and critical states
3826
extern lv_style_t style_warning;

inc/sp140/monitor_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static const Thresholds motorTempThresholds = {.warnLow = -20, .warnHigh = 90, .
1515
static const Thresholds bmsTempThresholds = {.warnLow = -10, .warnHigh = 50, .critLow = -15, .critHigh = 60};
1616
static const Thresholds bmsCellTempThresholds = {.warnLow = -10, .warnHigh = 50, .critLow = -15, .critHigh = 56};
1717
static const Thresholds bmsHighCellVoltageThresholds = {.warnLow = 0.0, .warnHigh = 4.1, .critLow = 0.0, .critHigh = 4.2};
18-
static const Thresholds bmsLowCellVoltageThresholds = {.warnLow = 3.2, .warnHigh = 5.0, .critLow = 3.0, .critHigh = 5.0};
18+
static const Thresholds bmsLowCellVoltageThresholds = {.warnLow = 3.2, .warnHigh = 4.5, .critLow = 3.0, .critHigh = 4.8};
1919
static const Thresholds bmsSOCThresholds = {.warnLow = 15.0, .warnHigh = 101.0, .critLow = 5.0, .critHigh = 110.0};
2020
static const Thresholds bmsTotalVoltageThresholds = {.warnLow = 79.2, .warnHigh = 100.4, .critLow = 69.6, .critHigh = 100.8};
2121
static const Thresholds bmsVoltageDifferentialThresholds = {.warnLow = -1.0, .warnHigh = 0.2, .critLow = -2.0, .critHigh = 0.4};

src/sp140/lvgl/lvgl_updates.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "../../../inc/sp140/lvgl/lvgl_updates.h"
22
#include "../../../inc/sp140/esp32s3-config.h"
3+
#include "../../../inc/sp140/monitor_config.h" // For direct threshold access
34
#include "../../../inc/sp140/globals.h"
45
#include "../../../inc/sp140/vibration_pwm.h"
56
#include "../../../inc/sp140/shared-config.h"
@@ -352,9 +353,9 @@ void updateLvglMainScreen(
352353

353354
// Set color based on percentage
354355
lv_color_t batteryColor = LVGL_RED;
355-
if (batteryPercent >= BATT_WARNING_SOC_THRESHOLD) {
356+
if (batteryPercent >= bmsSOCThresholds.warnLow) {
356357
batteryColor = LVGL_GREEN;
357-
} else if (batteryPercent >= BATT_CRITICAL_SOC_THRESHOLD) {
358+
} else if (batteryPercent >= bmsSOCThresholds.critLow) {
358359
batteryColor = LVGL_YELLOW;
359360
}
360361

@@ -654,10 +655,10 @@ void updateLvglMainScreen(
654655
if (bmsTelemetry.bmsState == TelemetryState::CONNECTED) {
655656
lv_label_set_text_fmt(batt_temp_label, "%d", static_cast<int>(batteryTemp));
656657

657-
if (batteryTemp >= BATT_TEMP_CRITICAL) {
658+
if (batteryTemp >= bmsTempThresholds.critHigh) {
658659
lv_obj_add_style(batt_temp_bg, &style_critical, 0);
659660
lv_obj_clear_flag(batt_temp_bg, LV_OBJ_FLAG_HIDDEN);
660-
} else if (batteryTemp >= BATT_TEMP_WARNING) {
661+
} else if (batteryTemp >= bmsTempThresholds.warnHigh) {
661662
lv_obj_add_style(batt_temp_bg, &style_warning, 0);
662663
lv_obj_clear_flag(batt_temp_bg, LV_OBJ_FLAG_HIDDEN);
663664
} else {
@@ -677,10 +678,10 @@ void updateLvglMainScreen(
677678
if (escTelemetry.escState == TelemetryState::CONNECTED) {
678679
lv_label_set_text_fmt(esc_temp_label, "%d", static_cast<int>(escTemp));
679680

680-
if (escTemp >= ESC_TEMP_CRITICAL) {
681+
if (escTemp >= escMosTempThresholds.critHigh) {
681682
lv_obj_add_style(esc_temp_bg, &style_critical, 0);
682683
lv_obj_clear_flag(esc_temp_bg, LV_OBJ_FLAG_HIDDEN);
683-
} else if (escTemp >= ESC_TEMP_WARNING) {
684+
} else if (escTemp >= escMosTempThresholds.warnHigh) {
684685
lv_obj_add_style(esc_temp_bg, &style_warning, 0);
685686
lv_obj_clear_flag(esc_temp_bg, LV_OBJ_FLAG_HIDDEN);
686687
} else {
@@ -700,10 +701,10 @@ void updateLvglMainScreen(
700701
if (escTelemetry.escState == TelemetryState::CONNECTED && motorTemp > -20.0f) {
701702
lv_label_set_text_fmt(motor_temp_label, "%d", static_cast<int>(motorTemp));
702703

703-
if (motorTemp >= MOTOR_TEMP_CRITICAL) {
704+
if (motorTemp >= motorTempThresholds.critHigh) {
704705
lv_obj_add_style(motor_temp_bg, &style_critical, 0);
705706
lv_obj_clear_flag(motor_temp_bg, LV_OBJ_FLAG_HIDDEN);
706-
} else if (motorTemp >= MOTOR_TEMP_WARNING) {
707+
} else if (motorTemp >= motorTempThresholds.warnHigh) {
707708
lv_obj_add_style(motor_temp_bg, &style_warning, 0);
708709
lv_obj_clear_flag(motor_temp_bg, LV_OBJ_FLAG_HIDDEN);
709710
} else {

0 commit comments

Comments
 (0)