From e8d0ad0a4ef3464df36a02f6cdaeae1f435a2dac Mon Sep 17 00:00:00 2001 From: Yurii Date: Mon, 23 Dec 2024 11:37:54 +0300 Subject: [PATCH] refactor: improved work with clones (not original) of DS18B20 sensors --- src/SensorsTask.h | 58 ++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 44 deletions(-) diff --git a/src/SensorsTask.h b/src/SensorsTask.h index de44a6a..cdd63cb 100644 --- a/src/SensorsTask.h +++ b/src/SensorsTask.h @@ -175,16 +175,19 @@ protected: continue; } - if (millis() - this->dallasSearchTime[gpio] > this->dallasSearchInterval) { - this->dallasSearchTime[gpio] = millis(); - instance.begin(); - - Log.straceln( - FPSTR(L_SENSORS_DALLAS), - F("GPIO %hhu, devices on bus: %hhu, DS18* devices: %hhu"), - gpio, instance.getDeviceCount(), instance.getDS18Count() - ); + if (millis() - this->dallasSearchTime[gpio] < this->dallasSearchInterval) { + continue; } + + this->dallasSearchTime[gpio] = millis(); + this->owInstances[gpio].reset(); + instance.begin(); + + Log.straceln( + FPSTR(L_SENSORS_DALLAS), + F("GPIO %hhu, devices on bus: %hhu, DS18* devices: %hhu"), + gpio, instance.getDeviceCount(), instance.getDS18Count() + ); } } @@ -274,25 +277,14 @@ protected: unsigned long ts = millis(); if (this->dallasPolling[gpio]) { - auto minPollingTime = instance.millisToWaitForConversion(12); + auto minPollingTime = instance.millisToWaitForConversion(12) * 2; unsigned long estimatePollingTime = ts - this->dallasLastPollingTime[gpio]; // check conversion time + // isConversionComplete does not work with chinese clones! if (estimatePollingTime < minPollingTime) { continue; } - - // check conversion - bool conversionComplete = instance.isConversionComplete(); - if (!conversionComplete) { - if (estimatePollingTime > (minPollingTime * 2)) { - this->dallasPolling[gpio] = false; - - Log.swarningln(FPSTR(L_SENSORS_DALLAS), F("GPIO %hhu, timeout receiving data"), gpio); - } - - continue; - } // read sensors data for current instance for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) { @@ -345,28 +337,6 @@ protected: continue; } - // check sensors on bus - if (!instance.getDeviceCount()) { - for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) { - auto& sSensor = Sensors::settings[sensorId]; - - // only target & valid sensors - if (!sSensor.enabled || sSensor.type != Sensors::Type::DALLAS_TEMP || sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) { - continue; - - } else if (sSensor.gpio != gpio || isEmptyAddress(sSensor.address)) { - continue; - } - - auto& rSensor = Sensors::results[sensorId]; - if (rSensor.signalQuality > 0) { - rSensor.signalQuality--; - } - } - - continue; - } - // start polling instance.setResolution(12); instance.requestTemperatures();