ESPHome  2024.11.0
zyaura.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
6 
7 namespace esphome {
8 namespace zyaura {
9 
10 static const uint8_t ZA_MAX_MS = 2;
11 static const uint8_t ZA_MSG_LEN = 5;
12 static const uint8_t ZA_FRAME_SIZE = 40;
13 static const uint8_t ZA_MSG_DELIMETER = 0x0D;
14 
15 static const uint8_t ZA_BYTE_TYPE = 0;
16 static const uint8_t ZA_BYTE_HIGH = 1;
17 static const uint8_t ZA_BYTE_LOW = 2;
18 static const uint8_t ZA_BYTE_SUM = 3;
19 static const uint8_t ZA_BYTE_END = 4;
20 
21 enum ZaDataType {
22  HUMIDITY = 0x41,
23  TEMPERATURE = 0x42,
24  CO2 = 0x50,
25 };
26 
27 struct ZaMessage {
29  uint16_t value;
30 };
31 
33  public:
34  bool decode(uint32_t ms, bool data);
35  ZaMessage *message = new ZaMessage;
36 
37  protected:
38  uint8_t buffer_[ZA_MSG_LEN];
39  int num_bits_ = 0;
40  uint32_t prev_ms_;
41 };
42 
44  public:
45  uint16_t co2 = -1;
46  uint16_t temperature = -1;
47  uint16_t humidity = -1;
48 
49  void setup(InternalGPIOPin *pin_clock, InternalGPIOPin *pin_data);
50  static void interrupt(ZaSensorStore *arg);
51 
52  protected:
56 
57  void set_data_(ZaMessage *message);
58 };
59 
62  public:
63  void set_pin_clock(InternalGPIOPin *pin) { pin_clock_ = pin; }
64  void set_pin_data(InternalGPIOPin *pin) { pin_data_ = pin; }
65  void set_co2_sensor(sensor::Sensor *co2_sensor) { co2_sensor_ = co2_sensor; }
66  void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
67  void set_humidity_sensor(sensor::Sensor *humidity_sensor) { humidity_sensor_ = humidity_sensor; }
68 
69  void setup() override { this->store_.setup(this->pin_clock_, this->pin_data_); }
70  void dump_config() override;
71  void update() override;
72  float get_setup_priority() const override { return setup_priority::DATA; }
73 
74  protected:
78  sensor::Sensor *co2_sensor_{nullptr};
79  sensor::Sensor *temperature_sensor_{nullptr};
80  sensor::Sensor *humidity_sensor_{nullptr};
81 
82  bool publish_state_(ZaDataType data_type, sensor::Sensor *sensor, uint16_t *data_value);
83 };
84 
85 } // namespace zyaura
86 } // namespace esphome
void setup()
Component for reading temperature/co2/humidity measurements from ZyAura sensors.
Definition: zyaura.h:61
InternalGPIOPin * pin_clock_
Definition: zyaura.h:76
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition: gpio.h:66
void set_co2_sensor(sensor::Sensor *co2_sensor)
Definition: zyaura.h:65
This class simplifies creating components that periodically check a state.
Definition: component.h:283
ZaSensorStore store_
Definition: zyaura.h:75
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition: zyaura.h:66
void setup() override
Definition: zyaura.h:69
InternalGPIOPin * pin_data_
Definition: zyaura.h:77
ISRInternalGPIOPin pin_data_
Definition: zyaura.h:54
uint16_t temperature
Definition: sun_gtil2.cpp:26
ZaDataProcessor processor_
Definition: zyaura.h:55
void set_humidity_sensor(sensor::Sensor *humidity_sensor)
Definition: zyaura.h:67
float get_setup_priority() const override
Definition: zyaura.h:72
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_pin_clock(InternalGPIOPin *pin)
Definition: zyaura.h:63
void set_pin_data(InternalGPIOPin *pin)
Definition: zyaura.h:64
ISRInternalGPIOPin pin_clock_
Definition: zyaura.h:53
Base-class for all sensors.
Definition: sensor.h:57
esphome::sensor::Sensor * sensor
Definition: statsd.h:38