ESPHome  2024.11.1
ina226.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace ina226 {
9 
10 enum AdcTime : uint16_t {
19 };
20 
21 enum AdcAvgSamples : uint16_t {
30 };
31 
33  uint16_t raw;
34  struct {
35  uint16_t mode : 3;
39  uint16_t reserved : 3;
40  uint16_t reset : 1;
41  } __attribute__((packed));
42 };
43 
45  public:
46  void setup() override;
47  void dump_config() override;
48  float get_setup_priority() const override;
49  void update() override;
50 
51  void set_shunt_resistance_ohm(float shunt_resistance_ohm) { shunt_resistance_ohm_ = shunt_resistance_ohm; }
52  void set_max_current_a(float max_current_a) { max_current_a_ = max_current_a; }
53  void set_adc_time_voltage(AdcTime time) { adc_time_voltage_ = time; }
54  void set_adc_time_current(AdcTime time) { adc_time_current_ = time; }
55  void set_adc_avg_samples(AdcAvgSamples samples) { adc_avg_samples_ = samples; }
56 
57  void set_bus_voltage_sensor(sensor::Sensor *bus_voltage_sensor) { bus_voltage_sensor_ = bus_voltage_sensor; }
58  void set_shunt_voltage_sensor(sensor::Sensor *shunt_voltage_sensor) { shunt_voltage_sensor_ = shunt_voltage_sensor; }
59  void set_current_sensor(sensor::Sensor *current_sensor) { current_sensor_ = current_sensor; }
60  void set_power_sensor(sensor::Sensor *power_sensor) { power_sensor_ = power_sensor; }
61 
62  protected:
65  AdcTime adc_time_voltage_{AdcTime::ADC_TIME_1100US};
66  AdcTime adc_time_current_{AdcTime::ADC_TIME_1100US};
68  uint32_t calibration_lsb_;
69  sensor::Sensor *bus_voltage_sensor_{nullptr};
70  sensor::Sensor *shunt_voltage_sensor_{nullptr};
71  sensor::Sensor *current_sensor_{nullptr};
72  sensor::Sensor *power_sensor_{nullptr};
73 
74  int32_t twos_complement_(int32_t val, uint8_t bits);
75 };
76 
77 } // namespace ina226
78 } // namespace esphome
void setup()
mopeka_std_values val[4]
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_shunt_resistance_ohm(float shunt_resistance_ohm)
Definition: ina226.h:51
void set_current_sensor(sensor::Sensor *current_sensor)
Definition: ina226.h:59
void set_shunt_voltage_sensor(sensor::Sensor *shunt_voltage_sensor)
Definition: ina226.h:58
struct esphome::ina226::ConfigurationRegister::@82 __attribute__((packed))
void set_power_sensor(sensor::Sensor *power_sensor)
Definition: ina226.h:60
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_adc_time_current(AdcTime time)
Definition: ina226.h:54
void set_max_current_a(float max_current_a)
Definition: ina226.h:52
void set_bus_voltage_sensor(sensor::Sensor *bus_voltage_sensor)
Definition: ina226.h:57
Base-class for all sensors.
Definition: sensor.h:57
void set_adc_avg_samples(AdcAvgSamples samples)
Definition: ina226.h:55
void set_adc_time_voltage(AdcTime time)
Definition: ina226.h:53
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133