37 if (!std::isfinite(voltage) || !std::isfinite(vcc) || voltage <= VENDOR_DEAD_INPUT_FRACTION * vcc || voltage > vcc)
44 if (!std::isfinite(
x) ||
x < 0.0f || !std::isfinite(x_air) || x_air <= 0.0f)
52 if (!std::isfinite(ratio))
78 if (!std::isfinite(voltage) || !std::isfinite(vcc) || !std::isfinite(rl) || rl <= 0.0f || voltage > vcc ||
81 return vcc * rl / voltage - rl;
86 if (!std::isfinite(rs) || rs < 0.0f || !std::isfinite(r0) || r0 <= 0.0f)
94 if (!std::isfinite(a) || !std::isfinite(b) || !std::isfinite(ratio) || ratio < 0.0f || a <= 0.0f)
97 const float ppm = a * powf(ratio, b);
98 return std::isnan(ppm) ? NAN : ppm;
104inline float clamp_ppm(
float ppm,
float min_ppm,
float max_ppm) {
109 if (std::isfinite(min_ppm) && ppm < min_ppm)
111 if (std::isfinite(max_ppm) && ppm > max_ppm)
113 return std::isfinite(ppm) ? ppm : NAN;
123 if (!std::isfinite(min_value) || !std::isfinite(max_value) || !std::isfinite(mean) || mean <= 0.0f)
constexpr float MAX_RS_OVER_RL
Largest RS the datasheet model reads, as a multiple of RL.
bool 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.
constexpr float VENDOR_DEAD_INPUT_FRACTION
Share of VCC at or below which the vendor model reads the output as disconnected: clean air sits a vo...
float ratio_from_rs(float rs, float r0)
ratio = RS / R0 (NaN when either value is unusable); 0 is the saturated end.
constexpr float MAX_CALIBRATION_SPREAD
Largest relative spread (max - min) / mean a clean-air calibration accepts.
float air_value_from_voltage(float voltage, float vcc)
x = VCC - V_ao: 0 at VCC (a saturated sensor, never clean air).
float 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 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 chang...
float rs_from_voltage(float voltage, float vcc, float rl)
RS = (VCC * RL) / V - RL in kOhm: 0 at VCC (a saturated sensor).
float ratio_from_air_value(float x, float x_air)
ratio = x / x_air (NaN when either value is unusable).
ConversionModel
Generated through CONVERSION_MODELS in init.py.
@ CONVERSION_MODEL_DFROBOT
@ CONVERSION_MODEL_DATASHEET
float ppm_from_vendor_curve(float ratio, const VendorCurve &curve)
ratio -> ppm as DFRobot_MICS getGasData(): 0 above the threshold or below the vendor range,...
float datasheet_dead_input_voltage(float vcc)
Smallest V_ao the datasheet model reads: the output of RS = MAX_RS_OVER_RL * RL.
Per-gas constants of the vendor model.
float max_ppm
upper end of the measuring range
float gain
ppm per unit ratio
float threshold
ratio at or below which the gas counts as detected
float min_ppm
the vendor reports 0 ppm below this