From 45d925ba88e55052353414662f21a81277676583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BB=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9=20=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B5?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Wed, 25 Oct 2023 00:28:26 +0300 Subject: [PATCH] pins protection,core fixes for grp ch stat& sched --- lighthub/colorchannel.cpp | 6 +- lighthub/colorchannel.h | 2 +- lighthub/item.cpp | 120 +++++++++++++++++++++----------- lighthub/item.h | 2 +- lighthub/main.cpp | 16 +++-- lighthub/modules/out_dmx.cpp | 2 +- lighthub/modules/out_dmx.h | 2 +- lighthub/modules/out_motor.cpp | 9 ++- lighthub/modules/out_pwm.cpp | 22 ++++-- lighthub/modules/out_pwm.h | 2 +- lighthub/modules/out_relay.cpp | 5 +- lighthub/modules/out_spiled.cpp | 2 +- lighthub/modules/out_spiled.h | 2 +- 13 files changed, 126 insertions(+), 66 deletions(-) diff --git a/lighthub/colorchannel.cpp b/lighthub/colorchannel.cpp index 33edc9c..7873626 100644 --- a/lighthub/colorchannel.cpp +++ b/lighthub/colorchannel.cpp @@ -60,7 +60,7 @@ toExecute = true; case S_SET: //case S_ESET: case S_HSV: - PixelCtrl(cmd, subItem, toExecute); + PixelCtrl(cmd, subItem, toExecute, authorized); return 1; case S_CMD: //item->setCmd(cmd.getCmd()); @@ -74,13 +74,13 @@ case S_CMD: cmd.saveItem(item); item->SendStatus(FLAG_PARAMETERS | FLAG_SEND_DEFFERED); }; - PixelCtrl(cmd,subItem, true); + PixelCtrl(cmd,subItem, true, authorized); // item->SendStatus(FLAG_COMMAND | FLAG_PARAMETERS ); return 1; case CMD_OFF: cmd.param.asInt32=0; - PixelCtrl(cmd, subItem, true); + PixelCtrl(cmd, subItem, true,authorized); // item->SendStatus(FLAG_COMMAND); return 1; diff --git a/lighthub/colorchannel.h b/lighthub/colorchannel.h index d1f163c..f6dae16 100644 --- a/lighthub/colorchannel.h +++ b/lighthub/colorchannel.h @@ -16,7 +16,7 @@ public: }; int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized=false) override; int getDefaultStorageType()override; - virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true ) =0; + virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true, bool authorized = false ) =0; short getChannelAddr(short n =0); // int isActive() override; protected: diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 830f29b..ac08b4a 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -598,14 +598,12 @@ if (suffixCode == S_RAW) ic.setSuffix(suffixCode); return Ctrl(ic,subItem); } -//debugSerial<0); digGroup(itemArg,&cmd,subItem,authorized); - } - res=1; + if ((suffixCode==S_CMD) && cmd.isValue()) + { + scheduleOppositeCommand(cmd,chActive,authorized); + scheduledOppositeCommand = true; + } + } + res=1; + + // 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 ? - if ((suffixCode==S_CMD) && cmd.isValue() && (!chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized); + ///if ((suffixCode==S_CMD) && cmd.isValue() && (!chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized); debugSerial << F("CTRL: Restored from:") << t << endl; cmd.loadItemDef(this); cmd.Cmd(CMD_ON); //turning on @@ -1065,7 +1090,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized case CMD_XOFF: // individual for group members switch (t = getCmd()) { case CMD_XON: //previous command was CMD_XON ? - if ((suffixCode==S_CMD) && cmd.isValue() && (chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized); + ///if ((suffixCode==S_CMD) && cmd.isValue() && (chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized); debugSerial << F("CTRL: Turned off from:") << t << endl; cmd.Cmd(CMD_OFF); //turning Off status2Send |= FLAG_COMMAND | FLAG_SEND_IMMEDIATE; @@ -1082,7 +1107,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized { if (chActive == -1) chActive=(isActive()>0); - if ((suffixCode==S_CMD) && cmd.isValue() && (!chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized); + ///if ((suffixCode==S_CMD) && cmd.isValue() && (!chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized); if (!chActive) //if channel was'nt active before CMD_XON @@ -1109,7 +1134,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized break; case CMD_HALT: if (chActive == -1) chActive=(isActive()>0); - if ((suffixCode==S_CMD) && cmd.isValue() && (chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized); + ///if ((suffixCode==S_CMD) && cmd.isValue() && (chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized); if (chActive) //if channel was active before CMD_HALT /// HERE bug - if cmd == On but 0 = active { cmd.Cmd(CMD_OFF); @@ -1126,7 +1151,12 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized status2Send |= FLAG_SEND_IMMEDIATE; if (cmd.isChannelCommand()) status2Send |= FLAG_COMMAND; - if (cmd.isValue() || cmd.loadItem(this,FLAG_PARAMETERS)) status2Send |= FLAG_PARAMETERS; ; + if (cmd.isValue() || cmd.loadItem(this,FLAG_PARAMETERS)) status2Send |= FLAG_PARAMETERS; + + if (scheduledOppositeCommand) status2Send &=~FLAG_PARAMETERS; + + // UPDATE internal variables for GROUP + if (status2Send) cmd.saveItem(this,status2Send); } // end GROUP else @@ -1156,7 +1186,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized ///// return 0; } } - + bool oppositeCommandToBeSchedulled = (suffixCode==S_CMD) && allowRecursion && cmd.isValue(); // Commands for NON GROUP //threating Restore, XOFF (special conditional commands)/ convert to ON, OFF and SET values switch (cmd.getCmd()) { @@ -1164,8 +1194,8 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized case CMD_RESTORE: // individual for group members switch (t = getCmd()) { case CMD_HALT: //previous command was HALT ? - if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule - scheduleOppositeCommand(cmd,authorized); + // if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue()) //invoked not as group part, delayed, non Active or re-schedule + // scheduleOppositeCommand(cmd,chActive,authorized); debugSerial << F("CTRL: Restored from:") << t << endl; cmd.loadItemDef(this); @@ -1182,8 +1212,8 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized case CMD_XOFF: // individual for group members switch (t = getCmd()) { case CMD_XON: //previous command was CMD_XON ? - if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule - scheduleOppositeCommand(cmd,authorized); + //if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue()) //invoked not as group part, delayed, non Active or re-schedule + // scheduleOppositeCommand(cmd,chActive,authorized); debugSerial << F("CTRL: Turned off from:") << t << endl; toExecute=true; cmd.Cmd(CMD_OFF); //turning Off @@ -1199,8 +1229,8 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized case CMD_XON: if (!getFlag(FLAG_DISABLED)) { - if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (!chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule - scheduleOppositeCommand(cmd,authorized); + //if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue()) //invoked not as group part, delayed, non Active or re-schedule + // scheduleOppositeCommand(cmd,chActive,authorized); if (!chActive) //if channel was'nt active before CMD_XON { @@ -1226,8 +1256,8 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized break; case CMD_HALT: - if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule - scheduleOppositeCommand(cmd,authorized); + //if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue()) //invoked not as group part, delayed, non Active or re-schedule + // scheduleOppositeCommand(cmd,chActive,authorized); if (chActive) //if channel was active before CMD_HALT { cmd.Cmd(CMD_OFF); @@ -1251,16 +1281,16 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized if (getCmd() == CMD_HALT) return 3; //Halted, ignore OFF - if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule - scheduleOppositeCommand(cmd,authorized); + //if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue()) //invoked not as group part, delayed, non Active or re-schedule + // scheduleOppositeCommand(cmd,chActive,authorized); status2Send |= FLAG_COMMAND | FLAG_SEND_IMMEDIATE; toExecute=true; break; case CMD_ON: - if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (!chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule - scheduleOppositeCommand(cmd,authorized); + //if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue()) //invoked not as group part, delayed, non Active or re-schedule + // scheduleOppositeCommand(cmd,chActive,authorized); if (!cmd.isChannelCommand()) //Command for driver, not for whole channel { @@ -1302,8 +1332,8 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized status2Send |= FLAG_FLAGS; toExecute=true; //debugSerial<setExt(0); +driverStatus = CST_UNKNOWN; + +if (isProtectedPin(pinUp)||isProtectedPin(pinDown)) {errorSerial<setExt(0); -driverStatus = CST_UNKNOWN; return 1; } @@ -116,6 +119,8 @@ if (!item->getFlag(FLAG_ACTION_IN_PROCESS)) } else return 0; } + +if (isProtectedPin(pinUp)||isProtectedPin(pinDown)) {return 0;} uint32_t motorOfftime = item->getExt(); itemCmd st; diff --git a/lighthub/modules/out_pwm.cpp b/lighthub/modules/out_pwm.cpp index 3b1e4a3..f841239 100644 --- a/lighthub/modules/out_pwm.cpp +++ b/lighthub/modules/out_pwm.cpp @@ -112,7 +112,7 @@ int out_pwm::getChanType() return 0; } -int out_pwm::PixelCtrl(itemCmd cmd, char* subItem, bool show) +int out_pwm::PixelCtrl(itemCmd cmd, char* subItem, bool show, bool authorized) { if (!item || !iaddr || !show) return 0; @@ -132,7 +132,8 @@ switch (cmd.getCmd()){ { case CH_PWM: { short k; - analogWrite(iaddr, k=cmd.getPercents255(inverse)); + if (authorized || !isProtectedPin(iaddr)) + analogWrite(iaddr, k=cmd.getPercents255(inverse)); debugSerial<setExt(0); @@ -148,6 +148,9 @@ int out_relay::Ctrl(itemCmd cmd, char* subItem, bool toExecute,bool authorized) debugSerial<