cv_process and helpers (frame_diff, extract_blob, find_centroids) now read diff_thresh, min_blob_px, max_move, max_missed, and line_offset from state.tuning instead of file-scope static const constants. The four thresholds are promoted to file-local constexpr defaults in cv.cpp (CV_DEFAULT_*) and are no longer part of the public cv.h API — external code can't depend on them. cv_process signature drops the line_pct parameter; callers use state.tuning.line_offset instead. This eliminates the drift hazard of having two sources of truth (DeviceConfig.line_offset vs CVTuning.line_offset); the former is deleted. main.cpp now calls config_load_tuning(g_cv.tuning) after cv_init on boot so previously persisted tuning survives reboot; logs whether tuning came from NVS or defaults. The legacy NVS key "line_offset" is intentionally left alone — harmless and flash_device.py may still write it during provisioning. Migration is out of scope. Tests: 12/12 passing (11 existing + 1 new test_cv_process_respects_runtime_min_blob proving the runtime-read path). Flash: 1,414,069 bytes (89.9%). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
32 lines
1.0 KiB
C
32 lines
1.0 KiB
C
// firmware/src/config.h
|
|
#pragma once
|
|
#include <Arduino.h>
|
|
#include "cv.h"
|
|
|
|
struct DeviceConfig {
|
|
String device_id; // e.g. "dc-0042"
|
|
String location_id; // e.g. "retailer-123"
|
|
String hmac_secret; // 32-byte hex string
|
|
String wifi_ssid;
|
|
String wifi_pass;
|
|
};
|
|
|
|
// Load all config from NVS. Returns false if device_id/location_id/hmac_secret missing.
|
|
bool config_load(DeviceConfig& cfg);
|
|
|
|
// Save WiFi credentials to NVS (called by provisioning after captive portal).
|
|
bool config_save_wifi(const String& ssid, const String& pass);
|
|
|
|
// Returns true if wifi_ssid is set in NVS.
|
|
bool config_has_wifi();
|
|
|
|
// Erase WiFi credentials only (factory reset — preserves device_id etc).
|
|
void config_clear_wifi();
|
|
|
|
// Load CV tuning from NVS. Returns true only if all keys present (cfg_version sentinel).
|
|
// If any key missing, tuning is NOT modified (caller keeps its defaults).
|
|
bool config_load_tuning(CVTuning& tuning);
|
|
|
|
// Save CV tuning to NVS atomically. Returns true if all writes succeeded.
|
|
bool config_save_tuning(const CVTuning& tuning);
|