Diff-lock inputs: DI0 rear / DI1 front via CH422G EXIO0/EXIO5 (bank flipped to input per read), Settings > System switch default OFF, DIFF LOCK pills on the Driveline, 'difflock' console; wiki diff-lock-inputs
Firmware / build (push) Successful in 7m26s

This commit is contained in:
2026-09-29 09:48:57 +02:00
parent f07590bbc5
commit 31ca44187e
13 changed files with 362 additions and 10 deletions
+60
View File
@@ -9,6 +9,7 @@
#include "drivers/can_driver.h"
#include "tuning_screen.h"
#include "settings_screen.h"
#include "diff_locks.h"
#include "esp_log.h"
namespace DrivelineScreen {
@@ -49,6 +50,9 @@ 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_diff_box = NULL; // top-right: DIFF LOCK [REAR] [FRONT]
static lv_obj_t* g_rear_pill = NULL;
static lv_obj_t* g_front_pill = NULL;
// ============================================================================
// PRIVATE HELPERS
@@ -111,6 +115,38 @@ static void setChip(lv_obj_t* chip, const char* text, lv_color_t colour) {
}
}
/** A diff-lock pill: text, fill and text colour, each written only on change. */
static void setPill(lv_obj_t* pill, const char* text, lv_color_t bg, lv_color_t fg) {
setText(pill, text);
if (lv_color_to32(lv_obj_get_style_bg_color(pill, 0)) != lv_color_to32(bg)) {
lv_obj_set_style_bg_color(pill, bg, 0);
}
setColour(pill, fg);
}
/**
* @brief Diff locks, from the isolated inputs (not CAN - shown with CAN off too).
* Locked = amber tell-tale. The front can only lock after the rear, so
* FRONT without REAR is a wiring/switch fault and shows red.
*/
static void refreshDiffLocks() {
bool on = DiffLocks::isEnabled();
if (lv_obj_has_flag(g_diff_box, LV_OBJ_FLAG_HIDDEN) == on) {
if (on) lv_obj_clear_flag(g_diff_box, LV_OBJ_FLAG_HIDDEN);
else lv_obj_add_flag(g_diff_box, LV_OBJ_FLAG_HIDDEN);
}
if (!on) return;
if (!DiffLocks::isValid()) {
setPill(g_rear_pill, "REAR ?", COL_PANEL, COL_MUTED);
setPill(g_front_pill, "FRONT ?", COL_PANEL, COL_MUTED);
return;
}
bool rear = DiffLocks::rearLocked(), front = DiffLocks::frontLocked();
setPill(g_rear_pill, "REAR", rear ? COL_AMBER : COL_PANEL, rear ? COL_BG : COL_MUTED);
if (front && !rear) setPill(g_front_pill, "FRONT", COL_ALERT, COL_TEXT);
else setPill(g_front_pill, "FRONT", front ? COL_AMBER : COL_PANEL, front ? COL_BG : COL_MUTED);
}
/**
* @brief Compose the hero gear label from the 0x1D2 pieces.
*
@@ -212,6 +248,28 @@ static void build() {
g_cool_chip = makeChip(bar, "COOLING --");
// Gear mismatch: the ring and the gear letter turn red, and the overlay banner says so.
// ---- diff locks, top-right under the overlay's Wi-Fi chip (hidden until enabled)
g_diff_box = lv_obj_create(g_screen);
lv_obj_remove_style_all(g_diff_box);
lv_obj_set_size(g_diff_box, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_set_flex_flow(g_diff_box, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(g_diff_box, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_style_pad_column(g_diff_box, 8, 0);
lv_obj_align(g_diff_box, LV_ALIGN_TOP_RIGHT, -24, 60);
lv_obj_clear_flag(g_diff_box, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_flag(g_diff_box, LV_OBJ_FLAG_HIDDEN);
lv_obj_t* diff_title = lv_label_create(g_diff_box);
lv_label_set_text(diff_title, "DIFF LOCK");
lv_obj_set_style_text_font(diff_title, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(diff_title, COL_MUTED, 0);
g_rear_pill = makeChip(g_diff_box, "REAR");
g_front_pill = makeChip(g_diff_box, "FRONT");
for (lv_obj_t* p : {g_rear_pill, g_front_pill}) {
lv_obj_set_style_text_font(p, &lv_font_montserrat_20, 0); // a tell-tale, bigger than the status chips
lv_obj_set_style_pad_hor(p, 14, 0);
}
// ---- gear hero -------------------------------------------------------
g_gear_ring = lv_obj_create(g_screen);
lv_obj_set_size(g_gear_ring, 220, 220);
@@ -322,6 +380,8 @@ void tick() {
(void)gear; // gear now comes from the driveline pieces, not the UART enum
lvgl_port_lock(-1);
refreshDiffLocks(); // hard-wired inputs: live even with CAN or the key off
// Blank every readout when there's nothing live to show: CAN off, or the key
// is off. The user asked for a full reset on ignition-off so the screen goes
// quiet with the car rather than freezing the last frame. 0x3B4 sends its