diff --git a/lighthub/colorchannel.cpp b/lighthub/colorchannel.cpp new file mode 100644 index 0000000..e5170d8 --- /dev/null +++ b/lighthub/colorchannel.cpp @@ -0,0 +1,86 @@ +#include "colorchannel.h" +#include "Arduino.h" +#include "options.h" +#include "Streaming.h" + +#include "item.h" +#include "main.h" + + +int out_dmx::Ctrl(itemCmd cmd, char* subItem) +{ + +int chActive = item->isActive(); +bool toExecute = (chActive>0); // execute if channel is active now +int suffixCode = cmd.getSuffix(); +itemCmd st(ST_HSV); + +if (!suffixCode) toExecute=true; //forced execute if no suffix +if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command recognized , but w/o correct cmd suffix - threat it as command + +switch(suffixCode) +{ +case S_NOTFOUND: + // turn on and set +toExecute = true; +case S_SET: +case S_HSV: + st.loadItem(item); + st.assignFrom(cmd); + PixelCtrl(st, subItem, toExecute); + st.saveItem(item); + + if (!suffixCode) + { + if (chActive>0 && !st.getPercents()) item->setCmd(CMD_OFF); + if (chActive==0 && st.getPercents()) item->setCmd(CMD_ON); + item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED); + } + else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED); + return 1; +/* +case S_HUE: + st.setH(uint16_t); + break; + +case S_SAT: + st.setS(uint8_t); + break; +*/ +case S_CMD: + item->setCmd(cmd.getCmd()); + switch (cmd.getCmd()) + { + case CMD_ON: + //retrive stored values + if (st.loadItem(item)) + { + if (st.param.aslong && (st.param.vSendStatus(SEND_COMMAND | SEND_PARAMETERS ); + return 1; + + case CMD_OFF: + st.Percents(0); + PixelCtrl(st, subItem, true); + item->SendStatus(SEND_COMMAND); + return 1; + } //switch cmd +} //switch suffix + +debugSerial< +#include + +class colorChannel : public abstractOut { +public: + + colorChannel(Item * _item):abstractOut(_item){}; + int Ctrl(itemCmd cmd, char* subItem=NULL) override; + virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true ) =0; + +protected: +}; diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 0f3690d..90a33f6 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -45,6 +45,7 @@ e-mail anklimov@gmail.com #include "modules/out_motor.h" #include "modules/out_modbus.h" #include "modules/out_dmx.h" +#include "modules/out_pwm.h" short modbusBusy = 0; extern aJsonObject *pollingItem; @@ -124,9 +125,14 @@ void Item::Parse() { itemExt = aJson.getArrayItem(itemArr, I_EXT); switch (itemType) { + case CH_PWM: + driver = new out_pwm (this); + break; + #ifndef DMX_DISABLE case CH_RGBW: case CH_RGB: + case CH_DIMMER: driver = new out_dmx (this); // debugSerial<isActive(); -bool toExecute = (chActive>0); // execute if channel is active now -int suffixCode = cmd.getSuffix(); -itemCmd st(ST_HSV); - -if (!suffixCode) toExecute=true; //forced execute if no suffix -if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command recognized , but w/o correct cmd suffix - threat it as command - -switch(suffixCode) -{ -case S_NOTFOUND: - // turn on and set -toExecute = true; -case S_SET: -case S_HSV: - st.loadItem(item); - st.assignFrom(cmd); - if (toExecute) PixelCtrl(st); - st.saveItem(item); - - if (!suffixCode) - { - if (chActive>0 && !st.getPercents()) item->setCmd(CMD_OFF); - if (chActive==0 && st.getPercents()) item->setCmd(CMD_ON); - item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED); - } - else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED); - return 1; -/* -case S_HUE: - st.setH(uint16_t); - break; - -case S_SAT: - st.setS(uint8_t); - break; -*/ -case S_CMD: - item->setCmd(cmd.getCmd()); - switch (cmd.getCmd()) - { - case CMD_ON: - //retrive stored values - if (st.loadItem(item)) - { - if (st.param.aslong && (st.param.vSendStatus(SEND_COMMAND | SEND_PARAMETERS ); - return 1; - - case CMD_OFF: - st.Percents(0); - PixelCtrl(st); - item->SendStatus(SEND_COMMAND); - return 1; - } //switch cmd -} //switch suffix - -debugSerial<getVal(); //Restore old params +debugSerial<< F(" val:")<itemType; + return 0; +} + +int out_pwm::PixelCtrl(itemCmd cmd) +{ +if (!item) return 0; +int iaddr = item->getArg(0); +itemCmd st(ST_RGB); +st.assignFrom(cmd); + + switch (getChanType()) + { case CH_PWM: +// DmxWrite(iaddr + 3, cmd.getPercents255()); + break; + + default: ; + } +return 1; +} diff --git a/lighthub/modules/out_pwm.h b/lighthub/modules/out_pwm.h new file mode 100644 index 0000000..5e12b2f --- /dev/null +++ b/lighthub/modules/out_pwm.h @@ -0,0 +1,26 @@ + +#pragma once +#include "options.h" +#ifndef DMX_DISABLE + +#include +#include +#include "colorchannel.h" + +class out_dmx : public colorChannel { +public: + + out_pwm(Item * _item):colorChannel(_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, char* subItem=NULL) override; + //int PixelCtrl(itemCmd cmd) override; + int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true ) override; + +protected: +}; +#endif diff --git a/lighthub/modules/out_spiled.cpp b/lighthub/modules/out_spiled.cpp index 0fd9d9c..e6eb44d 100644 --- a/lighthub/modules/out_spiled.cpp +++ b/lighthub/modules/out_spiled.cpp @@ -109,8 +109,20 @@ int out_SPILed::getChanType() return CH_RGBW; } -int out_SPILed::PixelCtrl(itemCmd cmd, int from, int to, bool show) +int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show ); +//int out_SPILed::PixelCtrl(itemCmd cmd, int from, int to, bool show) { + +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<isActive(); @@ -196,30 +209,6 @@ case S_HSV: //st.Int(item->getVal()); //Restore old params st.loadItem(item); st.assignFrom(cmd); -/* - switch (n) //How many parameters are passed? - { - case 1: - st.v = Parameters[0]; //Volume only - if (!st.hsv_flag) - { - st.h = 0; //Filling by default - st.s = 0; - st.hsv_flag = 1; // Mark stored vals as HSV - } - break; - case 2: // Just hue and saturation - st.h = Parameters[0]; - st.s = Parameters[1]; - st.hsv_flag = 1; - break; - case 3: //complete triplet - st.h = Parameters[0]; - st.s = Parameters[1]; - st.v = Parameters[2]; - st.hsv_flag = 1; - } -*/ PixelCtrl(st,from,to,toExecute); @@ -238,24 +227,6 @@ case S_HSV: return 1; //break; -/* -case S_RGB: - st.r = Parameters[0]; - st.g = Parameters[1]; - st.b = Parameters[2]; - st.w = 0; - st.hsv_flag = 0; -PixelCtrl(&st,0,from,to,toExecute,true); -//item->setVal(st.aslong); //Store -if (!suffixCode) -{ - if (chActive>0 && !st.aslong) item->setCmd(CMD_OFF); - if (chActive==0 && st.aslong) item->setCmd(CMD_ON); - item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED); -} -else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED); -return 1; -//break; */ case S_CMD: item->setCmd(cmd.getCmd()); switch (cmd.getCmd()) @@ -268,7 +239,7 @@ case S_CMD: PixelCtrl(st.Cmd(CMD_ON),from,to); else //whole strip { - if (st.param.aslong && (st.param.vsetVal(st.getInt()); st.saveItem(item); @@ -313,4 +284,6 @@ debugSerial< #include -#ifdef ADAFRUIT_LED +#ifdef ADAFRUIT_LED #include #else #include "FastLED.h" @@ -14,7 +15,7 @@ class out_SPILed : public abstractOut { public: - out_SPILed(Item * _item):abstractOut(_item){getConfig();}; + out_SPILed(Item * _item):colorChannel(_item){getConfig();}; int Setup() override; int Poll(short cause) override; int Stop() override; @@ -22,8 +23,9 @@ 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, char* subItem=NULL) override; - int PixelCtrl(itemCmd cmd, int from =0 , int to = 1024, bool show = 1); + //int Ctrl(itemCmd cmd, char* subItem=NULL) override; + int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true ) override; + //int PixelCtrl(itemCmd cmd, int from =0 , int to = 1024, bool show = 1) override; int numLeds; int8_t pin; int ledsType; diff --git a/prepareDue.bat b/prepareDue.bat new file mode 100644 index 0000000..04fa9e5 --- /dev/null +++ b/prepareDue.bat @@ -0,0 +1 @@ +cscript //NoLogo sed.vbs "s/void USART0_Handler(void)/void USART0_Handler(void ) __attribute__((weak)); void USART0_Handler(void )/" < %HOMEPATH%\.platformio\packages\framework-arduinosam\variants\arduino_due_x\variant.cpp diff --git a/sed.vbs b/sed.vbs new file mode 100644 index 0000000..1a8dbb1 --- /dev/null +++ b/sed.vbs @@ -0,0 +1,11 @@ +Dim pat, patparts, rxp, inp +pat = WScript.Arguments(0) +patparts = Split(pat,"/") +Set rxp = new RegExp +rxp.Global = True +rxp.Multiline = False +rxp.Pattern = patparts(1) +Do While Not WScript.StdIn.AtEndOfStream + inp = WScript.StdIn.ReadLine() + WScript.Echo rxp.Replace(inp, patparts(2)) +Loop \ No newline at end of file