From 896a22862f96a567a47c3bfa206deba3bab4a0c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BB=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9=20=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B5?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Mon, 30 Oct 2023 00:00:11 +0300 Subject: [PATCH] 1-wire errors/reset improved, cleaned up --- lighthub/main.cpp | 61 +----------------------------------- lighthub/owTerm.cpp | 75 +++++++++++++++++++++++---------------------- lighthub/owTerm.h | 14 +-------- 3 files changed, 41 insertions(+), 109 deletions(-) diff --git a/lighthub/main.cpp b/lighthub/main.cpp index dca0d76..abe69e8 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -1236,51 +1236,6 @@ void resetHard() { #endif } -#ifdef _owire -/* -void Changed(int i, DeviceAddress addr, float currentTemp) { - char addrstr[32] = "NIL"; - //char addrbuf[17]; - //char valstr[16] = "NIL"; - //char *owEmitString = NULL; - //char *owItem = NULL; - - SetBytes(addr, 8, addrstr); - addrstr[17] = 0; - if (!root) return; - aJsonObject *owObj = aJson.getObjectItem(owArr, addrstr); - - if (i<0) //just print note about address - { - if (owObj && owObj->child && owObj->child->type==aJson_String && owObj->child->valuestring) - debugSerial<child->valuestring<")<child && owObj->child->type==aJson_String && owObj->child->valuestring) - errorSerial<child->valuestring<type ==aJson_String && idx->valuestring) {//DOMOTICZ json format support - debugSerial << endl << idx->valuestring << F(" Domoticz valstr:"); - char valstr[50]; - sprintf(valstr, "{\"idx\":%s,\"svalue\":\"%.1f\"}", idx->valuestring, currentTemp); - debugSerial << valstr; - if (mqttClient.connected() && !ethernetIdleCount) - mqttClient.publish(owEmitString, valstr); - return; - } -#endif -//// -} -*/ -#endif //_owire int cmdFunctionHelp(int arg_cnt, char **args) { @@ -1329,7 +1284,7 @@ return 500; } int cmdFunctionSearch(int arg_cnt, char **args) { - infoSerial<child; owReady = owSetup(); if (owReady) infoSerial<type == aJson_Object)) { - DeviceAddress addr; - //infoSerial<name); - SetAddr(item->name, addr); - owAdd(addr); - } - yield(); - item = item->next; - } - - */ } #endif diff --git a/lighthub/owTerm.cpp b/lighthub/owTerm.cpp index 1fe6aff..29048f8 100644 --- a/lighthub/owTerm.cpp +++ b/lighthub/owTerm.cpp @@ -31,18 +31,10 @@ extern aJsonObject *owArr; aJsonObject *dev2Check = NULL; OneWire *oneWire = NULL; - -//DeviceAddress *term = NULL; -//uint16_t *wstat = NULL; - DallasTemperature *sensors = NULL; -//short si = 0; -//int t_count = 0; unsigned long owTimer = 0; -//owChangedType owChanged; - void owSearch() { owUpdate(); @@ -55,7 +47,7 @@ bool zero(const uint8_t *addr, uint8_t len) return true; } -char * getReableNote(aJsonObject * owObj) +char * getReadableNote(aJsonObject * owObj) { if (owObj && owObj->child) { @@ -67,7 +59,7 @@ char * getReableNote(aJsonObject * owObj) } void processTemp(aJsonObject * owObj, float currentTemp) { if (!owObj || !owArr) return; - char* note = getReableNote(owObj); + char* note = getReadableNote(owObj); debugSerial<name< "); if ((currentTemp != -127.0) && (currentTemp != 85.0) && (currentTemp != 0.0)) { @@ -76,7 +68,7 @@ void processTemp(aJsonObject * owObj, float currentTemp) { executeCommand(owObj,-1,itemCmd(currentTemp).setSuffix(S_VAL)); } else - if (note) errorSerial<reset_search(); - debugSerial << F("1WT: Searching dev")<wireSearch(dev) > 0) { + wdt_res(); char addrstr[17]; SetBytes(dev, 8, addrstr); addrstr[16] = 0; aJsonObject * owObj=aJson.getObjectItem(owArr,addrstr); - debugSerial<reset_search(); for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent @@ -183,15 +172,10 @@ int owSetup() { if (!oneWire) { - errorSerial<reset(); @@ -239,12 +222,33 @@ return false; int sensors_loop(void) { #ifdef DS2482_100_I2C_TO_1W_BRIDGE - if (oneWire->getError() == DS2482_ERROR_SHORT) - { - debugSerial<wireReset(); - return 10000; - } + switch (oneWire->getError()) + { + case 0: + break; + + case DS2482_ERROR_SHORT: + errorSerial<wireReset(); + return INTERVAL_1W; + + case DS2482_ERROR_CONFIG: + errorSerial<wireReset(); + return INTERVAL_1W; + + case DS2482_ERROR_TIMEOUT: + errorSerial<wireReset(); + return INTERVAL_1W; + + default: + errorSerial<wireReset(); + return INTERVAL_1W; + } + + #endif @@ -261,7 +265,6 @@ if (!sensors) if (!dev2Check && owArr) { - if (owArr && owArr->type == aJson_Object && owArr->child) dev2Check = owArr->child; ///owUpdate(); //every check circle - scan for new devices } diff --git a/lighthub/owTerm.h b/lighthub/owTerm.h index e3ba95f..c14f01b 100644 --- a/lighthub/owTerm.h +++ b/lighthub/owTerm.h @@ -30,7 +30,7 @@ e-mail anklimov@gmail.com #define SW_MASK 0xF #define SW_INMASK 0xFC -#define recheck_interval 5 +//#define recheck_interval 5 //#define check_circle 2000/t_count #define SW_FIND 1 @@ -79,24 +79,12 @@ extern aJsonObject *owArr; extern OneWire *oneWire; - extern DallasTemperature *sensors; -//extern DeviceAddress *term ; -//extern int *regs ; -//extern uint16_t *wstat; -//extern int t_count; -//extern short si; - -//extern owChangedType owChanged; - - int owUpdate(); int owSetup(); void owLoop(); void setupOwIdle(void (*)()) ; -//int owFind(DeviceAddress addr); -//void owAdd (DeviceAddress addr); void owSearch(); #endif