3#include <unordered_map>
16 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_HIGH,
17 spi::CLOCK_PHASE_TRAILING, spi::DATA_RATE_1MHZ> {
25 ATM90E32_REGISTER_UGAINC};
27 ATM90E32_REGISTER_IGAINC};
29 ATM90E32_REGISTER_UOFFSETC};
31 ATM90E32_REGISTER_IOFFSETC};
33 ATM90E32_REGISTER_POFFSETC};
35 ATM90E32_REGISTER_QOFFSETC};
36 const uint16_t
over_voltage_flags[3] = {ATM90E32_STATUS_S0_OVPHASEAST, ATM90E32_STATUS_S0_OVPHASEBST,
37 ATM90E32_STATUS_S0_OVPHASECST};
38 const uint16_t
voltage_sag_flags[3] = {ATM90E32_STATUS_S1_SAGPHASEAST, ATM90E32_STATUS_S1_SAGPHASEBST,
39 ATM90E32_STATUS_S1_SAGPHASECST};
40 const uint16_t
phase_loss_flags[3] = {ATM90E32_STATUS_S1_PHASELOSSAST, ATM90E32_STATUS_S1_PHASELOSSBST,
41 ATM90E32_STATUS_S1_PHASELOSSCST};
43 void setup()
override;
111#ifdef USE_TEXT_SENSOR
128 uint16_t
read16_(uint16_t a_register);
129 int read32_(uint16_t addr_h, uint16_t addr_l);
222#ifdef USE_TEXT_SENSOR
This class simplifies creating components that periodically check a state.
void set_chip_temperature_sensor(sensor::Sensor *chip_temperature_sensor)
bool enable_offset_calibration_
void set_freq_sensor(sensor::Sensor *freq_sensor)
float get_local_phase_reactive_power_(uint8_t phase)
float get_phase_forward_active_energy_(uint8_t phase)
void set_freq_status_text_sensor(text_sensor::TextSensor *sensor)
sensor::Sensor * freq_sensor_
void run_gain_calibrations()
float get_phase_current_avg_(uint8_t phase)
float get_local_phase_apparent_power_(uint8_t phase)
void set_apparent_power_sensor(int phase, sensor::Sensor *obj)
text_sensor::TextSensor * freq_status_text_sensor_
ESPPreferenceObject power_offset_pref_
const uint16_t voltage_gain_registers[3]
float get_phase_voltage_avg_(uint8_t phase)
void write_power_offsets_to_registers_(uint8_t phase, int16_t p_offset, int16_t q_offset)
const uint16_t current_gain_registers[3]
void run_offset_calibrations()
float get_reference_voltage(uint8_t phase)
number::Number * ref_voltages_[3]
void set_power_sensor(int phase, sensor::Sensor *obj)
struct esphome::atm90e32::ATM90E32Component::GainCalibration gain_phase_[3]
void set_current_offset(uint8_t phase, int16_t offset)
bool get_publish_interval_flag_()
const uint16_t current_offset_registers[3]
static const uint8_t PHASEB
float get_phase_reverse_active_energy_(uint8_t phase)
void set_reactive_power_offset(uint8_t phase, int16_t offset)
float get_local_phase_harmonic_active_power_(uint8_t phase)
void check_phase_status()
void set_line_freq(int freq)
float get_phase_angle_(uint8_t phase)
float get_local_phase_current_(uint8_t phase)
bool validate_spi_read_(uint16_t expected, const char *context=nullptr)
void restore_offset_calibrations_()
void set_peak_current_sensor(int phase, sensor::Sensor *obj)
const uint16_t reactive_power_offset_registers[3]
int32_t last_periodic_millis
const uint16_t over_voltage_flags[3]
void clear_power_offset_calibrations()
void set_reverse_active_energy_sensor(int phase, sensor::Sensor *obj)
float get_phase_voltage_(uint8_t phase)
void set_current_sensor(int phase, sensor::Sensor *obj)
float get_chip_temperature_()
int16_t calibrate_offset(uint8_t phase, bool voltage)
float get_local_phase_reverse_active_energy_(uint8_t phase)
void dump_config() override
void set_harmonic_active_power_sensor(int phase, sensor::Sensor *obj)
void restore_gain_calibrations_()
void set_current_phases(int phases)
float get_local_phase_forward_active_energy_(uint8_t phase)
bool peak_current_signed_
struct esphome::atm90e32::ATM90E32Component::OffsetCalibration offset_phase_[3]
void set_active_power_offset(uint8_t phase, int16_t offset)
void restore_power_offset_calibrations_()
uint16_t calculate_voltage_threshold(int line_freq, uint16_t ugain, float multiplier)
float get_local_phase_power_factor_(uint8_t phase)
float get_phase_reactive_power_(uint8_t phase)
void clear_offset_calibrations()
void set_enable_gain_calibration(bool flag)
const uint16_t phase_loss_flags[3]
float get_phase_apparent_power_(uint8_t phase)
void write_gains_to_registers_()
float get_local_phase_voltage_(uint8_t phase)
void set_phase_status_text_sensor(uint8_t phase, text_sensor::TextSensor *sensor)
void check_over_current()
void set_pga_gain(uint16_t gain)
void set_reference_current(uint8_t phase, number::Number *ref_current)
void write16_(uint16_t a_register, uint16_t val)
ESPPreferenceObject gain_calibration_pref_
void write_offsets_to_registers_(uint8_t phase, int16_t voltage_offset, int16_t current_offset)
static const uint8_t PHASEA
struct esphome::atm90e32::ATM90E32Component::PowerOffsetCalibration power_offset_phase_[3]
float get_reference_current(uint8_t phase)
number::Number * ref_currents_[3]
bool verify_gain_writes_()
bool using_saved_calibrations_
float get_phase_peak_current_(uint8_t phase)
void set_voltage_offset(uint8_t phase, int16_t offset)
void clear_gain_calibrations()
float get_phase_harmonic_active_power_(uint8_t phase)
const uint16_t voltage_sag_flags[3]
float get_phase_active_power_(uint8_t phase)
void run_power_offset_calibrations()
bool enable_gain_calibration_
static const uint8_t PHASEC
const uint16_t power_offset_registers[3]
float get_setup_priority() const override
uint16_t read16_(uint16_t a_register)
int read32_(uint16_t addr_h, uint16_t addr_l)
sensor::Sensor * chip_temperature_sensor_
float get_phase_power_factor_(uint8_t phase)
void set_voltage_sensor(int phase, sensor::Sensor *obj)
float get_local_phase_angle_(uint8_t phase)
const uint16_t voltage_offset_registers[3]
void set_ct_gain(int phase, uint16_t gain)
void save_gain_calibration_to_memory_()
void set_phase_angle_sensor(int phase, sensor::Sensor *obj)
void set_reference_voltage(uint8_t phase, number::Number *ref_voltage)
void set_power_factor_sensor(int phase, sensor::Sensor *obj)
void set_forward_active_energy_sensor(int phase, sensor::Sensor *obj)
void set_volt_gain(int phase, uint16_t gain)
bool publish_interval_flag_
text_sensor::TextSensor * phase_status_text_sensor_[3]
float get_phase_current_(uint8_t phase)
void set_peak_current_signed(bool flag)
float get_local_phase_peak_current_(uint8_t phase)
void set_publish_interval_flag_(bool flag)
int16_t calibrate_power_offset(uint8_t phase, bool reactive)
struct esphome::atm90e32::ATM90E32Component::ATM90E32Phase phase_[3]
const char * phase_labels[3]
void set_enable_offset_calibration(bool flag)
ESPPreferenceObject offset_pref_
void set_reactive_power_sensor(int phase, sensor::Sensor *obj)
float get_local_phase_active_power_(uint8_t phase)
Base-class for all numbers.
Base-class for all sensors.
The SPIDevice is what components using the SPI will create.
Providing packet encoding functions for exchanging data with a remote host.
uint32_t IRAM_ATTR HOT millis()
uint32_t cumulative_reverse_active_energy_
float reverse_active_energy_
int16_t active_power_offset_
sensor::Sensor * reactive_power_sensor_
sensor::Sensor * peak_current_sensor_
float forward_active_energy_
sensor::Sensor * power_factor_sensor_
sensor::Sensor * phase_angle_sensor_
sensor::Sensor * apparent_power_sensor_
sensor::Sensor * power_sensor_
sensor::Sensor * current_sensor_
sensor::Sensor * forward_active_energy_sensor_
sensor::Sensor * harmonic_active_power_sensor_
int16_t reactive_power_offset_
sensor::Sensor * reverse_active_energy_sensor_
float harmonic_active_power_
sensor::Sensor * voltage_sensor_
uint32_t cumulative_forward_active_energy_
int16_t reactive_power_offset
int16_t active_power_offset