mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 00:18:11 +01:00
Add delay after sending REG_READ_START (#7130)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
038f24fcea
commit
dfacf1bbfe
1 changed files with 31 additions and 30 deletions
|
@ -72,18 +72,18 @@ void PMWCS3Component::dump_config() {
|
|||
LOG_SENSOR(" ", "vwc", this->vwc_sensor_);
|
||||
}
|
||||
void PMWCS3Component::read_data_() {
|
||||
uint8_t data[8];
|
||||
float e25, ec, temperature, vwc;
|
||||
|
||||
/////// Super important !!!! first activate reading PMWCS3_REG_READ_START (if not, return always the same values) ////
|
||||
|
||||
if (!this->write_bytes(PMWCS3_REG_READ_START, nullptr, 0)) {
|
||||
this->status_set_warning();
|
||||
ESP_LOGVV(TAG, "Failed to write into REG_READ_START register !!!");
|
||||
return;
|
||||
}
|
||||
// NOLINT delay(100);
|
||||
|
||||
// Wait for the sensor to be ready.
|
||||
// 80ms empirically determined (conservative).
|
||||
this->set_timeout(80, [this] {
|
||||
uint8_t data[8];
|
||||
float e25, ec, temperature, vwc;
|
||||
if (!this->read_bytes(PMWCS3_REG_GET_DATA, (uint8_t *) &data, 8)) {
|
||||
ESP_LOGVV(TAG, "Error reading PMWCS3_REG_GET_DATA registers");
|
||||
this->mark_failed();
|
||||
|
@ -109,6 +109,7 @@ void PMWCS3Component::read_data_() {
|
|||
this->vwc_sensor_->publish_state(vwc);
|
||||
ESP_LOGVV(TAG, "vwc: data[6]=%d, data[7]=%d, result=%f", data[6], data[7], vwc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace pmwcs3
|
||||
|
|
Loading…
Reference in a new issue