ESPHome  2024.11.1
ens160_base.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace esphome {
7 namespace ens160_base {
8 
10  public:
11  void set_co2(sensor::Sensor *co2) { co2_ = co2; }
12  void set_tvoc(sensor::Sensor *tvoc) { tvoc_ = tvoc; }
13  void set_aqi(sensor::Sensor *aqi) { aqi_ = aqi; }
14 
15  void set_humidity(sensor::Sensor *humidity) { humidity_ = humidity; }
17 
18  void setup() override;
19  void update() override;
20  void dump_config() override;
21  float get_setup_priority() const override { return setup_priority::DATA; }
22 
23  protected:
24  void send_env_data_();
25 
26  enum ErrorCode {
27  NONE = 0,
34  } error_code_{NONE};
35 
36  enum ValidityFlag {
42 
43  bool warming_up_{false};
44  bool initial_startup_{false};
45 
46  virtual bool read_byte(uint8_t a_register, uint8_t *data) = 0;
47  virtual bool write_byte(uint8_t a_register, uint8_t data) = 0;
48  virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
49  virtual bool write_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
50 
51  uint8_t firmware_ver_major_{0};
52  uint8_t firmware_ver_minor_{0};
53  uint8_t firmware_ver_build_{0};
54 
55  sensor::Sensor *co2_{nullptr};
56  sensor::Sensor *tvoc_{nullptr};
57  sensor::Sensor *aqi_{nullptr};
58 
61 };
62 
63 } // namespace ens160_base
64 } // namespace esphome
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
void set_tvoc(sensor::Sensor *tvoc)
Definition: ens160_base.h:12
enum esphome::ens160_base::ENS160Component::ValidityFlag validity_flag_
virtual bool write_bytes(uint8_t a_register, uint8_t *data, size_t len)=0
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_humidity(sensor::Sensor *humidity)
Definition: ens160_base.h:15
void set_temperature(sensor::Sensor *temperature)
Definition: ens160_base.h:16
uint16_t temperature
Definition: sun_gtil2.cpp:26
virtual bool read_byte(uint8_t a_register, uint8_t *data)=0
virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len)=0
std::string size_t len
Definition: helpers.h:293
void set_aqi(sensor::Sensor *aqi)
Definition: ens160_base.h:13
float get_setup_priority() const override
Definition: ens160_base.h:21
void set_co2(sensor::Sensor *co2)
Definition: ens160_base.h:11
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
virtual bool write_byte(uint8_t a_register, uint8_t data)=0
enum esphome::ens160_base::ENS160Component::ErrorCode NONE
Base-class for all sensors.
Definition: sensor.h:57