diff --git a/build-flags/build_flags_mega2560slim2 b/build-flags/build_flags_mega2560slim2 index 477aa66..79b6129 100644 --- a/build-flags/build_flags_mega2560slim2 +++ b/build-flags/build_flags_mega2560slim2 @@ -17,7 +17,7 @@ -DMOTOR_DISABLE #-DWiz5100 -DARDUINO_OTA_MDNS_DISABLE --DMDNS_ENABLE +#-DMDNS_ENABLE # Example of UARTBRIDGE configuration #-DUARTBRIDGE_ENABLE diff --git a/compiled/lighthub21/firmware.bin b/compiled/lighthub21/firmware.bin index 7f8b42d..95a9ae9 100644 Binary files a/compiled/lighthub21/firmware.bin and b/compiled/lighthub21/firmware.bin differ diff --git a/lighthub/inputs.cpp b/lighthub/inputs.cpp index 6b23df5..ec54960 100644 --- a/lighthub/inputs.cpp +++ b/lighthub/inputs.cpp @@ -641,16 +641,22 @@ if (newState!=store->state && cause!=CHECK_INTERRUPT) debugSerial<reqState=newState; - store->delayedState=true; + if (newState != store->state) + { + store->reqState=newState; + store->delayedState=true; + } return true; } } +static volatile uint8_t contactPollBusy = 0; + void Input::contactPoll(short cause) { boolean currentInputState; - if (!store) return; + if (!store || contactPollBusy) return; + contactPollBusy++; changeState(IS_REQSTATE,cause); //Check for postponed states transitions @@ -853,6 +859,7 @@ if (cause != CHECK_INTERRUPT) switch (store->state) //Timer based transitions } } else // no change store->bounce = SAME_STATE_ATTEMPTS; +contactPollBusy--; } diff --git a/lighthub/item.cpp b/lighthub/item.cpp index f54691e..7888fe7 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -680,7 +680,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion) return -1; } cmd.debugOut(); - debugSerial<0); + + if (chActive>0 && !cmd.getInt()) {cmd.Cmd(CMD_OFF);status2Send |= SEND_COMMAND | SEND_IMMEDIATE;} + if (chActive==0 && cmd.getInt()) {cmd.Cmd(CMD_ON);status2Send |= SEND_COMMAND | SEND_IMMEDIATE;} + + // continue processing as SET + case S_SET: + stored.loadItemDef(this); + // if previous color was in RGB notation but new value is HSV - discard previous val and change type; + if ((stored.getArgType() == ST_RGB || stored.getArgType() == ST_RGBW) && + (cmd.getArgType() == ST_HSV255)) + stored.setArgType(cmd.getArgType()); + + if (itemType == CH_GROUP && cmd.isColor()) stored.setArgType(ST_HSV255);//Extend storage for group channel + + //Convert value to most approptiate type for channel + stored.assignFrom(cmd,getChanType()); + stored.debugOut(); + + if ((scale100 || SCALE_VOLUME_100) && (cmd.getArgType()==ST_HSV255 || cmd.getArgType()==ST_PERCENTS255 || cmd.getArgType()==ST_INT32 || cmd.getArgType()==ST_UINT32)) + stored.scale100(); + cmd=stored; + status2Send |= SEND_PARAMETERS | SEND_DEFFERED; + + break; + case S_VAL: + break; + + case S_SAT: + stored.loadItemDef(this); + if (stored.setS(cmd.getS())) + { + cmd=stored; + cmd.setSuffix(S_SET); + status2Send |= SEND_PARAMETERS | SEND_DEFFERED; + } else invalidArgument=true; + break; + + case S_HUE: + stored.loadItemDef(this); + if (stored.setH(cmd.getH())) + { + cmd=stored; + cmd.setSuffix(S_SET); + status2Send |= SEND_PARAMETERS | SEND_DEFFERED; + } else invalidArgument=true; + break; + case S_TEMP: + stored.loadItemDef(this); + stored.setColorTemp(cmd.getColorTemp()); + cmd=stored; + status2Send |= SEND_PARAMETERS | SEND_DEFFERED; + } + + } + break; case CMD_TOGGLE: chActive=(isActive()>0); toExecute=true; @@ -730,88 +796,13 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion) cmd.Cmd(CMD_ON); } status2Send |=SEND_COMMAND | SEND_IMMEDIATE; - break; - // TBD - INCREMENT-DECREMENT - } - - /// + break; - if (itemType==CH_GROUP) - { - - if (allowRecursion && itemArg->type == aJson_Array && operation) - { - digGroup(itemArg,&cmd,subItem); - status2Send |= SEND_COMMAND | SEND_PARAMETERS | SEND_IMMEDIATE; - res=1; - } - // return 1; - } // GROUP - - else - { // NON GROUP part - if (chActive<0) chActive = (isActive()>0); - toExecute=chActive || toExecute; // Execute if active - - if (subItem) - { - //Check if subitem is some sort of command - int subitemCmd = subitem2cmd(subItem); - short prevCmd = getCmd(); - if (!prevCmd && chActive) prevCmd=CMD_ON; - - if (subitemCmd) //Find some COMMAND in subitem - { - if (subitemCmd != prevCmd) - { - debugSerial<0 && !cmd.getInt()) {cmd.Cmd(CMD_OFF);status2Send |= SEND_COMMAND | SEND_IMMEDIATE;} - if (chActive==0 && cmd.getInt()) {cmd.Cmd(CMD_ON);status2Send |= SEND_COMMAND | SEND_IMMEDIATE;} - - // continue processing as SET - case S_SET: - stored.loadItemDef(this); - // if previous color was in RGB notation but new value is HSV - discard previous val and change type; - if ((stored.getArgType() == ST_RGB || stored.getArgType() == ST_RGBW) && - (cmd.getArgType() == ST_HSV255)) - stored.setArgType(cmd.getArgType()); + break; + // + } + if (itemType==CH_GROUP) + { + if (allowRecursion && itemArg->type == aJson_Array && operation) + { + digGroup(itemArg,&cmd,subItem); + res=1; + } - //if (itemType == CH_GROUP && cmd.isColor()) stored.setArgType(ST_HSV255);//Extend storage for group channel - - //Convert value to most approptiate type for channel - stored.assignFrom(cmd,getChanType()); - if (scale100 || SCALE_VOLUME_100) stored.scale100(); - cmd=stored; - status2Send |= SEND_PARAMETERS | SEND_DEFFERED; - - break; - case S_VAL: - break; - - case S_SAT: - stored.loadItemDef(this); - if (stored.setS(cmd.getS())) - { - cmd=stored; - cmd.setSuffix(S_SET); - status2Send |= SEND_PARAMETERS | SEND_DEFFERED; - } - break; - - case S_HUE: - stored.loadItemDef(this); - if (stored.setH(cmd.getH())) - { - cmd=stored; - cmd.setSuffix(S_SET); - status2Send |= SEND_PARAMETERS | SEND_DEFFERED; - } - break; - case S_TEMP: - stored.loadItemDef(this); - stored.setColorTemp(cmd.getColorTemp()); - cmd=stored; - status2Send |= SEND_PARAMETERS | SEND_DEFFERED; - } - - } - break; + // Post-processing of group command - converting HALT,REST,XON,XOFF to conventional ON/OFF for status + switch (cmd.getCmd()) { + int t; + case CMD_RESTORE: // individual for group members + switch (t = getCmd()) { + case CMD_HALT: //previous command was HALT ? + debugSerial << F("Restored from:") << t << endl; + cmd.loadItemDef(this); + cmd.Cmd(CMD_ON); //turning on + break; + default: + return -3; + } + status2Send |= SEND_COMMAND; + break; + case CMD_XOFF: // individual for group members + switch (t = getCmd()) { + case CMD_XON: //previous command was CMD_XON ? + debugSerial << F("Turned off from:") << t << endl; + cmd.Cmd(CMD_OFF); //turning Off + status2Send |= SEND_COMMAND | SEND_IMMEDIATE; + break; + default: + debugSerial << F("XOFF skipped. Prev cmd:") << t <0); + toExecute=chActive || toExecute; // Execute if active + debugSerial<name, sizeof(addrstr)-1); diff --git a/lighthub/itemCmd.cpp b/lighthub/itemCmd.cpp index 72a2668..427c827 100644 --- a/lighthub/itemCmd.cpp +++ b/lighthub/itemCmd.cpp @@ -106,7 +106,7 @@ uint8_t itemCmd::getStoragetypeByChanType(short chanType) case CH_RELAY: case CH_VC: case CH_MODBUS: - case CH_GROUP: + //case CH_GROUP: return ST_PERCENTS255; break; default: @@ -936,7 +936,7 @@ bool itemCmd::loadItem(Item * item, uint16_t optionsFlag) { cmd.itemArgType= subtype; if (optionsFlag & SEND_PARAMETERS) param.asInt32 = item->getVal(); - debugSerial<itemVal->valueint); - debugSerial<itemVal->valueint); - debugSerial<