ESPHome  2022.8.0
pmsx003.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace pmsx003 {
9 
10 // known command bytes
11 #define PMS_CMD_AUTO_MANUAL 0xE1 // data=0: perform measurement manually, data=1: perform measurement automatically
12 #define PMS_CMD_TRIG_MANUAL 0xE2 // trigger a manual measurement
13 #define PMS_CMD_ON_STANDBY 0xE4 // data=0: go to standby mode, data=1: go to normal mode
14 
15 static const uint16_t PMS_STABILISING_MS = 30000; // time taken for the sensor to become stable after power on
16 
22 };
23 
28 };
29 
31  public:
32  PMSX003Component() = default;
33  void loop() override;
34  float get_setup_priority() const override;
35  void dump_config() override;
36 
38 
40 
41  void set_pm_1_0_std_sensor(sensor::Sensor *pm_1_0_std_sensor);
42  void set_pm_2_5_std_sensor(sensor::Sensor *pm_2_5_std_sensor);
43  void set_pm_10_0_std_sensor(sensor::Sensor *pm_10_0_std_sensor);
44 
45  void set_pm_1_0_sensor(sensor::Sensor *pm_1_0_sensor);
46  void set_pm_2_5_sensor(sensor::Sensor *pm_2_5_sensor);
47  void set_pm_10_0_sensor(sensor::Sensor *pm_10_0_sensor);
48 
49  void set_pm_particles_03um_sensor(sensor::Sensor *pm_particles_03um_sensor);
50  void set_pm_particles_05um_sensor(sensor::Sensor *pm_particles_05um_sensor);
51  void set_pm_particles_10um_sensor(sensor::Sensor *pm_particles_10um_sensor);
52  void set_pm_particles_25um_sensor(sensor::Sensor *pm_particles_25um_sensor);
53  void set_pm_particles_50um_sensor(sensor::Sensor *pm_particles_50um_sensor);
54  void set_pm_particles_100um_sensor(sensor::Sensor *pm_particles_100um_sensor);
55 
56  void set_temperature_sensor(sensor::Sensor *temperature_sensor);
57  void set_humidity_sensor(sensor::Sensor *humidity_sensor);
58  void set_formaldehyde_sensor(sensor::Sensor *formaldehyde_sensor);
59 
60  protected:
62  void parse_data_();
63  void send_command_(uint8_t cmd, uint16_t data);
64  uint16_t get_16_bit_uint_(uint8_t start_index);
65 
66  uint8_t data_[64];
67  uint8_t data_index_{0};
68  uint8_t initialised_{0};
69  uint32_t fan_on_time_{0};
70  uint32_t last_update_{0};
71  uint32_t last_transmission_{0};
72  uint32_t update_interval_{0};
75 
76  // "Standard Particle"
80 
81  // "Under Atmospheric Pressure"
85 
86  // Particle counts by size
93 
97 };
98 
99 } // namespace pmsx003
100 } // namespace esphome
sensor::Sensor * pm_10_0_sensor_
Definition: pmsx003.h:84
sensor::Sensor * pm_particles_50um_sensor_
Definition: pmsx003.h:91
void set_update_interval(uint32_t val)
Definition: pmsx003.h:39
sensor::Sensor * pm_1_0_std_sensor_
Definition: pmsx003.h:77
sensor::Sensor * pm_10_0_std_sensor_
Definition: pmsx003.h:79
sensor::Sensor * pm_2_5_std_sensor_
Definition: pmsx003.h:78
void set_pm_2_5_std_sensor(sensor::Sensor *pm_2_5_std_sensor)
Definition: pmsx003.cpp:12
void set_pm_particles_10um_sensor(sensor::Sensor *pm_particles_10um_sensor)
Definition: pmsx003.cpp:29
void set_pm_2_5_sensor(sensor::Sensor *pm_2_5_sensor)
Definition: pmsx003.cpp:20
sensor::Sensor * pm_particles_10um_sensor_
Definition: pmsx003.h:89
void set_pm_particles_100um_sensor(sensor::Sensor *pm_particles_100um_sensor)
Definition: pmsx003.cpp:38
sensor::Sensor * pm_particles_25um_sensor_
Definition: pmsx003.h:90
void set_humidity_sensor(sensor::Sensor *humidity_sensor)
Definition: pmsx003.cpp:45
sensor::Sensor * formaldehyde_sensor_
Definition: pmsx003.h:96
void set_type(PMSX003Type type)
Definition: pmsx003.h:37
sensor::Sensor * pm_2_5_sensor_
Definition: pmsx003.h:83
sensor::Sensor * pm_particles_03um_sensor_
Definition: pmsx003.h:87
void set_pm_10_0_std_sensor(sensor::Sensor *pm_10_0_std_sensor)
Definition: pmsx003.cpp:15
sensor::Sensor * pm_1_0_sensor_
Definition: pmsx003.h:82
float get_setup_priority() const override
Definition: pmsx003.cpp:119
sensor::Sensor * temperature_sensor_
Definition: pmsx003.h:94
uint8_t type
uint16_t get_16_bit_uint_(uint8_t start_index)
Definition: pmsx003.cpp:291
void set_pm_particles_50um_sensor(sensor::Sensor *pm_particles_50um_sensor)
Definition: pmsx003.cpp:35
optional< bool > check_byte_()
Definition: pmsx003.cpp:120
sensor::Sensor * pm_particles_05um_sensor_
Definition: pmsx003.h:88
void set_pm_1_0_sensor(sensor::Sensor *pm_1_0_sensor)
Definition: pmsx003.cpp:19
sensor::Sensor * pm_particles_100um_sensor_
Definition: pmsx003.h:92
sensor::Sensor * humidity_sensor_
Definition: pmsx003.h:95
void set_pm_particles_25um_sensor(sensor::Sensor *pm_particles_25um_sensor)
Definition: pmsx003.cpp:32
void send_command_(uint8_t cmd, uint16_t data)
Definition: pmsx003.cpp:176
Definition: a4988.cpp:4
uint32_t val
Definition: datatypes.h:85
Base-class for all sensors.
Definition: sensor.h:48
void set_pm_particles_03um_sensor(sensor::Sensor *pm_particles_03um_sensor)
Definition: pmsx003.cpp:23
void set_formaldehyde_sensor(sensor::Sensor *formaldehyde_sensor)
Definition: pmsx003.cpp:46
void set_pm_10_0_sensor(sensor::Sensor *pm_10_0_sensor)
Definition: pmsx003.cpp:21
stm32_cmd_t * cmd
Definition: stm32flash.h:96
void set_pm_1_0_std_sensor(sensor::Sensor *pm_1_0_std_sensor)
Definition: pmsx003.cpp:9
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition: pmsx003.cpp:42
void set_pm_particles_05um_sensor(sensor::Sensor *pm_particles_05um_sensor)
Definition: pmsx003.cpp:26