ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
mics_math.h File Reference

Go to the source code of this file.

Data Structures

struct  esphome::mics_5524::micsmath::VendorCurve
 Per-gas constants of the vendor model. More...
 

Namespaces

namespace  esphome
 
namespace  esphome::mics_5524
 
namespace  esphome::mics_5524::micsmath
 

Enumerations

enum  esphome::mics_5524::micsmath::ConversionModel : uint8_t { esphome::mics_5524::micsmath::CONVERSION_MODEL_DFROBOT = 0 , esphome::mics_5524::micsmath::CONVERSION_MODEL_DATASHEET = 1 }
 Generated through CONVERSION_MODELS in init.py. More...
 

Functions

float esphome::mics_5524::micsmath::air_value_from_voltage (float voltage, float vcc)
 x = VCC - V_ao: 0 at VCC (a saturated sensor, never clean air).
 
float esphome::mics_5524::micsmath::ratio_from_air_value (float x, float x_air)
 ratio = x / x_air (NaN when either value is unusable).
 
float esphome::mics_5524::micsmath::ppm_from_vendor_curve (float ratio, const VendorCurve &curve)
 ratio -> ppm as DFRobot_MICS getGasData(): 0 above the threshold or below the vendor range, the top of the range at ratio 0 (a saturated sensor), NaN stays NaN.
 
float esphome::mics_5524::micsmath::datasheet_dead_input_voltage (float vcc)
 Smallest V_ao the datasheet model reads: the output of RS = MAX_RS_OVER_RL * RL.
 
float esphome::mics_5524::micsmath::rs_from_voltage (float voltage, float vcc, float rl)
 RS = (VCC * RL) / V - RL in kOhm: 0 at VCC (a saturated sensor).
 
float esphome::mics_5524::micsmath::ratio_from_rs (float rs, float r0)
 ratio = RS / R0 (NaN when either value is unusable); 0 is the saturated end.
 
float esphome::mics_5524::micsmath::ppm_from_power_law (float a, float b, float ratio)
 ppm = a * ratio^b; NaN for a ratio or coefficient that cannot produce a reading.
 
float esphome::mics_5524::micsmath::clamp_ppm (float ppm, float min_ppm, float max_ppm)
 Clamp to the configured range: below min_ppm counts as not detected and reads 0, 0 itself never changes, and a reading past a finite max_ppm (infinity included) is max_ppm.
 
bool esphome::mics_5524::micsmath::calibration_is_stable (float min_value, float max_value, float mean)
 True when the clean-air samples spread at most MAX_CALIBRATION_SPREAD of their mean.
 

Variables

constexpr float esphome::mics_5524::micsmath::VENDOR_DEAD_INPUT_FRACTION = 0.05f
 Share of VCC at or below which the vendor model reads the output as disconnected: clean air sits a volt or two below VCC, so a reading near 0 V is a wiring fault, not gas-free air.
 
constexpr float esphome::mics_5524::micsmath::MAX_RS_OVER_RL = 200.0f
 Largest RS the datasheet model reads, as a multiple of RL.
 
constexpr float esphome::mics_5524::micsmath::MAX_CALIBRATION_SPREAD = 0.25f
 Largest relative spread (max - min) / mean a clean-air calibration accepts.