mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 23:18:10 +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() {
|
void TMP102Component::update() {
|
||||||
uint16_t raw_temperature;
|
int16_t raw_temperature;
|
||||||
if (this->write(&TMP102_REGISTER_TEMPERATURE, 1) != i2c::ERROR_OK) {
|
if (this->write(&TMP102_REGISTER_TEMPERATURE, 1) != i2c::ERROR_OK) {
|
||||||
this->status_set_warning();
|
this->status_set_warning();
|
||||||
return;
|
return;
|
||||||
|
@ -39,7 +39,9 @@ void TMP102Component::update() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
raw_temperature = i2c::i2ctohs(raw_temperature);
|
raw_temperature = i2c::i2ctohs(raw_temperature);
|
||||||
|
if (raw_temperature & 0x8000) {
|
||||||
|
raw_temperature |= 0xF000;
|
||||||
|
}
|
||||||
raw_temperature = raw_temperature >> 4;
|
raw_temperature = raw_temperature >> 4;
|
||||||
float temperature = raw_temperature * TMP102_CONVERSION_FACTOR;
|
float temperature = raw_temperature * TMP102_CONVERSION_FACTOR;
|
||||||
ESP_LOGD(TAG, "Got Temperature=%.1f°C", temperature);
|
ESP_LOGD(TAG, "Got Temperature=%.1f°C", temperature);
|
||||||
|
|
Loading…
Reference in a new issue