ESPHome  2024.11.0
cse7761.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace cse7761 {
9 
11  uint32_t frequency = 0;
12  uint32_t voltage_rms = 0;
13  uint32_t current_rms[2] = {0};
14  uint32_t energy[2] = {0};
15  uint32_t active_power[2] = {0};
16  uint16_t coefficient[8] = {0};
17  uint8_t energy_update = 0;
18  bool ready = false;
19 };
20 
23  public:
24  void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; }
25  void set_active_power_1_sensor(sensor::Sensor *power_sensor_1) { power_sensor_1_ = power_sensor_1; }
26  void set_current_1_sensor(sensor::Sensor *current_sensor_1) { current_sensor_1_ = current_sensor_1; }
27  void set_active_power_2_sensor(sensor::Sensor *power_sensor_2) { power_sensor_2_ = power_sensor_2; }
28  void set_current_2_sensor(sensor::Sensor *current_sensor_2) { current_sensor_2_ = current_sensor_2; }
29  void setup() override;
30  void dump_config() override;
31  float get_setup_priority() const override;
32  void update() override;
33 
34  protected:
35  // Sensors
36  sensor::Sensor *voltage_sensor_{nullptr};
37  sensor::Sensor *power_sensor_1_{nullptr};
38  sensor::Sensor *current_sensor_1_{nullptr};
39  sensor::Sensor *power_sensor_2_{nullptr};
40  sensor::Sensor *current_sensor_2_{nullptr};
42 
43  void write_(uint8_t reg, uint16_t data);
44  bool read_once_(uint8_t reg, uint8_t size, uint32_t *value);
45  uint32_t read_(uint8_t reg, uint8_t size);
46  uint32_t coefficient_by_unit_(uint32_t unit);
47  bool chip_init_();
48  void get_data_();
49 };
50 
51 } // namespace cse7761
52 } // namespace esphome
void setup()
void set_current_1_sensor(sensor::Sensor *current_sensor_1)
Definition: cse7761.h:26
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_voltage_sensor(sensor::Sensor *voltage_sensor)
Definition: cse7761.h:24
This class implements support for the CSE7761 UART power sensor.
Definition: cse7761.h:22
void set_active_power_2_sensor(sensor::Sensor *power_sensor_2)
Definition: cse7761.h:27
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_current_2_sensor(sensor::Sensor *current_sensor_2)
Definition: cse7761.h:28
Base-class for all sensors.
Definition: sensor.h:57
void set_active_power_1_sensor(sensor::Sensor *power_sensor_1)
Definition: cse7761.h:25