ESPHome  2024.10.2
atm90e26.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace atm90e26 {
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 
21  void set_power_sensor(sensor::Sensor *obj) { this->power_sensor_ = obj; }
26  void set_freq_sensor(sensor::Sensor *freq_sensor) { freq_sensor_ = freq_sensor; }
27  void set_line_freq(int freq) { line_freq_ = freq; }
29  void set_pl_const(uint32_t pl_const) { pl_const_ = pl_const; }
30  void set_gain_metering(uint16_t gain) { this->gain_metering_ = gain; }
31  void set_gain_voltage(uint16_t gain) { this->gain_voltage_ = gain; }
32  void set_gain_ct(uint16_t gain) { this->gain_ct_ = gain; }
33  void set_gain_pga(uint16_t gain) { gain_pga_ = gain; }
34  void set_n_line_gain(uint16_t gain) { n_line_gain_ = gain; }
35 
36  protected:
37  uint16_t read16_(uint8_t a_register);
38  int read32_(uint8_t addr_h, uint8_t addr_l);
39  void write16_(uint8_t a_register, uint16_t val);
40 
41  float get_line_voltage_();
42  float get_line_current_();
43  float get_active_power_();
44  float get_reactive_power_();
45  float get_power_factor_();
48  float get_frequency_();
49  float get_chip_temperature_();
50 
61  uint16_t gain_metering_{7481};
62  uint16_t gain_voltage_{26400};
63  uint16_t gain_ct_{31251};
64  uint16_t gain_pga_{0x4};
65  uint16_t n_line_gain_{0x2};
66  int line_freq_{60};
67  float meter_constant_{3200.0f};
68  uint32_t pl_const_{1429876};
69 };
70 
71 } // namespace atm90e26
72 } // namespace esphome
void set_power_sensor(sensor::Sensor *obj)
Definition: atm90e26.h:21
void set_gain_voltage(uint16_t gain)
Definition: atm90e26.h:31
sensor::Sensor * current_sensor_
Definition: atm90e26.h:53
void set_pl_const(uint32_t pl_const)
Definition: atm90e26.h:29
void set_reverse_active_energy_sensor(sensor::Sensor *obj)
Definition: atm90e26.h:24
void set_meter_constant(float val)
Definition: atm90e26.h:28
void set_voltage_sensor(sensor::Sensor *obj)
Definition: atm90e26.h:19
sensor::Sensor * reactive_power_sensor_
Definition: atm90e26.h:55
void set_gain_pga(uint16_t gain)
Definition: atm90e26.h:33
mopeka_std_values val[4]
This class simplifies creating components that periodically check a state.
Definition: component.h:283
AlsGain501 gain
The SPIDevice is what components using the SPI will create.
Definition: spi.h:391
void write16_(uint8_t a_register, uint16_t val)
Definition: atm90e26.cpp:168
void set_n_line_gain(uint16_t gain)
Definition: atm90e26.h:34
void set_reactive_power_sensor(sensor::Sensor *obj)
Definition: atm90e26.h:22
void set_gain_metering(uint16_t gain)
Definition: atm90e26.h:30
int read32_(uint8_t addr_h, uint8_t addr_l)
sensor::Sensor * forward_active_energy_sensor_
Definition: atm90e26.h:57
float get_setup_priority() const override
Definition: atm90e26.cpp:150
uint16_t read16_(uint8_t a_register)
Definition: atm90e26.cpp:152
void set_current_sensor(sensor::Sensor *obj)
Definition: atm90e26.h:20
sensor::Sensor * voltage_sensor_
Definition: atm90e26.h:52
void set_forward_active_energy_sensor(sensor::Sensor *obj)
Definition: atm90e26.h:23
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
sensor::Sensor * power_factor_sensor_
Definition: atm90e26.h:56
Base-class for all sensors.
Definition: sensor.h:57
void set_power_factor_sensor(sensor::Sensor *obj)
Definition: atm90e26.h:25
void set_gain_ct(uint16_t gain)
Definition: atm90e26.h:32
void set_freq_sensor(sensor::Sensor *freq_sensor)
Definition: atm90e26.h:26
sensor::Sensor * reverse_active_energy_sensor_
Definition: atm90e26.h:58