Multitask & 1-wire optimzation, sensor fixes

This commit is contained in:
2023-11-07 01:48:48 +03:00
parent 7251e229b6
commit 6d4f76c642
5 changed files with 72 additions and 25 deletions

0
compiled/tools/arduinoOTA Normal file → Executable file
View File

View File

@@ -1358,7 +1358,7 @@ setupSyslog();
#ifdef _owire
owArr = aJson.getObjectItem(root, "ow");
if (owArr && !owReady) {
aJsonObject *item = owArr->child;
//aJsonObject *item = owArr->child;
owReady = owSetup();
if (owReady) infoSerial<<F("One wire Ready\n");
}
@@ -2661,6 +2661,8 @@ void loop_main() {
yield();
inputLoop(CHECK_INPUT);
yield();
inputSensorsLoop();
#if defined (_espdmx)
yield();
dmxout.update();
@@ -2705,7 +2707,14 @@ ethernetIdleCount++;
ethernetIdleCount--;
};
//static uint32_t tm=0;
void modbusIdle(void) {
/*
if (isTimeOver(tm,millis(),500))
{
tm=millis();
debugSerial<<F("MB: Tick")<<endl;
} */
wdt_res();
statusLED.poll();
yield();
@@ -2782,9 +2791,16 @@ configLocked++;
if (cause != CHECK_INTERRUPT) timerInputCheck = millis();// + INTERVAL_CHECK_INPUT;
inCache.invalidateInputCache();
}
configLocked--;
inputLoopBusy--;
}
//if (millis() > timerSensorCheck)
if (cause != CHECK_INTERRUPT && isTimeOver(timerSensorCheck,millis(),INTERVAL_CHECK_SENSOR))
void inputSensorsLoop() {
if (!inputs || inputLoopBusy) return;
//inputLoopBusy++;
configLocked++;
if (isTimeOver(timerSensorCheck,millis(),INTERVAL_CHECK_SENSOR))
{
aJsonObject *input = inputs->child;
while (input) {
@@ -2793,15 +2809,17 @@ configLocked++;
in.Poll(CHECK_SENSOR);
}
yield();
inputLoop(CHECK_INPUT);
input = input->next;
}
timerSensorCheck = millis();// + INTERVAL_CHECK_SENSOR;
timerSensorCheck = millis();
}
configLocked--;
inputLoopBusy--;
//inputLoopBusy--;
}
void inputSetup(void) {
if (!inputs) return;
configLocked++;

View File

@@ -287,6 +287,8 @@ void modbusIdle(void);
void inputLoop(short);
void inputSensorsLoop();
void inputSetup(void);
void pollingLoop(void);

View File

@@ -82,8 +82,9 @@ return 1;
}
void i2cReset(){
Wire.endTransmission(true);
#if defined (SCL_RESET)
Wire.endTransmission(true);
SCL_LOW();
delay(300);
SCL_HIGH();

View File

@@ -193,7 +193,7 @@ if (!term || ! wstat)
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
Wire.begin();
if (oneWire->checkPresence()) {
debugSerial.println(F("DS2482-100 present"));
infoSerial.println(F("1WT: DS2482-100 present"));
oneWire->deviceReset();
#ifdef APU_OFF
debugSerial.println(F("APU off"));
@@ -204,19 +204,49 @@ if (!term || ! wstat)
debugSerial.println(F("\tChecking for 1-Wire devices..."));
if (oneWire->wireReset())
debugSerial.println(F("\tReset done"));
return true;
}
debugSerial.println(F("\tDS2482 reset error"));
return true;
else
debugSerial.println(F("\tDS2482 reset error"));
//return true;
}
else
{
errorSerial.println(F("1WT: DS2482-100 not present"));
return false;
}
#else
// software driver
oneWire->reset();
delay(500);
return true;
// return true;
#endif //DS2482-100
#endif //1w is not disabled
if (!owArr) return false;
if (!sensors)
{
// Setup sensors library and resolution
sensors = new DallasTemperature(oneWire);
sensors->begin();
// IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
//for (short i = 0; i < t_count; i++) sensors->setResolution(term[i],TEMPERATURE_PRECISION);
sensors->setWaitForConversion(false);
}
aJsonObject *item = owArr->child;
DeviceAddress curDev;
while (owArr && item && SetAddr(item->name,curDev) )
{
debugSerial<<F("1WT: setup resolution ")<<item->name<<endl;
sensors->setResolution(curDev,TEMPERATURE_PRECISION);
item=item->next;
}
return true;
#else //1w is not disabled
return false;
#endif
}
@@ -251,17 +281,11 @@ int sensors_loop(void) {
#endif
if (!sensors)
{
// Setup sensors library and resolution
sensors = new DallasTemperature(oneWire);
sensors->begin();
// IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
//for (short i = 0; i < t_count; i++) sensors->setResolution(term[i],TEMPERATURE_PRECISION);
sensors->setWaitForConversion(false);
}
if (!sensors || !owArr)
{
errorSerial<<F("1WT: not init")<<endl;
return INTERVAL_1W;
}
if (!dev2Check && owArr)
{
@@ -284,10 +308,12 @@ if (!sensors)
switch (curDev[0]) {
case 0x28: // Thermomerer
sensors->setResolution(curDev,TEMPERATURE_PRECISION);
t = sensors->getTempC(curDev);//*10.0;
processTemp(dev2Check, t);
sensors->requestTemperaturesByAddress(curDev);
} //switch