Controller B updates from A: link_peer (pairing over the wire, encrypted credential handoff, B status + commands), ESP-NOW receive/unicast, Updates page with two cards; shared header maintenance frames; docs + wiki
Firmware / build (push) Successful in 7m1s
Firmware / build (push) Successful in 7m1s
This commit is contained in:
+150
-32
@@ -7,6 +7,7 @@
|
||||
#include "driveline_screen.h"
|
||||
#include "wifi_manager.h"
|
||||
#include "ota_update.h"
|
||||
#include "link_peer.h"
|
||||
#include "uart_manager.h"
|
||||
#include "espnow_link.h"
|
||||
#include "settings_manager.h"
|
||||
@@ -510,9 +511,17 @@ static void buildPasswordOverlay() {
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// UPDATES PAGE
|
||||
// UPDATES PAGE - Controller A (this board) and Controller B (over the link)
|
||||
// ============================================================================
|
||||
|
||||
static lv_obj_t* g_b_installed = NULL;
|
||||
static lv_obj_t* g_b_latest = NULL;
|
||||
static lv_obj_t* g_b_state = NULL;
|
||||
static lv_obj_t* g_b_check = NULL;
|
||||
static lv_obj_t* g_b_install = NULL;
|
||||
static char g_b_refusal[96] = "";
|
||||
static uint8_t g_b_refusal_phase = LINK_OTA_IDLE;
|
||||
|
||||
static void onInstallConfirmed(bool ok, void* user) {
|
||||
(void)user;
|
||||
if (!ok) return;
|
||||
@@ -547,7 +556,36 @@ static void onGoWifi(lv_event_t* e) {
|
||||
selectPage(PAGE_WIFI);
|
||||
}
|
||||
|
||||
static void refreshUpdates() {
|
||||
static void onBInstallConfirmed(bool ok, void* user) {
|
||||
(void)user;
|
||||
if (!ok) return;
|
||||
uint8_t before = LinkPeer::getStatus().st.ota_phase;
|
||||
if (!LinkPeer::requestInstall(g_b_refusal, sizeof(g_b_refusal))) g_b_refusal_phase = before;
|
||||
else g_b_refusal[0] = 0;
|
||||
refresh(true);
|
||||
}
|
||||
|
||||
static void onBInstall(lv_event_t* e) {
|
||||
(void)e;
|
||||
LinkPeer::peer_status_t p = LinkPeer::getStatus();
|
||||
char title[64];
|
||||
snprintf(title, sizeof(title), "Install %s on Controller B?", p.st.latest);
|
||||
confirm(title,
|
||||
"Controller B joins the Wi-Fi network, downloads its new firmware and restarts; "
|
||||
"its gauges hold still meanwhile and this card shows the progress.\n\n"
|
||||
"Only while parked with the engine off.",
|
||||
"Install", onBInstallConfirmed, NULL);
|
||||
}
|
||||
|
||||
static void onBCheck(lv_event_t* e) {
|
||||
(void)e;
|
||||
uint8_t before = LinkPeer::getStatus().st.ota_phase;
|
||||
if (!LinkPeer::requestCheck(g_b_refusal, sizeof(g_b_refusal))) g_b_refusal_phase = before;
|
||||
else g_b_refusal[0] = 0;
|
||||
refresh(true);
|
||||
}
|
||||
|
||||
static void refreshUpdatesA() {
|
||||
Ota::ui_status_t o = Ota::getStatus();
|
||||
bool wifi_ok = WiFiManager::getStatus().link == WiFiManager::LINK_CONNECTED;
|
||||
if (g_upd_refusal[0] && o.phase != g_upd_refusal_phase) g_upd_refusal[0] = 0; // superseded
|
||||
@@ -570,7 +608,7 @@ static void refreshUpdates() {
|
||||
} else if (!wifi_ok && o.phase != Ota::PHASE_IDLE && o.phase != Ota::PHASE_CHECKING) {
|
||||
// keep the last result, but say why the buttons are off
|
||||
size_t n = strlen(msg);
|
||||
snprintf(msg + n, sizeof(msg) - n, "\nConnect to Wi-Fi to check again.");
|
||||
snprintf(msg + n, sizeof(msg) - n, " Connect to Wi-Fi to check again.");
|
||||
}
|
||||
setText(g_upd_state, msg);
|
||||
setTextColor(g_upd_state, col);
|
||||
@@ -590,45 +628,125 @@ static void refreshUpdates() {
|
||||
setVisible(g_upd_wifi, !wifi_ok);
|
||||
}
|
||||
|
||||
static void refreshUpdatesB() {
|
||||
LinkPeer::peer_status_t p = LinkPeer::getStatus();
|
||||
if (g_b_refusal[0] && p.st.ota_phase != g_b_refusal_phase) g_b_refusal[0] = 0;
|
||||
|
||||
bool has_wifi = (p.st.flags & LINK_STATUS_HAVE_WIFI) != 0;
|
||||
bool ready = p.heard && p.paired && p.key_match && has_wifi;
|
||||
char msg[160];
|
||||
lv_color_t col = UI_COL_MUTED;
|
||||
if (!p.heard) {
|
||||
snprintf(msg, sizeof(msg), "Controller B not heard.%s",
|
||||
p.paired ? "" : " Not paired yet: connect the wire and run 'link pair' on the console.");
|
||||
} else if (!p.paired || !p.key_match) {
|
||||
snprintf(msg, sizeof(msg), LV_SYMBOL_WARNING " Not paired with this controller. "
|
||||
"Connect the wire and run 'link pair' on the console.");
|
||||
col = UI_COL_AMBER;
|
||||
} else if (!has_wifi) {
|
||||
snprintf(msg, sizeof(msg), "Controller B has no Wi-Fi credentials yet. Join a network here; "
|
||||
"they are passed on by themselves.");
|
||||
} else {
|
||||
switch (p.st.ota_phase) {
|
||||
case LINK_OTA_CHECKING: snprintf(msg, sizeof(msg), "Controller B is checking..."); break;
|
||||
case LINK_OTA_INSTALLING: snprintf(msg, sizeof(msg), "Installing %s on Controller B... %u %%",
|
||||
p.st.latest, p.st.ota_progress); col = UI_COL_ACCENT; break;
|
||||
case LINK_OTA_UP_TO_DATE: snprintf(msg, sizeof(msg), LV_SYMBOL_OK " Controller B is up to date."); col = UI_COL_OK; break;
|
||||
case LINK_OTA_AVAILABLE: snprintf(msg, sizeof(msg), "Version %s is available for Controller B.", p.st.latest); col = UI_COL_ACCENT; break;
|
||||
case LINK_OTA_FAILED: snprintf(msg, sizeof(msg), LV_SYMBOL_WARNING " %s", p.st.message); col = UI_COL_WARN; break;
|
||||
default: snprintf(msg, sizeof(msg), "Tap Check to look for a new version for Controller B."); break;
|
||||
}
|
||||
if (p.st.flags & LINK_STATUS_PENDING_VERIFY) {
|
||||
size_t n = strlen(msg);
|
||||
snprintf(msg + n, sizeof(msg) - n, " (new firmware, confirming...)");
|
||||
}
|
||||
}
|
||||
if (g_b_refusal[0]) {
|
||||
snprintf(msg, sizeof(msg), LV_SYMBOL_WARNING " %s", g_b_refusal);
|
||||
col = UI_COL_WARN;
|
||||
}
|
||||
setText(g_b_state, msg);
|
||||
setTextColor(g_b_state, col);
|
||||
setText(g_b_installed, p.heard ? p.st.version : "-");
|
||||
setText(g_b_latest, (p.heard && p.st.latest[0]) ? p.st.latest : "-");
|
||||
|
||||
bool busy = p.heard && (p.st.ota_phase == LINK_OTA_CHECKING || p.st.ota_phase == LINK_OTA_INSTALLING);
|
||||
setButtonText(g_b_check, busy ? "Working..." : LV_SYMBOL_REFRESH " Check for updates");
|
||||
if (busy || !ready) lv_obj_add_state(g_b_check, LV_STATE_DISABLED);
|
||||
else lv_obj_clear_state(g_b_check, LV_STATE_DISABLED);
|
||||
|
||||
bool can_install = ready && p.st.ota_phase == LINK_OTA_AVAILABLE;
|
||||
char inst[48];
|
||||
snprintf(inst, sizeof(inst), LV_SYMBOL_DOWNLOAD " Install %s", p.st.latest);
|
||||
setButtonText(g_b_install, inst);
|
||||
setVisible(g_b_install, can_install);
|
||||
}
|
||||
|
||||
static void refreshUpdates() {
|
||||
refreshUpdatesA();
|
||||
refreshUpdatesB();
|
||||
}
|
||||
|
||||
/** One controller's card: "Name Installed vX Latest vY", a status line, a button row. */
|
||||
static lv_obj_t* controllerCard(lv_obj_t* page, const char* name, const char* installed,
|
||||
lv_obj_t** installed_lbl, lv_obj_t** latest_lbl, lv_obj_t** state_lbl) {
|
||||
lv_obj_t* c = card(page);
|
||||
lv_obj_set_size(c, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_flex_flow(c, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_row(c, 8, 0);
|
||||
|
||||
lv_obj_t* row = box(c, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_size(row, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_flex_align(row, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_END);
|
||||
lv_obj_set_style_pad_column(row, 36, 0);
|
||||
lv_obj_t* title = label(row, name, &lv_font_montserrat_24, UI_COL_TEXT);
|
||||
lv_obj_set_width(title, 190);
|
||||
|
||||
lv_obj_t* a = box(row, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_size(a, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||
lv_obj_set_flex_align(a, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_END);
|
||||
lv_obj_set_style_pad_column(a, 10, 0);
|
||||
label(a, "Installed", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||
*installed_lbl = label(a, installed, &lv_font_montserrat_24, UI_COL_TEXT);
|
||||
|
||||
lv_obj_t* b = box(row, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_size(b, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||
lv_obj_set_flex_align(b, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_END);
|
||||
lv_obj_set_style_pad_column(b, 10, 0);
|
||||
label(b, "Latest", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||
*latest_lbl = label(b, "-", &lv_font_montserrat_24, UI_COL_TEXT);
|
||||
|
||||
*state_lbl = label(c, "", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||
lv_label_set_long_mode(*state_lbl, LV_LABEL_LONG_WRAP);
|
||||
lv_obj_set_width(*state_lbl, LV_PCT(100));
|
||||
return c;
|
||||
}
|
||||
|
||||
static void buildUpdatesPage(lv_obj_t* page) {
|
||||
label(page, "Firmware updates", &lv_font_montserrat_24, UI_COL_TEXT);
|
||||
|
||||
lv_obj_t* c = card(page);
|
||||
lv_obj_set_size(c, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_flex_flow(c, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_style_pad_column(c, 60, 0);
|
||||
|
||||
lv_obj_t* a = box(c, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_size(a, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_row(a, 6, 0);
|
||||
label(a, "Installed", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||
label(a, FW_VERSION, &lv_font_montserrat_30, UI_COL_TEXT);
|
||||
|
||||
lv_obj_t* b = box(c, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_size(b, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_row(b, 6, 0);
|
||||
label(b, "Latest release", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||
g_upd_latest = label(b, "-", &lv_font_montserrat_30, UI_COL_TEXT);
|
||||
|
||||
g_upd_state = label(page, "", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||
lv_label_set_long_mode(g_upd_state, LV_LABEL_LONG_WRAP);
|
||||
lv_obj_set_width(g_upd_state, LV_PCT(100));
|
||||
|
||||
lv_obj_t* btns = box(page, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_t* installed_a = NULL;
|
||||
lv_obj_t* a = controllerCard(page, "Controller A", FW_VERSION, &installed_a, &g_upd_latest, &g_upd_state);
|
||||
lv_obj_t* btns = box(a, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_size(btns, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_column(btns, 16, 0);
|
||||
g_upd_check = button(btns, LV_SYMBOL_REFRESH " Check for updates", 300, 64, BTN_PRIMARY, onCheck, NULL);
|
||||
g_upd_install = button(btns, "Install", 280, 64, BTN_SUCCESS, onInstall, NULL);
|
||||
g_upd_wifi = button(btns, LV_SYMBOL_WIFI " Wi-Fi settings", 260, 64, BTN_SECONDARY, onGoWifi, NULL);
|
||||
g_upd_check = button(btns, LV_SYMBOL_REFRESH " Check for updates", 300, 56, BTN_PRIMARY, onCheck, NULL);
|
||||
g_upd_install = button(btns, "Install", 280, 56, BTN_SUCCESS, onInstall, NULL);
|
||||
g_upd_wifi = button(btns, LV_SYMBOL_WIFI " Wi-Fi settings", 260, 56, BTN_SECONDARY, onGoWifi, NULL);
|
||||
|
||||
lv_obj_t* b = controllerCard(page, "Controller B", "-", &g_b_installed, &g_b_latest, &g_b_state);
|
||||
btns = box(b, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_size(btns, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_column(btns, 16, 0);
|
||||
g_b_check = button(btns, LV_SYMBOL_REFRESH " Check for updates", 300, 56, BTN_PRIMARY, onBCheck, NULL);
|
||||
g_b_install = button(btns, "Install", 280, 56, BTN_SUCCESS, onBInstall, NULL);
|
||||
|
||||
lv_obj_t* note = label(page,
|
||||
"Updates come from " OTA_SERVER " and are signed. Installing takes about a minute: "
|
||||
"a progress bar shows while the new firmware is written, then the controller restarts. "
|
||||
"If it doesn't start properly, it goes back to the current version by itself.",
|
||||
"Signed releases from " OTA_SERVER ". Each controller restarts after installing and keeps "
|
||||
"the previous version as a fallback.",
|
||||
&lv_font_montserrat_20, UI_COL_MUTED);
|
||||
lv_label_set_long_mode(note, LV_LABEL_LONG_WRAP);
|
||||
lv_obj_set_width(note, LV_PCT(100));
|
||||
lv_obj_set_style_pad_top(note, 12, 0);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user