Status overlay on every screen: Wi-Fi chip top-right, blinking alert banner; Driveline values red on crossed thresholds, ring red on gear mismatch
Firmware / build (push) Successful in 7m12s

This commit is contained in:
2026-09-27 21:40:37 +02:00
parent 7ae1ab726a
commit ae9327d91b
7 changed files with 228 additions and 16 deletions
+3
View File
@@ -18,6 +18,7 @@
#include "modules/diag_probe.h" // On-demand OBD-II requests (`diag` console) - the only CAN transmitter
#include "modules/ota_update.h" // Manual firmware updates from Gitea releases (`ota` console)
#include "modules/link_peer.h" // Controller B status, pairing, credential handoff, B updates (`link` console)
#include "modules/status_overlay.h" // Every screen: Wi-Fi chip top-right, blinking alert banner top-centre
// ============================================================================
// MINIMAL LVGL + UI SETTINGS + WIFI + UART
@@ -88,6 +89,7 @@ void setup()
ESP_LOGI("MAIN", "Initializing display and UI...");
DisplayInit::init();
ESP_LOGI("MAIN", "Display init COMPLETED!");
StatusOverlay::init(); // Wi-Fi chip + alert banner on lv_layer_top(), above every screen
// Initialize Settings Manager
ESP_LOGI("MAIN", "Initializing Settings Manager...");
@@ -167,6 +169,7 @@ void loop()
DrivelineScreen::tick();
TuningScreen::tick();
SettingsScreen::tick();
StatusOverlay::tick();
delay(100); // Check frequently to catch screen changes quickly
}
+44 -15
View File
@@ -24,6 +24,8 @@ namespace DrivelineScreen {
#define COL_ACCENT lv_color_hex(0x3DA9FC)
#define COL_OK lv_color_hex(0x3DD68C)
#define COL_WARN lv_color_hex(0xE5484D)
#define COL_ALERT lv_color_hex(0xFF3B30) // threshold crossed: value + title
#define COL_AMBER lv_color_hex(0xF5A524)
#define RPM_MAX 5000 // M57N redline is ~4500; a little headroom
@@ -36,6 +38,8 @@ static lv_obj_t* g_gear_lbl = NULL;
static lv_obj_t* g_gear_ring = NULL;
static lv_obj_t* g_coolant_lbl = NULL;
static lv_obj_t* g_gearbox_lbl = NULL;
static lv_obj_t* g_coolant_title = NULL;
static lv_obj_t* g_gearbox_title = NULL;
static lv_obj_t* g_rpm_bar = NULL;
static lv_obj_t* g_rpm_lbl = NULL;
static lv_obj_t* g_torque_lbl = NULL;
@@ -45,7 +49,6 @@ static lv_obj_t* g_ign_chip = NULL;
static lv_obj_t* g_eng_chip = NULL;
static lv_obj_t* g_clutch_chip = NULL;
static lv_obj_t* g_cool_chip = NULL;
static lv_obj_t* g_mismatch_lbl = NULL;
// ============================================================================
// PRIVATE HELPERS
@@ -81,6 +84,21 @@ static void setText(lv_obj_t* lbl, const char* text) {
lv_label_set_text(lbl, text);
}
/** Text colour, written only on change (a style write invalidates regardless). */
static void setColour(lv_obj_t* o, lv_color_t colour) {
if (o == NULL) return;
if (lv_color_to32(lv_obj_get_style_text_color(o, 0)) != lv_color_to32(colour)) {
lv_obj_set_style_text_color(o, colour, 0);
}
}
/** Ring border colour, written only on change. */
static void setRing(lv_color_t colour) {
if (lv_color_to32(lv_obj_get_style_border_color(g_gear_ring, 0)) != lv_color_to32(colour)) {
lv_obj_set_style_border_color(g_gear_ring, colour, 0);
}
}
/**
* @brief Set a chip's text and colour, touching the object only on a change
* (a style write invalidates the object even for an identical value).
@@ -184,20 +202,15 @@ static void build() {
lv_obj_set_size(bar, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_set_flex_flow(bar, LV_FLEX_FLOW_ROW);
lv_obj_set_style_pad_column(bar, 8, 0);
lv_obj_align(bar, LV_ALIGN_TOP_LEFT, 24, 18);
// y 60: the top 56 px belong to the StatusOverlay (alert banner centre, Wi-Fi chip right)
lv_obj_align(bar, LV_ALIGN_TOP_LEFT, 24, 60);
lv_obj_clear_flag(bar, LV_OBJ_FLAG_SCROLLABLE);
g_ign_chip = makeChip(bar, "IGN --");
g_eng_chip = makeChip(bar, "ENG --");
g_clutch_chip = makeChip(bar, "CLUTCH --");
g_cool_chip = makeChip(bar, "COOLING --");
g_mismatch_lbl = lv_label_create(g_screen);
lv_label_set_text(g_mismatch_lbl, LV_SYMBOL_WARNING " GEAR MISMATCH");
lv_obj_set_style_text_font(g_mismatch_lbl, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(g_mismatch_lbl, COL_WARN, 0);
lv_obj_align(g_mismatch_lbl, LV_ALIGN_TOP_RIGHT, -24, 24);
lv_obj_add_flag(g_mismatch_lbl, LV_OBJ_FLAG_HIDDEN);
// Gear mismatch: the ring and the gear letter turn red, and the overlay banner says so.
// ---- gear hero -------------------------------------------------------
g_gear_ring = lv_obj_create(g_screen);
@@ -220,6 +233,8 @@ static void build() {
LV_ALIGN_LEFT_MID, 110, -40);
g_gearbox_lbl = makeStat(g_screen, "GEARBOX OIL", &lv_font_montserrat_40,
LV_ALIGN_RIGHT_MID, -110, -40);
g_coolant_title = lv_obj_get_child(lv_obj_get_parent(g_coolant_lbl), 0);
g_gearbox_title = lv_obj_get_child(lv_obj_get_parent(g_gearbox_lbl), 0);
// ---- RPM bar ---------------------------------------------------------
lv_obj_t* rpm_title = lv_label_create(g_screen);
@@ -291,11 +306,13 @@ void tick() {
uint8_t gear = GEAR_UNKNOWN;
int16_t coolant = 0, gearbox = 0;
uint8_t flags = 0;
uint16_t alerts = 0;
if (xSemaphoreTake(UARTManager::g_data_mutex, pdMS_TO_TICKS(10)) == pdTRUE) {
gear = UARTManager::g_automotive_data.gear_lever;
coolant = UARTManager::g_automotive_data.coolant_temp;
gearbox = UARTManager::g_automotive_data.gearbox_oil_temp;
flags = UARTManager::g_automotive_data.valid_flags;
alerts = UARTManager::g_automotive_data.alerts;
xSemaphoreGive(UARTManager::g_data_mutex);
} else {
return; // couldn't read; leave the last frame on screen
@@ -318,7 +335,10 @@ void tick() {
setText(g_pedal_lbl, "--");
setText(g_shaft_lbl, "--");
lv_bar_set_value(g_rpm_bar, 0, LV_ANIM_OFF);
lv_obj_add_flag(g_mismatch_lbl, LV_OBJ_FLAG_HIDDEN);
setRing(COL_ACCENT);
setColour(g_gear_lbl, COL_TEXT);
setColour(g_coolant_lbl, COL_TEXT); setColour(g_coolant_title, COL_MUTED);
setColour(g_gearbox_lbl, COL_TEXT); setColour(g_gearbox_title, COL_MUTED);
// Leave the ignition chip telling the truth; mute the rest, since their
// values are meaningless with the key out (or absent with CAN off).
if (!can_up) {
@@ -352,6 +372,17 @@ void tick() {
setText(g_gearbox_lbl, buf);
}
// ---- thresholds crossed: the value AND its title go red (amber while the
// box only asks for cooling); the overlay banner blinks on top of it all.
if (!(flags & VALID_FLAG_ALERTS)) alerts = 0;
bool cool_hot = (alerts & ALERT_COOLANT_HOT) != 0;
bool gb_hot = (alerts & ALERT_GEARBOX_HOT) != 0;
bool gb_cool = (alerts & ALERT_GEARBOX_COOLING) != 0;
setColour(g_coolant_lbl, cool_hot ? COL_ALERT : COL_TEXT);
setColour(g_coolant_title, cool_hot ? COL_ALERT : COL_MUTED);
setColour(g_gearbox_lbl, gb_hot ? COL_ALERT : gb_cool ? COL_AMBER : COL_TEXT);
setColour(g_gearbox_title, gb_hot ? COL_ALERT : gb_cool ? COL_AMBER : COL_MUTED);
// ---- speeds ----------------------------------------------------------
snprintf(buf, sizeof(buf), "%u", dl.engine_rpm);
setText(g_rpm_lbl, buf);
@@ -394,11 +425,9 @@ void tick() {
default: setChip(g_cool_chip, "COOLING ?", COL_MUTED); break;
}
if (dl.gear_mismatch) {
lv_obj_clear_flag(g_mismatch_lbl, LV_OBJ_FLAG_HIDDEN);
} else {
lv_obj_add_flag(g_mismatch_lbl, LV_OBJ_FLAG_HIDDEN);
}
// Gear mismatch: the hero ring and the gear letter turn red.
setRing(dl.gear_mismatch ? COL_ALERT : COL_ACCENT);
setColour(g_gear_lbl, dl.gear_mismatch ? COL_ALERT : COL_TEXT);
lvgl_port_unlock();
}
+147
View File
@@ -0,0 +1,147 @@
/*
* Status Overlay implementation. See status_overlay.h.
*/
#include "status_overlay.h"
#include "wifi_manager.h"
#include "uart_manager.h"
#include "ui_kit.h"
#include "drivers/can_driver.h"
#include "display/lvgl_v8_port.h"
#include "protocol/automotive_data.h"
#include <lvgl.h>
namespace StatusOverlay {
#define BLINK_MS 500
static lv_obj_t* g_wifi = NULL;
static lv_obj_t* g_banner = NULL;
static bool g_banner_shown = false;
static const lv_color_t COL_RED_HI = lv_color_hex(0xFF3B30);
static const lv_color_t COL_RED_LO = lv_color_hex(0x8F1A14);
static void setText(lv_obj_t* lbl, const char* text) {
const char* cur = lv_label_get_text(lbl);
if (cur != NULL && strcmp(cur, text) == 0) return;
lv_label_set_text(lbl, text);
}
static void setTextColour(lv_obj_t* o, lv_color_t c) {
if (lv_color_to32(lv_obj_get_style_text_color(o, 0)) != lv_color_to32(c)) lv_obj_set_style_text_color(o, c, 0);
}
static void setBgColour(lv_obj_t* o, lv_color_t c) {
if (lv_color_to32(lv_obj_get_style_bg_color(o, 0)) != lv_color_to32(c)) lv_obj_set_style_bg_color(o, c, 0);
}
void init() {
lvgl_port_lock(-1);
// Wi-Fi chip, fixed width so the header layout never moves
g_wifi = lv_label_create(lv_layer_top());
lv_obj_set_width(g_wifi, 150);
lv_label_set_long_mode(g_wifi, LV_LABEL_LONG_DOT);
lv_label_set_text(g_wifi, LV_SYMBOL_WIFI " --");
lv_obj_set_style_text_font(g_wifi, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(g_wifi, UI_COL_MUTED, 0);
lv_obj_set_style_bg_color(g_wifi, UI_COL_PANEL, 0);
lv_obj_set_style_bg_opa(g_wifi, LV_OPA_COVER, 0);
lv_obj_set_style_radius(g_wifi, 13, 0);
lv_obj_set_style_pad_hor(g_wifi, 10, 0);
lv_obj_set_style_pad_ver(g_wifi, 5, 0);
lv_obj_align(g_wifi, LV_ALIGN_TOP_RIGHT, -16, 25);
// Alert banner, top centre
g_banner = lv_label_create(lv_layer_top());
lv_label_set_text(g_banner, "");
lv_obj_set_style_text_font(g_banner, &lv_font_montserrat_20, 0);
lv_obj_set_style_text_color(g_banner, lv_color_white(), 0);
lv_obj_set_style_bg_color(g_banner, COL_RED_HI, 0);
lv_obj_set_style_bg_opa(g_banner, LV_OPA_COVER, 0);
lv_obj_set_style_radius(g_banner, 10, 0);
lv_obj_set_style_pad_hor(g_banner, 18, 0);
lv_obj_set_style_pad_ver(g_banner, 8, 0);
lv_obj_align(g_banner, LV_ALIGN_TOP_MID, -20, 10);
lv_obj_add_flag(g_banner, LV_OBJ_FLAG_HIDDEN);
lvgl_port_unlock();
}
static void refreshWifi() {
WiFiManager::status_t w = WiFiManager::getStatus();
char txt[64];
lv_color_t col = UI_COL_MUTED;
switch (w.link) {
case WiFiManager::LINK_CONNECTED: snprintf(txt, sizeof(txt), LV_SYMBOL_WIFI " %s", w.ssid); col = UI_COL_TEXT; break;
case WiFiManager::LINK_CONNECTING: snprintf(txt, sizeof(txt), LV_SYMBOL_WIFI " joining..."); col = UI_COL_ACCENT; break;
case WiFiManager::LINK_FAILED: snprintf(txt, sizeof(txt), LV_SYMBOL_WIFI " failed"); col = UI_COL_AMBER; break;
case WiFiManager::LINK_OFF: snprintf(txt, sizeof(txt), LV_SYMBOL_WIFI " off"); break;
default: snprintf(txt, sizeof(txt), LV_SYMBOL_WIFI " not connected"); break;
}
setText(g_wifi, txt);
setTextColour(g_wifi, col);
}
static void refreshAlerts() {
bool can_up = CANDriver::isActive();
driveline_t dl = CANDriver::getDriveline();
uint16_t alerts = 0;
uint8_t flags = 0;
int16_t coolant = 0, gearbox = 0;
uint16_t batt = 0;
if (xSemaphoreTake(UARTManager::g_data_mutex, pdMS_TO_TICKS(10)) == pdTRUE) {
alerts = UARTManager::g_automotive_data.alerts;
flags = UARTManager::g_automotive_data.valid_flags;
coolant = UARTManager::g_automotive_data.coolant_temp;
gearbox = UARTManager::g_automotive_data.gearbox_oil_temp;
batt = UARTManager::g_automotive_data.battery_voltage;
xSemaphoreGive(UARTManager::g_data_mutex);
} else {
return;
}
bool live = can_up && dl.ignition_on && (flags & VALID_FLAG_ALERTS);
bool red = live && (alerts & ALERTS_RED);
bool amber = live && !red && (alerts & ALERTS_AMBER);
bool show = red || amber;
if (show != g_banner_shown) {
g_banner_shown = show;
if (show) lv_obj_clear_flag(g_banner, LV_OBJ_FLAG_HIDDEN);
else lv_obj_add_flag(g_banner, LV_OBJ_FLAG_HIDDEN);
}
if (!show) return;
char txt[64];
if (alerts & ALERT_COOLANT_HOT) snprintf(txt, sizeof(txt), LV_SYMBOL_WARNING " COOLANT %d °C HOT", coolant / 10);
else if (alerts & ALERT_GEARBOX_HOT) snprintf(txt, sizeof(txt), LV_SYMBOL_WARNING " GEARBOX OIL %d °C HOT", gearbox / 10);
else if (alerts & ALERT_GEAR_MISMATCH) snprintf(txt, sizeof(txt), LV_SYMBOL_WARNING " GEAR MISMATCH");
else if (alerts & ALERT_BATTERY_LOW) snprintf(txt, sizeof(txt), LV_SYMBOL_WARNING " BATTERY %d.%02d V LOW", batt / 100, batt % 100);
else snprintf(txt, sizeof(txt), LV_SYMBOL_WARNING " GEARBOX COOLING");
setText(g_banner, txt);
if (red) {
bool hi = (millis() / BLINK_MS) & 1;
setBgColour(g_banner, hi ? COL_RED_HI : COL_RED_LO);
setTextColour(g_banner, lv_color_white());
} else {
setBgColour(g_banner, UI_COL_AMBER);
setTextColour(g_banner, lv_color_hex(0x1A1200));
}
}
void tick() {
if (g_wifi == NULL) return;
static uint32_t last = 0;
if (millis() - last < 250) return;
last = millis();
lvgl_port_lock(-1);
refreshWifi();
refreshAlerts();
lvgl_port_unlock();
}
} // namespace StatusOverlay
+26
View File
@@ -0,0 +1,26 @@
/*
* Status Overlay - what every screen shows, on lv_layer_top():
*
* top-right Wi-Fi chip: off / not connected / joining / <network>
* top-centre ALERT BANNER: red and blinking (2 Hz) while any red alert from
* Tunables' thresholds is on (coolant hot, gearbox oil hot,
* gear mismatch, battery low), steady amber while the gearbox
* asks for cooling. Hidden with CAN off or ignition off.
*
* Both are labels, so they never take touches from the screen below. tick()
* runs from loop() and only touches an object when its text/colour changes.
*/
#pragma once
#include <Arduino.h>
namespace StatusOverlay {
/** Build the two labels. Call after DisplayInit::init(), before the screens tick. */
void init();
/** Refresh from WiFiManager / the shared automotive data. Call from loop(). */
void tick();
} // namespace StatusOverlay
+2 -1
View File
@@ -18,8 +18,9 @@ void header(lv_obj_t* scr, const char* title, lv_event_cb_t back_cb) {
lv_obj_t* t = label(scr, title, &lv_font_montserrat_30, UI_COL_TEXT);
lv_obj_align(t, LV_ALIGN_TOP_LEFT, 24, 18);
// -176: the StatusOverlay Wi-Fi chip owns the last 150 px of the top-right corner
lv_obj_t* back = button(scr, LV_SYMBOL_LEFT " Driveline", 200, 56, BTN_SECONDARY, back_cb, NULL);
lv_obj_align(back, LV_ALIGN_TOP_RIGHT, -16, 10);
lv_obj_align(back, LV_ALIGN_TOP_RIGHT, -176, 10);
}
lv_obj_t* label(lv_obj_t* parent, const char* text, const lv_font_t* font, lv_color_t color) {