From 6d4f76c64296267d4788e6e741bfb6e9d1d1ad5f Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 7 Nov 2023 01:48:48 +0300 Subject: [PATCH] Multitask & 1-wire optimzation, sensor fixes --- compiled/tools/arduinoOTA | Bin lighthub/main.cpp | 28 +++++++++-- lighthub/main.h | 2 + lighthub/modules/in_ccs811_hdc1080.cpp | 3 +- lighthub/owTerm.cpp | 64 +++++++++++++++++-------- 5 files changed, 72 insertions(+), 25 deletions(-) mode change 100644 => 100755 compiled/tools/arduinoOTA diff --git a/compiled/tools/arduinoOTA b/compiled/tools/arduinoOTA old mode 100644 new mode 100755 diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 6ea3ab4..365ecb1 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -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< 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++; diff --git a/lighthub/main.h b/lighthub/main.h index 9918f17..c9d0305 100644 --- a/lighthub/main.h +++ b/lighthub/main.h @@ -287,6 +287,8 @@ void modbusIdle(void); void inputLoop(short); +void inputSensorsLoop(); + void inputSetup(void); void pollingLoop(void); diff --git a/lighthub/modules/in_ccs811_hdc1080.cpp b/lighthub/modules/in_ccs811_hdc1080.cpp index 229eb30..0b1592a 100644 --- a/lighthub/modules/in_ccs811_hdc1080.cpp +++ b/lighthub/modules/in_ccs811_hdc1080.cpp @@ -82,8 +82,9 @@ return 1; } void i2cReset(){ -Wire.endTransmission(true); + #if defined (SCL_RESET) +Wire.endTransmission(true); SCL_LOW(); delay(300); SCL_HIGH(); diff --git a/lighthub/owTerm.cpp b/lighthub/owTerm.cpp index 2ec5726..dfa0dec 100644 --- a/lighthub/owTerm.cpp +++ b/lighthub/owTerm.cpp @@ -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<name<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<setResolution(curDev,TEMPERATURE_PRECISION); + t = sensors->getTempC(curDev);//*10.0; processTemp(dev2Check, t); + + sensors->requestTemperaturesByAddress(curDev); } //switch