ESPHome  2024.12.2
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 static const uint8_t PMS_CMD_AUTO_MANUAL =
12  0xE1; // data=0: perform measurement manually, data=1: perform measurement automatically
13 static const uint8_t PMS_CMD_TRIG_MANUAL = 0xE2; // trigger a manual measurement
14 static const uint8_t PMS_CMD_ON_STANDBY = 0xE4; // data=0: go to standby mode, data=1: go to normal mode
15 
16 static const uint16_t PMS_STABILISING_MS = 30000; // time taken for the sensor to become stable after power on
17 
23 };
24 
29 };
30 
32  public:
33  PMSX003Component() = default;
34  void loop() override;
35  float get_setup_priority() const override;
36  void dump_config() override;
37 
39 
41 
42  void set_pm_1_0_std_sensor(sensor::Sensor *pm_1_0_std_sensor);
43  void set_pm_2_5_std_sensor(sensor::Sensor *pm_2_5_std_sensor);
44  void set_pm_10_0_std_sensor(sensor::Sensor *pm_10_0_std_sensor);
45 
46  void set_pm_1_0_sensor(sensor::Sensor *pm_1_0_sensor);
47  void set_pm_2_5_sensor(sensor::Sensor *pm_2_5_sensor);
48  void set_pm_10_0_sensor(sensor::Sensor *pm_10_0_sensor);
49 
50  void set_pm_particles_03um_sensor(sensor::Sensor *pm_particles_03um_sensor);
51  void set_pm_particles_05um_sensor(sensor::Sensor *pm_particles_05um_sensor);
52  void set_pm_particles_10um_sensor(sensor::Sensor *pm_particles_10um_sensor);
53  void set_pm_particles_25um_sensor(sensor::Sensor *pm_particles_25um_sensor);
54  void set_pm_particles_50um_sensor(sensor::Sensor *pm_particles_50um_sensor);
55  void set_pm_particles_100um_sensor(sensor::Sensor *pm_particles_100um_sensor);
56 
57  void set_temperature_sensor(sensor::Sensor *temperature_sensor);
58  void set_humidity_sensor(sensor::Sensor *humidity_sensor);
59  void set_formaldehyde_sensor(sensor::Sensor *formaldehyde_sensor);
60 
61  protected:
63  void parse_data_();
64  void send_command_(uint8_t cmd, uint16_t data);
65  uint16_t get_16_bit_uint_(uint8_t start_index);
66 
67  uint8_t data_[64];
68  uint8_t data_index_{0};
69  uint8_t initialised_{0};
70  uint32_t fan_on_time_{0};
71  uint32_t last_update_{0};
72  uint32_t last_transmission_{0};
73  uint32_t update_interval_{0};
76 
77  // "Standard Particle"
81 
82  // "Under Atmospheric Pressure"
86 
87  // Particle counts by size
94 
98 };
99 
100 } // namespace pmsx003
101 } // namespace esphome
sensor::Sensor * pm_10_0_sensor_
Definition: pmsx003.h:85
sensor::Sensor * pm_particles_50um_sensor_
Definition: pmsx003.h:92
void set_update_interval(uint32_t val)
Definition: pmsx003.h:40
sensor::Sensor * pm_1_0_std_sensor_
Definition: pmsx003.h:78
sensor::Sensor * pm_10_0_std_sensor_
Definition: pmsx003.h:80
sensor::Sensor * pm_2_5_std_sensor_
Definition: pmsx003.h:79
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
mopeka_std_values val[4]
sensor::Sensor * pm_particles_10um_sensor_
Definition: pmsx003.h:90
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:91
void set_humidity_sensor(sensor::Sensor *humidity_sensor)
Definition: pmsx003.cpp:45
sensor::Sensor * formaldehyde_sensor_
Definition: pmsx003.h:97
void set_type(PMSX003Type type)
Definition: pmsx003.h:38
sensor::Sensor * pm_2_5_sensor_
Definition: pmsx003.h:84
sensor::Sensor * pm_particles_03um_sensor_
Definition: pmsx003.h:88
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:83
float get_setup_priority() const override
Definition: pmsx003.cpp:119
sensor::Sensor * temperature_sensor_
Definition: pmsx003.h:95
uint8_t type
uint16_t get_16_bit_uint_(uint8_t start_index)
Definition: pmsx003.cpp:330
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:89
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:93
sensor::Sensor * humidity_sensor_
Definition: pmsx003.h:96
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
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57
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