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 Jesse Hills
parent 0d47d41c85
commit c41547fd4a
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A

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;