45 void setup()
override;
50#ifdef MICS_5524_GAS_COUNT
78 float sample_voltage_();
128#ifdef MICS_5524_GAS_COUNT
This class simplifies creating components that periodically check a state.
Minimal static vector - saves memory by avoiding std::vector overhead.
The MiCS-5524 breakout: one analog output, converted for every configured gas against the clean-air r...
bool input_fault_
The out-of-range warning has been logged; the next usable reading clears it.
void begin_calibration_()
uint32_t calibration_samples_
void set_voltage_multiplier(float multiplier)
bool warming_up_
Set from setup() until the warm-up timeout fires.
bool save_reference_()
True when the reference reached the storage.
void publish_diagnostics_(float voltage, float ratio, float rs)
MiCS5524Component(voltage_sampler::VoltageSampler *source)
source must outlive this component, which code generation guarantees.
bool has_reference_() const
void set_enable_pin(GPIOPin *pin)
Driven active in setup(); EN of the breakout is active low, so inverted: true turns that on.
uint32_t calibration_count_
void register_gas_sensor(MiCS5524GasSensor *gas)
uint32_t sample_interval_
Spacing of the clean-air calibration samples (ms); the ~16 ms loop tick is the floor.
static constexpr uint32_t CALIBRATION_START_ID
bool calibration_pending_
A calibration waits for its start time; calibrating_ takes over from there.
ESPPreferenceObject reference_pref_
void finish_calibration_()
uint32_t calibration_delay_
float reference_
Clean-air reference, x_air in volts or R0 in kOhm, 0 while there is none.
void publish_ratio_(float ratio)
void request_calibration()
Deferred until the warm-up window ends.
StaticVector< MiCS5524GasSensor *, MICS_5524_GAS_COUNT > gases_
bool is_vendor_model_() const
void set_warmup_time(uint32_t warmup)
float voltage_multiplier_
void schedule_calibration_retry_()
SUB_SENSOR(voltage) SUB_SENSOR(ratio) SUB_SENSOR(rs) protected float model_value_(float voltage)
Value of the active model that the reference is taken from, x = VCC - V_AO (vendor) or RS (datasheet)...
micsmath::ConversionModel conversion_
void set_calibration(uint32_t delay, uint32_t samples, uint32_t sample_interval, bool persist, bool at_boot)
Calibration parameters: start after delay ms, average samples readings sample_interval ms apart; pers...
void set_conversion(micsmath::ConversionModel conversion)
void dump_config() override
voltage_sampler::VoltageSampler * source_
uint32_t calibration_last_sample_
void set_preference_key(uint32_t key)
Base of the flash key of the stored reference, a hash of the component ID and the front end.
void set_samples(uint8_t samples)
void schedule_calibration_(uint32_t delay)
Start a calibration after delay ms; every start goes through here.
static constexpr uint32_t CALIBRATION_RETRY_MIN_MS
Floor of the delay between two calibration attempts (ms).
uint32_t calibration_attempts_
void set_reference(float reference)
Clean-air reference from the configuration, x_air (dfrobot) or R0 (datasheet).
void process_calibration_()
float calibration_min_
Smallest and largest clean-air sample of the run, see calibration_is_stable().
One gas of a MiCS-5524: converts the measured ratio with the curve of that gas.
MiCS5524GasSensor(float p0, float p1, float min_ppm, float max_ppm)
p0/p1 are threshold and gain (dfrobot) or a and b (datasheet), from coefficients.py.
float get_max_ppm() const
float get_min_ppm() const
void publish_ratio(float ratio, micsmath::ConversionModel model)
Publish the concentration for ratio with the formula of model; NAN publishes unknown.
Base-class for all sensors.
Abstract interface for components to request voltage (usually ADC readings)
ConversionModel
Generated through CONVERSION_MODELS in init.py.
@ CONVERSION_MODEL_DFROBOT
void HOT delay(uint32_t ms)