Add Driveline screen; stop displaying values that were never measured

New hand-coded LVGL screen (src/modules/driveline_screen.*) showing only
signals verified on this bus: gear as the hero, coolant and gearbox oil temp
flanking it, an engine RPM bar, and turbine / output-shaft speeds, plus
ignition, engine-run, converter-clutch, gearbox-cooling and gear-mismatch
status. Reached by swiping right from Home.

It lives in src/ and hooks its gesture onto the Home screen at RUNTIME rather
than editing ui_Home_Screen.c, because SquareLine Studio overwrites
include/ui/ on every export - that is how the CAN toggle's event handler went
missing. LVGL dispatches to every registered callback, so the runtime hook
coexists with the generated left-swipe handler instead of replacing it. Same
reasoning the existing meters_manager already follows.

Output shaft is labelled "raw" and shown as counts: the x0.125 scaling is
still a hypothesis, so inventing a unit here would launder it into fact.

Also fixes a defect found while wiring this up: main.cpp updated the Home
screen's meters and battery label unconditionally, but those fields are
pre-seeded with DEFAULT_* constants. With no CAN data the display showed a
confident 92.0degC engine oil temp and 12.45V battery that had never been
measured. Two of them have no source on this bus at all - engine oil temp has
no sensor (0x1D0 byte 1 is permanently 0xFF), and 0x3B4 publishes the
battery's not-available marker on nearly every frame. Now gated on
valid_flags, so an unmeasured value reads "--.--" instead of a plausible lie.

Same class of bug in the driver: 0x3B4's U_BT was accepted even when it read
0xFFF, which would have put a confident 61V on screen. Now rejected, leaving
the valid flag clear.

Decodes ignition state from 0x3B4 byte 2 (user-verified: 0x00 = on, 0x09 =
off, unmoved by the engine starting). Both the E65 repo (ST_ENGINE_RUN) and
the E60 VFL sheet (engine flag, 0x09 = running) are wrong about this field on
our bus - inverted and mislabelled. Noted at the definition so it doesn't get
"corrected" back. It also restores ignition sensing, which we thought was
lost with CAS/0x130 absent from the swap.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-17 16:23:10 +02:00
parent 0bd8f5c14d
commit 0b31c6f5f7
6 changed files with 493 additions and 13 deletions
+30 -4
View File
@@ -211,6 +211,15 @@ typedef struct __attribute__((packed)) {
#define CAN_ID_BATTERY_VOLTAGE 0x3B4
#define CAN_BYTE_BATTERY_VOLT_L 0 // U_BT: 12-bit little-endian, V = raw * 0.015
#define CAN_BYTE_BATTERY_VOLT_H 1 // low nibble only (high nibble = ST_BTSW)
#define BATTERY_RAW_INVALID 0xFFF // U_BT's not-available marker
// Byte 2 low nibble. The E65 repo calls this ST_ENGINE_RUN and the E60 VFL sheet
// calls it an engine-running flag with 0x09=running — BOTH ARE WRONG FOR US.
// Verified on this bus 2026-07-17: it tracks IGNITION, inverted, and does not
// move when the engine starts. Use 0x1D0 ST_ENGINE_RUN for engine state.
#define CAN_BYTE_IGNITION 2
#define IGNITION_ON 0x00
#define IGNITION_OFF 0x09
// All IDs are 11-bit standard frames — the extended-ID assumption came from the
// bogus 0x1001/0x101F placeholders and is dead.
@@ -275,17 +284,34 @@ static inline int16_t can_to_temperature(uint8_t can_value, int16_t offset) {
return (int16_t)(((int16_t)can_value - offset) * 10);
}
/**
* Extract the raw 12-bit U_BT field from a 0x3B4 frame.
* The high nibble of byte 1 is ST_BTSW, NOT voltage — mask it off or you'll read
* ~4x too high.
* @param d Payload of a 0x3B4 frame (needs DLC >= 2)
* @return Raw 12-bit value; BATTERY_RAW_INVALID (0xFFF) means "not available"
*/
static inline uint16_t can_battery_raw(const uint8_t* d) {
return (uint16_t)(((d[CAN_BYTE_BATTERY_VOLT_H] & 0x0F) << 8) | d[CAN_BYTE_BATTERY_VOLT_L]);
}
/**
* Decode battery voltage from a 0x3B4 frame.
* U_BT is 12-bit little-endian, factor 0.015 V — i.e. 0.01 V units = raw * 1.5.
* (Verified: raw 0x3D9 = 985 -> 14.775 V.) The high nibble of byte 1 is ST_BTSW,
* NOT voltage — mask it off or you'll read ~4x too high.
* (Source example: raw 0x3D9 = 985 -> 14.775 V.)
*
* CAVEAT: on this bus the field reads BATTERY_RAW_INVALID almost always — the
* Power Module appears not to be retained in the swap. Check can_battery_raw()
* against BATTERY_RAW_INVALID before calling this; 0xFFF would otherwise decode
* to a confident-looking 61 V. The factor itself is also unconfirmed against a
* meter (0.015 here vs ~0.0147 implied by the E60 VFL sheet).
* See wiki/pages/can-id-candidates.md.
*
* @param d Payload of a 0x3B4 frame (needs DLC >= 2)
* @return Voltage in 0.01V units
*/
static inline uint16_t can_to_voltage(const uint8_t* d) {
uint16_t raw12 = (uint16_t)(((d[CAN_BYTE_BATTERY_VOLT_H] & 0x0F) << 8) | d[CAN_BYTE_BATTERY_VOLT_L]);
return (uint16_t)((raw12 * 3) / 2); // raw * 0.015 V -> 0.01 V units
return (uint16_t)((can_battery_raw(d) * 3) / 2); // raw * 0.015 V -> 0.01 V units
}
/**