Skip to content

Commit

Permalink
remove delay from tmp102 (#6577)
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Sieb <samuel@sieb.net>
  • Loading branch information
ssieb and Samuel Sieb committed Apr 18, 2024
1 parent 8c31aea commit 655dbc4
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions esphome/components/tmp102/tmp102.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,24 @@ void TMP102Component::dump_config() {
}

void TMP102Component::update() {
int16_t raw_temperature;
if (this->write(&TMP102_REGISTER_TEMPERATURE, 1) != i2c::ERROR_OK) {
this->status_set_warning();
return;
}
delay(50); // NOLINT
if (this->read(reinterpret_cast<uint8_t *>(&raw_temperature), 2) != i2c::ERROR_OK) {
this->status_set_warning();
return;
}
raw_temperature = i2c::i2ctohs(raw_temperature);
raw_temperature = raw_temperature >> 4;
float temperature = raw_temperature * TMP102_CONVERSION_FACTOR;
ESP_LOGD(TAG, "Got Temperature=%.1f°C", temperature);

this->publish_state(temperature);
this->status_clear_warning();
this->set_timeout("read_temp", 50, [this]() {
int16_t raw_temperature;
if (this->read(reinterpret_cast<uint8_t *>(&raw_temperature), 2) != i2c::ERROR_OK) {
this->status_set_warning();
return;
}
raw_temperature = i2c::i2ctohs(raw_temperature);
raw_temperature = raw_temperature >> 4;
float temperature = raw_temperature * TMP102_CONVERSION_FACTOR;
ESP_LOGD(TAG, "Got Temperature=%.1f°C", temperature);

this->publish_state(temperature);
this->status_clear_warning();
});
}

float TMP102Component::get_setup_priority() const { return setup_priority::DATA; }
Expand Down

0 comments on commit 655dbc4

Please sign in to comment.