1 Commits

Author SHA1 Message Date
julian 0254bf19e9 Diff-lock drawing: wheelbase -20 %, same square tyres all round, locked axle's tyres filled, no caption text
Firmware / build (push) Successful in 7m5s
2026-09-29 10:53:48 +02:00
3 changed files with 71 additions and 71 deletions
+1 -1
View File
@@ -234,7 +234,7 @@ Settings persist across power cycles via ESP32 NVS (Non-Volatile Storage):
### Diff-lock inputs (`difflock` console) ### Diff-lock inputs (`difflock` console)
`src/modules/diff_locks.cpp` reads the Patrol's two diff-lock signals (+12 V = locked) on the isolated inputs: DI0 = rear, DI1 = front, `DI_COM` to vehicle ground. The PC814 outputs reach the ESP32 only through the CH422G (DI0 = EXIO0, DI1 = EXIO5, active LOW), and the CH422G's IO0-7 are one bank, all in or all out - the same bank drives touch reset (EXIO1), backlight (EXIO2) and LCD reset (EXIO3). Each poll (4 Hz, under the LVGL lock so no touch read shares the bus) writes WR_SET input (0x24 <- 0x00), reads 0x26, and writes output back (0x01), restore retried; the chip keeps its output latch. Raw I2C on host 0 (legacy driver, as the panel library), never the library's `enableAllIO_Input()` (it sleeps 2 ms with the bank floating). A state counts after two equal reads. Behind the Settings → System switch, default OFF, so a board without the wiring never flips the bank. The Driveline shows a top view of the chassis in the top-right corner, drawn from the user's sketch with `lv_line` objects and two border boxes, geometry in sketch pixels scaled by `DL_S`. A locked axle turns amber, with its wheels and an X on its diff. The front axle turns red if it reads locked without the rear. A caption below reads DIFFS OPEN, REAR LOCKED, REAR + FRONT or FRONT ONLY. The whole drawing is hidden when the switch is off; the System row's sub-line shows the live state for testing. Wiring and evidence: wiki `diff-lock-inputs`. `src/modules/diff_locks.cpp` reads the Patrol's two diff-lock signals (+12 V = locked) on the isolated inputs: DI0 = rear, DI1 = front, `DI_COM` to vehicle ground. The PC814 outputs reach the ESP32 only through the CH422G (DI0 = EXIO0, DI1 = EXIO5, active LOW), and the CH422G's IO0-7 are one bank, all in or all out - the same bank drives touch reset (EXIO1), backlight (EXIO2) and LCD reset (EXIO3). Each poll (4 Hz, under the LVGL lock so no touch read shares the bus) writes WR_SET input (0x24 <- 0x00), reads 0x26, and writes output back (0x01), restore retried; the chip keeps its output latch. Raw I2C on host 0 (legacy driver, as the panel library), never the library's `enableAllIO_Input()` (it sleeps 2 ms with the bank floating). A state counts after two equal reads. Behind the Settings → System switch, default OFF, so a board without the wiring never flips the bank. The Driveline shows a top view of the chassis in the top-right corner, drawn from the user's sketch with `lv_line` objects and two border boxes, geometry in sketch pixels scaled by `DL_S`. All four tyres are the same square-cornered rectangle, and the wheelbase is the sketch's shortened by 20 %. A locked axle turns amber: axle, tyres filled solid, and an X on its diff. A filled tyre is one `lv_line` as wide as the tyre with square ends, because LVGL 8 cannot rotate a box. The front axle turns red if it reads locked without the rear. There is no text caption (user). The whole drawing is hidden when the switch is off; the System row's sub-line shows the live state for testing. Wiring and evidence: wiki `diff-lock-inputs`.
### Screens ### Screens
+69 -69
View File
@@ -52,7 +52,6 @@ static lv_obj_t* g_eng_chip = NULL;
static lv_obj_t* g_clutch_chip = NULL; static lv_obj_t* g_clutch_chip = NULL;
static lv_obj_t* g_cool_chip = NULL; static lv_obj_t* g_cool_chip = NULL;
static lv_obj_t* g_diff_box = NULL; // top-right: chassis top view, locked axles lit static lv_obj_t* g_diff_box = NULL; // top-right: chassis top view, locked axles lit
static lv_obj_t* g_diff_caption = NULL;
// ============================================================================ // ============================================================================
// PRIVATE HELPERS // PRIVATE HELPERS
@@ -116,27 +115,40 @@ static void setChip(lv_obj_t* chip, const char* text, lv_color_t colour) {
} }
// ---- diff-lock drawing ------------------------------------------------------ // ---- diff-lock drawing ------------------------------------------------------
// A top view of the chassis, after the user's sketch (209 x 285 px, front up): // A top view of the chassis, after the user's sketch (front up): steered front
// steered front wheels on the front axle, prop shaft, rear axle on straight // tyres on the front axle, prop shaft, rear axle on straight tyres. All four
// wheels. A locked axle lights up (axle, wheels, and an X on its diff). All // tyres are the same square-cornered 24 x 76 rectangle. A locked axle lights up:
// geometry below is in sketch pixels, scaled by DL_S. // axle, tyres filled, and an X on its diff. Geometry is in sketch pixels, scaled
// by DL_S. Wheelbase 151 = the sketch's 189 shortened by 20 % (user, 2026-09-29).
static const float DL_S = 0.46f; // sketch -> screen static const float DL_S = 0.46f; // sketch -> screen
static const lv_coord_t DL_BOX_W = 150; // wide enough for "REAR + FRONT" static const lv_coord_t DL_BOX_W = 110; // hugs the drawing (dl(DL_W) = 98)
static const float DL_W = 212; // sketch width the drawing is centred in
static const float DL_SHAFT_X = 106;
static const float DL_FRONT_Y = 45;
static const float DL_REAR_Y = DL_FRONT_Y + 151;
static const float DL_TRACK_L = 45, DL_TRACK_R = 167; // tyre centres, symmetric about the shaft
static const float DL_TYRE_W = 24, DL_TYRE_L = 76;
static const float DL_STEER = 25; // front tyres, degrees, top leaning right
static lv_coord_t dl(float v) { return (lv_coord_t)lroundf(v * DL_S); } static lv_coord_t dl(float v) { return (lv_coord_t)lroundf(v * DL_S); }
/** Sketch point -> box point (drawing centred horizontally in the box). */ /** Sketch point -> box point (drawing centred horizontally in the box). */
static lv_point_t dlPoint(float x, float y) { static lv_point_t dlPoint(float x, float y) {
lv_point_t pt; lv_point_t pt;
pt.x = (DL_BOX_W - dl(209)) / 2 + dl(x); pt.x = (DL_BOX_W - dl(DL_W)) / 2 + dl(x);
pt.y = dl(y) + 2; pt.y = dl(y) + 2;
return pt; return pt;
} }
struct TyreView {
lv_obj_t* outline;
lv_obj_t* fill; // shown only while the axle is locked
};
struct AxleView { struct AxleView {
lv_obj_t* axle; lv_obj_t* axle;
lv_obj_t* wheel[2]; TyreView tyre[2];
lv_obj_t* cross[2]; // the X on the diff, shown only while locked lv_obj_t* cross[2]; // the X on the diff, shown only while locked
}; };
static AxleView g_front_axle, g_rear_axle; static AxleView g_front_axle, g_rear_axle;
@@ -144,45 +156,43 @@ static AxleView g_front_axle, g_rear_axle;
// lv_line keeps a pointer to its points: they must outlive the objects. // lv_line keeps a pointer to its points: they must outlive the objects.
static lv_point_t g_pts_shaft[2]; static lv_point_t g_pts_shaft[2];
static lv_point_t g_pts_axle[2][2]; // [front, rear][end] static lv_point_t g_pts_axle[2][2]; // [front, rear][end]
static lv_point_t g_pts_front_wheel[2][5]; // closed outlines of the steered wheels static lv_point_t g_pts_tyre[2][2][5]; // [front, rear][left, right] closed outline
static lv_point_t g_pts_fill[2][2][2]; // [front, rear][left, right] centre line of the fill
static lv_point_t g_pts_cross[2][2][2]; // [front, rear][stroke][end] static lv_point_t g_pts_cross[2][2][2]; // [front, rear][stroke][end]
static lv_obj_t* makeLine(lv_obj_t* parent, lv_point_t* pts, uint16_t n, lv_coord_t width) { static lv_obj_t* makeLine(lv_obj_t* parent, lv_point_t* pts, uint16_t n, lv_coord_t width, bool rounded) {
lv_obj_t* l = lv_line_create(parent); lv_obj_t* l = lv_line_create(parent);
lv_line_set_points(l, pts, n); lv_line_set_points(l, pts, n);
lv_obj_set_style_line_width(l, width, 0); lv_obj_set_style_line_width(l, width, 0);
lv_obj_set_style_line_rounded(l, true, 0); lv_obj_set_style_line_rounded(l, rounded, 0);
lv_obj_set_style_line_color(l, COL_MUTED, 0); lv_obj_set_style_line_color(l, COL_MUTED, 0);
lv_obj_clear_flag(l, LV_OBJ_FLAG_CLICKABLE); lv_obj_clear_flag(l, LV_OBJ_FLAG_CLICKABLE);
return l; return l;
} }
/** Steered wheel: a 24 x 76 outline around (cx, cy), top leaning 25 deg to the right. */ /**
static void steeredWheel(lv_point_t* out, float cx, float cy) { * A tyre centred on (cx, cy), `steer` degrees from straight (top leaning right).
const float a = 12, b = 38, t = 25.0f * (float)M_PI / 180.0f; * The fill is ONE line as wide as the tyre with square ends, which is exactly
* the filled rectangle, rotated or not (LVGL 8 cannot rotate a plain box).
*/
static TyreView makeTyre(lv_obj_t* parent, lv_point_t* outline, lv_point_t* fill,
float cx, float cy, float steer) {
const float a = DL_TYRE_W / 2, b = DL_TYRE_L / 2, t = steer * (float)M_PI / 180.0f;
const float ux = sinf(t), uy = -cosf(t); // long axis, towards the top const float ux = sinf(t), uy = -cosf(t); // long axis, towards the top
const float vx = cosf(t), vy = sinf(t); // short axis const float vx = cosf(t), vy = sinf(t); // short axis
const float k[4][2] = {{b, a}, {b, -a}, {-b, -a}, {-b, a}}; const float k[4][2] = {{b, a}, {b, -a}, {-b, -a}, {-b, a}};
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
out[i] = dlPoint(cx + k[i][0] * ux + k[i][1] * vx, cy + k[i][0] * uy + k[i][1] * vy); outline[i] = dlPoint(cx + k[i][0] * ux + k[i][1] * vx, cy + k[i][0] * uy + k[i][1] * vy);
} }
out[4] = out[0]; outline[4] = outline[0];
} fill[0] = dlPoint(cx + b * ux, cy + b * uy);
fill[1] = dlPoint(cx - b * ux, cy - b * uy);
/** Straight (rear) wheel: rounded outline, sketch x/y of its top-left corner. */ TyreView v;
static lv_obj_t* straightWheel(lv_obj_t* parent, float x, float y) { v.fill = makeLine(parent, fill, 2, dl(DL_TYRE_W), false);
lv_obj_t* w = lv_obj_create(parent); lv_obj_add_flag(v.fill, LV_OBJ_FLAG_HIDDEN);
lv_obj_remove_style_all(w); v.outline = makeLine(parent, outline, 5, 2, true); // 2 px rounded joins read as square corners
lv_point_t p = dlPoint(x, y); return v;
lv_obj_set_pos(w, p.x, p.y);
lv_obj_set_size(w, dl(24), dl(76));
lv_obj_set_style_radius(w, dl(10), 0);
lv_obj_set_style_border_width(w, 2, 0);
lv_obj_set_style_border_opa(w, LV_OPA_COVER, 0);
lv_obj_set_style_border_color(w, COL_MUTED, 0);
lv_obj_clear_flag(w, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_clear_flag(w, LV_OBJ_FLAG_CLICKABLE);
return w;
} }
/** The X on a diff at (cx, cy); idx 0 = front, 1 = rear. */ /** The X on a diff at (cx, cy); idx 0 = front, 1 = rear. */
@@ -191,19 +201,15 @@ static void diffCross(lv_obj_t* parent, AxleView& a, int idx, float cx, float cy
g_pts_cross[idx][0][0] = dlPoint(cx - r, cy - r); g_pts_cross[idx][0][1] = dlPoint(cx + r, cy + r); g_pts_cross[idx][0][0] = dlPoint(cx - r, cy - r); g_pts_cross[idx][0][1] = dlPoint(cx + r, cy + r);
g_pts_cross[idx][1][0] = dlPoint(cx + r, cy - r); g_pts_cross[idx][1][1] = dlPoint(cx - r, cy + r); g_pts_cross[idx][1][0] = dlPoint(cx + r, cy - r); g_pts_cross[idx][1][1] = dlPoint(cx - r, cy + r);
for (int k = 0; k < 2; k++) { for (int k = 0; k < 2; k++) {
a.cross[k] = makeLine(parent, g_pts_cross[idx][k], 2, 4); a.cross[k] = makeLine(parent, g_pts_cross[idx][k], 2, 4, true);
lv_obj_add_flag(a.cross[k], LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(a.cross[k], LV_OBJ_FLAG_HIDDEN);
} }
} }
/** Line colour for lines, border colour for the wheel boxes; written only on change. */ /** Line colour, written only on change. */
static void setPartColour(lv_obj_t* o, lv_color_t c) { static void setPartColour(lv_obj_t* o, lv_color_t c) {
if (lv_obj_check_type(o, &lv_line_class)) { if (lv_color_to32(lv_obj_get_style_line_color(o, 0)) != lv_color_to32(c)) {
if (lv_color_to32(lv_obj_get_style_line_color(o, 0)) != lv_color_to32(c)) { lv_obj_set_style_line_color(o, c, 0);
lv_obj_set_style_line_color(o, c, 0);
}
} else if (lv_color_to32(lv_obj_get_style_border_color(o, 0)) != lv_color_to32(c)) {
lv_obj_set_style_border_color(o, c, 0);
} }
} }
@@ -217,7 +223,9 @@ static void setAxle(AxleView& a, bool locked, lv_color_t colour) {
lv_color_t c = locked ? colour : COL_MUTED; lv_color_t c = locked ? colour : COL_MUTED;
setPartColour(a.axle, c); setPartColour(a.axle, c);
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
setPartColour(a.wheel[i], c); setPartColour(a.tyre[i].outline, c);
setPartColour(a.tyre[i].fill, c);
setHidden(a.tyre[i].fill, !locked);
setPartColour(a.cross[i], c); setPartColour(a.cross[i], c);
setHidden(a.cross[i], !locked); setHidden(a.cross[i], !locked);
} }
@@ -235,17 +243,11 @@ static void refreshDiffLocks() {
if (!DiffLocks::isValid()) { if (!DiffLocks::isValid()) {
setAxle(g_front_axle, false, COL_MUTED); setAxle(g_front_axle, false, COL_MUTED);
setAxle(g_rear_axle, false, COL_MUTED); setAxle(g_rear_axle, false, COL_MUTED);
setText(g_diff_caption, "DIFF LOCK ?");
setColour(g_diff_caption, COL_MUTED);
return; return;
} }
bool rear = DiffLocks::rearLocked(), front = DiffLocks::frontLocked(); bool rear = DiffLocks::rearLocked(), front = DiffLocks::frontLocked();
setAxle(g_rear_axle, rear, COL_AMBER); setAxle(g_rear_axle, rear, COL_AMBER);
setAxle(g_front_axle, front, rear ? COL_AMBER : COL_ALERT); setAxle(g_front_axle, front, rear ? COL_AMBER : COL_ALERT); // no caption: the drawing says it all (user)
if (front && rear) { setText(g_diff_caption, "REAR + FRONT"); setColour(g_diff_caption, COL_AMBER); }
else if (rear) { setText(g_diff_caption, "REAR LOCKED"); setColour(g_diff_caption, COL_AMBER); }
else if (front) { setText(g_diff_caption, "FRONT ONLY"); setColour(g_diff_caption, COL_ALERT); }
else { setText(g_diff_caption, "DIFFS OPEN"); setColour(g_diff_caption, COL_MUTED); }
} }
/** /**
@@ -353,36 +355,34 @@ static void build() {
// Box bottom stays above the GEARBOX OIL stat (its top is at y ~227). // Box bottom stays above the GEARBOX OIL stat (its top is at y ~227).
g_diff_box = lv_obj_create(g_screen); g_diff_box = lv_obj_create(g_screen);
lv_obj_remove_style_all(g_diff_box); lv_obj_remove_style_all(g_diff_box);
lv_obj_set_size(g_diff_box, DL_BOX_W, dl(285) + 30); lv_obj_set_size(g_diff_box, DL_BOX_W, dl(DL_REAR_Y + DL_TYRE_L / 2) + 6); // drawing only, no caption
lv_obj_align(g_diff_box, LV_ALIGN_TOP_RIGHT, -16, 60); lv_obj_align(g_diff_box, LV_ALIGN_TOP_RIGHT, -16, 60);
lv_obj_clear_flag(g_diff_box, LV_OBJ_FLAG_SCROLLABLE); lv_obj_clear_flag(g_diff_box, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_clear_flag(g_diff_box, LV_OBJ_FLAG_CLICKABLE); // swipes pass through to the screen lv_obj_clear_flag(g_diff_box, LV_OBJ_FLAG_CLICKABLE); // swipes pass through to the screen
lv_obj_add_flag(g_diff_box, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(g_diff_box, LV_OBJ_FLAG_HIDDEN);
g_pts_shaft[0] = dlPoint(106, 45); g_pts_shaft[0] = dlPoint(DL_SHAFT_X, DL_FRONT_Y);
g_pts_shaft[1] = dlPoint(106, 234); g_pts_shaft[1] = dlPoint(DL_SHAFT_X, DL_REAR_Y);
makeLine(g_diff_box, g_pts_shaft, 2, 3); makeLine(g_diff_box, g_pts_shaft, 2, 3, true);
g_pts_axle[0][0] = dlPoint(57, 45); g_pts_axle[0][1] = dlPoint(160, 45); // axles run between the tyres' inner edges (a steered tyre's edge sits a little further out)
g_pts_axle[1][0] = dlPoint(57, 234); g_pts_axle[1][1] = dlPoint(159, 234); const float half = DL_TYRE_W / 2;
g_front_axle.axle = makeLine(g_diff_box, g_pts_axle[0], 2, 3); const float half_steered = half / cosf(DL_STEER * (float)M_PI / 180.0f);
g_rear_axle.axle = makeLine(g_diff_box, g_pts_axle[1], 2, 3); g_pts_axle[0][0] = dlPoint(DL_TRACK_L + half_steered, DL_FRONT_Y);
g_pts_axle[0][1] = dlPoint(DL_TRACK_R - half_steered, DL_FRONT_Y);
g_pts_axle[1][0] = dlPoint(DL_TRACK_L + half, DL_REAR_Y);
g_pts_axle[1][1] = dlPoint(DL_TRACK_R - half, DL_REAR_Y);
g_front_axle.axle = makeLine(g_diff_box, g_pts_axle[0], 2, 3, true);
g_rear_axle.axle = makeLine(g_diff_box, g_pts_axle[1], 2, 3, true);
steeredWheel(g_pts_front_wheel[0], 45, 47); g_front_axle.tyre[0] = makeTyre(g_diff_box, g_pts_tyre[0][0], g_pts_fill[0][0], DL_TRACK_L, DL_FRONT_Y, DL_STEER);
steeredWheel(g_pts_front_wheel[1], 172, 47); g_front_axle.tyre[1] = makeTyre(g_diff_box, g_pts_tyre[0][1], g_pts_fill[0][1], DL_TRACK_R, DL_FRONT_Y, DL_STEER);
g_front_axle.wheel[0] = makeLine(g_diff_box, g_pts_front_wheel[0], 5, 2); g_rear_axle.tyre[0] = makeTyre(g_diff_box, g_pts_tyre[1][0], g_pts_fill[1][0], DL_TRACK_L, DL_REAR_Y, 0);
g_front_axle.wheel[1] = makeLine(g_diff_box, g_pts_front_wheel[1], 5, 2); g_rear_axle.tyre[1] = makeTyre(g_diff_box, g_pts_tyre[1][1], g_pts_fill[1][1], DL_TRACK_R, DL_REAR_Y, 0);
g_rear_axle.wheel[0] = straightWheel(g_diff_box, 33, 196);
g_rear_axle.wheel[1] = straightWheel(g_diff_box, 159, 196);
diffCross(g_diff_box, g_front_axle, 0, 106, 45); diffCross(g_diff_box, g_front_axle, 0, DL_SHAFT_X, DL_FRONT_Y);
diffCross(g_diff_box, g_rear_axle, 1, 106, 234); diffCross(g_diff_box, g_rear_axle, 1, DL_SHAFT_X, DL_REAR_Y);
g_diff_caption = lv_label_create(g_diff_box);
lv_label_set_text(g_diff_caption, "DIFF LOCK ?");
lv_obj_set_style_text_font(g_diff_caption, &lv_font_montserrat_20, 0);
lv_obj_set_style_text_color(g_diff_caption, COL_MUTED, 0);
lv_obj_align(g_diff_caption, LV_ALIGN_BOTTOM_MID, 0, 0);
// ---- gear hero ------------------------------------------------------- // ---- gear hero -------------------------------------------------------
g_gear_ring = lv_obj_create(g_screen); g_gear_ring = lv_obj_create(g_screen);
+1 -1
View File
@@ -32,7 +32,7 @@ The CH422G's IO0–7 are **one bank, all inputs or all outputs**, and the same b
> [!warning] Not yet verified on this board > [!warning] Not yet verified on this board
> Whether the 0.1 ms float disturbs the panel (flicker) or touch is **unknown** until tried. That is why the feature sits behind **Settings → System → Diff lock inputs**, default OFF. A board without the wiring never flips the bank. If the panel flickers with the switch on, turn it off. The fallback is to move the inputs to spare GPIOs on the Inst. Cluster. > Whether the 0.1 ms float disturbs the panel (flicker) or touch is **unknown** until tried. That is why the feature sits behind **Settings → System → Diff lock inputs**, default OFF. A board without the wiring never flips the bank. If the panel flickers with the switch on, turn it off. The fallback is to move the inputs to spare GPIOs on the Inst. Cluster.
A state counts after two equal reads, so it can lag the real switch by up to 0.5 s. The Driveline draws a top view of the chassis, after the user's sketch. A locked axle turns amber: axle, wheels, and an X on the diff. Front locked without rear turns the front axle red, as a wiring or switch fault (verified on the bench by the user, 2026-09-29, with the earlier pill display: DI1 alone showed red, both inputs showed amber). A state counts after two equal reads, so it can lag the real switch by up to 0.5 s. The Driveline draws a top view of the chassis, after the user's sketch. A locked axle turns amber: axle, tyres filled, and an X on the diff. There is no text; the drawing alone carries the state (user, 2026-09-29). Front locked without rear turns the front axle red, as a wiring or switch fault (verified on the bench by the user, 2026-09-29, with the earlier pill display: DI1 alone showed red, both inputs showed amber).
## Test on the bench ## Test on the bench