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:
2026-07-17 18:36:26 +02:00
parent 037227ba34
commit 894178e7f0
3 changed files with 71 additions and 11 deletions
+14 -2
View File
@@ -163,10 +163,18 @@ static bool parseCANMessage(const twai_message_t& message) {
g_automotive_data.valid_flags |= VALID_FLAG_GEAR_POS;
parsed = true;
}
// Keep the bare lever (not the resolved display value) for the
// cross-check below: 0x0BA reports a gear, never a mode.
// Break the frame into its pieces for the driveline screen, which
// composes its own richer label (e.g. "D3"). Keep the bare lever for
// the cross-check below: 0x0BA reports a gear, never a mode.
if (dlc > CAN_BYTE_GEAR_LEVER) {
g_last_lever = can_to_gear_lever(data[CAN_BYTE_GEAR_LEVER]);
g_driveline.lever = (uint8_t)g_last_lever;
}
if (dlc > CAN_BYTE_GEAR_ENGAGED) {
g_driveline.engaged_gear = can_to_engaged_gear(data[CAN_BYTE_GEAR_ENGAGED]);
}
if (dlc > CAN_BYTE_GEAR_MODE) {
g_driveline.gear_mode = data[CAN_BYTE_GEAR_MODE];
}
break;
}
@@ -422,6 +430,9 @@ static void canTask(void* parameter) {
memset(&g_can_stats, 0, sizeof(g_can_stats));
// Drop stale driveline/gear state from a previous session
memset(&g_driveline, 0, sizeof(g_driveline));
// GEAR_PARK is 0, so a zeroed lever would read as "P"
// before the first 0x1D2 frame — force UNKNOWN instead.
g_driveline.lever = (uint8_t)GEAR_UNKNOWN;
g_last_lever = GEAR_UNKNOWN;
g_mismatch_since = 0;
ESP_LOGI("CANTask", "CAN reception active");
@@ -575,6 +586,7 @@ driveline_t getDriveline() {
// Never hand back a torn read; an all-zero snapshot is honest about
// having no fresh data (engine_run_state 0 == ENGINE_RUN_OFF).
memset(&snapshot, 0, sizeof(snapshot));
snapshot.lever = (uint8_t)GEAR_UNKNOWN; // 0 would mean GEAR_PARK
}
return snapshot;
}