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
Firmware / build (push) Successful in 7m12s
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user