ESPHome  2024.10.0
gp2y1010au0f.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 namespace esphome {
9 namespace gp2y1010au0f {
10 
12  public:
13  void update() override;
14  void loop() override;
15  void dump_config() override;
16  float get_setup_priority() const override {
17  // after the base sensor has been initialized
18  return setup_priority::DATA - 1.0f;
19  }
20 
22  void set_voltage_refs(float offset, float multiplier) {
23  this->voltage_offset_ = offset;
24  this->voltage_multiplier_ = multiplier;
25  }
26  void set_led_output(output::BinaryOutput *output) { led_output_ = output; }
27 
28  protected:
29  // duration in ms of the sampling phase
30  uint32_t sample_duration_ = 100;
31  // duration in us of the wait before sampling
32  // ref: https://global.sharp/products/device/lineup/data/pdf/datasheet/gp2y1010au_appl_e.pdf
33  uint32_t sample_wait_before_ = 280;
34  // duration in us of the wait after sampling
35  // it seems no need to delay on purpose since one ADC sampling takes longer than that (300-400 us on ESP8266)
36  // uint32_t sample_wait_after_ = 40;
37  // the sampling source to read voltage from
39  // ADC voltage reading offset
40  float voltage_offset_ = 0.0f;
41  // ADC voltage reading multiplier
42  float voltage_multiplier_ = 1.0f;
43  // the binary output to control the sampling LED
45 
46  float sample_sum_ = 0.0f;
47  uint32_t num_samples_ = 0;
48  bool is_sampling_ = false;
49 };
50 
51 } // namespace gp2y1010au0f
52 } // namespace esphome
void set_voltage_refs(float offset, float multiplier)
Definition: gp2y1010au0f.h:22
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
void set_adc_source(voltage_sampler::VoltageSampler *source)
Definition: gp2y1010au0f.h:21
Abstract interface for components to request voltage (usually ADC readings)
This class simplifies creating components that periodically check a state.
Definition: component.h:283
voltage_sampler::VoltageSampler * source_
Definition: gp2y1010au0f.h:38
float get_setup_priority() const override
Definition: gp2y1010au0f.h:16
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57
void set_led_output(output::BinaryOutput *output)
Definition: gp2y1010au0f.h:26