Skip to content

Commit

Permalink
handling with the negative temperature in the sensor tmp102 (esphome#…
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingFeng2021 authored Mar 4, 2024
1 parent 0298adb commit bc74dd4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions esphome/components/tmp102/tmp102.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void TMP102Component::dump_config() {
}

void TMP102Component::update() {
uint16_t raw_temperature;
int16_t raw_temperature;
if (this->write(&TMP102_REGISTER_TEMPERATURE, 1) != i2c::ERROR_OK) {
this->status_set_warning();
return;
Expand All @@ -39,7 +39,9 @@ void TMP102Component::update() {
return;
}
raw_temperature = i2c::i2ctohs(raw_temperature);

if (raw_temperature & 0x8000) {
raw_temperature |= 0xF000;
}
raw_temperature = raw_temperature >> 4;
float temperature = raw_temperature * TMP102_CONVERSION_FACTOR;
ESP_LOGD(TAG, "Got Temperature=%.1f°C", temperature);
Expand Down

0 comments on commit bc74dd4

Please sign in to comment.