mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
core fixes
This commit is contained in:
@@ -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)))
|
if ((itemArg->type == aJson_Array) && ( n < aJson.getArraySize(itemArg)))
|
||||||
{
|
{
|
||||||
aJsonObject * obj = aJson.getArrayItem(itemArg, n);
|
aJsonObject * obj = aJson.getArrayItem(itemArg, n);
|
||||||
if (obj->type == aJson_Int) return obj->valueint;
|
if (obj && obj->type == aJson_Int) return obj->valueint;
|
||||||
if (obj->type == aJson_Float) return obj->valuefloat;
|
if (obj && obj->type == aJson_Float) return obj->valuefloat;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -908,11 +908,14 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion)
|
|||||||
case S_NOTFOUND:
|
case S_NOTFOUND:
|
||||||
toExecute=true;
|
toExecute=true;
|
||||||
case S_SET:
|
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;
|
status2Send |= SEND_PARAMETERS | SEND_DEFFERED;
|
||||||
} else {cmd=fallbackCmd;invalidArgument=true;}
|
} else {cmd=fallbackCmd;invalidArgument=true;}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_HUE:
|
case S_HUE:
|
||||||
|
|||||||
@@ -253,11 +253,25 @@ bool itemCmd::incrementPercents(long int dif, long int limit )
|
|||||||
|
|
||||||
case ST_INT32:
|
case ST_INT32:
|
||||||
case ST_UINT32:
|
case ST_UINT32:
|
||||||
|
if (dif<TENS_BASE) // Step < 1 - convert to tens
|
||||||
|
{
|
||||||
|
par=param.asInt32*TENS_BASE;
|
||||||
|
par+=dif;
|
||||||
|
|
||||||
|
if (limit && par>limit*TENS_BASE) par=limit*TENS_BASE;
|
||||||
|
if (limit && par<0) par=0;
|
||||||
|
|
||||||
|
param.asInt32=par;
|
||||||
|
cmd.itemArgType=ST_TENS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
par=param.asInt32;
|
par=param.asInt32;
|
||||||
par+=dif/TENS_BASE;
|
par+=dif/TENS_BASE;
|
||||||
if (par>limit) par=limit;
|
if (limit && par>limit) par=limit;
|
||||||
if (limit && par<0) par=0;
|
if (limit && par<0) par=0;
|
||||||
param.asInt32=par;
|
param.asInt32=par;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ST_FLOAT:
|
case ST_FLOAT:
|
||||||
@@ -274,8 +288,8 @@ bool itemCmd::incrementPercents(long int dif, long int limit )
|
|||||||
|
|
||||||
par=param.asInt32;
|
par=param.asInt32;
|
||||||
par+=dif;
|
par+=dif;
|
||||||
// if (par>100*TENS_BASE) par=100*TENS_BASE;
|
if (limit && par>limit*TENS_BASE) par=limit*TENS_BASE;
|
||||||
// if (par<0) par=0;
|
if (limit && par<0) par=0;
|
||||||
param.asInt32=par;
|
param.asInt32=par;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -143,9 +143,10 @@ int8_t mqttErrorRate=0;
|
|||||||
void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE
|
void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void cleanConf()
|
bool cleanConf()
|
||||||
{
|
{
|
||||||
if (!root) return;
|
if (!root) return;
|
||||||
|
bool clean = true;
|
||||||
debugSerial<<F("Unlocking config ...")<<endl;
|
debugSerial<<F("Unlocking config ...")<<endl;
|
||||||
uint32_t stamp=millis();
|
uint32_t stamp=millis();
|
||||||
while (configLocked && !isTimeOver(stamp,millis(),10000))
|
while (configLocked && !isTimeOver(stamp,millis(),10000))
|
||||||
@@ -167,6 +168,7 @@ while (configLocked && !isTimeOver(stamp,millis(),10000))
|
|||||||
if (configLocked)
|
if (configLocked)
|
||||||
{
|
{
|
||||||
errorSerial<<F("Not unlocked in 10s - continue ...")<<endl;
|
errorSerial<<F("Not unlocked in 10s - continue ...")<<endl;
|
||||||
|
clean = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
debugSerial<<F("Stopping channels ...")<<endl;
|
debugSerial<<F("Stopping channels ...")<<endl;
|
||||||
@@ -219,6 +221,7 @@ debugSerial<<F("Deleting conf. RAM was:")<<freeRam();
|
|||||||
|
|
||||||
configOk=false;
|
configOk=false;
|
||||||
timerHandlerBusy--;
|
timerHandlerBusy--;
|
||||||
|
return clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNotRetainingStatus() {
|
bool isNotRetainingStatus() {
|
||||||
|
|||||||
@@ -44,14 +44,14 @@ int out_counter::Poll(short cause)
|
|||||||
|
|
||||||
uint32_t timer = item->getExt();
|
uint32_t timer = item->getExt();
|
||||||
|
|
||||||
if (timer && isTimeOver(timer,millis(),period))
|
if (timer && period && isTimeOver(timer,millis(),period))
|
||||||
{
|
{
|
||||||
item->setExt(millisNZ());
|
item->setExt(millisNZ());
|
||||||
itemCmd st;
|
itemCmd st;
|
||||||
st.loadItem(item);
|
st.loadItem(item,SEND_PARAMETERS|SEND_COMMAND);
|
||||||
float val = st.getFloat();
|
float val = st.getFloat();
|
||||||
//short cmd = st.getCmd();
|
//short cmd = st.getCmd();
|
||||||
val+=period;
|
val+=impulse;
|
||||||
st.Float(val);
|
st.Float(val);
|
||||||
st.saveItem(item);
|
st.saveItem(item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -315,11 +315,14 @@ int out_Modbus::findRegister(int registerNum, int posInBuffer, int regType)
|
|||||||
//Retrive previous data
|
//Retrive previous data
|
||||||
aJsonObject *lastMeasured = aJson.getObjectItem(execObj,"@S");
|
aJsonObject *lastMeasured = aJson.getObjectItem(execObj,"@S");
|
||||||
if (lastMeasured)
|
if (lastMeasured)
|
||||||
|
{
|
||||||
|
if (lastMeasured->type == aJson_Int)
|
||||||
{
|
{
|
||||||
if (lastMeasured->valueint == param)
|
if (lastMeasured->valueint == param)
|
||||||
submitParam=false; //supress repeating execution for same val
|
submitParam=false; //supress repeating execution for same val
|
||||||
else lastMeasured->valueint=param;
|
else lastMeasured->valueint=param;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else //No container to store value yet
|
else //No container to store value yet
|
||||||
{
|
{
|
||||||
debugSerial<<F("Add @S: ")<<paramObj->name<<endl;
|
debugSerial<<F("Add @S: ")<<paramObj->name<<endl;
|
||||||
@@ -614,7 +617,7 @@ if (itemParametersObj && itemParametersObj->type ==aJson_Object)
|
|||||||
if (execObj && execObj->type == aJson_Object)
|
if (execObj && execObj->type == aJson_Object)
|
||||||
{
|
{
|
||||||
aJsonObject *polledValue = aJson.getObjectItem(execObj,"@S");
|
aJsonObject *polledValue = aJson.getObjectItem(execObj,"@S");
|
||||||
if (polledValue && (polledValue->valueint == Value))
|
if (polledValue && polledValue->type == aJson_Int && (polledValue->valueint == Value))
|
||||||
{
|
{
|
||||||
debugSerial<<F("Ignored - not changed")<<endl;
|
debugSerial<<F("Ignored - not changed")<<endl;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user