mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-11 18:54:28 +05:00
refactor: improved work with clones (not original) of DS18B20 sensors
This commit is contained in:
@@ -175,16 +175,19 @@ protected:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (millis() - this->dallasSearchTime[gpio] > this->dallasSearchInterval) {
|
if (millis() - this->dallasSearchTime[gpio] < this->dallasSearchInterval) {
|
||||||
this->dallasSearchTime[gpio] = millis();
|
continue;
|
||||||
instance.begin();
|
|
||||||
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_DALLAS),
|
|
||||||
F("GPIO %hhu, devices on bus: %hhu, DS18* devices: %hhu"),
|
|
||||||
gpio, instance.getDeviceCount(), instance.getDS18Count()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
unsigned long ts = millis();
|
||||||
|
|
||||||
if (this->dallasPolling[gpio]) {
|
if (this->dallasPolling[gpio]) {
|
||||||
auto minPollingTime = instance.millisToWaitForConversion(12);
|
auto minPollingTime = instance.millisToWaitForConversion(12) * 2;
|
||||||
unsigned long estimatePollingTime = ts - this->dallasLastPollingTime[gpio];
|
unsigned long estimatePollingTime = ts - this->dallasLastPollingTime[gpio];
|
||||||
|
|
||||||
// check conversion time
|
// check conversion time
|
||||||
|
// isConversionComplete does not work with chinese clones!
|
||||||
if (estimatePollingTime < minPollingTime) {
|
if (estimatePollingTime < minPollingTime) {
|
||||||
continue;
|
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
|
// read sensors data for current instance
|
||||||
for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) {
|
for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) {
|
||||||
@@ -345,28 +337,6 @@ protected:
|
|||||||
continue;
|
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
|
// start polling
|
||||||
instance.setResolution(12);
|
instance.setResolution(12);
|
||||||
instance.requestTemperatures();
|
instance.requestTemperatures();
|
||||||
|
|||||||
Reference in New Issue
Block a user