mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
parent
72cce391ab
commit
6f83a49c63
1 changed files with 17 additions and 2 deletions
|
@ -134,7 +134,6 @@ void DallasComponent::update() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!sensor->check_scratch_pad()) {
|
if (!sensor->check_scratch_pad()) {
|
||||||
ESP_LOGW(TAG, "'%s' - Scratch pad checksum invalid!", sensor->get_name().c_str());
|
|
||||||
sensor->publish_state(NAN);
|
sensor->publish_state(NAN);
|
||||||
this->status_set_warning();
|
this->status_set_warning();
|
||||||
return;
|
return;
|
||||||
|
@ -241,13 +240,29 @@ bool DallasTemperatureSensor::setup_sensor() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool DallasTemperatureSensor::check_scratch_pad() {
|
bool DallasTemperatureSensor::check_scratch_pad() {
|
||||||
|
bool chksum_validity = (crc8(this->scratch_pad_, 8) == this->scratch_pad_[8]);
|
||||||
|
bool config_validity = false;
|
||||||
|
|
||||||
|
switch (this->get_address8()[0]) {
|
||||||
|
case DALLAS_MODEL_DS18B20:
|
||||||
|
config_validity = ((this->scratch_pad_[4] & 0x9F) == 0x1F);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
config_validity = ((this->scratch_pad_[4] & 0x10) == 0x10);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ESPHOME_LOG_LEVEL_VERY_VERBOSE
|
#ifdef ESPHOME_LOG_LEVEL_VERY_VERBOSE
|
||||||
ESP_LOGVV(TAG, "Scratch pad: %02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X (%02X)", this->scratch_pad_[0],
|
ESP_LOGVV(TAG, "Scratch pad: %02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X (%02X)", this->scratch_pad_[0],
|
||||||
this->scratch_pad_[1], this->scratch_pad_[2], this->scratch_pad_[3], this->scratch_pad_[4],
|
this->scratch_pad_[1], this->scratch_pad_[2], this->scratch_pad_[3], this->scratch_pad_[4],
|
||||||
this->scratch_pad_[5], this->scratch_pad_[6], this->scratch_pad_[7], this->scratch_pad_[8],
|
this->scratch_pad_[5], this->scratch_pad_[6], this->scratch_pad_[7], this->scratch_pad_[8],
|
||||||
crc8(this->scratch_pad_, 8));
|
crc8(this->scratch_pad_, 8));
|
||||||
#endif
|
#endif
|
||||||
return crc8(this->scratch_pad_, 8) == this->scratch_pad_[8];
|
if (!chksum_validity) {
|
||||||
|
ESP_LOGW(TAG, "'%s' - Scratch pad checksum invalid!", this->get_name().c_str());
|
||||||
|
} else if (!config_validity) {
|
||||||
|
ESP_LOGW(TAG, "'%s' - Scratch pad config register invalid!", this->get_name().c_str());
|
||||||
|
}
|
||||||
|
return chksum_validity && config_validity;
|
||||||
}
|
}
|
||||||
float DallasTemperatureSensor::get_temp_c() {
|
float DallasTemperatureSensor::get_temp_c() {
|
||||||
int16_t temp = (int16_t(this->scratch_pad_[1]) << 11) | (int16_t(this->scratch_pad_[0]) << 3);
|
int16_t temp = (int16_t(this->scratch_pad_[1]) << 11) | (int16_t(this->scratch_pad_[0]) << 3);
|
||||||
|
|
Loading…
Reference in a new issue