mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
[dallas_temp] fix ds18s20 temp calc (#6988)
This commit is contained in:
parent
cc4f1c667e
commit
91766afb64
1 changed files with 15 additions and 18 deletions
|
@ -145,24 +145,21 @@ bool DallasTemperatureSensor::check_scratch_pad_() {
|
||||||
float DallasTemperatureSensor::get_temp_c_() {
|
float DallasTemperatureSensor::get_temp_c_() {
|
||||||
int16_t temp = (this->scratch_pad_[1] << 8) | this->scratch_pad_[0];
|
int16_t temp = (this->scratch_pad_[1] << 8) | this->scratch_pad_[0];
|
||||||
if ((this->address_ & 0xff) == DALLAS_MODEL_DS18S20) {
|
if ((this->address_ & 0xff) == DALLAS_MODEL_DS18S20) {
|
||||||
if (this->scratch_pad_[7] != 0x10)
|
return (temp >> 1) + (this->scratch_pad_[7] - this->scratch_pad_[6]) / float(this->scratch_pad_[7]) - 0.25;
|
||||||
ESP_LOGE(TAG, "unexpected COUNT_PER_C value: %u", this->scratch_pad_[7]);
|
}
|
||||||
temp = ((temp & 0xfff7) << 3) + (0x10 - this->scratch_pad_[6]) - 4;
|
switch (this->resolution_) {
|
||||||
} else {
|
case 9:
|
||||||
switch (this->resolution_) {
|
temp &= 0xfff8;
|
||||||
case 9:
|
break;
|
||||||
temp &= 0xfff8;
|
case 10:
|
||||||
break;
|
temp &= 0xfffc;
|
||||||
case 10:
|
break;
|
||||||
temp &= 0xfffc;
|
case 11:
|
||||||
break;
|
temp &= 0xfffe;
|
||||||
case 11:
|
break;
|
||||||
temp &= 0xfffe;
|
case 12:
|
||||||
break;
|
default:
|
||||||
case 12:
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return temp / 16.0f;
|
return temp / 16.0f;
|
||||||
|
|
Loading…
Reference in a new issue