dallas: bus not idle error handling

This commit is contained in:
MichaelDvP
2021-01-29 11:27:56 +01:00
parent ddfb7b76bb
commit 61c67be510
2 changed files with 20 additions and 6 deletions

View File

@@ -69,10 +69,20 @@ void DallasSensor::loop() {
YIELD;
bus_.skip();
bus_.write(CMD_CONVERT_TEMP, parasite_ ? 1 : 0);
state_ = State::READING;
state_ = State::READING;
scanretry_ = 0;
} else {
// no sensors found
// LOG_ERROR(F("Bus reset failed")); // uncomment for debug
if (sensors_.size()) {
sensorfails_++;
if (++scanretry_ > SCAN_MAX) { // every 30 sec
scanretry_ = 0;
LOG_ERROR(F("Bus reset failed"));
for (auto & sensor : sensors_) {
sensor.temperature_c = EMS_VALUE_SHORT_NOTSET;
}
}
}
}
last_activity_ = time_now;
}
@@ -142,7 +152,7 @@ void DallasSensor::loop() {
bus_.depower();
}
// check for missing sensors after some samples
if (++scancnt_ > 5) {
if (++scancnt_ > SCAN_MAX) {
for (auto & sensor : sensors_) {
if (!sensor.read) {
sensor.temperature_c = EMS_VALUE_SHORT_NOTSET;
@@ -151,11 +161,11 @@ void DallasSensor::loop() {
sensor.read = false;
}
scancnt_ = 0;
} else if (scancnt_ == -2) { // startup
} else if (scancnt_ == SCAN_START + 1) { // startup
firstscan_ = sensors_.size();
LOG_DEBUG(F("Adding %d dallassensor(s) from first scan"), firstscan_);
} else if ((scancnt_ <= 0) && (firstscan_ != sensors_.size())) { // check 2 times for no change of sensor #
scancnt_ = -3;
scancnt_ = SCAN_START;
sensors_.clear(); // restart scaning and clear to get correct numbering
}
state_ = State::IDLE;