ESPHome  2022.12.8
atm90e32.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace atm90e32 {
9 
11  public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_HIGH,
12  spi::CLOCK_PHASE_TRAILING, spi::DATA_RATE_200KHZ> {
13  public:
14  void setup() override;
15  void dump_config() override;
16  float get_setup_priority() const override;
17  void update() override;
18 
19  void set_voltage_sensor(int phase, sensor::Sensor *obj) { this->phase_[phase].voltage_sensor_ = obj; }
20  void set_current_sensor(int phase, sensor::Sensor *obj) { this->phase_[phase].current_sensor_ = obj; }
21  void set_power_sensor(int phase, sensor::Sensor *obj) { this->phase_[phase].power_sensor_ = obj; }
22  void set_reactive_power_sensor(int phase, sensor::Sensor *obj) { this->phase_[phase].reactive_power_sensor_ = obj; }
24  this->phase_[phase].forward_active_energy_sensor_ = obj;
25  }
27  this->phase_[phase].reverse_active_energy_sensor_ = obj;
28  }
29  void set_power_factor_sensor(int phase, sensor::Sensor *obj) { this->phase_[phase].power_factor_sensor_ = obj; }
30  void set_volt_gain(int phase, uint16_t gain) { this->phase_[phase].volt_gain_ = gain; }
31  void set_ct_gain(int phase, uint16_t gain) { this->phase_[phase].ct_gain_ = gain; }
32 
33  void set_freq_sensor(sensor::Sensor *freq_sensor) { freq_sensor_ = freq_sensor; }
34  void set_chip_temperature_sensor(sensor::Sensor *chip_temperature_sensor) {
35  chip_temperature_sensor_ = chip_temperature_sensor;
36  }
37  void set_line_freq(int freq) { line_freq_ = freq; }
38  void set_current_phases(int phases) { current_phases_ = phases; }
39  void set_pga_gain(uint16_t gain) { pga_gain_ = gain; }
40 
41  protected:
42  uint16_t read16_(uint16_t a_register);
43  int read32_(uint16_t addr_h, uint16_t addr_l);
44  void write16_(uint16_t a_register, uint16_t val);
45 
46  float get_line_voltage_a_();
47  float get_line_voltage_b_();
48  float get_line_voltage_c_();
49  float get_line_current_a_();
50  float get_line_current_b_();
51  float get_line_current_c_();
52  float get_active_power_a_();
53  float get_active_power_b_();
54  float get_active_power_c_();
55  float get_reactive_power_a_();
56  float get_reactive_power_b_();
57  float get_reactive_power_c_();
58  float get_power_factor_a_();
59  float get_power_factor_b_();
60  float get_power_factor_c_();
67  float get_frequency_();
68  float get_chip_temperature_();
69 
70  struct ATM90E32Phase {
71  uint16_t volt_gain_{7305};
72  uint16_t ct_gain_{27961};
82  } phase_[3];
85  uint16_t pga_gain_{0x15};
86  int line_freq_{60};
88 };
89 
90 } // namespace atm90e32
91 } // namespace esphome
void set_chip_temperature_sensor(sensor::Sensor *chip_temperature_sensor)
Definition: atm90e32.h:34
float get_setup_priority() const override
Definition: atm90e32.cpp:159
void write16_(uint16_t a_register, uint16_t val)
Definition: atm90e32.cpp:191
void set_current_sensor(int phase, sensor::Sensor *obj)
Definition: atm90e32.h:20
void set_reverse_active_energy_sensor(int phase, sensor::Sensor *obj)
Definition: atm90e32.h:26
int read32_(uint16_t addr_h, uint16_t addr_l)
Definition: atm90e32.cpp:180
This class simplifies creating components that periodically check a state.
Definition: component.h:267
void set_ct_gain(int phase, uint16_t gain)
Definition: atm90e32.h:31
struct esphome::atm90e32::ATM90E32Component::ATM90E32Phase phase_[3]
void set_voltage_sensor(int phase, sensor::Sensor *obj)
Definition: atm90e32.h:19
void set_power_factor_sensor(int phase, sensor::Sensor *obj)
Definition: atm90e32.h:29
void set_volt_gain(int phase, uint16_t gain)
Definition: atm90e32.h:30
void set_power_sensor(int phase, sensor::Sensor *obj)
Definition: atm90e32.h:21
void set_current_phases(int phases)
Definition: atm90e32.h:38
uint16_t read16_(uint16_t a_register)
Definition: atm90e32.cpp:161
sensor::Sensor * chip_temperature_sensor_
Definition: atm90e32.h:84
Definition: a4988.cpp:4
void set_pga_gain(uint16_t gain)
Definition: atm90e32.h:39
uint32_t val
Definition: datatypes.h:85
void set_reactive_power_sensor(int phase, sensor::Sensor *obj)
Definition: atm90e32.h:22
Base-class for all sensors.
Definition: sensor.h:50
void set_forward_active_energy_sensor(int phase, sensor::Sensor *obj)
Definition: atm90e32.h:23
void set_freq_sensor(sensor::Sensor *freq_sensor)
Definition: atm90e32.h:33