Fix senseair component uart read timeout (#2658)

Co-authored-by: DAVe3283 <DAVe3283+GitHub@gmail.com>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: Chua Jun Chieh <junchieh.chua@softspace.com.my>
This commit is contained in:
rotarykite 2021-11-17 02:57:03 +08:00 committed by GitHub
parent 57bdc2b885
commit df68403b6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -141,12 +141,16 @@ void SenseAirComponent::abc_get_period() {
}
bool SenseAirComponent::senseair_write_command_(const uint8_t *command, uint8_t *response, uint8_t response_length) {
// Verify we have somewhere to store the response
if (response == nullptr) {
return false;
}
// Write wake up byte required by some S8 sensor models
this->write_byte(0);
this->flush();
delay(5);
this->write_array(command, SENSEAIR_REQUEST_LENGTH);
if (response == nullptr)
return true;
bool ret = this->read_array(response, response_length);
this->flush();
return ret;