mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 08:55:22 +01:00
handling with the negative temperature in the sensor tmp102 (#6316)
This commit is contained in:
parent
a3fc1acdcb
commit
1aab87b41c
1 changed files with 4 additions and 2 deletions
|
@ -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;
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue