ESPHome  2021.9.3
hlw8012.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/esphal.h"
7 
8 namespace esphome {
9 namespace hlw8012 {
10 
12 
17 };
18 
20  public:
21  void setup() override;
22  void dump_config() override;
23  float get_setup_priority() const override;
24  void update() override;
25 
26  void set_initial_mode(HLW8012InitialMode initial_mode) {
28  }
29  void set_sensor_model(HLW8012SensorModels sensor_model) { sensor_model_ = sensor_model; }
30  void set_change_mode_every(uint32_t change_mode_every) { change_mode_every_ = change_mode_every; }
31  void set_current_resistor(float current_resistor) { current_resistor_ = current_resistor; }
32  void set_voltage_divider(float voltage_divider) { voltage_divider_ = voltage_divider; }
33  void set_sel_pin(GPIOPin *sel_pin) { sel_pin_ = sel_pin; }
34  void set_cf_pin(GPIOPin *cf_pin) { cf_pin_ = cf_pin; }
35  void set_cf1_pin(GPIOPin *cf1_pin) { cf1_pin_ = cf1_pin; }
36  void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; }
37  void set_current_sensor(sensor::Sensor *current_sensor) { current_sensor_ = current_sensor; }
38  void set_power_sensor(sensor::Sensor *power_sensor) { power_sensor_ = power_sensor; }
39  void set_energy_sensor(sensor::Sensor *energy_sensor) { energy_sensor_ = energy_sensor; }
40 
41  protected:
42  uint32_t nth_value_{0};
43  bool current_mode_{false};
44  uint32_t change_mode_at_{0};
45  uint32_t change_mode_every_{8};
46  float current_resistor_{0.001};
47  float voltage_divider_{2351};
49  uint64_t cf_total_pulses_{0};
59 
60  float voltage_multiplier_{0.0f};
61  float current_multiplier_{0.0f};
62  float power_multiplier_{0.0f};
63 };
64 
65 } // namespace hlw8012
66 } // namespace esphome
void set_power_sensor(sensor::Sensor *power_sensor)
Definition: hlw8012.h:38
void set_initial_mode(HLW8012InitialMode initial_mode)
Definition: hlw8012.h:26
void set_current_sensor(sensor::Sensor *current_sensor)
Definition: hlw8012.h:37
void set_voltage_divider(float voltage_divider)
Definition: hlw8012.h:32
void set_sel_pin(GPIOPin *sel_pin)
Definition: hlw8012.h:33
This class simplifies creating components that periodically check a state.
Definition: component.h:230
sensor::Sensor * energy_sensor_
Definition: hlw8012.h:58
sensor::Sensor * power_sensor_
Definition: hlw8012.h:57
void set_energy_sensor(sensor::Sensor *energy_sensor)
Definition: hlw8012.h:39
void set_cf_pin(GPIOPin *cf_pin)
Definition: hlw8012.h:34
HLW8012SensorModels sensor_model_
Definition: hlw8012.h:48
void set_current_resistor(float current_resistor)
Definition: hlw8012.h:31
void set_change_mode_every(uint32_t change_mode_every)
Definition: hlw8012.h:30
sensor::Sensor * voltage_sensor_
Definition: hlw8012.h:55
float get_setup_priority() const override
Definition: hlw8012.cpp:50
pulse_counter::PulseCounterStorage cf1_store_
Definition: hlw8012.h:54
Library based on https://github.com/miguelbalboa/rfid and adapted to ESPHome by . ...
Definition: a4988.cpp:4
sensor::Sensor * current_sensor_
Definition: hlw8012.h:56
pulse_counter::PulseCounterStorage cf_store_
Definition: hlw8012.h:52
Base-class for all sensors.
Definition: sensor.h:45
void set_voltage_sensor(sensor::Sensor *voltage_sensor)
Definition: hlw8012.h:36
void set_sensor_model(HLW8012SensorModels sensor_model)
Definition: hlw8012.h:29
A high-level abstraction class that can expose a pin together with useful options like pinMode...
Definition: esphal.h:69
void set_cf1_pin(GPIOPin *cf1_pin)
Definition: hlw8012.h:35