Fix for odd Dallas sensor "not found" behaviour.

Minor flash use reduction.
This commit is contained in:
Blaz Kristan 2021-07-04 14:23:53 +02:00
parent de8a244500
commit bbdd1915eb
3 changed files with 2206 additions and 2202 deletions

View File

@ -42,6 +42,8 @@ class UsermodTemperature : public Usermod {
bool waitingForConversion = false;
// flag set at startup if DS18B20 sensor not found, avoids trying to keep getting
// temperature if flashed to a board without a sensor attached
bool sensorFound = false;
bool enabled = true;
// strings to reduce flash memory usage (used more than twice)
@ -87,7 +89,9 @@ class UsermodTemperature : public Usermod {
uint8_t deviceAddress[8] = {0,0,0,0,0,0,0,0};
// find out if we have DS18xxx sensor attached
oneWire->reset_search();
delay(10);
while (oneWire->search(deviceAddress)) {
DEBUG_PRINTLN(F("Found something..."));
if (oneWire->crc8(deviceAddress, 7) == deviceAddress[7]) {
switch (deviceAddress[0]) {
case 0x10: // DS18S20
@ -114,15 +118,16 @@ class UsermodTemperature : public Usermod {
if (temperaturePin >= 0 && pinManager.allocatePin(temperaturePin)) {
oneWire = new OneWire(temperaturePin);
if (!oneWire->reset())
enabled = false; // resetting 1-Wire bus yielded an error
sensorFound = false; // resetting 1-Wire bus yielded an error
else
while ((enabled=findSensor()) && retries--) delay(25); // try to find sensor
while ((sensorFound=findSensor()) && retries--) delay(25); // try to find sensor
} else {
if (temperaturePin >= 0) DEBUG_PRINTLN(F("Temperature pin allocation failed."));
temperaturePin = -1; // allocation failed
enabled = false;
sensorFound = false;
}
}
lastMeasurement = millis() - readingInterval + 10000;
initDone = true;
}
@ -190,7 +195,7 @@ class UsermodTemperature : public Usermod {
JsonArray temp = user.createNestedArray(FPSTR(_name));
//temp.add(F("Loaded."));
if (temperature <= -100) {
if (temperature <= -100.0 || (!sensorFound && temperature == -1.0)) {
temp.add(0);
temp.add(F(" Sensor Error!"));
return;
@ -262,8 +267,10 @@ class UsermodTemperature : public Usermod {
temperaturePin = newTemperaturePin;
DEBUG_PRINTLN(F(" config loaded."));
} else {
DEBUG_PRINTLN(F(" config (re)loaded."));
// changing paramters from settings page
if (newTemperaturePin != temperaturePin) {
DEBUG_PRINTLN(F("Re-init temperature."));
// deallocate pin and release memory
delete oneWire;
pinManager.deallocatePin(temperaturePin);
@ -271,7 +278,6 @@ class UsermodTemperature : public Usermod {
// initialise
setup();
}
DEBUG_PRINTLN(F(" config (re)loaded."));
}
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
return !top[FPSTR(_parasite)].isNull();

View File

@ -408,8 +408,7 @@ function loadPresets(callback = null)
clearErrorToast();
pJson = json;
populatePresets();
// Create UI update WS handler
if (!ws && lastinfo.ws > -1) setTimeout(makeWS,1000);
reconnectWS();
if (callback) callback();
})
.catch(function (error) {
@ -435,8 +434,7 @@ function loadPalettes(callback = null)
clearErrorToast();
lJson = Object.entries(json);
populatePalettes();
// Create UI update WS handler
if (!ws && lastinfo.ws > -1) setTimeout(makeWS,1000);
reconnectWS();
if (callback) callback();
})
.catch(function (error) {
@ -566,8 +564,7 @@ function loadInfo(callback=null)
pmt = json.fs.pmt;
showNodes();
populateInfo(json);
// Create UI update WS handler
if (!ws && json.ws > -1) setTimeout(makeWS,1000);
reconnectWS();
reqsLegal = true;
if (callback) callback();
})
@ -762,8 +759,7 @@ function loadNodes()
.then(json => {
clearErrorToast();
populateNodes(lastinfo, json);
// Create UI update WS handler
if (!ws && lastinfo.ws > -1) setTimeout(makeWS,1000);
reconnectWS();
})
.catch(function (error) {
showToast(error, true);
@ -1083,6 +1079,10 @@ function makeWS() {
}
}
function reconnectWS() {// Create UI update WS handler
if (!ws && lastinfo.ws > -1) setTimeout(makeWS,1000);
}
function readState(s,command=false)
{
if (!s) return false;
@ -1209,8 +1209,7 @@ function requestJson(command, rinfo = true, verbose = true, callback = null)
var s = json.state ? json.state : json;
readState(s);
reqsLegal = true;
// Create UI update WS handler
if (!ws && lastinfo.ws > -1) setTimeout(makeWS,1000);
reconnectWS();
if (callback) callback();
})
.catch(function (error) {

File diff suppressed because it is too large Load Diff