mirror of
https://github.com/esphome/esphome.git
synced 2026-05-26 11:17:00 +08:00
[ltr390] Reduce data polling delay and timeout (#15507)
This commit is contained in:
@@ -45,6 +45,7 @@ optional<uint32_t> LTR390Component::read_sensor_data_(LTR390MODE mode) {
|
||||
uint8_t buffer[num_bytes];
|
||||
|
||||
// Wait until data available
|
||||
constexpr uint32_t max_wait_ms = 25;
|
||||
const uint32_t now = millis();
|
||||
while (true) {
|
||||
std::bitset<8> status = this->reg(LTR390_MAIN_STATUS).get();
|
||||
@@ -52,12 +53,12 @@ optional<uint32_t> LTR390Component::read_sensor_data_(LTR390MODE mode) {
|
||||
if (available)
|
||||
break;
|
||||
|
||||
if (millis() - now > 100) {
|
||||
if (millis() - now > max_wait_ms) {
|
||||
ESP_LOGW(TAG, "Sensor didn't return any data, aborting");
|
||||
return {};
|
||||
}
|
||||
ESP_LOGD(TAG, "Waiting for data");
|
||||
delay(2);
|
||||
ESP_LOGV(TAG, "Waiting for data");
|
||||
delay(1);
|
||||
}
|
||||
|
||||
if (!this->read_bytes(MODEADDRESSES[mode], buffer, num_bytes)) {
|
||||
|
||||
Reference in New Issue
Block a user