1#ifndef CUBIC_CALIBRATION_STORE_HPP
2#define CUBIC_CALIBRATION_STORE_HPP
31 double A = 0.0,
B = 0.0,
C = 0.0,
D = 0.0;
171 const std::string& role,
const std::string& active_model =
"cubic",
180 void note_capture(uint16_t uid,
const CaptureQuality& q);
183 void set_fit_curve(uint16_t uid,
const std::vector<std::pair<double, double>>& curve);
190 std::vector<uint16_t>
uids()
const;
CubicCalibrationStore(std::string file_path)
void note_capture(uint16_t uid, const CaptureQuality &q)
Record how the last capture on this uid went, for the UI to show.
std::map< uint16_t, CubicChannel > channels_
size_t load()
Load the JSON record, resume points, and re-fit each channel.
static constexpr size_t kMaxPoints
bool load_failed_
Set when load() could not read an existing file.
void clear_channel(uint16_t uid)
Drop all points, fit, and fit-curve for a uid (channel goes back to PENDING).
const CubicFit * fit_for(uint16_t uid) const
void register_channel(uint16_t uid, uint8_t board_id, uint8_t connector, uint8_t logical_ch, const std::string &role, const std::string &active_model="cubic", SensorKind kind=SensorKind::PT, const std::string &raw_unit="adc")
Attach/refresh identity + role + streaming model for a uid (idempotent; call at startup).
static void refit(CubicChannel &ch)
Recompute fit_cubic / fit_linear / fit / status from ch.points per ch.active_model.
static CubicFit compute_fit(const std::vector< CubicPoint > &pts, int max_degree=3)
Least-squares polynomial of degree min(max_degree, n - 1) over pts.
bool load_failed() const
True when load() could not read an existing file, so every curve here is a fallback rather than the o...
CubicCalibrationStore(std::string file_path)
std::vector< uint16_t > uids() const
CubicFit add_point(uint16_t uid, double adc, double psi)
Append a capture point (raw ADC, reference PSI), cap history, and re-fit.
const CubicChannel * channel(uint16_t uid) const
std::string serialize() const
void set_fit_curve(uint16_t uid, const std::vector< std::pair< double, double > > &curve)
Replace a robust uid's display fit-curve (sampled predict_pressure_psi points).
bool save() const
Atomically write the JSON record (temp + rename).
static STAR_MCP3201 adc(MCP3201_CS_PIN, &mcp_spi)
Output smoothing for calibrated PT pressure, per sensor uid (ESP32 and LabJack T7 alike).
constexpr const char * kRawUnitAdc
CubicChannel::raw_unit values.
CalTarget cal_target(const CubicChannel &ch)
CalTarget
Which live calibration manager a store entry's fit belongs in — the one rule every caller that applie...
constexpr const char * kRawUnitMicrovolts
SensorKind
Which family of sensor a channel belongs to.
Motorized ball valve position: raw ADC counts -> % open.
Per-sensor calibration record: identity, captured points, and the current fit.
Result of a least-squares polynomial fit over a channel's captured points.
How trustworthy the most recent capture on this channel was.
Per-sensor calibration record: identity, captured points, and the current fit.
std::string raw_unit
What a point's adc means: kRawUnitAdc for an ESP32 board's ADC code, kRawUnitMicrovolts for a LabJack...
bool live
True when the RUNNING config declares a board/connector that owns this uid, i.e.
std::vector< std::pair< double, double > > fit_curve
std::vector< CubicPoint > points
CaptureQuality last_capture
Result of a least-squares polynomial fit over a channel's captured points.
std::vector< double > poly
One operator-captured calibration point: raw ADC code paired with a known reference PSI.
static std::string ch(int ain, const std::string &kind, const std::string &extra="", const std::string &board="lj")