Retire SquareLine: hand-coded gauge screen (oil quadrant dropped), LVGL lock, updates on change only; LVGL pool in PSRAM, millis tick, log off; 16 MB flash + OTA partitions; docs and wiki

This commit is contained in:
2026-09-27 18:50:44 +02:00
parent bde1f57f62
commit de6752d558
43 changed files with 439 additions and 19804 deletions
+4 -173
View File
@@ -13,121 +13,13 @@
#include "modules/espnow_receiver.h"
#include "modules/gauge_outputs.h"
#include "modules/debug_monitor.h"
#include "ui/ui.h"
#include "ui/screens/ui_Home_Screen.h"
#include "modules/gauge_screen.h"
// FreeRTOS task handles
TaskHandle_t lvglTaskHandle = NULL;
// Link is considered lost after this long without an applied DATA frame
#define LINK_TIMEOUT_MS 1000
// A shift pulse is shown for at least this long, so a fast shift still blinks
#define SHIFT_PULSE_MIN_MS 600
/**
* Helper function to update sensor icon position, visibility, and color
*/
void update_sensor_icon(lv_obj_t* icon_normal, lv_obj_t* icon_red,
lv_obj_t* label_ref, bool position_below,
bool show, bool use_red) {
if (icon_normal == NULL || icon_red == NULL || label_ref == NULL) {
return;
}
if (show) {
lv_obj_t* icon_to_show = use_red ? icon_red : icon_normal;
lv_obj_t* icon_to_hide = use_red ? icon_normal : icon_red;
if (position_below) {
lv_obj_align_to(icon_to_show, label_ref, LV_ALIGN_OUT_BOTTOM_MID, 0, 2);
} else {
lv_obj_align_to(icon_to_show, label_ref, LV_ALIGN_OUT_TOP_MID, 0, -2);
}
lv_obj_clear_flag(icon_to_show, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(icon_to_hide, LV_OBJ_FLAG_HIDDEN);
} else {
lv_obj_add_flag(icon_normal, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(icon_red, LV_OBJ_FLAG_HIDDEN);
}
}
// ============================================================================
// GEAR LABEL: pulse while the gearbox is still moving to the target gear
// ============================================================================
static lv_anim_t g_gear_anim;
static bool g_gear_pulsing = false;
static uint32_t g_gear_pulse_started = 0;
static bool g_gear_color_saved = false;
static lv_color_t g_gear_color_default;
static void gearOpaCb(void* obj, int32_t v) {
lv_obj_set_style_opa((lv_obj_t*)obj, (lv_opa_t)v, 0);
}
static void startGearPulse() {
if (g_gear_pulsing || ui_Gear_State_LBL == NULL) return;
lv_anim_init(&g_gear_anim);
lv_anim_set_var(&g_gear_anim, ui_Gear_State_LBL);
lv_anim_set_exec_cb(&g_gear_anim, gearOpaCb);
lv_anim_set_values(&g_gear_anim, 255, 60);
lv_anim_set_time(&g_gear_anim, 300);
lv_anim_set_playback_time(&g_gear_anim, 300);
lv_anim_set_repeat_count(&g_gear_anim, LV_ANIM_REPEAT_INFINITE);
lv_anim_start(&g_gear_anim);
g_gear_pulsing = true;
g_gear_pulse_started = millis();
}
static void stopGearPulse() {
if (!g_gear_pulsing || ui_Gear_State_LBL == NULL) return;
lv_anim_del(ui_Gear_State_LBL, gearOpaCb);
lv_obj_set_style_opa(ui_Gear_State_LBL, LV_OPA_COVER, 0);
g_gear_pulsing = false;
}
/**
* Compose and show the gear label from lever + target/engaged nibbles.
* While target != engaged the TARGET digit is shown and the label pulses;
* once they agree the label goes solid on the engaged gear.
*/
static void updateGearLabel(const automotive_data_t& d, bool valid) {
if (ui_Gear_State_LBL == NULL) return;
if (!g_gear_color_saved) {
g_gear_color_default = lv_obj_get_style_text_color(ui_Gear_State_LBL, 0);
g_gear_color_saved = true;
}
if (!valid) {
stopGearPulse();
lv_label_set_text(ui_Gear_State_LBL, "?");
lv_obj_set_style_text_color(ui_Gear_State_LBL, g_gear_color_default, 0);
return;
}
uint8_t target = gear_target(d.gear_nibbles);
uint8_t engaged = gear_engaged(d.gear_nibbles);
bool shifting = gear_shifting(d.gear_nibbles);
uint8_t number = engaged;
if (shifting || (engaged == 0 && target != 0)) number = target;
char buf[8];
gear_compose(d.gear_lever, number, buf, sizeof(buf));
lv_label_set_text(ui_Gear_State_LBL, buf);
if (shifting) {
startGearPulse();
} else if (g_gear_pulsing && (millis() - g_gear_pulse_started) >= SHIFT_PULSE_MIN_MS) {
stopGearPulse();
}
bool mismatch = (d.valid_flags & VALID_FLAG_ALERTS) && (d.alerts & ALERT_GEAR_MISMATCH);
lv_obj_set_style_text_color(ui_Gear_State_LBL,
mismatch ? lv_color_hex(0xFF3B30) : g_gear_color_default, 0);
}
/**
* LVGL update task (runs on Core 1)
@@ -170,9 +62,7 @@ void setup() {
}
}
Serial.println("[UI] Initializing SquareLine Studio UI...");
ui_init();
Serial.println("[UI] SquareLine Studio UI initialized");
GaugeScreen::init(); // hand-coded screen, built once, loaded
xTaskCreatePinnedToCore(lvglTask, "LVGL_Task", 8192, NULL, 2, &lvglTaskHandle, 1);
@@ -271,67 +161,8 @@ void loop() {
GaugeOutputs::update(data, is_connected);
if (is_connected) {
char gearbox_buf[16], engine_buf[16], coolant_buf[16], voltage_buf[16];
bool alerts_valid = (data.valid_flags & VALID_FLAG_ALERTS);
uint16_t alerts = alerts_valid ? data.alerts : 0;
if (data.valid_flags & VALID_FLAG_GEARBOX_TEMP) {
lv_label_set_text(ui_GB_Oil_Temp_LBL, format_temperature(data.gearbox_oil_temp, gearbox_buf));
} else {
lv_label_set_text(ui_GB_Oil_Temp_LBL, "---");
}
if (data.valid_flags & VALID_FLAG_ENGINE_TEMP) {
lv_label_set_text(ui_Engine_Oil_Temp_LBL, format_temperature(data.engine_oil_temp, engine_buf));
} else {
lv_label_set_text(ui_Engine_Oil_Temp_LBL, "---");
}
if (data.valid_flags & VALID_FLAG_COOLANT_TEMP) {
lv_label_set_text(ui_Water_Temp_LBL, format_temperature(data.coolant_temp, coolant_buf));
} else {
lv_label_set_text(ui_Water_Temp_LBL, "---");
}
if (data.valid_flags & VALID_FLAG_BATTERY_VOLT) {
lv_label_set_text(ui_Battery_Voltage_LBL, format_voltage(data.battery_voltage, voltage_buf));
} else {
lv_label_set_text(ui_Battery_Voltage_LBL, "---");
}
updateGearLabel(data, (data.valid_flags & VALID_FLAG_GEAR_POS) != 0);
// Icons: shown when the value is valid, red when A raised the alert.
// Thresholds live on A (Tunables); B only renders the bits.
bool coolant_valid = (data.valid_flags & VALID_FLAG_COOLANT_TEMP);
update_sensor_icon(ui_Engine_Water, ui_Engine_Water_Red, ui_Water_Temp_LBL, true,
coolant_valid, (alerts & ALERT_COOLANT_HOT) != 0);
bool gearbox_valid = (data.valid_flags & VALID_FLAG_GEARBOX_TEMP);
update_sensor_icon(ui_GearBox_Oil, ui_GearBox_Oil_Red, ui_GB_Oil_Temp_LBL, true,
gearbox_valid, (alerts & (ALERT_GEARBOX_HOT | ALERT_GEARBOX_COOLING)) != 0);
bool battery_valid = (data.valid_flags & VALID_FLAG_BATTERY_VOLT);
update_sensor_icon(ui_Battery_Voltage, ui_Battery_Voltage_Red, ui_Battery_Voltage_LBL, false,
battery_valid, (alerts & ALERT_BATTERY_LOW) != 0);
// Engine oil has no sensor on this engine and no alert bit; never red.
bool engine_oil_valid = (data.valid_flags & VALID_FLAG_ENGINE_TEMP);
update_sensor_icon(ui_Engine_Oil, ui_Engine_Oil_Red, ui_Engine_Oil_Temp_LBL, false,
engine_oil_valid, false);
} else {
lv_label_set_text(ui_GB_Oil_Temp_LBL, "N/A");
lv_label_set_text(ui_Engine_Oil_Temp_LBL, "N/A");
lv_label_set_text(ui_Water_Temp_LBL, "N/A");
lv_label_set_text(ui_Battery_Voltage_LBL, "N/A");
updateGearLabel(data, false);
update_sensor_icon(ui_Engine_Water, ui_Engine_Water_Red, ui_Water_Temp_LBL, true, false, false);
update_sensor_icon(ui_GearBox_Oil, ui_GearBox_Oil_Red, ui_GB_Oil_Temp_LBL, true, false, false);
update_sensor_icon(ui_Battery_Voltage, ui_Battery_Voltage_Red, ui_Battery_Voltage_LBL, false, false, false);
update_sensor_icon(ui_Engine_Oil, ui_Engine_Oil_Red, ui_Engine_Oil_Temp_LBL, false, false, false);
}
GaugeScreen::update(data, is_connected);
DebugMonitor::tick(); // apply A's debug flag under the LVGL lock
}
delay(10);