Diff-lock drawing: wheelbase -20 %, same square tyres all round, locked axle's tyres filled, no caption text
Firmware / build (push) Successful in 7m5s
Firmware / build (push) Successful in 7m5s
This commit is contained in:
@@ -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_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_caption = NULL;
|
||||
|
||||
// ============================================================================
|
||||
// PRIVATE HELPERS
|
||||
@@ -116,27 +115,40 @@ static void setChip(lv_obj_t* chip, const char* text, lv_color_t colour) {
|
||||
}
|
||||
|
||||
// ---- 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.
|
||||
// A top view of the chassis, after the user's sketch (front up): steered front
|
||||
// tyres on the front axle, prop shaft, rear axle on straight tyres. All four
|
||||
// tyres are the same square-cornered 24 x 76 rectangle. A locked axle lights up:
|
||||
// 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 lv_coord_t DL_BOX_W = 150; // wide enough for "REAR + FRONT"
|
||||
static const float DL_S = 0.46f; // sketch -> screen
|
||||
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); }
|
||||
|
||||
/** 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.x = (DL_BOX_W - dl(DL_W)) / 2 + dl(x);
|
||||
pt.y = dl(y) + 2;
|
||||
return pt;
|
||||
}
|
||||
|
||||
struct TyreView {
|
||||
lv_obj_t* outline;
|
||||
lv_obj_t* fill; // shown only while the axle is locked
|
||||
};
|
||||
|
||||
struct AxleView {
|
||||
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
|
||||
};
|
||||
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.
|
||||
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_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_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_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_rounded(l, rounded, 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;
|
||||
/**
|
||||
* A tyre centred on (cx, cy), `steer` degrees from straight (top leaning right).
|
||||
* 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 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);
|
||||
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. */
|
||||
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;
|
||||
TyreView v;
|
||||
v.fill = makeLine(parent, fill, 2, dl(DL_TYRE_W), false);
|
||||
lv_obj_add_flag(v.fill, LV_OBJ_FLAG_HIDDEN);
|
||||
v.outline = makeLine(parent, outline, 5, 2, true); // 2 px rounded joins read as square corners
|
||||
return v;
|
||||
}
|
||||
|
||||
/** 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][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);
|
||||
a.cross[k] = makeLine(parent, g_pts_cross[idx][k], 2, 4, true);
|
||||
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) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +223,9 @@ 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.tyre[i].outline, c);
|
||||
setPartColour(a.tyre[i].fill, c);
|
||||
setHidden(a.tyre[i].fill, !locked);
|
||||
setPartColour(a.cross[i], c);
|
||||
setHidden(a.cross[i], !locked);
|
||||
}
|
||||
@@ -235,17 +243,11 @@ static void refreshDiffLocks() {
|
||||
if (!DiffLocks::isValid()) {
|
||||
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();
|
||||
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); }
|
||||
setAxle(g_front_axle, front, rear ? COL_AMBER : COL_ALERT); // no caption: the drawing says it all (user)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,36 +355,34 @@ static void build() {
|
||||
// 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, 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_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);
|
||||
|
||||
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_shaft[0] = dlPoint(DL_SHAFT_X, DL_FRONT_Y);
|
||||
g_pts_shaft[1] = dlPoint(DL_SHAFT_X, DL_REAR_Y);
|
||||
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);
|
||||
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);
|
||||
// axles run between the tyres' inner edges (a steered tyre's edge sits a little further out)
|
||||
const float half = DL_TYRE_W / 2;
|
||||
const float half_steered = half / cosf(DL_STEER * (float)M_PI / 180.0f);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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_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_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);
|
||||
|
||||
diffCross(g_diff_box, g_front_axle, 0, 106, 45);
|
||||
diffCross(g_diff_box, g_rear_axle, 1, 106, 234);
|
||||
diffCross(g_diff_box, g_front_axle, 0, DL_SHAFT_X, DL_FRONT_Y);
|
||||
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 -------------------------------------------------------
|
||||
g_gear_ring = lv_obj_create(g_screen);
|
||||
|
||||
Reference in New Issue
Block a user