Link protocol v2, ESP-NOW leg, gauge tunables + tuning screen; remove Home screen

Protocol v2 (shared header, byte-identical with the 1.3 repo):
- typed DATA/CONFIG frames: 0xAA | ver | type | len | payload | XOR | 0x55
- gear split into lever (P/R/N/D/S/M) + target/engaged nibbles, engine rpm,
  alert bitmap decided here from tunable thresholds, link_config_t tunables
- docs/UART_PROTOCOL.md rewritten for v2

Controller A modules:
- tunables: gauge calibration + alert thresholds in NVS, 'cfg' serial console,
  bench override (never persisted)
- espnow_link: every frame also broadcast on ESP-NOW ch 1; radio stays in STA
  (WiFiManager no longer powers it off)
- uart_manager: DATA at 5 Hz + CONFIG on change/5 s on both transports
- can_driver: publishes gear pieces and rpm, evaluates alerts
- tuning_screen: hand-coded Gauge Tuning page (swipe right from Driveline),
  -/+ rows, enable switches, override sliders, Driveline/Defaults buttons

UI: SquareLine Home screen (3 meters + battery) and meters_manager removed;
Driveline is the boot screen; Settings back-gesture calls app_show_driveline().

tools/fix_penv_deps.ps1: repairs the shared PlatformIO penv after a 1.3 build.
Bench-verified with Controller B: both transports alive, dedupe, override
rpm 2000 -> 133.3 Hz tach output.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-09-21 19:12:31 +02:00
parent a8f68ebc27
commit f60bdac268
33 changed files with 1743 additions and 2266 deletions
+17 -38
View File
@@ -6,6 +6,7 @@
#include "uart_manager.h"
#include "display/lvgl_v8_port.h"
#include "drivers/can_driver.h"
#include "tuning_screen.h"
#include "esp_log.h"
extern "C" {
@@ -48,9 +49,6 @@ static lv_obj_t* g_clutch_chip = NULL;
static lv_obj_t* g_cool_chip = NULL;
static lv_obj_t* g_mismatch_lbl = NULL;
// Home screen instance we've already hooked the right-swipe onto.
static lv_obj_t* g_hooked_home = NULL;
// ============================================================================
// PRIVATE HELPERS
// ============================================================================
@@ -139,32 +137,22 @@ static lv_obj_t* makeStat(lv_obj_t* parent, const char* title,
}
/**
* @brief Gesture handler on OUR screen: swipe right/left goes back to Home.
* @brief Gesture handler on OUR screen: swipe LEFT opens Settings (SquareLine),
* swipe RIGHT continues to the Gauge Tuning screen.
*/
static void onScreenGesture(lv_event_t* e) {
if (lv_event_get_code(e) != LV_EVENT_GESTURE) return;
lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
if (dir == LV_DIR_LEFT || dir == LV_DIR_RIGHT) {
if (dir == LV_DIR_LEFT) {
lv_indev_wait_release(lv_indev_get_act());
_ui_screen_change(&ui_Home_Screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0,
&ui_Home_Screen_screen_init);
_ui_screen_change(&ui_Settings_Screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0,
&ui_Settings_Screen_screen_init);
} else if (dir == LV_DIR_RIGHT) {
lv_indev_wait_release(lv_indev_get_act());
TuningScreen::show();
}
}
/**
* @brief Gesture handler we bolt onto the Home screen at runtime.
*
* The generated ui_event_Home_Screen() already claims LEFT (-> Settings). LVGL
* dispatches to every registered callback, so this one coexists with it rather
* than replacing it — which is the whole point: we never edit the generated file.
*/
static void onHomeGesture(lv_event_t* e) {
if (lv_event_get_code(e) != LV_EVENT_GESTURE) return;
if (lv_indev_get_gesture_dir(lv_indev_get_act()) != LV_DIR_RIGHT) return;
lv_indev_wait_release(lv_indev_get_act());
show();
}
/**
* @brief Build the screen. Idempotent — returns immediately if already built.
*/
@@ -255,7 +243,7 @@ static void build() {
LV_ALIGN_BOTTOM_MID, 340, -34);
lv_obj_t* hint = lv_label_create(g_screen);
lv_label_set_text(hint, LV_SYMBOL_LEFT " swipe back to Home");
lv_label_set_text(hint, LV_SYMBOL_LEFT " swipe left: Settings | swipe right: Gauge tuning " LV_SYMBOL_RIGHT);
lv_obj_set_style_text_font(hint, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(hint, COL_MUTED, 0);
lv_obj_align(hint, LV_ALIGN_BOTTOM_LEFT, 24, -14);
@@ -272,21 +260,6 @@ void show() {
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, false);
}
void attachHomeGesture() {
if (ui_Home_Screen == NULL) {
g_hooked_home = NULL; // screen gone; re-hook when it returns
return;
}
if (g_hooked_home == ui_Home_Screen) return;
lvgl_port_lock(-1);
lv_obj_add_event_cb(ui_Home_Screen, onHomeGesture, LV_EVENT_GESTURE, NULL);
lvgl_port_unlock();
g_hooked_home = ui_Home_Screen;
ESP_LOGI("Driveline", "Right-swipe hooked onto Home screen");
}
void tick() {
// Nothing to do unless we're built AND actually the screen being shown.
if (g_screen == NULL || lv_scr_act() != g_screen) return;
@@ -305,7 +278,7 @@ void tick() {
int16_t coolant = 0, gearbox = 0;
uint8_t flags = 0;
if (xSemaphoreTake(UARTManager::g_data_mutex, pdMS_TO_TICKS(10)) == pdTRUE) {
gear = UARTManager::g_automotive_data.gear_position;
gear = UARTManager::g_automotive_data.gear_lever;
coolant = UARTManager::g_automotive_data.coolant_temp;
gearbox = UARTManager::g_automotive_data.gearbox_oil_temp;
flags = UARTManager::g_automotive_data.valid_flags;
@@ -417,3 +390,9 @@ void tick() {
}
} // namespace DrivelineScreen
// C entry point used by the SquareLine-generated Settings screen's back gesture.
// Runs inside an LVGL event handler, so the LVGL lock is already held.
extern "C" void app_show_driveline(void) {
DrivelineScreen::show();
}