Link protocol v2 receiver, ESP-NOW leg, Patrol gauge outputs, gear pulse

- protocol header v2 copied byte-identical from the 5B repo
- uart_receiver: processFrame() shared by the UART framing task and ESP-NOW,
  version check, dedupe on packet_id+timestamp, per-transport liveness,
  CONFIG cache with sequence number
- espnow_receiver: STA mode, channel hopping while silent, locks on frames
- gauge_outputs: tach on IO7 (LEDC ch2, 14-bit), coolant PWM on IO8 (LEDC
  ch4, 8-bit), config cached in NVS, overrides applied but not saved
- main: gear label from lever + engaged/target (pulses while shifting, red on
  mismatch), icons driven by A's alert bits, gauge update at 5 Hz, link stats
- wiki: temp_stage.cfd (user's old CANNY program) decoded as prior art;
  controller-link, link-redundancy, patrol-gauge-outputs, open-questions
  updated with the bench-verified v2 results and calibration procedure

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-09-21 19:12:38 +02:00
parent 3613387d41
commit 5fe313b7fa
18 changed files with 1658 additions and 514 deletions
+56
View File
@@ -0,0 +1,56 @@
/**
* Gauge Outputs Module (Controller B)
*
* Drives the Nissan Patrol cluster from the data Controller A sends:
* - tachometer: variable-frequency square wave on IO7 (LEDC timer 1)
* - coolant gauge: fixed-frequency PWM with variable duty on IO8 (LEDC timer 2)
*
* Everything tunable comes from link_config_t (pushed by A in CONFIG frames,
* cached in NVS so a reboot of B does not wait for A). Both outputs are held
* OFF while the link is down or the source value is invalid, unless A has set
* a calibration override.
*
* External driver stages are mandatory: 3.3 V logic drives neither gauge
* directly. See wiki/pages/patrol-gauge-outputs.md
*/
#ifndef GAUGE_OUTPUTS_H
#define GAUGE_OUTPUTS_H
#include <Arduino.h>
#include "protocol/automotive_data.h"
namespace GaugeOutputs {
#define GAUGE_TACH_PIN 7
#define GAUGE_TEMP_PIN 8
/**
* Load the last config from NVS (defaults if none) and set up both LEDC channels
* with the outputs OFF.
*/
void init();
/**
* Apply a configuration received from A. Persists it to NVS when persist is true
* (overrides arrive unsaved by design: A does not persist them either).
*/
void applyConfig(const link_config_t& cfg, bool persist);
link_config_t getConfig();
/**
* Recompute both outputs from the latest data. Call at the data rate (5 Hz).
* @param d latest automotive_data_t from A
* @param link_ok false when no valid frame has arrived within the link timeout
*/
void update(const automotive_data_t& d, bool link_ok);
/**
* Print a one-line status (frequency, duty, source of each output) to Serial.
*/
void printStatus();
} // namespace GaugeOutputs
#endif // GAUGE_OUTPUTS_H