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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user