diff --git a/lighthub/item.cpp b/lighthub/item.cpp index c2e694b..2c523b8 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -109,6 +109,8 @@ Item::Item(aJsonObject *obj)//Constructor { itemArr = obj; driver = NULL; + *defaultSubItem = 0; + defaultSuffixCode = 0; Parse(); } @@ -570,6 +572,37 @@ st.setSuffix(suffixCode); return 0; } +// Recursive function with small stack consumption +int digGroup (aJsonObject *itemArr, itemCmd *cmd, char* subItem) +{ if (!itemArr || itemArr->type!=aJson_Array) return 0; + debugSerial<< F("Sub:")<child; + configLocked++; + while (i) { + if (i->type == aJson_String) + { debugSerial<< i->valuestring<valuestring); + if (nextItem && nextItem->type == aJson_Array) + { + short itemtype = aJson.getArrayItem(nextItem,0)->valueint; + if (itemtype == CH_GROUP) + { + aJsonObject * itemSubArray = aJson.getArrayItem(nextItem,1); + digGroup(itemSubArray,cmd,subItem); + } + else // Normal channel + { + Item it(nextItem); + if (it.isValid()) it.Ctrl(*cmd,subItem); + } + } + } + i = i->next; + } //while + configLocked--; +return 1; +} int Item::Ctrl(itemCmd cmd, char* subItem) { @@ -593,7 +626,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem) debugSerial<type == aJson_Array && operation) { + digGroup(itemArg,&cmd,subItem); + /* aJsonObject *i = itemArg->child; configLocked++; while (i) { @@ -879,6 +914,7 @@ switch (itemType) { i = i->next; } //while configLocked--; + */ } //if } //case break; diff --git a/lighthub/item.h b/lighthub/item.h index cadebde..9818c04 100644 --- a/lighthub/item.h +++ b/lighthub/item.h @@ -91,7 +91,7 @@ extern aJsonObject *items; extern short thermoSetCurTemp(char *name, float t); int txt2cmd (char * payload); - +int digGroup (aJsonObject *itemArr, itemCmd *cmd, char* subItem); class Item { public: