Refactored beta

+Doxigen autogenerated docs
This commit is contained in:
2020-11-19 23:47:35 +03:00
parent 9fa9e0f481
commit 7bfe7ed330
601 changed files with 70469 additions and 72 deletions

View File

@@ -20,26 +20,7 @@ int colorChannel::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
{
debugSerial<<F("clrCtr: ");
cmd.debugOut();
//int chActive = item->isActive();
//bool toExecute = (chActive>0); // execute if channel is active now
int suffixCode = cmd.getSuffix();
/*
// Since this driver working both, for single-dimmed or PWM channel and color - define storage type
uint8_t storageType;
switch (getChanType())
{
case CH_RGB:
case CH_RGBW:
storageType=ST_HSV;
break;
default:
storageType=ST_PERCENTS;
}
itemCmd st(storageType,CMD_VOID);
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)
{
@@ -56,13 +37,12 @@ case S_CMD:
{
case CMD_ON:
PixelCtrl(cmd,subItem, true);
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
// item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
return 1;
case CMD_OFF:
cmd.Percents(0);
PixelCtrl(cmd, subItem, true);
item->SendStatus(SEND_COMMAND);
// item->SendStatus(SEND_COMMAND);
return 1;
default:

View File

@@ -346,7 +346,7 @@ void Item::setVal(short n, int par) // Only store if VAL is array defined in c
void Item::setVal(long int par) // Only store if VAL is int (autogenerated or config-defined)
{
if (!itemVal || itemVal->type != aJson_Int) return;
debugSerial<<F(" Store ")<<F(" Val=")<<par<<endl;
//debugSerial<<F(" Store ")<<F(" Val=")<<par<<endl;
itemVal->valueint = par;
}
@@ -487,7 +487,7 @@ st.setSuffix(suffixCode);
while (payload && i < 3)
Par[i++] = getInt((char **) &payload);
switch(suffixCode)
switch(suffixCode)
{case S_HUE:
st.setH(Par[0]);
break;
@@ -497,10 +497,9 @@ st.setSuffix(suffixCode);
default:
switch (i) //Number of params
{
case 1: st.Percents(Par[0]);
case 1: st.Percents(Par[0]); //ToDo float
break;
case 2: st.setH(Par[0]);
st.setS(Par[0]);
case 2: st.HS(Par[0],Par[1]);
break;
case 3: st.HSV(Par[0],Par[1],Par[2]);
default:;
@@ -559,22 +558,27 @@ int Item::Ctrl(itemCmd cmd, char* subItem)
debugSerial<<F("RAM=")<<freeRam()<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItem<<F(" Suff=")<<suffixCode<<F(" Cmd=")<<cmd.getCmd()<<F(" Par=")<<cmd.toString(stringBuffer, sizeof(stringBuffer))<<endl;
if (!itemArr) return -1;
bool chActive = (isActive()>0);
bool toExecute = (chActive>0); // execute if channel is active now
if (itemType != CH_GROUP )
{
//Check if subitem is some sort of command
int subitemCmd = subitem2cmd(subItem);
if (subitemCmd && subitemCmd != getCmd())
short prevCmd = getCmd();
if (!prevCmd && chActive>0) prevCmd=CMD_ON;
if (subitemCmd && subitemCmd != prevCmd)
{
debugSerial<<F("Ignored, channel cmd=")<<getCmd()<<endl;
debugSerial<<F("Ignored, channel cmd=")<<prevCmd<<endl;
return -1;
}
}
else
// else
// Group channel
if (! operation) return -1;
// if (! operation) return -1;
bool chActive = (isActive()>0);
bool toExecute = (chActive>0); // execute if channel is active now
itemCmd st(ST_VOID,CMD_VOID);
@@ -674,19 +678,21 @@ int Item::Ctrl(itemCmd cmd, char* subItem)
{
case S_NOTFOUND: //For empty (universal) suffix - turn ON/OFF automatically
toExecute=true;
if (chActive>0 && !cmd.getPercents()) st.Cmd(CMD_OFF);
if (chActive==0 && cmd.getPercents()) st.Cmd(CMD_ON);
if (chActive>0 && !cmd.getInt()) st.Cmd(CMD_OFF);
if (chActive==0 && cmd.getInt()) st.Cmd(CMD_ON);
setCmd(st.getCmd());
SendStatus(SEND_COMMAND | SEND_DEFFERED);
// continue processing as SET
case S_SET:
if (itemType == CH_GROUP && cmd.isColor()) st.setArgType(ST_HSV);//Extend storage for group channel
st.assignFrom(cmd);
st.saveItem(this);
SendStatus(SEND_PARAMETERS | SEND_DEFFERED);
break;
case S_SAT:
if (itemType == CH_GROUP && cmd.isColor()) st.setArgType(ST_HSV);//Extend storage for group channel
if (st.setS(cmd.getS()))
{
st.saveItem(this);
@@ -695,6 +701,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem)
break;
case S_HUE:
if (itemType == CH_GROUP && cmd.isColor()) st.setArgType(ST_HSV);//Extend storage for group channel
if (st.setH(cmd.getH()))
{
st.saveItem(this);
@@ -778,7 +785,7 @@ else //Driver not found
switch (itemType) {
case CH_GROUP:
{
if (itemArg->type == aJson_Array) {
if (itemArg->type == aJson_Array && operation) {
aJsonObject *i = itemArg->child;
configLocked++;
while (i) {
@@ -832,13 +839,13 @@ switch (itemType) {
#ifndef MODBUS_DISABLE
case CH_MODBUS:
modbusDimmerSet(st.getPercents());
modbusDimmerSet(st);
break;
case CH_VC:
VacomSetFan(st.getPercents(), st.getCmd());
VacomSetFan(st);
break;
case CH_VCTEMP:
VacomSetHeat(st.getPercents(), st.getCmd());
VacomSetHeat(st);
break;
#endif
@@ -1005,14 +1012,18 @@ POLL 2101x10
*/
#ifndef MODBUS_DISABLE
int Item::modbusDimmerSet(uint16_t value)
int Item::modbusDimmerSet(itemCmd st)
{
switch (getCmd())
{
int value=st.getPercents();
int cmd=st.getCmd();
switch (cmd){
case CMD_OFF:
case CMD_HALT:
value=0;
break;
}
short numpar=0;
@@ -1041,7 +1052,18 @@ extern ModbusMaster node;
int Item::VacomSetFan(int8_t val, int8_t cmd) {
int Item::VacomSetFan(itemCmd st) {
int val=st.getPercents();
int cmd=st.getCmd();
switch (cmd){
case CMD_OFF:
case CMD_HALT:
val=0;
break;
}
uint8_t result;
int addr = getArg();
debugSerial<<F("VC#")<<addr<<F("=")<<val<<endl;
@@ -1074,9 +1096,14 @@ int Item::VacomSetFan(int8_t val, int8_t cmd) {
#define a 0.1842f
#define b -36.68f
int Item::VacomSetHeat(int8_t val, int8_t cmd) {
uint8_t result;
int addr;
///move to float todo
int Item::VacomSetHeat(itemCmd st)
{
int val=st.getPercents();
int cmd=st.getCmd();
uint8_t result;
int addr;
if (itemArg->type != aJson_String) return 0;
Item it(itemArg->valuestring);
@@ -1268,7 +1295,8 @@ boolean Item::checkModbusRetry() {
if (modbusBusy) return false;
// int cmd = getCmd();
if (getFlag(SEND_RETRY)) { // if last sending attempt of command was failed
int val = getVal();
itemCmd val(ST_VOID,CMD_VOID);
val.loadItem(this, true);
debugSerial<<F("Retrying dimmer CMD\n");
clearFlag(SEND_RETRY); // Clean retry flag
modbusDimmerSet(val);
@@ -1279,12 +1307,13 @@ return false;
boolean Item::checkVCRetry() {
if (modbusBusy) return false;
int cmd = getCmd();
//int cmd = getCmd();
if (getFlag(SEND_RETRY)) { // if last sending attempt of command was failed
int val = getVal();
itemCmd val(ST_VOID,CMD_VOID);
val.loadItem(this, true);
debugSerial<<F("Retrying VC CMD\n");
clearFlag(SEND_RETRY); // Clean retry flag
VacomSetFan(val,cmd);
VacomSetFan(val);
return true;
}
return false;
@@ -1292,12 +1321,13 @@ return false;
boolean Item::checkHeatRetry() {
if (modbusBusy) return false;
int cmd = getCmd();
//int cmd = getCmd();
if (getFlag(SEND_RETRY)) { // if last sending attempt of command was failed
int val = getVal();
itemCmd val(ST_VOID,CMD_VOID);
val.loadItem(this, true);
debugSerial<<F("Retrying VC temp CMD\n");
clearFlag(SEND_RETRY); // Clean retry flag
VacomSetHeat(val,cmd);
VacomSetHeat(val);
return true;
}
return false;

View File

@@ -132,10 +132,11 @@ class Item
protected:
//short cmd2changeActivity(int lastActivity, short defaultCmd = CMD_SET);
int VacomSetFan (int8_t val, int8_t cmd=0);
int VacomSetHeat(int8_t val, int8_t cmd=0);
int VacomSetFan (itemCmd st);
int VacomSetHeat(itemCmd st);
int modbusDimmerSet(itemCmd st);
int modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint16_t value);
int modbusDimmerSet(uint16_t value);
void mb_fail();
void Parse();
int checkModbusDimmer();

View File

@@ -88,7 +88,9 @@ itemCmd itemCmd::setDefault()
break;
case ST_FLOAT_FARENHEIT: param.asfloat=75.;
break;
case ST_HSV: param.h=100; param.s=0; param.v=100;
case ST_HSV:
case ST_HS:
param.h=100; param.s=0; param.v=100;
break;
case ST_HSV255: param.h=100; param.s=0; param.v=255;
break;
@@ -239,9 +241,10 @@ itemCmd itemCmd::assignFrom(itemCmd from)
cmd.itemArgType=from.cmd.itemArgType; //Changing if type
break;
case ST_HSV:
param.v=from.param.v;
case ST_HS:
param.h=from.param.h;
param.s=from.param.s;
param.v=from.param.v;
break;
case ST_PERCENTS:
param.v=from.param.v;
@@ -254,6 +257,9 @@ itemCmd itemCmd::assignFrom(itemCmd from)
case ST_PERCENTS255:
param.v=map(from.param.v,0,255,0,100);
break;
case ST_FLOAT:
param.v = (int) from.param.asfloat;
break;
default:
debugSerial<<F("Wrong Assignment ")<<from.cmd.itemArgType<<F("->")<<cmd.itemArgType<<endl;
}
@@ -270,10 +276,11 @@ itemCmd itemCmd::assignFrom(itemCmd from)
param.b=from.param.b;
cmd.itemArgType=from.cmd.itemArgType;
break;
case ST_HS:
param.v=map(from.param.v,0,100,0,255);
case ST_HSV:
param.h=from.param.h;
param.s=map(from.param.s,0,100,0,255);
param.v=map(from.param.v,0,100,0,255);
break;
case ST_PERCENTS:
param.v=map(from.param.v,0,100,0,255);
@@ -334,7 +341,7 @@ itemCmd itemCmd::assignFrom(itemCmd from)
param.w=map((127 - rgbSaturation) * rgbValue, 0, 127*255, 0, 255);
int rgbvLevel = map (rgbSaturation,0,127,0,255*2);
rgbValue = map(rgbValue, 0, 255, 0, rgbvLevel);
rgbSaturation = map(rgbSaturation, 0, 127, 255, 100);
rgbSaturation = map(rgbSaturation, 0, 127, 100, 255);
if (rgbValue>255) rgbValue = 255;
}
else
@@ -342,6 +349,7 @@ itemCmd itemCmd::assignFrom(itemCmd from)
rgbSaturation = map(rgbSaturation, 128, 255, 100, 255);
param.w=0;
}
debugSerial<<F("Converted S:")<<rgbSaturation<<F(" Converted V:")<<rgbValue<<endl;
}
#ifdef ADAFRUIT_LED
Adafruit_NeoPixel strip(0, 0, 0);
@@ -355,6 +363,8 @@ itemCmd itemCmd::assignFrom(itemCmd from)
param.g=rgb.g;
param.b=rgb.b;
#endif
debugSerial<<F("RGBx: ");
debugOut();
break;
}
default:
@@ -375,18 +385,25 @@ bool itemCmd::isValue()
return (cmd.itemArgType);
}
bool itemCmd::isColor()
{
return (cmd.itemArgType==ST_HS || cmd.itemArgType==ST_HSV || cmd.itemArgType==ST_HSV255 || cmd.itemArgType==ST_RGB || cmd.itemArgType==ST_RGBW);
}
long int itemCmd::getInt()
{
switch (cmd.itemArgType) {
case ST_INT32:
case ST_PERCENTS:
case ST_UINT32:
return param.aslong;
case ST_PERCENTS:
case ST_PERCENTS255:
case ST_HSV:
case ST_HSV255:
return param.aslong;
return param.v;
case ST_FLOAT:
case ST_FLOAT_CELSIUS:
@@ -471,11 +488,11 @@ itemCmd itemCmd::Percents(int i)
case ST_HSV255:
case ST_PERCENTS255:
param.v=map(i,0,100,0,255);
break;
default:
cmd.itemArgType=ST_PERCENTS;
param.v=i;
}
return *this;
}
@@ -493,12 +510,12 @@ itemCmd itemCmd::Percents(int i)
case ST_HSV255:
case ST_PERCENTS255:
param.v=i;;
param.v=i;
break;
default:
cmd.itemArgType=ST_PERCENTS255;
param.v=i;
}
return *this;
}
@@ -521,6 +538,16 @@ itemCmd itemCmd::HSV(uint16_t h, uint8_t s, uint8_t v)
return *this;
}
itemCmd itemCmd::HS(uint16_t h, uint8_t s)
{
cmd.itemArgType=ST_HS;
param.h=h;
param.s=s;
return *this;
}
itemCmd itemCmd::RGB(uint8_t r, uint8_t g, uint8_t b)
{
cmd.itemArgType=ST_RGB;
@@ -637,6 +664,10 @@ char * itemCmd::toString(char * Buffer, int bufLen, int sendFlags )
case ST_HSV255:
snprintf(argPtr, bufLen, "%d,%d,%d", param.h, param.s, param.v);
break;
case ST_HS:
snprintf(argPtr, bufLen, "%d,%d", param.h, param.s);
break;
case ST_FLOAT_CELSIUS:
case ST_FLOAT_FARENHEIT:

View File

@@ -99,7 +99,7 @@ ST_FLOAT = 13//,
#define ST_PERCENTS 1
#define ST_TENS 2
#define ST_HSV 3
#define ST_HSVW 4
#define ST_HS 4
#define ST_FLOAT_CELSIUS 5
#define ST_FLOAT_FARENHEIT 6
#define ST_RGB 7
@@ -187,6 +187,7 @@ public:
itemCmd Int(uint32_t i);
itemCmd Cmd(uint8_t i);
itemCmd HSV(uint16_t h, uint8_t s, uint8_t v);
itemCmd HS(uint16_t h, uint8_t s);
itemCmd RGB(uint8_t r, uint8_t g, uint8_t b);
itemCmd RGBW(uint8_t r, uint8_t g, uint8_t b, uint8_t w);
bool setH(uint16_t);
@@ -214,7 +215,7 @@ public:
bool isCommand();
bool isValue();
bool isHSV();
bool isColor();
itemCmd setDefault();
itemCmd setChanType(short chanType);

View File

@@ -64,7 +64,17 @@ int out_dmx::PixelCtrl(itemCmd cmd, char* subItem, bool show)
//int out_dmx::PixelCtrl(itemCmd cmd)
{
if (!item || !show) return 0;
short cType=getChanType();
short cType=getChanType();
uint8_t storageType;
switch (cmd.getCmd()){
case CMD_OFF:
cmd.Percents(0);
break;
}
debugSerial<<F("DMX ctrl: "); cmd.debugOut();
if (cType==CH_DIMMER) //Single channel
{
@@ -72,9 +82,22 @@ if (cType==CH_DIMMER) //Single channel
return 1;
}
itemCmd st(ST_RGB,CMD_VOID);
st.assignFrom(cmd);
switch (cType)
{
case CH_RGB:
storageType=ST_RGB;
break;
case CH_RGBW:
storageType=ST_RGBW;
break;
default:
storageType=ST_PERCENTS;
}
itemCmd st(storageType,CMD_VOID);
st.assignFrom(cmd);
debugSerial<<F("Assigned:");st.debugOut();
switch (cType)
{
case CH_RGBW:

View File

@@ -119,6 +119,12 @@ if (!item || !iaddr || !show) return 0;
bool inverse = (item->getArg()<0);
short cType = getChanType();
switch (cmd.getCmd()){
case CMD_OFF:
cmd.Percents(0);
break;
}
if (cType=CH_PWM)
{ short k;
analogWrite(iaddr, k=cmd.getPercents255(inverse));