mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 03:39:49 +03:00
Refactoring st3 (untested/uncomplete)
This commit is contained in:
86
lighthub/colorchannel.cpp
Normal file
86
lighthub/colorchannel.cpp
Normal file
@@ -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.v<MIN_VOLUME)) {
|
||||
st.Percents(INIT_VOLUME);
|
||||
}
|
||||
|
||||
debugSerial<<F("Restored: ")<<st.param.h<<F(",")<<st.param.s<<F(",")<<st.param.v<<endl;
|
||||
}
|
||||
else // Not restored
|
||||
{
|
||||
st.setDefault();
|
||||
debugSerial<<st.param.aslong<<F(": No stored values - default\n");
|
||||
}
|
||||
|
||||
st.saveItem(item, subItem, true);
|
||||
PixelCtrl(st);
|
||||
item->SendStatus(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<<F("Unknown cmd")<<endl;
|
||||
return 0;
|
||||
|
||||
}
|
||||
17
lighthub/colorchannel.h
Normal file
17
lighthub/colorchannel.h
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
#pragma once
|
||||
#include "options.h"
|
||||
|
||||
|
||||
#include <abstractout.h>
|
||||
#include <item.h>
|
||||
|
||||
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:
|
||||
};
|
||||
@@ -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<<F("SPILED driver created")<<endl;
|
||||
break;
|
||||
|
||||
@@ -57,7 +57,9 @@ itemCmd st(ST_RGB);
|
||||
st.assignFrom(cmd);
|
||||
|
||||
switch (getChanType())
|
||||
{
|
||||
{ case CH_DIMMER:
|
||||
DmxWrite(iaddr + 3, cmd.getPercents255());
|
||||
break;
|
||||
case CH_RGBW:
|
||||
DmxWrite(iaddr + 3, st.param.w);
|
||||
case CH_RGB:
|
||||
@@ -70,84 +72,5 @@ st.assignFrom(cmd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
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);
|
||||
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.v<MIN_VOLUME)) {
|
||||
st.Percents(INIT_VOLUME);
|
||||
}
|
||||
|
||||
debugSerial<<F("Restored: ")<<st.param.h<<F(",")<<st.param.s<<F(",")<<st.param.v<<endl;
|
||||
}
|
||||
else // Not restored
|
||||
{
|
||||
st.setDefault();
|
||||
debugSerial<<st.param.aslong<<F(": No stored values - default\n");
|
||||
}
|
||||
|
||||
st.saveItem(item);
|
||||
PixelCtrl(st);
|
||||
item->SendStatus(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<<F("Unknown cmd")<<endl;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
65
lighthub/modules/out_pwm.cpp
Normal file
65
lighthub/modules/out_pwm.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "modules/out_pwm.h"
|
||||
#include "Arduino.h"
|
||||
#include "options.h"
|
||||
#include "Streaming.h"
|
||||
|
||||
#include "item.h"
|
||||
#include "main.h"
|
||||
#include "dmx.h"
|
||||
|
||||
static int driverStatus = CST_UNKNOWN;
|
||||
|
||||
int out_pwm::Setup()
|
||||
{
|
||||
debugSerial<<F("PWM-Out Init")<<endl;
|
||||
driverStatus = CST_INITIALIZED;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_pwm::Stop()
|
||||
{
|
||||
debugSerial<<F("PWM-Out stop")<<endl;
|
||||
driverStatus = CST_UNKNOWN;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_pwm::Status()
|
||||
{
|
||||
return driverStatus;
|
||||
}
|
||||
|
||||
int out_pwm::isActive()
|
||||
{
|
||||
itemArgStore st;
|
||||
st.aslong = item->getVal(); //Restore old params
|
||||
debugSerial<< F(" val:")<<st.v<<endl;
|
||||
return st.v;
|
||||
}
|
||||
|
||||
int out_pwm::Poll(short cause)
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
|
||||
int out_pwm::getChanType()
|
||||
{
|
||||
if (item) return item->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;
|
||||
}
|
||||
26
lighthub/modules/out_pwm.h
Normal file
26
lighthub/modules/out_pwm.h
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
#pragma once
|
||||
#include "options.h"
|
||||
#ifndef DMX_DISABLE
|
||||
|
||||
#include <abstractout.h>
|
||||
#include <item.h>
|
||||
#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
|
||||
@@ -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<<F("Range:")<<subItem<<endl;
|
||||
if (sscanf(subItem,"%d-%d",&from,&to) == 1) to=from;
|
||||
}
|
||||
debugSerial<<from<<F("-")<<to<<F(" cmd=")<<cmd.getCmd()<<endl;
|
||||
|
||||
|
||||
itemCmd st(ST_RGB);
|
||||
|
||||
#ifdef ADAFRUIT_LED
|
||||
@@ -162,12 +174,13 @@ CRGB pixel;
|
||||
#else
|
||||
FastLED.show();
|
||||
#endif
|
||||
|
||||
debugSerial<<F("Show")<<endl;
|
||||
}
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
int out_SPILed::Ctrl(itemCmd cmd, char* subItem)
|
||||
{
|
||||
int chActive = item->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.v<MIN_VOLUME) /* && send */) st.Percents(INIT_VOLUME);
|
||||
if (st.param.aslong && (st.param.v<MIN_VOLUME) ) st.Percents(INIT_VOLUME);
|
||||
//item->setVal(st.getInt());
|
||||
st.saveItem(item);
|
||||
|
||||
@@ -313,4 +284,6 @@ debugSerial<<F("Unknown cmd")<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
|
||||
#pragma once
|
||||
#include "options.h"
|
||||
#include "colorchannel.h"
|
||||
#ifndef SPILED_DISABLE
|
||||
#include <abstractout.h>
|
||||
#include <item.h>
|
||||
#ifdef ADAFRUIT_LED
|
||||
|
||||
#ifdef ADAFRUIT_LED
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#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;
|
||||
|
||||
1
prepareDue.bat
Normal file
1
prepareDue.bat
Normal file
@@ -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
|
||||
11
sed.vbs
Normal file
11
sed.vbs
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user