ESPHome  2023.11.6
mhz19.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 namespace esphome {
9 namespace mhz19 {
10 
12 
14  public:
15  float get_setup_priority() const override;
16 
17  void setup() override;
18  void update() override;
19  void dump_config() override;
20 
21  void calibrate_zero();
22  void abc_enable();
23  void abc_disable();
24 
25  void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
26  void set_co2_sensor(sensor::Sensor *co2_sensor) { co2_sensor_ = co2_sensor; }
27  void set_abc_enabled(bool abc_enabled) { abc_boot_logic_ = abc_enabled ? MHZ19_ABC_ENABLED : MHZ19_ABC_DISABLED; }
28 
29  protected:
30  bool mhz19_write_command_(const uint8_t *command, uint8_t *response);
31 
35 };
36 
37 template<typename... Ts> class MHZ19CalibrateZeroAction : public Action<Ts...> {
38  public:
39  MHZ19CalibrateZeroAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
40 
41  void play(Ts... x) override { this->mhz19_->calibrate_zero(); }
42 
43  protected:
45 };
46 
47 template<typename... Ts> class MHZ19ABCEnableAction : public Action<Ts...> {
48  public:
49  MHZ19ABCEnableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
50 
51  void play(Ts... x) override { this->mhz19_->abc_enable(); }
52 
53  protected:
55 };
56 
57 template<typename... Ts> class MHZ19ABCDisableAction : public Action<Ts...> {
58  public:
59  MHZ19ABCDisableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
60 
61  void play(Ts... x) override { this->mhz19_->abc_disable(); }
62 
63  protected:
65 };
66 
67 } // namespace mhz19
68 } // namespace esphome
void update() override
Definition: mhz19.cpp:31
uint16_t x
Definition: tt21100.cpp:17
void play(Ts... x) override
Definition: mhz19.h:61
sensor::Sensor * temperature_sensor_
Definition: mhz19.h:32
This class simplifies creating components that periodically check a state.
Definition: component.h:282
sensor::Sensor * co2_sensor_
Definition: mhz19.h:33
MHZ19ABCEnableAction(MHZ19Component *mhz19)
Definition: mhz19.h:49
void set_abc_enabled(bool abc_enabled)
Definition: mhz19.h:27
void dump_config() override
Definition: mhz19.cpp:93
MHZ19ABCDisableAction(MHZ19Component *mhz19)
Definition: mhz19.h:59
void play(Ts... x) override
Definition: mhz19.h:51
bool mhz19_write_command_(const uint8_t *command, uint8_t *response)
Definition: mhz19.cpp:79
void setup() override
Definition: mhz19.cpp:23
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_co2_sensor(sensor::Sensor *co2_sensor)
Definition: mhz19.h:26
MHZ19ABCLogic abc_boot_logic_
Definition: mhz19.h:34
void play(Ts... x) override
Definition: mhz19.h:41
Base-class for all sensors.
Definition: sensor.h:57
float get_setup_priority() const override
Definition: mhz19.cpp:92
MHZ19CalibrateZeroAction(MHZ19Component *mhz19)
Definition: mhz19.h:39
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition: mhz19.h:25