1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-15 15:18:16 +00:00

mhz19: flush TX queue before reading reply

otherwise there might not be reply to ready since
not all data might be sent over TX line

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
This commit is contained in:
Igor Mammedov 2019-05-23 19:09:18 +02:00 committed by nur
parent fd6e49f94d
commit 8d45dff31b

View File

@ -53,12 +53,12 @@ void MHZ19Component::update() {
bool MHZ19Component::mhz19_write_command_(const uint8_t *command, uint8_t *response) { bool MHZ19Component::mhz19_write_command_(const uint8_t *command, uint8_t *response) {
this->write_array(command, MHZ19_REQUEST_LENGTH); this->write_array(command, MHZ19_REQUEST_LENGTH);
this->write_byte(mhz19_checksum(command)); this->write_byte(mhz19_checksum(command));
this->flush();
if (response == nullptr) if (response == nullptr)
return true; return true;
bool ret = this->read_array(response, MHZ19_RESPONSE_LENGTH); bool ret = this->read_array(response, MHZ19_RESPONSE_LENGTH);
this->flush();
return ret; return ret;
} }
float MHZ19Component::get_setup_priority() const { return setup_priority::DATA; } float MHZ19Component::get_setup_priority() const { return setup_priority::DATA; }