4 Commits

7 changed files with 325 additions and 107 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ include/
**DisplayInit** — `init()`, `update()`, `lock(timeout_ms)` / `unlock()`, `setBrightness(0–255)`, `getBrightness()`. Default brightness 128. `DISPLAY_RADIUS 120` defines the circular mask.
**GaugeScreen** — `init()` builds and loads the screen once; `update(data, link_ok)` at 5 Hz writes a label, colour or icon **only when it changed** (`lv_label_set_text()` and style setters invalidate even for identical values, and every redraw is SPI time). Gear label: engaged gear, or the target gear pulsing while `target != engaged`, red on the mismatch alert; icons red from A's alert bits; everything N/A when the link is lost.
**GaugeScreen** (round-panel layout, user's design 2026-09-28: two ARC GAUGES on the rim with no digits - coolant on the left from compass 230° (bottom, 50 °C) to 320° (top, 120 °C), gearbox oil on the right from 140° (bottom, 40 °C) to 40° (top, 150 °C); each a blue→neutral→red gradient built from 10° `lv_arc` segments, a white `lv_line` needle recomputed only when its angle changes, and the gauge's icon just past the hot end (red variant while that alert is on); 6 px warning-lamp ring at the very rim - dim / RED BLINKING 2 Hz on any red alert / amber on gearbox cooling; gear 110 px centre; battery [icon][12.4] bottom; Wi-Fi tell-tale at 9 o'clock (green only while joined for an update), red `!` at 3 o'clock when the link is lost. LVGL angle = compass − 90; everything placed absolutely inside the circle) — `init()` builds and loads the screen once; `setNotice(text)` shows the updater's progress line; `update(data, link_ok)` at 5 Hz writes a label, colour or icon **only when it changed** (`lv_label_set_text()` and style setters invalidate even for identical values, and every redraw is SPI time). Gear label: engaged gear, or the target gear pulsing while `target != engaged`, red on the mismatch alert; icons red from A's alert bits; everything N/A when the link is lost.
**UARTReceiver** — `init()`, `processFrame(frame, len, source)`, `getLatestData()`, `getStats()` (applied / per-transport / duplicate / config counts, checksum / framing / version errors, last times), `isConnected()`, `isSourceAlive(source)`, `getConfig()` + `getConfigSeq()`. Link lost after 1000 ms without an applied DATA frame on any transport.
+3 -11
View File
@@ -772,16 +772,8 @@ static inline char* format_voltage(uint16_t voltage_x100, char* buffer) {
return buffer;
}
// ============================================================================
// DEFAULT/TEST VALUES
// ============================================================================
// Default values for testing (before CAN data is available)
#define DEFAULT_GEAR_LEVER LEVER_PARK
#define DEFAULT_GEARBOX_TEMP 850 // 85.0°C
#define DEFAULT_ENGINE_OIL_TEMP 920 // 92.0°C
#define DEFAULT_COOLANT_TEMP 890 // 89.0°C
#define DEFAULT_BATTERY_VOLTAGE 1245 // 12.45V
#define DEFAULT_ALERTS 0x0000 // No alerts
// No default / test values: a field is only ever filled from a CAN frame, and
// its VALID_FLAG_* bit says so. Removed 2026-09-28 - the bench defaults
// (89 / 85 degC, 12.45 V) looked like real readings on Controller B.
#endif // _AUTOMOTIVE_DATA_H
+296 -86
View File
@@ -1,46 +1,104 @@
/*
* Gauge Screen implementation. See gauge_screen.h.
*
* Layout for the ROUND 240x240 panel (2026-09-28, user's design):
*
* - two ARC GAUGES on the rim, no digits: coolant on the LEFT (compass 230°
* at the bottom-left up to 320° at the top-left), gearbox oil on the RIGHT
* (compass 140° bottom-right up to 40° top-right). Each arc is a blue ->
* red gradient (cold at the bottom, hot at the top) with a white needle.
* LVGL angles are compass - 90: coolant 140..230, gearbox 310..410 (=50).
* - the gauge's icon sits just past the hot end, upper-left / upper-right;
* it switches to its red variant while that alert is on.
* - outer ring, 6 px, at the very rim: dim normally, RED BLINKING while any
* red alert is on, amber while the gearbox asks for cooling.
* - gear letter 110 px in the centre, battery [icon][12.4] at the bottom.
* - tell-tales: Wi-Fi at 9 o'clock (green only while joined for an update),
* red "!" at 3 o'clock when the link to A is lost.
*
* Geometry (centre 120,120): ring r 114-120, arc band r 100-110, needle
* r 92-113, icons centred at r 66, gear ink roughly y 94-174, battery row
* y 176-220. Everything placed absolutely inside the circle.
*/
#include "modules/gauge_screen.h"
#include "modules/display_init.h"
#include "assets/assets.h"
#include <lvgl.h>
#include <WiFi.h>
#include <string.h>
#include <math.h>
namespace GaugeScreen {
// A shift pulse is shown for at least this long, so a fast shift still blinks
#define SHIFT_PULSE_MIN_MS 600
#define BLINK_MS 500
static const lv_color_t COL_ALERT = lv_color_hex(0xFF3B30);
static const lv_color_t COL_TEXT = lv_color_hex(0xE8EDF2);
static const lv_color_t COL_MUTED = lv_color_hex(0x3A4450);
static const lv_color_t COL_ALERT = lv_color_hex(0xFF3B30);
static const lv_color_t COL_ALERT2 = lv_color_hex(0x7A1410); // blink low phase
static const lv_color_t COL_AMBER = lv_color_hex(0xF5A524);
static const lv_color_t COL_RING = lv_color_hex(0x2A323C);
static const lv_color_t COL_OK = lv_color_hex(0x3DD68C);
static const lv_color_t COL_COLD = lv_color_hex(0x2F80ED); // arc, cold end
static const lv_color_t COL_MID = lv_color_hex(0xC8D0D8); // arc, middle
static const lv_color_t COL_HOT = lv_color_hex(0xFF3B30); // arc, hot end
// ---- one value cell: label + normal/red icon pair --------------------------
struct Cell {
// Arc geometry / scales
#define ARC_DIAMETER 220 // outer radius 110
#define ARC_WIDTH 10 // band r 100..110
#define NEEDLE_R0 92
#define NEEDLE_R1 113
#define ICON_R 66
#define COOL_A0 140 // LVGL degrees, cold end (bottom-left)
#define COOL_A1 230 // hot end (top-left)
#define COOL_T_MIN 50 // degC at the cold end
#define COOL_T_MAX 120 // degC at the hot end
#define GB_A0 50 // cold end (bottom-right)
#define GB_A1 -50 // hot end (top-right) == 310
#define GB_T_MIN 40
#define GB_T_MAX 150
// ---- an arc gauge -------------------------------------------------------------
struct Gauge {
lv_obj_t* needle;
lv_point_t pts[2];
int last_angle; // LVGL degrees, -1000 = hidden
lv_obj_t* icon;
lv_obj_t* icon_red;
int8_t shown; // -1 none, 0 normal, 1 red
};
struct Cell { // battery: icon + digits
lv_obj_t* cont;
lv_obj_t* lbl;
lv_obj_t* icon;
lv_obj_t* icon_red;
int8_t shown; // -1 none, 0 normal icon, 1 red icon
int8_t shown;
bool red;
};
static lv_obj_t* g_screen = NULL;
static lv_obj_t* g_notice = NULL; // on lv_layer_top(): update progress line
static Cell g_coolant = {0};
static Cell g_gearbox = {0};
static Cell g_battery = {0};
static lv_obj_t* g_ring = NULL;
static lv_obj_t* g_wifi_tt = NULL;
static lv_obj_t* g_link_tt = NULL;
static lv_obj_t* g_notice = NULL;
static Gauge g_coolant = {0};
static Gauge g_gearbox = {0};
static Cell g_battery = {0};
static lv_obj_t* g_gear_lbl = NULL;
static lv_color_t g_gear_col_default;
static bool g_gear_red = false;
static lv_color_t g_ring_col;
static bool g_wifi_bright = false;
static bool g_link_lost_shown = false;
// gear pulse
static lv_anim_t g_gear_anim;
static bool g_gear_pulsing = false;
static uint32_t g_gear_pulse_started = 0;
// ---- helpers ---------------------------------------------------------------
/** lv_label_set_text() only when the text differs. */
static void setText(lv_obj_t* lbl, const char* text) {
if (lbl == NULL) return;
const char* cur = lv_label_get_text(lbl);
@@ -48,60 +106,154 @@ static void setText(lv_obj_t* lbl, const char* text) {
lv_label_set_text(lbl, text);
}
/** Show the normal icon, the red icon, or neither - touching objects only on change. */
static void setIcon(Cell& c, bool visible, bool red) {
static void setTextColour(lv_obj_t* lbl, lv_color_t c) {
if (lv_color_to32(lv_obj_get_style_text_color(lbl, 0)) != lv_color_to32(c))
lv_obj_set_style_text_color(lbl, c, 0);
}
static void showIconPair(lv_obj_t* icon, lv_obj_t* icon_red, int8_t& shown, bool visible, bool red) {
int8_t want = !visible ? -1 : (red ? 1 : 0);
if (want == c.shown) return;
c.shown = want;
if (want == 0) lv_obj_clear_flag(c.icon, LV_OBJ_FLAG_HIDDEN); else lv_obj_add_flag(c.icon, LV_OBJ_FLAG_HIDDEN);
if (want == 1) lv_obj_clear_flag(c.icon_red, LV_OBJ_FLAG_HIDDEN); else lv_obj_add_flag(c.icon_red, LV_OBJ_FLAG_HIDDEN);
}
static lv_obj_t* makeContainer(lv_obj_t* parent, lv_coord_t w, lv_coord_t h, lv_flex_flow_t flow,
lv_flex_align_t main_place, lv_flex_align_t cross_place) {
lv_obj_t* o = lv_obj_create(parent);
lv_obj_remove_style_all(o);
lv_obj_set_size(o, w, h);
lv_obj_set_flex_flow(o, flow);
lv_obj_set_flex_align(o, main_place, cross_place, cross_place);
lv_obj_clear_flag(o, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE);
return o;
}
static lv_obj_t* makeValueLabel(lv_obj_t* parent) {
lv_obj_t* l = lv_label_create(parent);
lv_label_set_text(l, "---");
lv_obj_set_style_text_font(l, &ui_font_UbuntuLight_35, 0);
return l;
if (want == shown) return;
shown = want;
if (want == 0) lv_obj_clear_flag(icon, LV_OBJ_FLAG_HIDDEN); else lv_obj_add_flag(icon, LV_OBJ_FLAG_HIDDEN);
if (want == 1) lv_obj_clear_flag(icon_red, LV_OBJ_FLAG_HIDDEN); else lv_obj_add_flag(icon_red, LV_OBJ_FLAG_HIDDEN);
}
static lv_obj_t* makeIcon(lv_obj_t* parent, const lv_img_dsc_t* src) {
lv_obj_t* i = lv_img_create(parent);
lv_img_set_src(i, src);
lv_obj_add_flag(i, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(i, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_clear_flag(i, LV_OBJ_FLAG_SCROLLABLE | LV_OBJ_FLAG_CLICKABLE);
return i;
}
/** Blue -> neutral -> red along t in [0,1]. */
static lv_color_t arcColour(float t) {
if (t < 0.5f) return lv_color_mix(COL_MID, COL_COLD, (uint8_t)(t * 2 * 255));
return lv_color_mix(COL_HOT, COL_MID, (uint8_t)((t - 0.5f) * 2 * 255));
}
/** One static arc segment on the rim band. Angles in LVGL degrees, may exceed 360. */
static void makeArcSegment(lv_obj_t* parent, int a0, int a1, lv_color_t col) {
lv_obj_t* a = lv_arc_create(parent);
lv_obj_remove_style(a, NULL, LV_PART_KNOB);
lv_obj_set_style_arc_opa(a, LV_OPA_TRANSP, LV_PART_INDICATOR);
lv_obj_set_style_arc_width(a, ARC_WIDTH, LV_PART_MAIN);
lv_obj_set_style_arc_color(a, col, LV_PART_MAIN);
lv_obj_set_style_arc_rounded(a, false, LV_PART_MAIN);
lv_obj_set_style_bg_opa(a, LV_OPA_TRANSP, 0);
lv_obj_set_size(a, ARC_DIAMETER, ARC_DIAMETER);
lv_obj_center(a);
lv_arc_set_rotation(a, 0);
lv_arc_set_bg_angles(a, (uint16_t)((a0 % 360 + 360) % 360), (uint16_t)((a1 % 360 + 360) % 360));
lv_obj_clear_flag(a, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE);
}
/**
* A cell: 112x80, column. icon_above=false puts the value on top and the icon
* under it (top row); icon_above=true puts the icon on top (bottom row), as
* the original screen did.
* The gradient band from angle a_cold to a_hot (either direction), in ~10°
* segments overlapping by 1° so no seams show.
*/
static void makeCell(Cell& c, lv_obj_t* parent, const lv_img_dsc_t* icon, const lv_img_dsc_t* icon_red,
lv_flex_align_t cross, bool icon_above) {
c.cont = makeContainer(parent, 112, icon_above ? 85 : 80, LV_FLEX_FLOW_COLUMN,
icon_above ? LV_FLEX_ALIGN_SPACE_BETWEEN : LV_FLEX_ALIGN_START, cross);
if (icon_above) {
c.icon_red = makeIcon(c.cont, icon_red);
c.icon = makeIcon(c.cont, icon);
c.lbl = makeValueLabel(c.cont);
} else {
c.lbl = makeValueLabel(c.cont);
c.icon_red = makeIcon(c.cont, icon_red);
c.icon = makeIcon(c.cont, icon);
static void makeBand(lv_obj_t* parent, int a_cold, int a_hot) {
int span = a_hot - a_cold; // signed
int n = abs(span) / 10;
int dir = span > 0 ? 1 : -1;
for (int k = 0; k < n; k++) {
int s = a_cold + dir * 10 * k;
int e = s + dir * 10;
if (k < n - 1) e += dir; // overlap the next segment by 1°
int lo = dir > 0 ? s : e, hi = dir > 0 ? e : s;
makeArcSegment(parent, lo, hi, arcColour((k + 0.5f) / n));
}
}
static void makeNeedle(Gauge& g, lv_obj_t* parent) {
g.needle = lv_line_create(parent);
lv_obj_set_pos(g.needle, 0, 0);
lv_obj_set_size(g.needle, 240, 240);
lv_obj_set_style_line_width(g.needle, 3, 0);
lv_obj_set_style_line_color(g.needle, lv_color_white(), 0);
lv_obj_set_style_line_rounded(g.needle, true, 0);
lv_obj_clear_flag(g.needle, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE);
g.pts[0].x = g.pts[1].x = 120;
g.pts[0].y = g.pts[1].y = 120;
lv_line_set_points(g.needle, g.pts, 2);
lv_obj_add_flag(g.needle, LV_OBJ_FLAG_HIDDEN);
g.last_angle = -1000;
}
/** Point the needle at an LVGL angle (degrees), or hide it (angle == -1000). */
static void setNeedle(Gauge& g, int angle) {
if (angle == g.last_angle) return;
g.last_angle = angle;
if (angle == -1000) { lv_obj_add_flag(g.needle, LV_OBJ_FLAG_HIDDEN); return; }
float rad = angle * (float)M_PI / 180.0f;
float c = cosf(rad), s = sinf(rad);
g.pts[0].x = (lv_coord_t)lroundf(120 + NEEDLE_R0 * c);
g.pts[0].y = (lv_coord_t)lroundf(120 + NEEDLE_R0 * s);
g.pts[1].x = (lv_coord_t)lroundf(120 + NEEDLE_R1 * c);
g.pts[1].y = (lv_coord_t)lroundf(120 + NEEDLE_R1 * s);
lv_line_set_points(g.needle, g.pts, 2);
lv_obj_clear_flag(g.needle, LV_OBJ_FLAG_HIDDEN);
}
/** Temperature (0.1 degC) -> LVGL angle on a gauge running a_cold..a_hot over t_min..t_max. */
static int tempAngle(int16_t t_x10, int t_min, int t_max, int a_cold, int a_hot) {
float t = (t_x10 / 10.0f - t_min) / (float)(t_max - t_min);
if (t < 0) t = 0;
if (t > 1) t = 1;
return (int)lroundf(a_cold + (a_hot - a_cold) * t);
}
static void placeIcon(lv_obj_t* icon, int angle) {
float rad = angle * (float)M_PI / 180.0f;
lv_coord_t cx = (lv_coord_t)lroundf(120 + ICON_R * cosf(rad));
lv_coord_t cy = (lv_coord_t)lroundf(120 + ICON_R * sinf(rad));
lv_obj_set_pos(icon, cx - 25, cy - 22); // icons are 50x44
}
static void makeGauge(Gauge& g, lv_obj_t* parent, int a_cold, int a_hot, int icon_angle,
const lv_img_dsc_t* icon, const lv_img_dsc_t* icon_red) {
makeBand(parent, a_cold, a_hot);
makeNeedle(g, parent);
g.icon_red = makeIcon(parent, icon_red);
g.icon = makeIcon(parent, icon);
placeIcon(g.icon, icon_angle);
placeIcon(g.icon_red, icon_angle);
g.shown = -1;
}
static void setCellIcon(Cell& c, bool visible, bool red) {
showIconPair(c.icon, c.icon_red, c.shown, visible, red);
bool want_red = visible && red;
if (want_red != c.red) {
c.red = want_red;
setTextColour(c.lbl, want_red ? COL_ALERT : COL_TEXT);
}
}
static void makeBatteryCell(Cell& c, lv_obj_t* parent) {
c.cont = lv_obj_create(parent);
lv_obj_remove_style_all(c.cont);
lv_obj_set_pos(c.cont, 55, 176);
lv_obj_set_size(c.cont, 130, 44);
lv_obj_set_flex_flow(c.cont, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(c.cont, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_style_pad_column(c.cont, 8, 0);
lv_obj_clear_flag(c.cont, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE);
lv_obj_t* icons = lv_obj_create(c.cont);
lv_obj_remove_style_all(icons);
lv_obj_set_size(icons, 50, 44);
lv_obj_clear_flag(icons, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE);
c.icon_red = makeIcon(icons, &ui_img_batteryvoltagered_png);
c.icon = makeIcon(icons, &ui_img_batteryvoltage_png);
c.lbl = lv_label_create(c.cont);
lv_label_set_text(c.lbl, "--");
lv_obj_set_style_text_font(c.lbl, &ui_font_UbuntuLight_35, 0);
lv_obj_set_style_text_color(c.lbl, COL_TEXT, 0);
c.shown = -1;
c.red = false;
}
// ---- gear pulse --------------------------------------------------------------
@@ -134,14 +286,9 @@ static void stopGearPulse() {
static void setGearColour(bool red) {
if (red == g_gear_red) return;
g_gear_red = red;
lv_obj_set_style_text_color(g_gear_lbl, red ? COL_ALERT : g_gear_col_default, 0);
lv_obj_set_style_text_color(g_gear_lbl, red ? COL_ALERT : COL_TEXT, 0);
}
/**
* Gear label from lever + target/engaged nibbles. While target != engaged the
* TARGET digit is shown and the label pulses; once they agree it goes solid on
* the engaged gear. Red on the gear-mismatch alert.
*/
static void updateGear(const automotive_data_t& d, bool valid) {
if (!valid) {
stopGearPulse();
@@ -170,6 +317,40 @@ static void updateGear(const automotive_data_t& d, bool valid) {
setGearColour(mismatch);
}
// ---- ring + tell-tales -------------------------------------------------------
static void setRing(lv_color_t c) {
if (lv_color_to32(c) == lv_color_to32(g_ring_col)) return;
g_ring_col = c;
lv_obj_set_style_border_color(g_ring, c, 0);
}
static void updateRing(uint16_t alerts, bool alerts_valid) {
if (!alerts_valid) { setRing(COL_RING); return; }
if (alerts & ALERTS_RED) {
bool hi = (millis() / BLINK_MS) & 1;
setRing(hi ? COL_ALERT : COL_ALERT2);
} else if (alerts & ALERTS_AMBER) {
setRing(COL_AMBER);
} else {
setRing(COL_RING);
}
}
static void updateTellTales(bool link_ok) {
bool joined = WiFi.status() == WL_CONNECTED;
if (joined != g_wifi_bright) {
g_wifi_bright = joined;
lv_obj_set_style_text_color(g_wifi_tt, joined ? COL_OK : COL_MUTED, 0);
}
bool lost = !link_ok;
if (lost != g_link_lost_shown) {
g_link_lost_shown = lost;
if (lost) lv_obj_clear_flag(g_link_tt, LV_OBJ_FLAG_HIDDEN);
else lv_obj_add_flag(g_link_tt, LV_OBJ_FLAG_HIDDEN);
}
}
// ---- public -----------------------------------------------------------------
void init() {
@@ -178,26 +359,49 @@ void init() {
g_screen = lv_obj_create(NULL);
lv_obj_clear_flag(g_screen, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_flex_flow(g_screen, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(g_screen, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_style_bg_color(g_screen, lv_color_black(), 0);
// top row: coolant (left, contents left-aligned) | gearbox oil (right, contents right-aligned)
lv_obj_t* top = makeContainer(g_screen, 230, 80, LV_FLEX_FLOW_ROW, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_START);
makeCell(g_coolant, top, &ui_img_enginetemp_png, &ui_img_enginetempred_png, LV_FLEX_ALIGN_START, false);
makeCell(g_gearbox, top, &ui_img_gearboxoiltemp_png, &ui_img_gearboxoiltempred_png, LV_FLEX_ALIGN_END, false);
// Warning-lamp ring at the rim
g_ring = lv_obj_create(g_screen);
lv_obj_remove_style_all(g_ring);
lv_obj_set_pos(g_ring, 0, 0);
lv_obj_set_size(g_ring, 240, 240);
lv_obj_set_style_radius(g_ring, LV_RADIUS_CIRCLE, 0);
lv_obj_set_style_border_width(g_ring, 6, 0);
lv_obj_set_style_border_color(g_ring, COL_RING, 0);
lv_obj_set_style_border_opa(g_ring, LV_OPA_COVER, 0);
lv_obj_clear_flag(g_ring, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE);
g_ring_col = COL_RING;
// middle: the gear
lv_obj_t* mid = makeContainer(g_screen, 115, 100, LV_FLEX_FLOW_ROW, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
g_gear_lbl = lv_label_create(mid);
// Arc gauges: coolant left (140 -> 230), gearbox right (50 -> -50 i.e. 310); icons past the hot ends
makeGauge(g_coolant, g_screen, COOL_A0, COOL_A1, 245, &ui_img_enginetemp_png, &ui_img_enginetempred_png);
makeGauge(g_gearbox, g_screen, GB_A0, GB_A1, 295, &ui_img_gearboxoiltemp_png, &ui_img_gearboxoiltempred_png);
// Centre: the gear
g_gear_lbl = lv_label_create(g_screen);
lv_label_set_text(g_gear_lbl, "?");
lv_obj_set_style_text_font(g_gear_lbl, &ui_font_UbuntuBold_110, 0);
g_gear_col_default = lv_obj_get_style_text_color(g_gear_lbl, 0);
lv_obj_set_style_text_color(g_gear_lbl, COL_TEXT, 0);
lv_obj_align(g_gear_lbl, LV_ALIGN_CENTER, 0, 20);
// bottom row: battery, centred (the engine-oil cell that used to sit beside it is gone)
lv_obj_t* bottom = makeContainer(g_screen, 230, 85, LV_FLEX_FLOW_ROW, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_END);
makeCell(g_battery, bottom, &ui_img_batteryvoltage_png, &ui_img_batteryvoltagered_png, LV_FLEX_ALIGN_CENTER, true);
// Bottom: battery [icon][value]
makeBatteryCell(g_battery, g_screen);
// Notice line for the updater: a dark pill low on the round panel, hidden until used.
// Tell-tales at 9 and 3 o'clock
g_wifi_tt = lv_label_create(g_screen);
lv_label_set_text(g_wifi_tt, LV_SYMBOL_WIFI);
lv_obj_set_style_text_font(g_wifi_tt, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(g_wifi_tt, COL_MUTED, 0);
lv_obj_align(g_wifi_tt, LV_ALIGN_LEFT_MID, 24, 0);
g_link_tt = lv_label_create(g_screen);
lv_label_set_text(g_link_tt, LV_SYMBOL_WARNING);
lv_obj_set_style_text_font(g_link_tt, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(g_link_tt, COL_ALERT, 0);
lv_obj_align(g_link_tt, LV_ALIGN_RIGHT_MID, -24, 0);
lv_obj_add_flag(g_link_tt, LV_OBJ_FLAG_HIDDEN);
// Updater notice line, on the top layer
g_notice = lv_label_create(lv_layer_top());
lv_obj_set_style_text_font(g_notice, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(g_notice, lv_color_white(), 0);
@@ -211,7 +415,7 @@ void init() {
lv_scr_load(g_screen);
DisplayInit::unlock();
Serial.println("[GaugeScreen] built (coolant, gearbox oil, gear, battery)");
Serial.println("[GaugeScreen] built (ring, coolant arc, gearbox arc, gear, battery, tell-tales)");
}
void setNotice(const char* text) {
@@ -229,16 +433,19 @@ void setNotice(const char* text) {
void update(const automotive_data_t& d, bool link_ok) {
if (g_screen == NULL) return;
if (!DisplayInit::lock(50)) return; // never stall the loop on a busy renderer
if (!DisplayInit::lock(50)) return;
updateTellTales(link_ok);
if (!link_ok) {
setText(g_coolant.lbl, "N/A");
setText(g_gearbox.lbl, "N/A");
setText(g_battery.lbl, "N/A");
setIcon(g_coolant, false, false);
setIcon(g_gearbox, false, false);
setIcon(g_battery, false, false);
setNeedle(g_coolant, -1000);
setNeedle(g_gearbox, -1000);
showIconPair(g_coolant.icon, g_coolant.icon_red, g_coolant.shown, true, false);
showIconPair(g_gearbox.icon, g_gearbox.icon_red, g_gearbox.shown, true, false);
setText(g_battery.lbl, "--");
setCellIcon(g_battery, true, false);
updateGear(d, false);
updateRing(0, false);
DisplayInit::unlock();
return;
}
@@ -248,18 +455,21 @@ void update(const automotive_data_t& d, bool link_ok) {
uint16_t alerts = alerts_valid ? d.alerts : 0;
bool coolant_valid = (d.valid_flags & VALID_FLAG_COOLANT_TEMP) != 0;
setText(g_coolant.lbl, coolant_valid ? format_temperature(d.coolant_temp, buf) : "---");
setIcon(g_coolant, coolant_valid, (alerts & ALERT_COOLANT_HOT) != 0);
setNeedle(g_coolant, coolant_valid ? tempAngle(d.coolant_temp, COOL_T_MIN, COOL_T_MAX, COOL_A0, COOL_A1) : -1000);
showIconPair(g_coolant.icon, g_coolant.icon_red, g_coolant.shown, true, (alerts & ALERT_COOLANT_HOT) != 0);
bool gearbox_valid = (d.valid_flags & VALID_FLAG_GEARBOX_TEMP) != 0;
setText(g_gearbox.lbl, gearbox_valid ? format_temperature(d.gearbox_oil_temp, buf) : "---");
setIcon(g_gearbox, gearbox_valid, (alerts & (ALERT_GEARBOX_HOT | ALERT_GEARBOX_COOLING)) != 0);
setNeedle(g_gearbox, gearbox_valid ? tempAngle(d.gearbox_oil_temp, GB_T_MIN, GB_T_MAX, GB_A0, GB_A1) : -1000);
showIconPair(g_gearbox.icon, g_gearbox.icon_red, g_gearbox.shown, true,
(alerts & (ALERT_GEARBOX_HOT | ALERT_GEARBOX_COOLING)) != 0);
bool battery_valid = (d.valid_flags & VALID_FLAG_BATTERY_VOLT) != 0;
setText(g_battery.lbl, battery_valid ? format_voltage(d.battery_voltage, buf) : "---");
setIcon(g_battery, battery_valid, (alerts & ALERT_BATTERY_LOW) != 0);
if (battery_valid) snprintf(buf, sizeof(buf), "%d.%d", d.battery_voltage / 100, (d.battery_voltage % 100) / 10);
setText(g_battery.lbl, battery_valid ? buf : "--");
setCellIcon(g_battery, true, (alerts & ALERT_BATTERY_LOW) != 0);
updateGear(d, (d.valid_flags & VALID_FLAG_GEAR_POS) != 0);
updateRing(alerts, alerts_valid);
DisplayInit::unlock();
}
+1 -1
View File
@@ -15,7 +15,7 @@ Catalog of every page in the wiki. Read this first when answering questions. Kee
- [[controller-link]] — the A → B link, **protocol v2 (verified 2026-09-21)**: typed DATA/CONFIG frames on UART1 **and** ESP-NOW with dedupe, split gear fields, rpm, A-side alerts; pins (A TX = GPIO 44 → 485_A → B IO1 on the bench); the RS485-in-the-car question; v1 and the old enum drift kept for the record
- [[link-redundancy]] — wired + wireless redundancy: **ESP-NOW leg built and bench-verified** (both paths carry every frame, B dedupes and hops channels); RS485 for the car and BLE still open; failover policy notes
- [[controller-b-ota]] — **implemented 2026-09-27 (STATUS + gates verified, pairing/first release pending)**: B pulls its own signed release over Wi-Fi; `link pair` on A sends a random key over the UART wire once; credentials and OTA commands travel in AES-256-GCM `SECURE` frames; B reports version/phase/progress in `STATUS` frames; A's Updates page has a Controller B card; B's updater = port of A's; CI workflow + `v0.1.0` procedure
- [[controller-b-ota]] — **implemented and verified end-to-end 2026-09-27 (B `dev` → `v0.1.0` from A's console)**: B pulls its own signed release over Wi-Fi; `link pair` on A sends a random key over the UART wire once; credentials and OTA commands travel in AES-256-GCM `SECURE` frames; B reports version/phase/progress in `STATUS` frames; A's Updates page has a Controller B card; B's updater = port of A's; CI workflow + `v0.1.0` procedure
- [[patrol-gauge-outputs]] — Patrol tachometer (IO7, 14-bit LEDC, 4 ppr) and coolant gauge (IO8, 8-bit PWM, CANNY duty law) **outputs implemented and bench-verified**; tunables on A via `cfg` console; prior art from the CANNY program; driver stage and needle calibration still to do
## Synthesis
+12
View File
@@ -66,3 +66,15 @@ User asked about updating B "via ESP-NOW". Compared A-pushes-chunks vs B-pulls-i
## [2026-09-27] update | Controller B OTA implemented on both boards; STATUS + gates verified; pairing awaits the wire
Implemented the [[controller-b-ota]] design end to end. Shared header: `STATUS` 0x03 / `PAIR` 0x04 / `SECURE` 0x05 (+ inner `OTA_CMD` 0x11, `WIFI_CREDS` 0x12), `PACKET_MAX_PAYLOAD` 160, new `include/protocol/link_secure.h` (AES-256-GCM seal/open, key fingerprint; mbedtls names differ between IDF 4.4 and 5.5, handled). Decision: application-level GCM instead of ESP-NOW peer encryption (no PMK/LMK bookkeeping, no broadcast-vs-encrypted-peer doubt). B: `link_peer.cpp` (NVS key + A's MAC, credentials in namespace `wifi`, mailboxes so the Wi-Fi/UART tasks never touch NVS, STATUS every 5 s / on change, nonce replay window), `console.cpp` (line reader + handler chain, `help`), `ota_update.cpp` (port of A's: link-data gate, joins Wi-Fi only for the job, notice line on the screen via `GaugeScreen::setNotice()`, pumps STATUS from the download loop), `include/config/ota_config.h` (`patrol-b`, this repo, same roots + public key), `.gitea/workflows/firmware.yml`, `tools/ota/firmware_signing_pub.pem`. A: `link_peer.cpp` (`link status|pair|unpair|creds|ota ...`, automatic credential sync, B card on Settings → Updates), `EspNowLink` receive callback + `sendTo()`, `UARTManager::sendWire()`, `WiFiManager::getSavedCredentials()`, `Ota::isParked()`. Bench (A COM14, B COM13): B's STATUS frames reach A (MAC 10:51:DB:8F:B6:5C, `dev`, heap 234 KB); `ota check` on B refuses "no Wi-Fi credentials from A yet"; `link ota check` on A refuses "not paired"; `link pair` on A sent PAIR ×3 but B never saw it: **B's UART leg is silent (uart=0) — no wire on the bench right now**. Next: connect `485_A → IO1` + GND, `link pair`, credentials, tag `v0.1.0`, install from A's screen. Build notes: run `pio` from PowerShell (idf_tools refuses MSYS/Git Bash); the first build after switching between the two projects reinstalls the other Arduino core and can fail once with a `TypeError` — run it again.
## [2026-09-27] verify | Controller B updated over the air from A: dev → v0.1.0, end to end
User connected `485_A → IO1` (ground via the USB hub). B had rebooted on plug-in (A's card flipped to "not heard" for 15 s) and logged checksum-error bursts, but `uart alive` with good frames. `link pair` on A: PAIR ×3 over the wire, B `PAIRED ... fingerprint A9B7`, A `Controller B confirmed pairing` in < 5 s, then A pushed the `ArtServis` credentials by itself and B stored them. `link ota check` before the release existed: B joined the AP in ~2 s, got 404 → "no release published yet", reported to A as *failed* + reason (truncated to 32 chars), left Wi-Fi, re-locked on channel 1. CI: B's `main-latest` built in < 3 min; the `v0.1.0` tag build took ~12 min but published `firmware.bin` 1,248,432 B + `manifest.txt` (target patrol-b, sha256 `3c33d20f…3415`, ECDSA sig). `link ota check` → `update available, latest v0.1.0`; `link ota install` → download + flash to app1 in ~50 s with 0/10/…/100 % on B's console, `verified and installed v0.1.0`, reboot, `Firmware v0.1.0` banner, STATUS to A resumed, `confirmed - rollback cancelled` at 30 s, `ota status` slot app1 valid. Heap 230 KB before/after, loop stack headroom 3.4 KB. Not yet eyeballed: the Updates-page buttons on A and the progress line on B's screen (same code path as the console). Wiki [[controller-b-ota]] verification table and risks updated, [[open-questions]] #12 answered.
## [2026-09-27] update | Round-panel redesign of B's screen: warning ring, tell-tales, whole-degree values
User asked for an automotive look, a Wi-Fi indicator and a sense of urgency on crossed thresholds. `gauge_screen.cpp` rebuilt for the circle: a 6 px ring at the rim acts as a warning lamp (dim; red blinking at 2 Hz while any red alert bit is set; amber while the gearbox asks for cooling), the affected value's digits and icon go red, temperatures show whole degrees and the battery a tenth (fewer, bigger digits), coolant/gearbox sit at 10 and 2 o'clock as icon + digits, the 110 px gear stays in the centre, battery centred low; tell-tales at 9 o'clock (Wi-Fi: green only while joined for an update) and 3 o'clock (red `!` when the link to A is lost). Everything is positioned absolutely inside the circle - the old flex column overflowed 240 px, so the battery digits sat partly off-panel. Built and flashed COM13; the user has not yet looked at it. The bench cannot show an alert (A's alerts come from CAN frames only), so the ring/red-value path is untested until the car.
## [2026-09-28] update | B's screen: arc gauges with needles instead of digits (user's design)
User saw the 2026-09-27 layout ("not bad") and redesigned it: no temperature digits; coolant as an arc on the LEFT rim from compass 230° (bottom-left, cold) to 320° (top-left, hot) with a needle, gearbox oil mirrored on the RIGHT from 140° to 40°; arcs blue when cool grading to red at the hot end; each icon just past the hot end, upper-left / upper-right; battery digits stay at the bottom. Implemented in `gauge_screen.cpp`: gradient = 9-10 `lv_arc` segments of 10° (1° overlap, no seams) coloured blue→neutral→red, needle = 3 px white `lv_line` from r 92 to 113 recomputed only on an angle change, band r 100-110 inside the 6 px warning ring, icons centred at r 66 (angles 245° / 295° LVGL). Scales: coolant 50-120 °C, gearbox 40-150 °C (thresholds 100 / 130 sit at ~70 % / ~80 % of the sweep). Ring blink / red icons / tell-tales unchanged. Built and flashed COM13, clean boot; the user is looking at it.
+11 -7
View File
@@ -1,12 +1,12 @@
---
type: concept
tags: [ota, wifi, esp-now, security, design, verified]
tags: [ota, wifi, esp-now, security, verified]
updated: 2026-09-27
---
# Over-the-air updates for Controller B
**Status 2026-09-27: implemented on both controllers, bench-tested up to the pairing step.** B pulls its own signed release from Gitea over Wi-Fi; A hands B the network credentials and the trigger over the existing link, and shows B's progress on its own Updates page. Design chosen by the user over "A streams the image through ESP-NOW" (comparison below). Everything reuses A's proven pipeline ([[ota-updates]] in the sibling wiki).
**Status 2026-09-27: implemented on both controllers and VERIFIED END-TO-END on the bench - B went from `dev` to `v0.1.0` on a command typed on A, rebooted and confirmed itself.** B pulls its own signed release from Gitea over Wi-Fi; A hands B the network credentials and the trigger over the existing link, and shows B's progress on its own Updates page. Design chosen by the user over "A streams the image through ESP-NOW" (comparison below). Everything reuses A's proven pipeline ([[ota-updates]] in the sibling wiki).
## What is verified, what is not
@@ -14,9 +14,11 @@ updated: 2026-09-27
|---|---|
| B → A STATUS frames (version, phase, heap, uptime) over ESP-NOW unicast | `(verified 2026-09-27)` A's console `link status` lists B's MAC, `dev`, heap 234 KB; A's Updates page shows the Controller B card |
| Gates on both sides (unpaired → refused, no credentials → refused, key mismatch → refused) | `(verified 2026-09-27)` each refusal text seen on the consoles |
| `link pair` over the UART wire | **not yet**: the bench had no wire connected when tested (B: `uart=0 ... uart silent`). Needs `485_A → IO1`, GND → GND, 120 Ω switch OFF ([[controller-link]] bench wiring) |
| Encrypted credential handoff, B joins the network | not yet (needs pairing) |
| `link ota check` / install from A's screen, first signed B release | not yet (needs pairing + release `v0.1.0` of this repo) |
| `link pair` over the UART wire | `(verified 2026-09-27 21:2x)` wire `485_A → IO1`, ground shared through the USB hub only. A: `PAIR sent over the wire 3 time(s); new key fingerprint A9B7`; B: `PAIRED over the wire ... A = 30:ED:A0:17:B2:4C` (+ one "re-confirmed" for the repeats); A: `Controller B confirmed pairing (fingerprint A9B7)` within 5 s |
| Encrypted credential handoff | `(verified)` A pushed `ArtServis` on its own right after pairing; B: `Wi-Fi credentials for 'ArtServis' stored`; `wifi status` on B lists the network |
| `link ota check` from A | `(verified)` B joined the AP (IP 10.0.10.101, channel 1) in ~2 s, before the release existed: `no release published yet (push a v* tag)` reported back to A as phase *failed* + message; after the release: `latest release v0.1.0 (1248432 bytes, signature OK)`, A: `update available, latest v0.1.0` |
| `link ota install` from A, first signed release `v0.1.0` | `(verified)` download + flash of 1,248,432 B into `app1` in ~50 s, `verified and installed v0.1.0`, reboot, banner `Firmware v0.1.0`, `NEW IMAGE, unconfirmed`, STATUS to A resumed within seconds (`firmware v0.1.0`), `firmware v0.1.0 confirmed - rollback cancelled` at 30 s; `ota status`: slot app1 state valid. Loop stack headroom after a job: 3.4 KB; heap 230 KB before/after |
| Screen path (Controller B card on A's Updates page, B's on-screen notice line) | same request functions as the console commands, but the buttons have **not been tapped yet** and the "Updating v0.1.0 N%" line on B's round screen was not watched - user to confirm on the next update |
## Why pull, not push
@@ -71,8 +73,10 @@ Port of A's module. Differences: gate = link data (`rpm == 0`, lever P/N/unknown
## Risks / open
- **Wi-Fi + ESP-NOW coexistence on B while joined**: A and B on the same AP share the channel; B's receiver follows the AP channel while joined and hops back after `WiFi.disconnect(false)`. Not yet observed live.
- **Internal RAM on B during TLS**: 235 KB free today; the job logs heap before/after. Measure once on the first check.
- **Wi-Fi + ESP-NOW coexistence on B while joined**: `(verified)` A on `ArtServis` channel 1, B joined the same AP on channel 1, STATUS kept flowing during the download (A saw phase *installing*), B re-locked on channel 1 after `WiFi.disconnect(false)`. Untested: A **not** on Wi-Fi or on a different AP - by design A refuses B commands unless it is on Wi-Fi itself.
- **Internal RAM on B during TLS**: `(verified)` 230.7 KB free before the job, 230.4 KB after; largest block 164 KB. No PSRAM tricks needed.
- **UART wire quality on the bench**: with ground shared only through the USB hub, B logs bursts of `Checksum error on uart` (7 in a row at times) and an occasional `Framing error` / `Version mismatch got v0`; 2026-09-21 with a direct GND wire it was 0 errors. Harmless for the data (ESP-NOW copy wins, dedupe) and PAIR got through (sent 3×), but run a real GND wire next time → [[open-questions]] #1 / [[link-redundancy]].
- **`link_status_t::message` is 32 bytes**: B's failure reason `no release published yet (push a v* tag)` arrived truncated at "(push". Cosmetic; lengthen if it ever matters.
- **Pairing key lost** (NVS erase on either side): re-pair at home over the wire.
- Two boards, one PlatformIO penv: the first `pio run` after switching projects reinstalls the other Arduino core and can fail once with a `TypeError`; run it again. Builds must be started from PowerShell, not Git Bash (`idf_tools.py` refuses MSYS).
+1 -1
View File
@@ -22,7 +22,7 @@ The research frontier for Controller B. Answering any of these should trigger up
13. **CANNY 5.3 pico details**: what is the HR PWM base clock (period 255 = what frequency), and what sat between the CANNY pin and the gauge wire? The user may still have the unit and harness. → [[temp-stage-cfd]]
8. ~~**Does `engine_oil_temp` stay in the packet?**~~ **Answered 2026-09-27 (user): dropped from the screen.** The field stays in the packet (protocol v2 unchanged, never valid on this engine), but B's hand-coded screen no longer has an oil quadrant - the battery cell sits alone at the bottom.
12. **OTA for Controller B** — design agreed and **implemented 2026-09-27** → [[controller-b-ota]]. STATUS frames and every gate verified on the bench; signing secret set on the B repo (user, 2026-09-27). Still open: `link pair` over the wire (the bench had no wire connected), the automatic credential handoff, the first signed release `v0.1.0` and the first install from A's screen.
12. **OTA for Controller B** — **answered 2026-09-27** → [[controller-b-ota]]: implemented and verified end-to-end on the bench (pair over the wire, automatic credential handoff, `link ota check` / `install` from A, B `dev` → `v0.1.0`, reboot, self-confirm). Left to eyeball: the Controller B card on A's Updates page and B's on-screen progress line during the next update; the bench wire wants a proper GND (checksum-error bursts with hub-only ground).
## Hardware