ESPHome  2024.10.2
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  void set_warmup_seconds(uint32_t seconds) { warmup_seconds_ = seconds; }
29 
30  protected:
31  bool mhz19_write_command_(const uint8_t *command, uint8_t *response);
32 
36  uint32_t warmup_seconds_;
37 };
38 
39 template<typename... Ts> class MHZ19CalibrateZeroAction : public Action<Ts...> {
40  public:
41  MHZ19CalibrateZeroAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
42 
43  void play(Ts... x) override { this->mhz19_->calibrate_zero(); }
44 
45  protected:
47 };
48 
49 template<typename... Ts> class MHZ19ABCEnableAction : public Action<Ts...> {
50  public:
51  MHZ19ABCEnableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
52 
53  void play(Ts... x) override { this->mhz19_->abc_enable(); }
54 
55  protected:
57 };
58 
59 template<typename... Ts> class MHZ19ABCDisableAction : public Action<Ts...> {
60  public:
61  MHZ19ABCDisableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
62 
63  void play(Ts... x) override { this->mhz19_->abc_disable(); }
64 
65  protected:
67 };
68 
69 } // namespace mhz19
70 } // namespace esphome
void update() override
Definition: mhz19.cpp:33
uint16_t x
Definition: tt21100.cpp:17
void play(Ts... x) override
Definition: mhz19.h:63
sensor::Sensor * temperature_sensor_
Definition: mhz19.h:33
void set_warmup_seconds(uint32_t seconds)
Definition: mhz19.h:28
This class simplifies creating components that periodically check a state.
Definition: component.h:283
sensor::Sensor * co2_sensor_
Definition: mhz19.h:34
MHZ19ABCEnableAction(MHZ19Component *mhz19)
Definition: mhz19.h:51
void set_abc_enabled(bool abc_enabled)
Definition: mhz19.h:27
void dump_config() override
Definition: mhz19.cpp:103
MHZ19ABCDisableAction(MHZ19Component *mhz19)
Definition: mhz19.h:61
void play(Ts... x) override
Definition: mhz19.h:53
bool mhz19_write_command_(const uint8_t *command, uint8_t *response)
Definition: mhz19.cpp:89
void setup() override
Definition: mhz19.cpp:25
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:35
void play(Ts... x) override
Definition: mhz19.h:43
Base-class for all sensors.
Definition: sensor.h:57
float get_setup_priority() const override
Definition: mhz19.cpp:102
MHZ19CalibrateZeroAction(MHZ19Component *mhz19)
Definition: mhz19.h:41
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition: mhz19.h:25