/* * Tunables Module * * Owns the link_config_t that Controller A pushes to Controller B: Patrol gauge * calibration (tach pulses/rev, coolant PWM law) and the alert thresholds A * evaluates. Persisted in NVS. Editable at runtime over the USB serial console * ("cfg help") until a settings-screen UI exists. */ #pragma once #include #include "protocol/automotive_data.h" namespace Tunables { /** * Load from NVS (or defaults if absent / size mismatch). Call after Serial.begin(). */ void init(); /** * Snapshot of the current configuration (thread-safe copy). */ link_config_t get(); /** * Current cfg_version. Increments on every change; the UART manager re-sends * a CONFIG frame when it sees a new value. */ uint8_t version(); /** * Replace the whole configuration (bumps cfg_version, saves to NVS). */ void set(const link_config_t& cfg); /** * Reset to link_config_defaults() and save. */ void resetDefaults(); /** * Set the bench override (bumps cfg_version so it is pushed to B, but NEVER * saved to NVS - a reboot must not leave the gauges pinned to a test value). */ void setOverride(uint8_t mode, uint16_t rpm, uint8_t duty); /** * Execute one console command line ("cfg show", "cfg set tach_ppr 4", ...). * @return true if the line was a recognised command */ bool handleCommand(const char* line); /** * Non-blocking: read pending bytes from Serial, dispatch complete lines to * handleCommand(), then to the extra handler (if registered). Call from loop(). */ void pollSerial(); /** * Register a second console command handler (e.g. DiagProbe::handleCommand) * that gets lines `cfg` does not recognise. Returns true if it consumed the line. */ void setExtraCommandHandler(bool (*handler)(const char* line)); } // namespace Tunables