11static constexpr uint32_t READ_TIMEOUT_ID = 0;
13static const float MIN_VOLTAGE = 0.0f;
14static const float MAX_VOLTAGE = 4.0f;
17 LOG_SENSOR(
"",
"Sharp GP2Y1010AU0F PM2.5 Sensor",
this);
19 " Sampling duration: %" PRId32
" ms\n"
20 " ADC voltage multiplier: %.3f",
22 LOG_UPDATE_INTERVAL(
this);
34 ESP_LOGD(TAG,
"ADC read voltage: %.3f V (mean from %" PRId32
" samples)", mean, this->
num_samples_);
38 int16_t pm_2_5_value = 170 * mean;
60 if (std::isnan(read_voltage))
63 if (read_voltage < MIN_VOLTAGE || read_voltage > MAX_VOLTAGE)
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void dump_config() override
uint32_t sample_wait_before_
uint32_t sample_duration_
float voltage_multiplier_
output::BinaryOutput * led_output_
voltage_sampler::VoltageSampler * source_
virtual void turn_off()
Disable this binary output.
virtual void turn_on()
Enable this binary output.
void publish_state(float state)
Publish a new state to the front-end.
virtual float sample()=0
Get a voltage reading, in V.
ESPHOME_LOG_TAG(TAG, "gp2y1010au0f")
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)