37 lines
include/pressure_monitor.h
Declares PressureMonitor, safe-limit constants, and the shouldAlarm contract.
// PressureMonitor: evaluates vessel pressure against safe operating limits.
#pragma once
#include <cstdint>
 
// Safe operating limits in kPa.
static constexpr float kMaxPressure = 200.0f; // upper safe limit
static constexpr float kMinPressure =  50.0f; // lower operating limit
 
// Calibrated pressure reading with a monotonic sample counter.
struct PressureReading {
  float    valuekPa; // calibrated pressure in kPa
  uint32_t sampleId; // monotonically increasing sample identifier
};
 
// Monitors vessel pressure and drives the alarm relay.
class PressureMonitor {
public:
  // Parameters:
  //   calibrationFactor - volts-to-kPa scaling factor for this sensor model
  // Returns: new PressureMonitor ready to evaluate pressure readings
  explicit PressureMonitor(float calibrationFactor);
 
  // Parameters:
  //   pressure - calibrated pressure reading in kPa
  // Returns: true if pressure is outside the safe operating range, false otherwise.
  //   An alarm fires when pressure is above kMaxPressure OR below kMinPressure.
  bool shouldAlarm(float pressure) const;
 
  // Parameters:
  //   rawVoltage - uncalibrated voltage output from the sensor ADC
  // Returns: calibrated PressureReading with an incremented sampleId
  PressureReading normalize(float rawVoltage) const;
 
private:
  float            calibrationFactor_; // volts-to-kPa scaling factor
  mutable uint32_t sampleId_ = 0;      // incremented on every normalize() call
};