diff --git a/lighthub/abstractout.h b/lighthub/abstractout.h index e88226a..c1279db 100644 --- a/lighthub/abstractout.h +++ b/lighthub/abstractout.h @@ -8,7 +8,7 @@ class chPersistent {}; class abstractOut : public abstractCh{ public: abstractOut(Item * _item):abstractCh(){item=_item;}; - virtual int Ctrl(itemCmd cmd, int suffixCode=0, char* subItem=NULL) =0; + virtual int Ctrl(itemCmd cmd, char* subItem=NULL) =0; virtual int isActive(){return 0;}; virtual int getDefaultOnVal(){return 100;}; virtual int getChanType(){return 0;} diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 64320fc..0f3690d 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -44,6 +44,7 @@ e-mail anklimov@gmail.com #include "modules/out_ac.h" #include "modules/out_motor.h" #include "modules/out_modbus.h" +#include "modules/out_dmx.h" short modbusBusy = 0; extern aJsonObject *pollingItem; @@ -123,6 +124,13 @@ void Item::Parse() { itemExt = aJson.getArrayItem(itemArr, I_EXT); switch (itemType) { +#ifndef DMX_DISABLE + case CH_RGBW: + case CH_RGB: + driver = new out_dmx (this); + // debugSerial<0); itemCmd st; @@ -609,11 +618,13 @@ int Item::Ctrl(itemCmd cmd, int suffixCode, char* subItem) case CMD_UP: { if (itemType == CH_GROUP) break; ////bug here - short step=cmd.getCmdParam(); + + short step=0; + if (cmd.isValue()) step=cmd.getInt(); if (!step) step=DEFAULT_INC_STEP; if (cmd.getCmd() == CMD_DN) step=-step; - int cType=getChanType(); + //int cType=getChanType(); //debugSerial<<"from: h="<Ctrl(cmd.Cmd(CMD_ON), suffixCode, subItem); + res = driver->Ctrl(cmd.Cmd(CMD_ON), subItem); setCmd(CMD_XON); } else @@ -674,7 +685,7 @@ if (driver) //New style modular code case CMD_HALT: if (chActive>0) //if channel was active before CMD_HALT { - res = driver->Ctrl(cmd.Cmd(CMD_OFF), suffixCode, subItem); + res = driver->Ctrl(cmd.Cmd(CMD_OFF), subItem); setCmd(CMD_HALT); return res; } @@ -687,7 +698,7 @@ if (driver) //New style modular code case CMD_OFF: if (getCmd() != CMD_HALT) //Halted, ignore OFF { - res = driver->Ctrl(cmd.Cmd(CMD_OFF), suffixCode, subItem); + res = driver->Ctrl(cmd.Cmd(CMD_OFF), subItem); setCmd(CMD_OFF); } else @@ -697,12 +708,12 @@ if (driver) //New style modular code } break; - case CMD_NUM: - res = driver->Ctrl(st, suffixCode, subItem); + case CMD_VOID: + res = driver->Ctrl(st, subItem); break; default: //another command - res = driver->Ctrl(cmd, suffixCode, subItem); + res = driver->Ctrl(cmd, subItem); if (cmd.isCommand()) setCmd(cmd.getCmd()); } return res; @@ -719,7 +730,7 @@ switch (itemType) { if (i->type == aJson_String) { Item it(i->valuestring); - it.Ctrl(cmd, suffixCode,subItem); + it.Ctrl(cmd,subItem); } i = i->next; } //while @@ -833,7 +844,7 @@ bool send = isNotRetainingStatus() ; case 2: _itemCmd.setH(Parameters[0]); _itemCmd.setS(Parameters[1]); - _itemCmd.type=ST_HSV; + _itemCmd.setArgType(ST_HSV); break; case 3: _itemCmd.HSV(Parameters[0],Parameters[1],Parameters[2]); @@ -864,7 +875,7 @@ bool send = isNotRetainingStatus() ; int iaddr = getArg(); int chActive =isActive(); - itemStore st; + itemArgStore st; switch (cmd) { int t; /* @@ -939,7 +950,7 @@ bool send = isNotRetainingStatus() ; if (Par[0]>100) Par[0]=100; if (Par[0]<0) Par[0]=0; n=1; - cmd=CMD_NUM; + cmd=CMD_VOID; debugSerial<<" to v="<Ctrl(CMD_ON, n, Par, suffixCode, subItem); - res = driver->Ctrl(_itemCmd.Cmd(CMD_ON), suffixCode, subItem); + res = driver->Ctrl(_itemCmd.Cmd(CMD_ON), subItem); setCmd(CMD_XON); } else @@ -1052,7 +1063,7 @@ bool send = isNotRetainingStatus() ; case CMD_HALT: if (chActive>0) //if channel was active before CMD_HALT { - res = driver->Ctrl(_itemCmd.Cmd(CMD_OFF), suffixCode, subItem); + res = driver->Ctrl(_itemCmd.Cmd(CMD_OFF), subItem); setCmd(CMD_HALT); return res; } @@ -1065,7 +1076,7 @@ bool send = isNotRetainingStatus() ; case CMD_OFF: if (getCmd() != CMD_HALT) //Halted, ignore OFF { - res = driver->Ctrl(_itemCmd, suffixCode, subItem); + res = driver->Ctrl(_itemCmd, subItem); setCmd(CMD_OFF); } else @@ -1080,7 +1091,7 @@ bool send = isNotRetainingStatus() ; break; */ default: - res = driver->Ctrl(_itemCmd, suffixCode, subItem); + res = driver->Ctrl(_itemCmd, subItem); if (cmd) setCmd(cmd); } return res; @@ -1482,8 +1493,14 @@ bool send = isNotRetainingStatus() ; return 1; } + + + + + + int Item::isActive() { - itemStore st; + itemArgStore st; int val = 0; @@ -2106,7 +2123,7 @@ int Item::SendStatus(int sendFlags) { if (sendFlags & SEND_PARAMETERS) { // Preparing parameters payload ////////// - itemStore st; + itemArgStore st; int chanType = itemType; if (driver) chanType = driver->getChanType(); //retrive stored values diff --git a/lighthub/item.h b/lighthub/item.h index 2f6be9b..98f3f85 100644 --- a/lighthub/item.h +++ b/lighthub/item.h @@ -23,7 +23,7 @@ e-mail anklimov@gmail.com #include "itemCmd.h" #define S_NOTFOUND 0 -#define S_SETnCMD 0 +//#define S_SETnCMD 0 #define S_CMD 1 #define S_SET 2 #define S_HSV 3 @@ -33,7 +33,7 @@ e-mail anklimov@gmail.com #define S_HUE 7 #define S_SAT 8 #define S_TEMP 9 -#define S_ADDITIONAL 64 +#define S_ADDITIONAL 9 #define CH_DIMMER 0 //DMX 1 ch #define CH_RGBW 1 //DMX 4 ch @@ -103,7 +103,7 @@ class Item boolean Setup(); void Stop(); int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL); - int Ctrl(itemCmd cmd, int suffixCode=0, char* subItem=NULL); + int Ctrl(itemCmd cmd, char* subItem=NULL); int Ctrl(char * payload, char * subItem=NULL); int getArg(short n=0); diff --git a/lighthub/itemCmd.cpp b/lighthub/itemCmd.cpp index aeed57a..9770aae 100644 --- a/lighthub/itemCmd.cpp +++ b/lighthub/itemCmd.cpp @@ -15,7 +15,7 @@ int txt2cmd(char *payload) { if (!payload || !payload[0]) return cmd; // Check for command - if (*payload == '-' || (*payload >= '0' && *payload <= '9')) cmd = CMD_NUM; + if (*payload == '-' || (*payload >= '0' && *payload <= '9')) cmd = CMD_VOID; else if (*payload == '%') cmd = CMD_UP; else if (*payload == '{') cmd = CMD_JSON; else if (*payload == '#') cmd = CMD_RGB; @@ -37,14 +37,15 @@ int txt2cmd(char *payload) { return cmd; } -itemCmd::itemCmd(itemStoreType _type) +itemCmd::itemCmd(uint8_t _type, uint8_t _code) { - type=_type; + cmd.itemArgType=_type; + cmd.cmdCode=_code; } itemCmd itemCmd::setDefault() { - switch (type){ + switch (cmd.itemArgType){ case ST_FLOAT_CELSIUS: param.asfloat=20.; break; case ST_FLOAT_FARENHEIT: param.asfloat=75.; @@ -66,10 +67,10 @@ itemCmd itemCmd::setDefault() itemCmd itemCmd::setH(uint16_t h) { int par=h; - switch (type) + switch (cmd.itemArgType) { case ST_VOID: - type=ST_HSV; + cmd.itemArgType=ST_HSV; case ST_HSV: if (par>100) par=100; case ST_HSV255: @@ -83,10 +84,10 @@ itemCmd itemCmd::setH(uint16_t h) itemCmd itemCmd::setS(uint8_t s) { int par=s; - switch (type) + switch (cmd.itemArgType) { case ST_VOID: - type=ST_HSV; + cmd.itemArgType=ST_HSV; case ST_HSV: if (par>100) par=100; case ST_HSV255: @@ -99,7 +100,7 @@ itemCmd itemCmd::setS(uint8_t s) itemCmd itemCmd::incrementPercents(int16_t dif) { int par=param.v; - switch (type) + switch (cmd.itemArgType) { case ST_PERCENTS: case ST_HSV: @@ -120,7 +121,7 @@ itemCmd itemCmd::incrementPercents(int16_t dif) itemCmd itemCmd::incrementH(int16_t dif) { int par=param.h; - switch (type) + switch (cmd.itemArgType) { case ST_HSV: case ST_HSV255: @@ -135,7 +136,7 @@ return *this; itemCmd itemCmd::incrementS(int16_t dif) {int par=param.s; - switch (type) + switch (cmd.itemArgType) { case ST_PERCENTS: case ST_HSV: @@ -161,10 +162,10 @@ itemCmd itemCmd::assignFrom(itemCmd from) bool RGBW_flag = false; bool HSV255_flag = false; - switch (type){ //Destination + switch (cmd.itemArgType){ //Destination case ST_HSV: case ST_PERCENTS: - switch (from.type) + switch (from.cmd.itemArgType) { case ST_RGBW: param.w=from.param.w; @@ -172,7 +173,7 @@ itemCmd itemCmd::assignFrom(itemCmd from) param.r=from.param.r; param.g=from.param.g; param.b=from.param.b; - type=from.type; //Changing if type + cmd.itemArgType=from.cmd.itemArgType; //Changing if type break; case ST_HSV: param.h=from.param.h; @@ -191,11 +192,11 @@ itemCmd itemCmd::assignFrom(itemCmd from) param.v=map(from.param.v,0,255,0,100); break; default: - debugSerial<")<")<")<")<")<")<100) i=100; + + switch (cmd.itemArgType) + { + case ST_HSV: + case ST_PERCENTS: + param.v=i; + break; + + case ST_HSV255: + case ST_PERCENTS255: + param.v=map(i,0,100,0,255); + default: + cmd.itemArgType=ST_PERCENTS; + param.v=i; + } + return *this; } + itemCmd itemCmd::Percents255(int i) + { + if (i<0) i=0; + if (i>255) i=255; + + switch (cmd.itemArgType) + { + case ST_HSV: + case ST_PERCENTS: + param.v=map(i,0,255,0,100); + break; + + case ST_HSV255: + case ST_PERCENTS255: + param.v=i;; + default: + cmd.itemArgType=ST_PERCENTS255; + param.v=i; + } + + return *this; + } + itemCmd itemCmd::Int(int32_t i) { - type=ST_INT32; + cmd.itemArgType=ST_INT32; param.asInt32=i; return *this; } @@ -406,7 +446,7 @@ itemCmd itemCmd::Int(int32_t i) itemCmd itemCmd::HSV(uint16_t h, uint8_t s, uint8_t v) { - type=ST_HSV; + cmd.itemArgType=ST_HSV; param.h=h; param.s=s; param.v=v; @@ -416,7 +456,7 @@ itemCmd itemCmd::HSV(uint16_t h, uint8_t s, uint8_t v) itemCmd itemCmd::Int(uint32_t i) { - type=ST_UINT32; + cmd.itemArgType=ST_UINT32; param.asUint32=i; return *this; } @@ -424,29 +464,42 @@ itemCmd itemCmd::Int(uint32_t i) itemCmd itemCmd::Cmd(uint8_t i) { - type=ST_COMMAND; - param.cmd_code=i; + // cmd.itemArgType=ST_COMMAND; + cmd.cmdCode=i; return *this; } -bool itemCmd::loadItem(Item * item) +uint8_t itemCmd::getSuffix() +{ + return cmd.suffixCode; +} + +itemCmd itemCmd::setSuffix(uint8_t suffix) +{ + cmd.suffixCode=suffix; + return *this; +} + +bool itemCmd::loadItem(Item * item, bool includeCommand) { if (item && item->isValid()) { param.asInt32=item->getVal(); - type=(itemStoreType) item->getSubtype(); - return (type!=ST_VOID); + cmd.itemArgType=item->getSubtype(); + if (includeCommand) cmd.cmdCode=item->getCmd(); + return (cmd.itemArgType!=ST_VOID); } return false; } -bool itemCmd::saveItem(Item * item) +bool itemCmd::saveItem(Item * item, bool includeCommand) { if (item && item->isValid()) { item->setVal(param.asInt32); - item->setSubtype(type); + item->setSubtype(cmd.itemArgType); + if (includeCommand) item->setCmd(cmd.cmdCode); return true; } return false; @@ -456,45 +509,56 @@ return false; char * itemCmd::toString(char * Buffer, int bufLen) { - if (!Buffer) return NULL; - switch (type) + + if (!Buffer || !bufLen) return NULL; + *Buffer=0; + char * argPtr=Buffer; + if (isCommand()) + { + int len; + strncpy_P(Buffer, commands_P[cmd.cmdCode], bufLen); + strncat(Buffer, " ", bufLen); + len=strlen(Buffer); + argPtr+=len; + bufLen-=len; + } + + switch (cmd.itemArgType) { - case ST_VOID: - return NULL; case ST_PERCENTS: case ST_PERCENTS255: case ST_UINT32: - snprintf(Buffer, bufLen, "%lu", param.asUint32); + snprintf(argPtr, bufLen, "%lu", param.asUint32); break; case ST_INT32: - snprintf(Buffer, bufLen, "%ld", param.asInt32); + snprintf(argPtr, bufLen, "%ld", param.asInt32); break; case ST_HSV: case ST_HSV255: - snprintf(Buffer, bufLen, "%d,%d,%d", param.h, param.s, param.v); + snprintf(argPtr, bufLen, "%d,%d,%d", param.h, param.s, param.v); break; case ST_FLOAT_CELSIUS: case ST_FLOAT_FARENHEIT: case ST_FLOAT: - snprintf(Buffer, bufLen, "%.1f", param.asfloat); + snprintf(argPtr, bufLen, "%.1f", param.asfloat); break; case ST_RGB: - snprintf(Buffer, bufLen, "%d,%d,%d", param.r, param.g, param.b); + snprintf(argPtr, bufLen, "%d,%d,%d", param.r, param.g, param.b); break; case ST_RGBW: - snprintf(Buffer, bufLen, "%d,%d,%d,%d", param.r, param.g, param.b,param.w); + snprintf(argPtr, bufLen, "%d,%d,%d,%d", param.r, param.g, param.b,param.w); break; case ST_STRING: - strncpy(Buffer, param.asString,bufLen); + strncpy(argPtr, param.asString,bufLen); break; - case ST_COMMAND: - strncpy_P(Buffer, commands_P[param.cmd_code], bufLen); + default: + ; } return Buffer; } diff --git a/lighthub/itemCmd.h b/lighthub/itemCmd.h index 32a0cf6..c872de5 100644 --- a/lighthub/itemCmd.h +++ b/lighthub/itemCmd.h @@ -58,7 +58,7 @@ const cmdstr commands_P[] PROGMEM = #define CMD_MASK 0xff #define FLAG_MASK 0xff00 -#define CMD_NUM 0 +#define CMD_VOID 0 #define CMD_UNKNOWN -1 #define CMD_JSON -2 //#define CMD_RGB -3 @@ -74,6 +74,7 @@ const cmdstr commands_P[] PROGMEM = int txt2cmd (char * payload); +/* enum itemStoreType { ST_VOID = 0, ST_PERCENTS = 1, @@ -88,12 +89,49 @@ ST_HSV255 = 9, ST_INT32 = 10, ST_UINT32 = 11, ST_STRING = 12, -ST_FLOAT = 13, -ST_COMMAND = 15 - +ST_FLOAT = 13//, +//ST_COMMAND = 15 }; +*/ + +#define ST_VOID 0 +#define ST_PERCENTS 1 +#define ST_TENS 2 +#define ST_HSV 3 +#define ST_FLOAT_CELSIUS 4 +#define ST_FLOAT_FARENHEIT 5 +#define ST_RGB 6 +#define ST_RGBW 7 +#define ST_PERCENTS255 8 +#define ST_HSV255 9 +#define ST_INT32 10 +#define ST_UINT32 11 +#define ST_STRING 12 +#define ST_FLOAT 13 + #pragma pack(push, 1) + +typedef union +{ + long int aslong; + int32_t asInt32; + uint32_t asUint32; + struct + { + uint8_t cmdCode; + union { + uint8_t cmdFlag; + struct + { uint8_t suffixCode:4; + uint8_t itemArgType:4; + }; + }; + uint8_t cmdEffect; + uint8_t cmdParam; + }; +} itemCmdStore; + typedef union { long int aslong; @@ -101,13 +139,7 @@ typedef union uint32_t asUint32; char* asString; float asfloat; - struct - { - uint8_t cmd_code; - uint8_t cmd_flag; - uint8_t cmd_effect; - uint8_t cmd_param; - }; + struct { uint8_t v; uint8_t s; @@ -127,19 +159,20 @@ typedef union uint8_t b; uint8_t w; }; -} itemStore; +} itemArgStore; + class Item; class itemCmd { public: - itemStoreType type; - itemStore param; + itemCmdStore cmd; + itemArgStore param; - itemCmd(itemStoreType _type=ST_VOID); + itemCmd(uint8_t _type=ST_VOID, uint8_t _code=CMD_VOID); itemCmd assignFrom(itemCmd from); - bool loadItem(Item * item); - bool saveItem(Item * item); + bool loadItem(Item * item, bool includeCommand=false ); + bool saveItem(Item * item, bool includeCommand=false); itemCmd Int(int32_t i); itemCmd Int(uint32_t i); @@ -147,7 +180,12 @@ public: itemCmd HSV(uint16_t h, uint8_t s, uint8_t v); itemCmd setH(uint16_t); itemCmd setS(uint8_t); + itemCmd setArgType(uint8_t); itemCmd Percents(int i); + itemCmd Percents255(int i); + + uint8_t getSuffix(); + itemCmd setSuffix(uint8_t suffix); itemCmd incrementPercents(int16_t); itemCmd incrementH(int16_t); @@ -156,8 +194,9 @@ public: long int getInt(); short getPercents(); short getPercents255(); - short getCmd(); - short getCmdParam(); + uint8_t getCmd(); + uint8_t getArgType(); + uint8_t getCmdParam(); char * toString(char * Buffer, int bufLen); bool isCommand(); diff --git a/lighthub/modules/out_ac.cpp b/lighthub/modules/out_ac.cpp index 7dab40b..0238d61 100644 --- a/lighthub/modules/out_ac.cpp +++ b/lighthub/modules/out_ac.cpp @@ -263,8 +263,9 @@ return INTERVAL_POLLING; }; //int out_AC::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* subItem) -int out_AC::Ctrl(itemCmd cmd, int suffixCode, char* subItem) +int out_AC::Ctrl(itemCmd cmd, char* subItem) {char s_mode[10]; + int suffixCode = cmd.getSuffix(); // Some additional Subitems if (strcmp_P(subItem, LOCK_P) == 0) suffixCode = S_LOCK; else if (strcmp_P(subItem, SWING_P) == 0) suffixCode = S_SWING; diff --git a/lighthub/modules/out_ac.h b/lighthub/modules/out_ac.h index 88aa161..3f74ce0 100644 --- a/lighthub/modules/out_ac.h +++ b/lighthub/modules/out_ac.h @@ -30,7 +30,7 @@ public: int Status() override; int isActive() override; //int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override; - int Ctrl(itemCmd cmd, int suffixCode=0, char* subItem=NULL) override; + int Ctrl(itemCmd cmd, char* subItem=NULL) override; protected: void InsertData(byte data[], size_t size); diff --git a/lighthub/modules/out_dmx.cpp b/lighthub/modules/out_dmx.cpp index d246153..eb29243 100644 --- a/lighthub/modules/out_dmx.cpp +++ b/lighthub/modules/out_dmx.cpp @@ -1,5 +1,5 @@ -//#ifndef DMX_DISABLE -#ifdef XXXX +#ifndef DMX_DISABLE + #include "modules/out_dmx.h" #include "Arduino.h" #include "options.h" @@ -7,128 +7,79 @@ #include "item.h" #include "main.h" +#include "dmx.h" static int driverStatus = CST_UNKNOWN; - - - int out_dmx::Setup() { - debugSerial<getVal(); //Restore old params debugSerial<< F(" val:")<>4) == (ledsType>>6)) - return CH_RGB; - else - return CH_RGBW; + if (item) return item->itemType; + return 0; } -int out_SPILed::PixelCtrl(itemCmd cmd, int from, int to, bool show) +int out_dmx::PixelCtrl(itemCmd cmd) { +if (!item) return 0; +int iaddr = item->getArg(0); itemCmd st(ST_RGB); +st.assignFrom(cmd); -#ifdef ADAFRUIT_LED -uint32_t pixel; -#else -CRGB pixel; -#endif - - if (to>numLeds-1) to=numLeds-1; - if (from<0) from=0; - - for (int i=from;i<=to;i++) - { - switch (cmd.getCmd()) { - case CMD_ON: - - #ifdef ADAFRUIT_LED - if (!leds->getPixelColor(i)) leds->setPixelColor(i, leds->Color(255, 255, 255)); - #else - if (!leds[i].r && !leds[i].g &&!leds[i].b) leds[i] = CRGB::White; - #endif + switch (getChanType()) + { + case CH_RGBW: + DmxWrite(iaddr + 3, st.param.w); + case CH_RGB: + DmxWrite(iaddr, st.param.r); + DmxWrite(iaddr + 1, st.param.g); + DmxWrite(iaddr + 2, st.param.b); break; - - case CMD_OFF: - #ifdef ADAFRUIT_LED - leds->setPixelColor(i, leds->Color(0, 0, 0)); - #else - leds[i] = CRGB::Black; - #endif - - break; - default: - st.assignFrom(cmd); - - #ifdef ADAFRUIT_LED - leds->setPixelColor(i, leds->Color(st.param.r,st.param.g,st.param.b)); - #else - leds[i] = CRGB(st.param.r,st.param.g,st.param.b); - #endif - } - } //for - - - - if (show) - { - #ifdef ADAFRUIT_LED - leds->show(); - #else - FastLED.show(); - #endif - - debugSerial<isActive(); -bool toExecute = (chActive>0); +bool toExecute = (chActive>0); // execute if channel is active now +int suffixCode = cmd.getSuffix(); itemCmd st(ST_HSV); -if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it - -int from=0, to=numLeds-1; //All LEDs on the strip by default -// retrive LEDs range from suffix -if (subItem) -{ //Just single LED to control todo - range -// debugSerial<setVal(st.getInt()); - st.saveItem(item); - item->SendStatus(SEND_COMMAND | SEND_PARAMETERS ); - } - - PixelCtrl(st,from,to); + debugSerial<SendStatus(SEND_COMMAND | SEND_PARAMETERS ); return 1; case CMD_OFF: - if (subItem) // LED range, not whole strip - PixelCtrl(st.Cmd(CMD_OFF)); - else - { st.Percents(0); - PixelCtrl(st,from,to); + PixelCtrl(st); item->SendStatus(SEND_COMMAND); - // if (send) item->publishTopic(item->itemArr->name,"OFF","/cmd"); - } return 1; - -} //switch cmd - -break; + } //switch cmd } //switch suffix + debugSerial< #include -#ifdef ADAFRUIT_LED -#include -#else -#include "FastLED.h" -#endif - class out_dmx : public abstractOut { public: - out_dmx(Item * _item):abstractOut(_item){getConfig();}; + out_dmx(Item * _item):abstractOut(_item){}; int Setup() override; int Poll(short cause) override; int Stop() override; int Status() override; int isActive() override; int getChanType() override; - int Ctrl(itemCmd cmd, int suffixCode=0, char* subItem=NULL) override; - int PixelCtrl(itemCmd cmd, int from =0 , int to = 1024, bool show = 1); - int numLeds; - int8_t pin; - int ledsType; + int Ctrl(itemCmd cmd, char* subItem=NULL) override; + int PixelCtrl(itemCmd cmd); + protected: - void getConfig(); }; #endif diff --git a/lighthub/modules/out_modbus.cpp b/lighthub/modules/out_modbus.cpp index 767b932..9c6e0de 100644 --- a/lighthub/modules/out_modbus.cpp +++ b/lighthub/modules/out_modbus.cpp @@ -338,11 +338,13 @@ int out_Modbus::getChanType() -int out_Modbus::Ctrl(itemCmd cmd, int suffixCode, char* subItem) +int out_Modbus::Ctrl(itemCmd cmd, char* subItem) { int chActive = item->isActive(); bool toExecute = (chActive>0); itemCmd st(ST_UINT32); +int suffixCode = cmd.getSuffix(); + if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it switch(suffixCode) diff --git a/lighthub/modules/out_modbus.h b/lighthub/modules/out_modbus.h index 82110b6..413844b 100644 --- a/lighthub/modules/out_modbus.h +++ b/lighthub/modules/out_modbus.h @@ -31,7 +31,7 @@ public: int Status() override; int isActive() override; int getChanType() override; - int Ctrl(itemCmd cmd, int suffixCode=0, char* subItem=NULL) override; + int Ctrl(itemCmd cmd, char* subItem=NULL) override; //int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override; protected: diff --git a/lighthub/modules/out_motor.cpp b/lighthub/modules/out_motor.cpp index 1082964..7cff267 100644 --- a/lighthub/modules/out_motor.cpp +++ b/lighthub/modules/out_motor.cpp @@ -211,10 +211,11 @@ int out_Motor::getChanType() -int out_Motor::Ctrl(itemCmd cmd, int suffixCode, char* subItem) +int out_Motor::Ctrl(itemCmd cmd, char* subItem) { int chActive = item->isActive(); bool toExecute = (chActive>0); +int suffixCode = cmd.getSuffix(); itemCmd st(ST_PERCENTS); if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it diff --git a/lighthub/modules/out_motor.h b/lighthub/modules/out_motor.h index 3197368..e9ab984 100644 --- a/lighthub/modules/out_motor.h +++ b/lighthub/modules/out_motor.h @@ -26,7 +26,7 @@ public: int isActive() override; int getChanType() override; //int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override; - int Ctrl(itemCmd cmd, int suffixCode=0, char* subItem=NULL) override; + int Ctrl(itemCmd cmd, char* subItem=NULL) override; int8_t pinUp; int8_t pinDown; diff --git a/lighthub/modules/out_spiled.cpp b/lighthub/modules/out_spiled.cpp index a7d73e2..0fd9d9c 100644 --- a/lighthub/modules/out_spiled.cpp +++ b/lighthub/modules/out_spiled.cpp @@ -89,7 +89,7 @@ return driverStatus; int out_SPILed::isActive() { -itemStore st; +itemArgStore st; st.aslong = item->getVal(); //Restore old params debugSerial<< F(" val:")<>4) == (ledsType>>6)) return CH_RGB; else @@ -167,10 +168,11 @@ CRGB pixel; return 1; } -int out_SPILed::Ctrl(itemCmd cmd, int suffixCode, char* subItem) +int out_SPILed::Ctrl(itemCmd cmd, char* subItem) { int chActive = item->isActive(); bool toExecute = (chActive>0); +int suffixCode = cmd.getSuffix(); itemCmd st(ST_HSV); if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it diff --git a/lighthub/modules/out_spiled.h b/lighthub/modules/out_spiled.h index 0a8334d..aa2737b 100644 --- a/lighthub/modules/out_spiled.h +++ b/lighthub/modules/out_spiled.h @@ -22,7 +22,7 @@ public: int isActive() override; int getChanType() override; //int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override; - int Ctrl(itemCmd cmd, int suffixCode=0, char* subItem=NULL) override; + int Ctrl(itemCmd cmd, char* subItem=NULL) override; int PixelCtrl(itemCmd cmd, int from =0 , int to = 1024, bool show = 1); int numLeds; int8_t pin; diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index d710a19..d20bb61 100644 --- a/lighthub/utils.cpp +++ b/lighthub/utils.cpp @@ -525,9 +525,8 @@ bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t m bool executeCommand(aJsonObject* cmd, int8_t toggle) { - itemCmd _itemCmd; - _itemCmd.type = ST_VOID; - return executeCommand(cmd,toggle,_itemCmd); + //itemCmd _itemCmd; + return executeCommand(cmd,toggle,itemCmd()); } bool executeCommand(aJsonObject* cmd, int8_t toggle, itemCmd _itemCmd)