ESPHome  2024.10.2
ccs811.h
Go to the documentation of this file.
1 #pragma once
2 
8 
9 namespace esphome {
10 namespace ccs811 {
11 
13  public:
14  void set_co2(sensor::Sensor *co2) { co2_ = co2; }
15  void set_tvoc(sensor::Sensor *tvoc) { tvoc_ = tvoc; }
17  void set_baseline(uint16_t baseline) { baseline_ = baseline; }
18  void set_humidity(sensor::Sensor *humidity) { humidity_ = humidity; }
20 
22  void setup() override;
24  void update() override;
25 
26  void dump_config() override;
27 
28  float get_setup_priority() const override { return setup_priority::DATA; }
29 
30  protected:
31  optional<uint8_t> read_status_() { return this->read_byte(0x00); }
32  bool status_has_error_() { return this->read_status_().value_or(1) & 1; }
33  bool status_app_is_valid_() { return this->read_status_().value_or(0) & (1 << 4); }
34  bool status_has_data_() { return this->read_status_().value_or(0) & (1 << 3); }
35  void send_env_data_();
36 
37  enum ErrorCode {
44  } error_code_{UNKNOWN};
45 
46  sensor::Sensor *co2_{nullptr};
47  sensor::Sensor *tvoc_{nullptr};
54 };
55 
56 } // namespace ccs811
57 } // namespace esphome
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
Definition: i2c.h:235
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
sensor::Sensor * humidity_
Input sensor for humidity reading.
Definition: ccs811.h:51
void set_tvoc(sensor::Sensor *tvoc)
Definition: ccs811.h:15
void set_humidity(sensor::Sensor *humidity)
Definition: ccs811.h:18
This class simplifies creating components that periodically check a state.
Definition: component.h:283
float get_setup_priority() const override
Definition: ccs811.h:28
sensor::Sensor * temperature_
Input sensor for temperature reading.
Definition: ccs811.h:53
text_sensor::TextSensor * version_
Definition: ccs811.h:48
void update() override
Schedule temperature+pressure readings.
Definition: ccs811.cpp:89
enum esphome::ccs811::CCS811Component::ErrorCode UNKNOWN
void setup() override
Setup the sensor and test for a connection.
Definition: ccs811.cpp:22
optional< uint8_t > read_status_()
Definition: ccs811.h:31
void set_temperature(sensor::Sensor *temperature)
Definition: ccs811.h:19
uint16_t temperature
Definition: sun_gtil2.cpp:26
optional< uint16_t > baseline_
Definition: ccs811.h:49
void set_baseline(uint16_t baseline)
Definition: ccs811.h:17
void set_version(text_sensor::TextSensor *version)
Definition: ccs811.h:16
sensor::Sensor * tvoc_
Definition: ccs811.h:47
void set_co2(sensor::Sensor *co2)
Definition: ccs811.h:14
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57
sensor::Sensor * co2_
Definition: ccs811.h:46
value_type value_or(U const &v) const
Definition: optional.h:93
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133