Diff locks on the Driveline: chassis top view after the user's sketch (steered front wheels, prop shaft, rear axle); locked axle amber with an X on its diff, front-only red, caption
Firmware / build (push) Successful in 6m59s
Firmware / build (push) Successful in 6m59s
This commit is contained in:
@@ -234,7 +234,7 @@ Settings persist across power cycles via ESP32 NVS (Non-Volatile Storage):
|
||||
|
||||
### 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. Driveline shows `DIFF LOCK [REAR] [FRONT]` top-right (amber = locked, FRONT red if it reads locked without REAR, hidden when 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`. 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`.
|
||||
|
||||
### Screens
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "driveline_screen.h"
|
||||
#include "uart_manager.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "display/lvgl_v8_port.h"
|
||||
#include "drivers/can_driver.h"
|
||||
#include "tuning_screen.h"
|
||||
@@ -50,9 +51,8 @@ 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;
|
||||
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
|
||||
@@ -115,36 +115,137 @@ 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);
|
||||
// ---- diff-lock drawing ------------------------------------------------------
|
||||
// A top view of the chassis, after the user's sketch (209 x 285 px, front up):
|
||||
// steered front wheels on the front axle, prop shaft, rear axle on straight
|
||||
// wheels. A locked axle lights up (axle, wheels, and an X on its diff). All
|
||||
// geometry below is in sketch pixels, scaled by DL_S.
|
||||
|
||||
static const float DL_S = 0.46f; // sketch -> screen
|
||||
static const lv_coord_t DL_BOX_W = 150; // wide enough for "REAR + FRONT"
|
||||
|
||||
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). */
|
||||
static lv_point_t dlPoint(float x, float y) {
|
||||
lv_point_t pt;
|
||||
pt.x = (DL_BOX_W - dl(209)) / 2 + dl(x);
|
||||
pt.y = dl(y) + 2;
|
||||
return pt;
|
||||
}
|
||||
|
||||
struct AxleView {
|
||||
lv_obj_t* axle;
|
||||
lv_obj_t* wheel[2];
|
||||
lv_obj_t* cross[2]; // the X on the diff, shown only while locked
|
||||
};
|
||||
static AxleView g_front_axle, g_rear_axle;
|
||||
|
||||
// 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_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_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) {
|
||||
lv_obj_t* l = lv_line_create(parent);
|
||||
lv_line_set_points(l, pts, n);
|
||||
lv_obj_set_style_line_width(l, width, 0);
|
||||
lv_obj_set_style_line_rounded(l, true, 0);
|
||||
lv_obj_set_style_line_color(l, COL_MUTED, 0);
|
||||
lv_obj_clear_flag(l, LV_OBJ_FLAG_CLICKABLE);
|
||||
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) {
|
||||
const float a = 12, b = 38, t = 25.0f * (float)M_PI / 180.0f;
|
||||
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 k[4][2] = {{b, a}, {b, -a}, {-b, -a}, {-b, a}};
|
||||
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);
|
||||
}
|
||||
out[4] = out[0];
|
||||
}
|
||||
|
||||
/** Straight (rear) wheel: rounded outline, sketch x/y of its top-left corner. */
|
||||
static lv_obj_t* straightWheel(lv_obj_t* parent, float x, float y) {
|
||||
lv_obj_t* w = lv_obj_create(parent);
|
||||
lv_obj_remove_style_all(w);
|
||||
lv_point_t p = dlPoint(x, y);
|
||||
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. */
|
||||
static void diffCross(lv_obj_t* parent, AxleView& a, int idx, float cx, float cy) {
|
||||
const float r = 16;
|
||||
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);
|
||||
for (int k = 0; k < 2; k++) {
|
||||
a.cross[k] = makeLine(parent, g_pts_cross[idx][k], 2, 4);
|
||||
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. */
|
||||
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)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
static void setHidden(lv_obj_t* o, bool hidden) {
|
||||
if (lv_obj_has_flag(o, LV_OBJ_FLAG_HIDDEN) == hidden) return;
|
||||
if (hidden) lv_obj_add_flag(o, LV_OBJ_FLAG_HIDDEN);
|
||||
else lv_obj_clear_flag(o, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
static void setAxle(AxleView& a, bool locked, lv_color_t colour) {
|
||||
lv_color_t c = locked ? colour : COL_MUTED;
|
||||
setPartColour(a.axle, c);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
setPartColour(a.wheel[i], c);
|
||||
setPartColour(a.cross[i], c);
|
||||
setHidden(a.cross[i], !locked);
|
||||
}
|
||||
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.
|
||||
* Locked axle = amber. 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);
|
||||
}
|
||||
setHidden(g_diff_box, !on);
|
||||
if (!on) return;
|
||||
if (!DiffLocks::isValid()) {
|
||||
setPill(g_rear_pill, "REAR ?", COL_PANEL, COL_MUTED);
|
||||
setPill(g_front_pill, "FRONT ?", COL_PANEL, COL_MUTED);
|
||||
setAxle(g_front_axle, false, COL_MUTED);
|
||||
setAxle(g_rear_axle, false, COL_MUTED);
|
||||
setText(g_diff_caption, "DIFF LOCK ?");
|
||||
setColour(g_diff_caption, 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);
|
||||
setAxle(g_rear_axle, rear, COL_AMBER);
|
||||
setAxle(g_front_axle, front, rear ? COL_AMBER : COL_ALERT);
|
||||
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); }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,27 +349,40 @@ 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)
|
||||
// ---- diff locks, top-right under the overlay's Wi-Fi chip (hidden until enabled).
|
||||
// Box bottom stays above the GEARBOX OIL stat (its top is at y ~227).
|
||||
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_set_size(g_diff_box, DL_BOX_W, dl(285) + 30);
|
||||
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_CLICKABLE); // swipes pass through to the screen
|
||||
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);
|
||||
}
|
||||
g_pts_shaft[0] = dlPoint(106, 45);
|
||||
g_pts_shaft[1] = dlPoint(106, 234);
|
||||
makeLine(g_diff_box, g_pts_shaft, 2, 3);
|
||||
|
||||
g_pts_axle[0][0] = dlPoint(57, 45); g_pts_axle[0][1] = dlPoint(160, 45);
|
||||
g_pts_axle[1][0] = dlPoint(57, 234); g_pts_axle[1][1] = dlPoint(159, 234);
|
||||
g_front_axle.axle = makeLine(g_diff_box, g_pts_axle[0], 2, 3);
|
||||
g_rear_axle.axle = makeLine(g_diff_box, g_pts_axle[1], 2, 3);
|
||||
|
||||
steeredWheel(g_pts_front_wheel[0], 45, 47);
|
||||
steeredWheel(g_pts_front_wheel[1], 172, 47);
|
||||
g_front_axle.wheel[0] = makeLine(g_diff_box, g_pts_front_wheel[0], 5, 2);
|
||||
g_front_axle.wheel[1] = makeLine(g_diff_box, g_pts_front_wheel[1], 5, 2);
|
||||
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_rear_axle, 1, 106, 234);
|
||||
|
||||
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 -------------------------------------------------------
|
||||
g_gear_ring = lv_obj_create(g_screen);
|
||||
|
||||
@@ -32,12 +32,12 @@ The CH422G's IO0–7 are **one bank, all inputs or all outputs**, and the same b
|
||||
> [!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.
|
||||
|
||||
A state counts after two equal reads, so it can lag the real switch by up to 0.5 s. Front-locked-without-rear is shown red on the Driveline, as a wiring or switch fault.
|
||||
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).
|
||||
|
||||
## Test on the bench
|
||||
|
||||
1. Settings → System → Diff lock inputs ON. The row's sub-line shows "Now: both open".
|
||||
2. Put 12 V (the board's own VIN supply) on `DI0`, with `DI_COM` on `GND`. It should show "rear LOCKED", and the Driveline REAR pill turns amber. Then do the same on `DI1`.
|
||||
2. Put 12 V (the board's own VIN supply) on `DI0`, with `DI_COM` on `GND`. It should show "rear LOCKED", and the rear axle in the Driveline chassis drawing turns amber with an X on the diff. Then do the same on `DI1`.
|
||||
3. Console: `difflock status` prints the raw IO byte: bit 0x01 (rear) and bit 0x20 (front) are SET while open, clear while locked.
|
||||
4. Watch the panel for flicker while the switch is on (see the warning above).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user