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

View File

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

View File

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

View File

@@ -193,7 +193,7 @@ if (!term || ! wstat)
#ifdef DS2482_100_I2C_TO_1W_BRIDGE #ifdef DS2482_100_I2C_TO_1W_BRIDGE
Wire.begin(); Wire.begin();
if (oneWire->checkPresence()) { if (oneWire->checkPresence()) {
debugSerial.println(F("DS2482-100 present")); infoSerial.println(F("1WT: DS2482-100 present"));
oneWire->deviceReset(); oneWire->deviceReset();
#ifdef APU_OFF #ifdef APU_OFF
debugSerial.println(F("APU off")); debugSerial.println(F("APU off"));
@@ -204,19 +204,49 @@ if (!term || ! wstat)
debugSerial.println(F("\tChecking for 1-Wire devices...")); debugSerial.println(F("\tChecking for 1-Wire devices..."));
if (oneWire->wireReset()) if (oneWire->wireReset())
debugSerial.println(F("\tReset done")); debugSerial.println(F("\tReset done"));
return true; else
} debugSerial.println(F("\tDS2482 reset error"));
debugSerial.println(F("\tDS2482 reset error")); //return true;
return true; }
else
{
errorSerial.println(F("1WT: DS2482-100 not present"));
return false;
}
#else #else
// software driver // software driver
oneWire->reset(); oneWire->reset();
delay(500); delay(500);
return true; // return true;
#endif //DS2482-100 #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; return false;
#endif
} }
@@ -251,17 +281,11 @@ int sensors_loop(void) {
#endif #endif
if (!sensors || !owArr)
if (!sensors) {
{ errorSerial<<F("1WT: not init")<<endl;
// Setup sensors library and resolution return INTERVAL_1W;
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 (!dev2Check && owArr) if (!dev2Check && owArr)
{ {
@@ -284,10 +308,12 @@ if (!sensors)
switch (curDev[0]) { switch (curDev[0]) {
case 0x28: // Thermomerer case 0x28: // Thermomerer
sensors->setResolution(curDev,TEMPERATURE_PRECISION);
t = sensors->getTempC(curDev);//*10.0; t = sensors->getTempC(curDev);//*10.0;
processTemp(dev2Check, t); processTemp(dev2Check, t);
sensors->requestTemperaturesByAddress(curDev); sensors->requestTemperaturesByAddress(curDev);
} //switch } //switch