From 81edb7f86ecc74222223588c751b98dd74ff8c7e Mon Sep 17 00:00:00 2001 From: Andrey Klimov Date: Fri, 22 Apr 2022 14:51:43 +0300 Subject: [PATCH] core fixes --- lighthub/item.cpp | 11 +++++++---- lighthub/itemCmd.cpp | 20 +++++++++++++++++--- lighthub/main.cpp | 5 ++++- lighthub/modules/out_counter.cpp | 6 +++--- lighthub/modules/out_modbus.cpp | 15 +++++++++------ 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/lighthub/item.cpp b/lighthub/item.cpp index c9a399a..482c6ef 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -368,8 +368,8 @@ float Item::getFloatArg(short n) //Return arg float or first array element if Ar if ((itemArg->type == aJson_Array) && ( n < aJson.getArraySize(itemArg))) { aJsonObject * obj = aJson.getArrayItem(itemArg, n); - if (obj->type == aJson_Int) return obj->valueint; - if (obj->type == aJson_Float) return obj->valuefloat; + if (obj && obj->type == aJson_Int) return obj->valueint; + if (obj && obj->type == aJson_Float) return obj->valuefloat; return 0; } @@ -908,11 +908,14 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion) case S_NOTFOUND: toExecute=true; case S_SET: - - if (cmd.incrementPercents(step,(suffixCode==S_NOTFOUND)?100:limitSetValue())) + { + long limit = limitSetValue(); + if (limit && suffixCode==S_NOTFOUND) limit = 100; + if (cmd.incrementPercents(step,limit)) { status2Send |= SEND_PARAMETERS | SEND_DEFFERED; } else {cmd=fallbackCmd;invalidArgument=true;} + } break; case S_HUE: diff --git a/lighthub/itemCmd.cpp b/lighthub/itemCmd.cpp index 6c1f96a..338a131 100644 --- a/lighthub/itemCmd.cpp +++ b/lighthub/itemCmd.cpp @@ -253,11 +253,25 @@ bool itemCmd::incrementPercents(long int dif, long int limit ) case ST_INT32: case ST_UINT32: + if (diflimit*TENS_BASE) par=limit*TENS_BASE; + if (limit && par<0) par=0; + + param.asInt32=par; + cmd.itemArgType=ST_TENS; + } + else + { par=param.asInt32; par+=dif/TENS_BASE; - if (par>limit) par=limit; + if (limit && par>limit) par=limit; if (limit && par<0) par=0; param.asInt32=par; + } break; case ST_FLOAT: @@ -274,8 +288,8 @@ bool itemCmd::incrementPercents(long int dif, long int limit ) par=param.asInt32; par+=dif; -// if (par>100*TENS_BASE) par=100*TENS_BASE; -// if (par<0) par=0; + if (limit && par>limit*TENS_BASE) par=limit*TENS_BASE; + if (limit && par<0) par=0; param.asInt32=par; break; diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 9203ee4..827aab2 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -143,9 +143,10 @@ int8_t mqttErrorRate=0; void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE #endif -void cleanConf() +bool cleanConf() { if (!root) return; + bool clean = true; debugSerial<getExt(); - if (timer && isTimeOver(timer,millis(),period)) + if (timer && period && isTimeOver(timer,millis(),period)) { item->setExt(millisNZ()); itemCmd st; - st.loadItem(item); + st.loadItem(item,SEND_PARAMETERS|SEND_COMMAND); float val = st.getFloat(); //short cmd = st.getCmd(); - val+=period; + val+=impulse; st.Float(val); st.saveItem(item); } diff --git a/lighthub/modules/out_modbus.cpp b/lighthub/modules/out_modbus.cpp index f8db09e..1745d4a 100644 --- a/lighthub/modules/out_modbus.cpp +++ b/lighthub/modules/out_modbus.cpp @@ -315,11 +315,14 @@ int out_Modbus::findRegister(int registerNum, int posInBuffer, int regType) //Retrive previous data aJsonObject *lastMeasured = aJson.getObjectItem(execObj,"@S"); if (lastMeasured) - { - if (lastMeasured->valueint == param) - submitParam=false; //supress repeating execution for same val - else lastMeasured->valueint=param; - } + { + if (lastMeasured->type == aJson_Int) + { + if (lastMeasured->valueint == param) + submitParam=false; //supress repeating execution for same val + else lastMeasured->valueint=param; + } + } else //No container to store value yet { debugSerial<name<type ==aJson_Object) if (execObj && execObj->type == aJson_Object) { aJsonObject *polledValue = aJson.getObjectItem(execObj,"@S"); - if (polledValue && (polledValue->valueint == Value)) + if (polledValue && polledValue->type == aJson_Int && (polledValue->valueint == Value)) { debugSerial<