"activate" cmd to switch RE sections by other INs

This commit is contained in:
2025-04-28 01:13:09 +03:00
parent 5aec014767
commit c2c863b8bd
2 changed files with 32 additions and 18 deletions

View File

@@ -147,16 +147,6 @@ void Input::Parse(aJsonObject * configObj)
store = (inStore *) &inputObj->valueint; store = (inStore *) &inputObj->valueint;
} }
/*
// Persistant storage
itemBuffer = aJson.getObjectItem(inputObj, "@S");
if (!itemBuffer) {
debugSerial<<F("In: ")<<pin<<F("/")<<inType<<endl;
aJson.addNumberToObject(inputObj, "@S", (long int) 0);
itemBuffer = aJson.getObjectItem(inputObj, "@S");
}
if (itemBuffer) store = (inStore *) &itemBuffer->valueint;
*/
} }
void Input::stop() void Input::stop()
@@ -604,17 +594,24 @@ debugSerial << F("IN:") << pin << F(" DHT22 type. T=") << temp << F("°C H=") <<
// To Be Refactored - move to Execute after class Input inheritation on abstract chan // To Be Refactored - move to Execute after class Input inheritation on abstract chan
bool Input::checkInstructions(aJsonObject * obj) bool Input::checkInstructions(aJsonObject * obj)
{ {
aJsonObject *gotoObj = aJson.getObjectItem(obj, "goto"); aJsonObject *gotoObj = aJson.getObjectItem(obj, "activate");
if (gotoObj) if (gotoObj)
switch (gotoObj->type) switch (gotoObj->type)
{ { case aJson_Array:
case aJson_Int: {
debugSerial<<F("Activate in ")<< gotoObj->valueint <<endl; char * name = getStringFromJson(gotoObj,0);
return setCurrentInput(gotoObj->valueint); if (name)
{
Input in (name);
debugSerial<<"IN: "<<name<< " is "<<in.isValid()<<endl;
if (in.isValid()) return in.setCurrentInput(aJson.getArrayItem(gotoObj,1));
}
}
break; break;
case aJson_Int:
case aJson_String: case aJson_String:
debugSerial<<F("Activate in ")<< gotoObj->valuestring <<endl; return setCurrentInput(gotoObj);
return setCurrentInput(gotoObj->valuestring); break;
} }
return false; return false;
} }
@@ -628,12 +625,27 @@ debugSerial << F("IN:") << pin << F(" DHT22 type. T=") << temp << F("°C H=") <<
return inputObj; return inputObj;
} }
bool Input::setCurrentInput(aJsonObject * obj)
{
if (!obj) return false;
switch (obj->type)
{
case aJson_Int:
debugSerial<<F("Activate in ")<<pin <<" to "<< obj->valueint <<endl;
return setCurrentInput(obj->valueint);
break;
case aJson_String:
debugSerial<<F("Activate in ")<<pin <<" to "<< obj->valuestring <<endl;
return setCurrentInput(obj->valuestring);
}
}
bool Input::setCurrentInput(int n) bool Input::setCurrentInput(int n)
{ {
if (!inputObj) return false; if (!inputObj) return false;
aJsonObject * curInput = NULL; aJsonObject * curInput = NULL;
aJsonObject *act = aJson.getObjectItem(inputObj, "act"); aJsonObject *act = aJson.getObjectItem(inputObj, "act");
if (act && act->type == aJson_Array) if (act && (act->type == aJson_Array || act->type ==aJson_Object))
{ {
if (n) if (n)
curInput = aJson.getArrayItem(act,n-1); curInput = aJson.getArrayItem(act,n-1);

View File

@@ -188,6 +188,8 @@ protected:
void setupRotaryEncoder(); void setupRotaryEncoder();
aJsonObject * getCurrentInput(); aJsonObject * getCurrentInput();
bool setCurrentInput(aJsonObject * obj);
bool setCurrentInput(int n); bool setCurrentInput(int n);
bool setCurrentInput(char * name); bool setCurrentInput(char * name);
bool checkInstructions(aJsonObject * obj); bool checkInstructions(aJsonObject * obj);