mirror of
https://github.com/esphome/esphome.git
synced 2026-06-01 17:57:37 +08:00
[pmsx003] Keep active-mode reads aligned (#14832)
This commit is contained in:
@@ -95,10 +95,6 @@ void PMSX003Component::loop() {
|
|||||||
// Just go ahead and read stuff
|
// Just go ahead and read stuff
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (now - this->last_update_ < this->update_interval_) {
|
|
||||||
// Otherwise just leave the sensor powered up and come back when we hit the update
|
|
||||||
// time
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (now - this->last_transmission_ >= 500) {
|
if (now - this->last_transmission_ >= 500) {
|
||||||
@@ -114,10 +110,11 @@ void PMSX003Component::loop() {
|
|||||||
this->read_byte(&this->data_[this->data_index_]);
|
this->read_byte(&this->data_[this->data_index_]);
|
||||||
auto check = this->check_byte_();
|
auto check = this->check_byte_();
|
||||||
if (!check.has_value()) {
|
if (!check.has_value()) {
|
||||||
// finished
|
if (this->update_interval_ > STABILISING_MS || now - this->last_update_ >= this->update_interval_) {
|
||||||
this->parse_data_();
|
this->parse_data_();
|
||||||
this->data_index_ = 0;
|
|
||||||
this->last_update_ = now;
|
this->last_update_ = now;
|
||||||
|
}
|
||||||
|
this->data_index_ = 0;
|
||||||
} else if (!*check) {
|
} else if (!*check) {
|
||||||
// wrong data
|
// wrong data
|
||||||
this->data_index_ = 0;
|
this->data_index_ = 0;
|
||||||
@@ -138,7 +135,7 @@ optional<bool> PMSX003Component::check_byte_() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGW(TAG, "Start character %u mismatch: 0x%02X != 0x%02X", index + 1, byte, START_CHARACTER_1);
|
ESP_LOGW(TAG, "Start character %u mismatch: 0x%02X != 0x%02X", index + 1, byte, start_char);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user