7static const char *
const TAG =
"pm2005";
10static const LogString *pm2005_get_situation_string(
int status) {
13 return LOG_STR(
"Close");
15 return LOG_STR(
"Malfunction");
17 return LOG_STR(
"Under detecting");
19 return LOG_STR(
"Detecting completed");
21 return LOG_STR(
"Invalid");
26static const LogString *pm2005_get_measuring_mode_string(
int status) {
29 return LOG_STR(
"Single");
31 return LOG_STR(
"Continuous");
33 return LOG_STR(
"Dynamic");
35 return LOG_STR(
"Timing");
39static inline uint16_t get_sensor_value(
const uint8_t *data, uint8_t i) {
return data[i] * 0x100 + data[i + 1]; }
43 ESP_LOGCONFIG(TAG,
"Setting up PM2005...");
51 ESP_LOGCONFIG(TAG,
"Setting up PM2105...");
61 ESP_LOGE(TAG,
"Communication failed!");
69 ESP_LOGW(TAG,
"Read result failed.");
79 ESP_LOGD(TAG,
"Sensor situation: %s.", LOG_STR_ARG(pm2005_get_situation_string(this->
sensor_situation_)));
92 ESP_LOGD(TAG,
"PM1.0: %d, PM2.5: %d, PM10: %d, Measuring mode: %s.", pm1, pm25, pm10,
93 LOG_STR_ARG(pm2005_get_measuring_mode_string(sensor_measuring_mode)));
109 ESP_LOGCONFIG(TAG,
"PM2005:");
112 LOG_I2C_DEVICE(
this);
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message="unspecified")
void status_clear_warning()
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
uint8_t pm_10_0_value_index_
uint8_t situation_value_index_
uint8_t pm_1_0_value_index_
sensor::Sensor * pm_10_0_sensor_
uint8_t pm_2_5_value_index_
void dump_config() override
uint8_t sensor_situation_
sensor::Sensor * pm_1_0_sensor_
sensor::Sensor * pm_2_5_sensor_
uint8_t measuring_value_index_
void publish_state(float state)
Publish a new state to the front-end.
@ ERROR_OK
No error found during execution of method.
Providing packet encoding functions for exchanging data with a remote host.