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
+80
View File
@@ -0,0 +1,80 @@
/*
* ESP-NOW Link Module Implementation (Controller A, transmit only)
*/
#include "espnow_link.h"
#include "protocol/automotive_data.h"
#include <WiFi.h>
#include <esp_wifi.h>
#include <esp_now.h>
#include "esp_log.h"
namespace EspNowLink {
static const uint8_t BROADCAST_MAC[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
static bool g_ready = false;
static uint32_t g_sent = 0;
static uint32_t g_fail = 0;
// IDF 5.5 (pioarduino / Arduino 3.3) passes wifi_tx_info_t*; older cores passed the MAC.
static void onSent(const wifi_tx_info_t* info, esp_now_send_status_t status) {
(void)info;
// Broadcast frames are never ACKed, so "success" only means the radio
// transmitted. Failures here mean the radio itself refused the frame.
if (status != ESP_NOW_SEND_SUCCESS) g_fail++;
}
bool init() {
if (g_ready) return true;
// Radio must be up for ESP-NOW. Keep STA regardless of the WiFi toggle.
if (WiFi.getMode() == WIFI_OFF) {
WiFi.mode(WIFI_STA);
}
WiFi.setSleep(false); // modem sleep adds latency/loss to ESP-NOW
// Fixed channel while not associated. If the WiFi manager later joins an
// AP the channel follows the AP; B's receiver hops to find us.
if (WiFi.status() != WL_CONNECTED) {
esp_wifi_set_channel(ESPNOW_CHANNEL, WIFI_SECOND_CHAN_NONE);
}
if (esp_now_init() != ESP_OK) {
ESP_LOGE("EspNow", "esp_now_init failed");
return false;
}
esp_now_register_send_cb(onSent);
esp_now_peer_info_t peer = {};
memcpy(peer.peer_addr, BROADCAST_MAC, 6);
peer.channel = 0; // current channel
peer.encrypt = false;
peer.ifidx = WIFI_IF_STA;
if (esp_now_add_peer(&peer) != ESP_OK) {
ESP_LOGE("EspNow", "esp_now_add_peer(broadcast) failed");
return false;
}
g_ready = true;
ESP_LOGI("EspNow", "ESP-NOW ready: STA %s, channel %d, broadcast peer added",
WiFi.macAddress().c_str(), WiFi.channel());
return true;
}
bool send(const uint8_t* frame, size_t len) {
if (!g_ready || len == 0 || len > ESP_NOW_MAX_DATA_LEN) return false;
esp_err_t err = esp_now_send(BROADCAST_MAC, frame, len);
if (err == ESP_OK) {
g_sent++;
return true;
}
g_fail++;
return false;
}
bool isReady() { return g_ready; }
uint32_t sentCount() { return g_sent; }
uint32_t failCount() { return g_fail; }
} // namespace EspNowLink