ESPHome  2023.5.5
hydreon_rgxx.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/defines.h"
6 #ifdef USE_BINARY_SENSOR
8 #endif
10 
11 namespace esphome {
12 namespace hydreon_rgxx {
13 
14 enum RGModel {
15  RG9 = 1,
16  RG15 = 2,
17 };
18 
19 #ifdef HYDREON_RGXX_NUM_SENSORS
20 static const uint8_t NUM_SENSORS = HYDREON_RGXX_NUM_SENSORS;
21 #else
22 static const uint8_t NUM_SENSORS = 1;
23 #endif
24 
25 #ifndef HYDREON_RGXX_PROTOCOL_LIST
26 #define HYDREON_RGXX_PROTOCOL_LIST(F, SEP) F("")
27 #endif
28 
29 #define HYDREON_RGXX_IGNORE_LIST(F, SEP) F("Emitters") SEP F("Event") SEP F("Reset")
30 
32  public:
33  void set_sensor(sensor::Sensor *sensor, int index) { this->sensors_[index] = sensor; }
34 #ifdef USE_BINARY_SENSOR
38 #endif
39  void set_model(RGModel model) { model_ = model; }
41 
43  void update() override;
45  void loop() override;
47  void setup() override;
48  void dump_config() override;
49 
50  float get_setup_priority() const override;
51 
52  protected:
53  void process_line_();
54  void schedule_reboot_();
55  bool buffer_starts_with_(const std::string &prefix);
56  bool buffer_starts_with_(const char *prefix);
58 
59  sensor::Sensor *sensors_[NUM_SENSORS] = {nullptr};
60 #ifdef USE_BINARY_SENSOR
64 #endif
65 
66  int16_t boot_count_ = 0;
67  int16_t no_response_count_ = 0;
68  std::string buffer_;
70  int sw_version_ = 0;
71  bool too_cold_ = false;
72  bool lens_bad_ = false;
73  bool em_sat_ = false;
74  bool request_temperature_ = false;
75 
76  // bit field showing which sensors we have received data for
78 };
79 
81  public:
83 };
84 
85 } // namespace hydreon_rgxx
86 } // namespace esphome
binary_sensor::BinarySensor * too_cold_sensor_
Definition: hydreon_rgxx.h:61
binary_sensor::BinarySensor * lens_bad_sensor_
Definition: hydreon_rgxx.h:62
HydreonRGxxBinaryComponent(HydreonRGxxComponent *parent)
Definition: hydreon_rgxx.h:82
void set_too_cold_sensor(binary_sensor::BinarySensor *sensor)
Definition: hydreon_rgxx.h:35
void setup() override
Setup the sensor and test for a connection.
This class simplifies creating components that periodically check a state.
Definition: component.h:282
void schedule_reboot_()
Communication with the sensor is asynchronous.
void set_lens_bad_sensor(binary_sensor::BinarySensor *sensor)
Definition: hydreon_rgxx.h:36
void set_sensor(sensor::Sensor *sensor, int index)
Definition: hydreon_rgxx.h:33
void set_em_sat_sensor(binary_sensor::BinarySensor *sensor)
Definition: hydreon_rgxx.h:37
sensor::Sensor * sensors_[NUM_SENSORS]
Definition: hydreon_rgxx.h:59
Definition: a4988.cpp:4
binary_sensor::BinarySensor * em_sat_sensor_
Definition: hydreon_rgxx.h:63
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:37
void loop() override
Read data once available.
bool buffer_starts_with_(const std::string &prefix)
Base-class for all sensors.
Definition: sensor.h:57
void update() override
Schedule data readings.