ESPHome  2024.12.2
sds011.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace sds011 {
9 
10 class SDS011Component : public Component, public uart::UARTDevice {
11  public:
12  SDS011Component() = default;
13 
15  void set_rx_mode_only(bool rx_mode_only);
16 
17  void set_pm_2_5_sensor(sensor::Sensor *pm_2_5_sensor) { pm_2_5_sensor_ = pm_2_5_sensor; }
18  void set_pm_10_0_sensor(sensor::Sensor *pm_10_0_sensor) { pm_10_0_sensor_ = pm_10_0_sensor; }
19  void setup() override;
20  void dump_config() override;
21  void loop() override;
22 
23  float get_setup_priority() const override;
24 
25  void set_update_interval(uint32_t val) { /* ignore */
26  }
27  void set_update_interval_min(uint8_t update_interval_min);
28  void set_working_state(bool working_state);
29 
30  protected:
31  void sds011_write_command_(const uint8_t *command);
32  uint8_t sds011_checksum_(const uint8_t *command_data, uint8_t length) const;
34  void parse_data_();
35  uint16_t get_16_bit_uint_(uint8_t start_index) const;
36 
39 
40  uint8_t data_[10];
41  uint8_t data_index_{0};
42  uint32_t last_transmission_{0};
44 
46 };
47 
48 } // namespace sds011
49 } // namespace esphome
uint8_t sds011_checksum_(const uint8_t *command_data, uint8_t length) const
Definition: sds011.cpp:120
void set_working_state(bool working_state)
Definition: sds011.cpp:53
sensor::Sensor * pm_10_0_sensor_
Definition: sds011.h:38
void set_pm_10_0_sensor(sensor::Sensor *pm_10_0_sensor)
Definition: sds011.h:18
mopeka_std_values val[4]
float get_setup_priority() const override
Definition: sds011.cpp:108
sensor::Sensor * pm_2_5_sensor_
Definition: sds011.h:37
void set_update_interval_min(uint8_t update_interval_min)
Definition: sds011.cpp:185
uint16_t get_16_bit_uint_(uint8_t start_index) const
Definition: sds011.cpp:182
void dump_config() override
Definition: sds011.cpp:68
uint16_t length
Definition: tt21100.cpp:12
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57
optional< bool > check_byte_() const
Definition: sds011.cpp:128
void set_rx_mode_only(bool rx_mode_only)
Manually set the rx-only mode. Defaults to false.
Definition: sds011.cpp:110
void sds011_write_command_(const uint8_t *command)
Definition: sds011.cpp:112
void set_pm_2_5_sensor(sensor::Sensor *pm_2_5_sensor)
Definition: sds011.h:17
void set_update_interval(uint32_t val)
Definition: sds011.h:25