ESPHome  2022.12.8
ads1115.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include <vector>
9 
10 namespace esphome {
11 namespace ads1115 {
12 
22 };
23 
31 };
32 
33 class ADS1115Sensor;
34 
35 class ADS1115Component : public Component, public i2c::I2CDevice {
36  public:
37  void register_sensor(ADS1115Sensor *obj) { this->sensors_.push_back(obj); }
39  void setup() override;
40  void dump_config() override;
42  float get_setup_priority() const override { return setup_priority::DATA; }
43  void set_continuous_mode(bool continuous_mode) { continuous_mode_ = continuous_mode; }
44 
46  float request_measurement(ADS1115Sensor *sensor);
47 
48  protected:
49  std::vector<ADS1115Sensor *> sensors_;
50  uint16_t prev_config_{0};
52 };
53 
56  public:
57  ADS1115Sensor(ADS1115Component *parent) : parent_(parent) {}
58  void update() override;
59  void set_multiplexer(ADS1115Multiplexer multiplexer) { multiplexer_ = multiplexer; }
60  void set_gain(ADS1115Gain gain) { gain_ = gain; }
61 
62  float sample() override;
63  uint8_t get_multiplexer() const { return multiplexer_; }
64  uint8_t get_gain() const { return gain_; }
65 
66  protected:
70 };
71 
72 } // namespace ads1115
73 } // namespace esphome
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:18
uint8_t get_multiplexer() const
Definition: ads1115.h:63
float request_measurement(ADS1115Sensor *sensor)
Helper method to request a measurement from a sensor.
Definition: ads1115.cpp:82
Abstract interface for components to request voltage (usually ADC readings)
This class simplifies creating components that periodically check a state.
Definition: component.h:267
Internal holder class that is in instance of Sensor so that the hub can create individual sensors...
Definition: ads1115.h:55
void set_continuous_mode(bool continuous_mode)
Definition: ads1115.h:43
ADS1115Multiplexer multiplexer_
Definition: ads1115.h:68
ADS1115Sensor(ADS1115Component *parent)
Definition: ads1115.h:57
ADS1115Component * parent_
Definition: ads1115.h:67
uint8_t get_gain() const
Definition: ads1115.h:64
void set_gain(ADS1115Gain gain)
Definition: ads1115.h:60
std::vector< ADS1115Sensor * > sensors_
Definition: ads1115.h:49
void setup() override
Set up the internal sensor array.
Definition: ads1115.cpp:14
float get_setup_priority() const override
HARDWARE_LATE setup priority.
Definition: ads1115.h:42
void set_multiplexer(ADS1115Multiplexer multiplexer)
Definition: ads1115.h:59
Definition: a4988.cpp:4
Base-class for all sensors.
Definition: sensor.h:50
void register_sensor(ADS1115Sensor *obj)
Definition: ads1115.h:37