Driveline screen: show engaged gear number; reset on ignition-off
Gear hero now shows the engaged gear, not just the lever letter. P/R/N stay as letters; in the Drive detent it composes mode + number - D3 / S3 / M3 - from 0x1D2 byte 1 (engaged gear, populated in plain D too, verified climbing 1..6 in the drive capture) and byte 4 (mode). Falls back to the bare mode letter before the box reports a number, and in R (unnumbered here). The three 0x1D2 pieces (lever, engaged gear, mode) are now carried in driveline_t so the screen can compose its own label without disturbing the UART packet's gear_position enum. lever defaults to GEAR_UNKNOWN, not 0 (which is GEAR_PARK), so it doesn't read "P" before the first frame. Ignition-off now blanks every readout instead of freezing the last frame, per request - the screen goes quiet with the car. The ignition chip still shows IGN OFF; the rest mute, since their values are meaningless with the key out. Driven by 0x3B4's ignition nibble (5 s message, so the reset lags key-off by up to a few seconds). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -80,6 +80,37 @@ static void setChip(lv_obj_t* chip, const char* text, lv_color_t colour) {
|
||||
lv_obj_set_style_text_color(chip, colour, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compose the hero gear label from the 0x1D2 pieces.
|
||||
*
|
||||
* P/R/N are shown as the bare letter. In the Drive detent we prefix the engaged
|
||||
* gear number with the mode: D3 (auto), S3 (sport gate), M3 (manual). If the box
|
||||
* hasn't reported a number yet (or is in R, which is unnumbered here) the mode
|
||||
* letter stands alone.
|
||||
*
|
||||
* @param dl Driveline snapshot
|
||||
* @param out Output buffer (>= 4 bytes)
|
||||
*/
|
||||
static void composeGear(const driveline_t& dl, char* out, size_t n) {
|
||||
switch ((gear_position_t)dl.lever) {
|
||||
case GEAR_PARK: snprintf(out, n, "P"); return;
|
||||
case GEAR_REVERSE: snprintf(out, n, "R"); return;
|
||||
case GEAR_NEUTRAL: snprintf(out, n, "N"); return;
|
||||
case GEAR_DRIVE: break; // fall through to compose D/S/M + number
|
||||
default: snprintf(out, n, "--"); return;
|
||||
}
|
||||
|
||||
char mode = 'D';
|
||||
if (dl.gear_mode == GEAR_MODE_SPORT) mode = 'S';
|
||||
if (dl.gear_mode == GEAR_MODE_MANUAL) mode = 'M';
|
||||
|
||||
if (dl.engaged_gear >= 1 && dl.engaged_gear <= 6) {
|
||||
snprintf(out, n, "%c%u", mode, dl.engaged_gear);
|
||||
} else {
|
||||
snprintf(out, n, "%c", mode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create a title + value stack. Returns the value label.
|
||||
*/
|
||||
@@ -284,11 +315,13 @@ void tick() {
|
||||
}
|
||||
|
||||
char buf[24];
|
||||
(void)gear; // gear now comes from the driveline pieces, not the UART enum
|
||||
lvgl_port_lock(-1);
|
||||
|
||||
if (!can_up) {
|
||||
// Be explicit that there is no data, rather than showing a stale frame
|
||||
// that looks live.
|
||||
// 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.
|
||||
if (!can_up || !dl.ignition_on) {
|
||||
lv_label_set_text(g_gear_lbl, "--");
|
||||
lv_label_set_text(g_coolant_lbl, "--");
|
||||
lv_label_set_text(g_gearbox_lbl, "--");
|
||||
@@ -297,18 +330,26 @@ void tick() {
|
||||
lv_label_set_text(g_pedal_lbl, "--");
|
||||
lv_label_set_text(g_shaft_lbl, "--");
|
||||
lv_bar_set_value(g_rpm_bar, 0, LV_ANIM_OFF);
|
||||
setChip(g_ign_chip, "IGN --", COL_MUTED);
|
||||
lv_obj_add_flag(g_mismatch_lbl, LV_OBJ_FLAG_HIDDEN);
|
||||
// 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) {
|
||||
setChip(g_ign_chip, "IGN --", COL_MUTED);
|
||||
setChip(g_cool_chip, "CAN OFF", COL_WARN);
|
||||
} else {
|
||||
setChip(g_ign_chip, "IGN OFF", COL_MUTED);
|
||||
setChip(g_cool_chip, "COOLING --", COL_MUTED);
|
||||
}
|
||||
setChip(g_eng_chip, "ENG --", COL_MUTED);
|
||||
setChip(g_clutch_chip, "CLUTCH --", COL_MUTED);
|
||||
setChip(g_cool_chip, "CAN OFF", COL_WARN);
|
||||
lv_obj_add_flag(g_mismatch_lbl, LV_OBJ_FLAG_HIDDEN);
|
||||
lvgl_port_unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
// ---- gear ------------------------------------------------------------
|
||||
if (flags & VALID_FLAG_GEAR_POS) {
|
||||
lv_label_set_text(g_gear_lbl, gear_to_string((gear_position_t)gear));
|
||||
// ---- gear (composed: P/R/N, or D/S/M + engaged number) ---------------
|
||||
if ((gear_position_t)dl.lever != GEAR_UNKNOWN) {
|
||||
composeGear(dl, buf, sizeof(buf));
|
||||
lv_label_set_text(g_gear_lbl, buf);
|
||||
} else {
|
||||
lv_label_set_text(g_gear_lbl, "--");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user