1#ifndef PT_CALIBRATION_HPP
2#define PT_CALIBRATION_HPP
35 double adc =
static_cast<double>(adc_code);
44 std::optional<int32_t>
invert_to_adc(
double target_psi)
const;
52 if (local_connector == 0 || local_connector > 10)
53 return local_connector;
55 (
static_cast<int>(board_slot_number) - 1) * 10 +
static_cast<int>(local_connector);
56 if (idx < 1 || idx > 255)
57 return local_connector;
58 return static_cast<uint8_t
>(idx);
81 bool load_from_json(
const std::string& json_path,
bool merge_missing_only =
false);
149 static void set_default_paths(
const std::string& json_dir,
const std::string& csv_path);
std::string find_latest_json_file(const std::string &json_dir) const
PTCalibrationManager(bool auto_load=true)
bool parse_csv_file(const std::string &csv_path)
bool load_calibration()
Auto-load calibration from default paths Default: factory CSV first, then newest GUI JSON overlays ev...
size_t get_calibrated_count() const
Get number of calibrated channels.
bool load_from_json(const std::string &json_path, bool merge_missing_only=false)
Load calibration from JSON file (from calibration GUI).
void set_calibration(uint8_t channel_id, const PTCalibrationCoeffs &coeffs)
Set/replace the cubic coefficients for a logical channel at runtime.
bool parse_json_file(const std::string &json_path)
std::map< uint8_t, PTCalibrationCoeffs > calibrations_
bool is_calibrated(uint8_t channel_id) const
Check if a channel has calibration.
static std::string default_json_dir_
~PTCalibrationManager()=default
static std::string default_csv_path_
double calculate_pressure(uint8_t channel_id, int32_t adc_code) const
Calculate calibrated pressure for a channel.
void clear_calibration(uint8_t channel_id)
Remove any cubic for a logical channel, so is_calibrated() returns false again.
bool load_from_csv(const std::string &csv_path)
Load calibration from CSV file (from DiabloAvionics).
const PTCalibrationCoeffs * get_calibration(uint8_t channel_id) const
Get calibration coefficients for a sensor channel.
static void set_default_paths(const std::string &json_dir, const std::string &csv_path)
Set default calibration file paths.
static STAR_MCP3201 adc(MCP3201_CS_PIN, &mcp_spi)
*brief create JSON pointer *sa reference_tokens const string_t const string_t & b
*brief create JSON pointer *sa reference_tokens const string_t & a
Output smoothing for calibrated PT pressure, per sensor uid (ESP32 and LabJack T7 alike).
uint8_t pt_logical_calibration_channel(uint8_t board_slot_number, uint8_t local_connector)
PT board slot (1–10, from board_id % 10 with 0→10) + local connector (1–10) → factory/JSON logical ch...
Motorized ball valve position: raw ADC counts -> % open.
PT Calibration Coefficients.
std::optional< int32_t > invert_to_adc(double target_psi) const
Invert psi = A*x^3 + B*x^2 + C*x + D to find ADC code for target PSI.
double calculate_pressure(int32_t adc_code) const
Calculate pressure (psi) from ADC code.
PTCalibrationCoeffs(double a, double b, double c, double d)