mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
UNTESTED interim commit with refactoring
This commit is contained in:
BIN
compiled/lighthub21/2020-10-27 23.51.11.jpg
Normal file
BIN
compiled/lighthub21/2020-10-27 23.51.11.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 54 KiB |
@@ -1,13 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "abstractch.h"
|
#include "abstractch.h"
|
||||||
|
#include "itemCmd.h"
|
||||||
|
|
||||||
class Item;
|
class Item;
|
||||||
class chPersistent {};
|
class chPersistent {};
|
||||||
class abstractOut : public abstractCh{
|
class abstractOut : public abstractCh{
|
||||||
public:
|
public:
|
||||||
abstractOut(Item * _item):abstractCh(){item=_item;};
|
abstractOut(Item * _item):abstractCh(){item=_item;};
|
||||||
virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) =0;
|
virtual int Ctrl(itemCmd cmd, int suffixCode=0, char* subItem=NULL) =0;
|
||||||
virtual int isActive(){return 0;};
|
virtual int isActive(){return 0;};
|
||||||
virtual int getDefaultOnVal(){return 100;};
|
virtual int getDefaultOnVal(){return 100;};
|
||||||
virtual int getChanType(){return 0;}
|
virtual int getChanType(){return 0;}
|
||||||
|
|||||||
@@ -55,134 +55,6 @@ extern lan_status lanStatus;
|
|||||||
int retrieveCode(char **psubItem);
|
int retrieveCode(char **psubItem);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
itemCmd itemCmd::Percents(int i)
|
|
||||||
{
|
|
||||||
type=ST_PERCENTS;
|
|
||||||
param.aslong=i;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemCmd itemCmd::Int(int32_t i)
|
|
||||||
{
|
|
||||||
type=ST_INT32;
|
|
||||||
param.asInt32=i;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemCmd itemCmd::Int(uint32_t i)
|
|
||||||
{
|
|
||||||
type=ST_UINT32;
|
|
||||||
param.asUint32=i;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
itemCmd itemCmd::Cmd(uint8_t i)
|
|
||||||
{
|
|
||||||
type=ST_COMMAND;
|
|
||||||
param.cmd_code=i;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
char * itemCmd::toString(char * Buffer, int bufLen)
|
|
||||||
{
|
|
||||||
if (!Buffer) return NULL;
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case ST_VOID:
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
case ST_PERCENTS:
|
|
||||||
case ST_PERCENTS255:
|
|
||||||
case ST_UINT32:
|
|
||||||
snprintf(Buffer, bufLen, "%u", param.asUint32);
|
|
||||||
break;
|
|
||||||
case ST_INT32:
|
|
||||||
snprintf(Buffer, bufLen, "%d", param.asInt32);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ST_HS:
|
|
||||||
case ST_HSV:
|
|
||||||
case ST_HSV255:
|
|
||||||
snprintf(Buffer, 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, "%d", param.asfloat);
|
|
||||||
break;
|
|
||||||
case ST_RGB:
|
|
||||||
snprintf(Buffer, bufLen, "%d,%d,%d", param.r, param.g, param.b);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ST_RGBW:
|
|
||||||
snprintf(Buffer, bufLen, "%d,%d,%d", param.r, param.g, param.b,param.w);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ST_STRING:
|
|
||||||
strncpy(Buffer, param.asString,bufLen);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ST_COMMAND:
|
|
||||||
strncpy_P(Buffer, commands_P[param.cmd_code], bufLen);
|
|
||||||
}
|
|
||||||
return Buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
int txt2cmd(char *payload) {
|
|
||||||
int cmd = CMD_UNKNOWN;
|
|
||||||
if (!payload || !payload[0]) return cmd;
|
|
||||||
|
|
||||||
// Check for command
|
|
||||||
if (*payload == '-' || (*payload >= '0' && *payload <= '9')) cmd = CMD_NUM;
|
|
||||||
else if (*payload == '%') cmd = CMD_UP;
|
|
||||||
/*
|
|
||||||
else if (strcmp_P(payload, ON_P) == 0) cmd = CMD_ON;
|
|
||||||
else if (strcmp_P(payload, OFF_P) == 0) cmd = CMD_OFF;
|
|
||||||
else if (strcmp_P(payload, REST_P) == 0) cmd = CMD_RESTORE;
|
|
||||||
else if (strcmp_P(payload, TOGGLE_P) == 0) cmd = CMD_TOGGLE;
|
|
||||||
else if (strcmp_P(payload, HALT_P) == 0) cmd = CMD_HALT;
|
|
||||||
else if (strcmp_P(payload, XON_P) == 0) cmd = CMD_XON;
|
|
||||||
else if (strcmp_P(payload, XOFF_P) == 0) cmd = CMD_XOFF;
|
|
||||||
else if (strcmp_P(payload, HEAT_P) == 0) cmd = CMD_HEAT;
|
|
||||||
else if (strcmp_P(payload, COOL_P) == 0) cmd = CMD_COOL;
|
|
||||||
else if (strcmp_P(payload, AUTO_P) == 0) cmd = CMD_AUTO;
|
|
||||||
else if (strcmp_P(payload, FAN_ONLY_P) == 0) cmd = CMD_FAN;
|
|
||||||
else if (strcmp_P(payload, DRY_P) == 0) cmd = CMD_DRY;
|
|
||||||
else if (strcmp_P(payload, TRUE_P) == 0) cmd = CMD_ON;
|
|
||||||
else if (strcmp_P(payload, FALSE_P) == 0) cmd = CMD_OFF;
|
|
||||||
else if (strcmp_P(payload, ENABLED_P) == 0) cmd = CMD_ON;
|
|
||||||
else if (strcmp_P(payload, DISABLED_P) == 0) cmd = CMD_OFF;
|
|
||||||
else if (strcmp_P(payload, INCREASE_P) == 0) cmd = CMD_UP;
|
|
||||||
else if (strcmp_P(payload, DECREASE_P) == 0) cmd = CMD_DN;
|
|
||||||
else if (strcmp_P(payload, HIGH_P) == 0) cmd = CMD_HIGH;
|
|
||||||
else if (strcmp_P(payload, MED_P) == 0) cmd = CMD_MED;
|
|
||||||
else if (strcmp_P(payload, LOW_P) == 0) cmd = CMD_LOW;
|
|
||||||
*/
|
|
||||||
else if (*payload == '{') cmd = CMD_JSON;
|
|
||||||
else if (*payload == '#') cmd = CMD_RGB;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for(uint8_t i=1; i<commandsNum ;i++)
|
|
||||||
if (strcmp_P(payload, commands_P[i]) == 0)
|
|
||||||
{
|
|
||||||
// debugSerial<< i << F(" ") << pgm_read_word_near(&serialModes_P[i].mode)<< endl;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
// debugSerial<< F("Default serial mode N81 used");
|
|
||||||
// return static_cast<uint16_t> (SERIAL_8N1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
else if (strncmp_P(payload, HSV_P, strlen (HSV_P)) == 0) cmd = CMD_HSV;
|
|
||||||
else if (strncmp_P(payload, RGB_P, strlen (RGB_P)) == 0) cmd = CMD_RGB;
|
|
||||||
*/
|
|
||||||
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
int subitem2cmd(char *payload) {
|
int subitem2cmd(char *payload) {
|
||||||
int cmd = 0;
|
int cmd = 0;
|
||||||
|
|
||||||
@@ -220,6 +92,7 @@ int txt2subItem(char *payload) {
|
|||||||
else if (strcmp_P(payload, FAN_P) == 0) cmd = S_FAN;
|
else if (strcmp_P(payload, FAN_P) == 0) cmd = S_FAN;
|
||||||
else if (strcmp_P(payload, HUE_P) == 0) cmd = S_HUE;
|
else if (strcmp_P(payload, HUE_P) == 0) cmd = S_HUE;
|
||||||
else if (strcmp_P(payload, SAT_P) == 0) cmd = S_SAT;
|
else if (strcmp_P(payload, SAT_P) == 0) cmd = S_SAT;
|
||||||
|
else if (strcmp_P(payload, TEMP_P) == 0) cmd = S_TEMP;
|
||||||
/* UnUsed now
|
/* UnUsed now
|
||||||
else if (strcmp_P(payload, SETPOINT_P) == 0) cmd = S_SETPOINT;
|
else if (strcmp_P(payload, SETPOINT_P) == 0) cmd = S_SETPOINT;
|
||||||
else if (strcmp_P(payload, TEMP_P) == 0) cmd = S_TEMP;
|
else if (strcmp_P(payload, TEMP_P) == 0) cmd = S_TEMP;
|
||||||
@@ -426,6 +299,16 @@ long int Item::getVal() //Return Val if val is int or first elem of Value array
|
|||||||
} else return 0;//-2;
|
} else return 0;//-2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t Item::getSubtype()
|
||||||
|
{
|
||||||
|
if (!itemVal) return 0;//-1;
|
||||||
|
if (itemVal->type == aJson_Int) return itemVal->subtype;
|
||||||
|
else if (itemVal->type == aJson_Array) {
|
||||||
|
aJsonObject *t = aJson.getArrayItem(itemVal, 0);
|
||||||
|
if (t) return t->subtype;
|
||||||
|
else return 0;//-3;
|
||||||
|
} else return 0;//-2;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
void Item::setVal(short n, int par) // Only store if VAL is array defined in config to avoid waste of RAM
|
void Item::setVal(short n, int par) // Only store if VAL is array defined in config to avoid waste of RAM
|
||||||
{
|
{
|
||||||
@@ -445,6 +328,12 @@ void Item::setVal(long int par) // Only store if VAL is int (autogenerated or c
|
|||||||
itemVal->valueint = par;
|
itemVal->valueint = par;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Item::setSubtype(uint8_t 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;
|
||||||
|
itemVal->subtype = par;
|
||||||
|
}
|
||||||
|
|
||||||
long int Item::getExt() //Return Val if val is int or first elem of Value array
|
long int Item::getExt() //Return Val if val is int or first elem of Value array
|
||||||
{
|
{
|
||||||
@@ -643,9 +532,8 @@ short Item::cmd2changeActivity(int lastActivity, short defaultCmd)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int Ctrl(itemCmd cmd, int suffixCode, char* subItem)
|
int Item::Ctrl(itemCmd cmd, int suffixCode, char* subItem)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
char stringBuffer[16];
|
char stringBuffer[16];
|
||||||
bool operation = isNotRetainingStatus() ;
|
bool operation = isNotRetainingStatus() ;
|
||||||
|
|
||||||
@@ -659,7 +547,7 @@ int Ctrl(itemCmd cmd, int suffixCode, char* subItem)
|
|||||||
suffixCode = defaultSuffixCode;
|
suffixCode = defaultSuffixCode;
|
||||||
|
|
||||||
|
|
||||||
debugSerial<<F("RAM=")<<freeRam()<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItem<<F(" Suff=")<<suffixCode<<F(" Cmd=")<<cmd.toCmd()<<F(" Par=")<<cmd.toString(stringBuffer, sizeof(stringBuffer));
|
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));
|
||||||
if (!itemArr) return -1;
|
if (!itemArr) return -1;
|
||||||
|
|
||||||
|
|
||||||
@@ -677,12 +565,15 @@ int Ctrl(itemCmd cmd, int suffixCode, char* subItem)
|
|||||||
// Group channel
|
// Group channel
|
||||||
if (! operation) return -1;
|
if (! operation) return -1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int iaddr = getArg();
|
int iaddr = getArg();
|
||||||
bool chActive =(isActive()>0);
|
bool chActive =(isActive()>0);
|
||||||
|
|
||||||
switch (cmd.toCmd()) {
|
itemCmd st;
|
||||||
|
st.loadItem(this); //Restore previous channel state to "st"
|
||||||
|
|
||||||
|
//threating Toggle, Restore, XOFF special conditional commands/ convert to ON, OFF
|
||||||
|
|
||||||
|
switch (cmd.getCmd()) {
|
||||||
int t;
|
int t;
|
||||||
case CMD_TOGGLE:
|
case CMD_TOGGLE:
|
||||||
if (chActive) cmd.Cmd(CMD_OFF);
|
if (chActive) cmd.Cmd(CMD_OFF);
|
||||||
@@ -718,117 +609,128 @@ int Ctrl(itemCmd cmd, int suffixCode, char* subItem)
|
|||||||
case CMD_UP:
|
case CMD_UP:
|
||||||
{
|
{
|
||||||
if (itemType == CH_GROUP) break; ////bug here
|
if (itemType == CH_GROUP) break; ////bug here
|
||||||
if (!n || !Par[0]) Par[0] = DEFAULT_INC_STEP;
|
short step=cmd.getCmdParam();
|
||||||
if (cmd == CMD_DN) Par[0]=-Par[0];
|
if (!step) step=DEFAULT_INC_STEP;
|
||||||
st.aslong = getVal();
|
if (cmd.getCmd() == CMD_DN) step=-step;
|
||||||
int cType=getChanType();
|
|
||||||
|
|
||||||
debugSerial<<"from: h="<<st.h<<" s="<<st.s <<" v="<<st.v<<endl;
|
int cType=getChanType();
|
||||||
|
//debugSerial<<"from: h="<<st.h<<" s="<<st.s <<" v="<<st.v<<endl;
|
||||||
switch (suffixCode)
|
switch (suffixCode)
|
||||||
{
|
{
|
||||||
case S_NOTFOUND:
|
case S_NOTFOUND:
|
||||||
case S_SET:
|
case S_SET:
|
||||||
Par[0] += st.v;
|
st.incrementPercents(step);
|
||||||
if (Par[0]>100) Par[0]=100;
|
|
||||||
if (Par[0]<0) Par[0]=0;
|
|
||||||
n=1;
|
|
||||||
cmd=CMD_NUM;
|
|
||||||
debugSerial<<" to v="<<Par[0]<<endl;
|
|
||||||
break;
|
break;
|
||||||
case S_HUE:
|
case S_HUE:
|
||||||
|
st.incrementH(step);
|
||||||
|
break;
|
||||||
case S_SAT:
|
case S_SAT:
|
||||||
if ( cType != CH_RGB && cType != CH_RGBW && cType != CH_GROUP) return 0; //HUE and SAT only applicable for RGBx channels
|
st.incrementS(step);
|
||||||
}
|
|
||||||
|
|
||||||
if ( cType == CH_RGB || cType == CH_RGBW)
|
|
||||||
{
|
|
||||||
bool modified = false;
|
|
||||||
switch (suffixCode)
|
|
||||||
{
|
|
||||||
case S_HSV:
|
|
||||||
Par[0] += st.h;
|
|
||||||
Par[1] += st.s;
|
|
||||||
Par[2] += st.v;
|
|
||||||
modified = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case S_HUE:
|
|
||||||
Par[0] += st.h;
|
|
||||||
Par[1] = st.s;
|
|
||||||
Par[2] = st.v;
|
|
||||||
|
|
||||||
modified = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case S_SAT:
|
|
||||||
Par[1] = st.s + Par[0];
|
|
||||||
Par[0] = st.h;
|
|
||||||
Par[2] = st.v;
|
|
||||||
|
|
||||||
modified = true;
|
|
||||||
break;
|
|
||||||
} //switch suffix
|
} //switch suffix
|
||||||
|
|
||||||
if (modified)
|
} //Case UP/DOWN
|
||||||
{
|
|
||||||
if (Par[0]>365 ) Par[0]=0;
|
|
||||||
if (Par[0]<0) Par[0]=365;
|
|
||||||
if (Par[1]>100) Par[1]=100;
|
|
||||||
if (Par[1]<0) Par[1]=0;
|
|
||||||
if (Par[2]>100) Par[2]=100;
|
|
||||||
if (Par[2]<0) Par[2]=0;
|
|
||||||
|
|
||||||
n=3;
|
|
||||||
cmd=CMD_NUM;
|
|
||||||
suffixCode=S_SET;
|
|
||||||
debugSerial<<"to: h="<<Par[0]<<" s="<<Par[1] <<" v="<<Par[2]<<endl;
|
|
||||||
} // if modified
|
|
||||||
} //RGBx channel
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case CMD_NUM:
|
case CMD_NUM:
|
||||||
//if (itemType == CH_GROUP || n!=1) break;
|
//if (itemType == CH_GROUP || n!=1) break;
|
||||||
if (n!=1) break;
|
if (!cmd.isValue()) break;
|
||||||
int cType=getChanType();
|
//// if ( cType == CH_RGB || cType == CH_RGBW || cType == CH_GROUP )
|
||||||
if ( cType == CH_RGB || cType == CH_RGBW || cType == CH_GROUP )
|
|
||||||
{
|
|
||||||
st.aslong = getVal();
|
|
||||||
st.hsv_flag=1;
|
|
||||||
switch (suffixCode)
|
switch (suffixCode)
|
||||||
{
|
{ case S_SET:
|
||||||
|
case S_NOTFOUND:
|
||||||
|
st.assignFrom(cmd);
|
||||||
|
break;
|
||||||
case S_SAT:
|
case S_SAT:
|
||||||
st.s = Par[0];
|
st.setS(cmd.getInt());
|
||||||
|
st.saveItem(this);
|
||||||
Par[0] = st.h;
|
|
||||||
Par[1] = st.s;
|
|
||||||
Par[2] = st.v;
|
|
||||||
|
|
||||||
n=3;
|
|
||||||
setVal(st.aslong);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_HUE:
|
case S_HUE:
|
||||||
st.h = Par[0];
|
st.setH(cmd.getInt());
|
||||||
Par[1] = st.s;
|
st.saveItem(this);
|
||||||
Par[2] = st.v;
|
|
||||||
|
|
||||||
n=3;
|
|
||||||
setVal(st.aslong);
|
|
||||||
}
|
|
||||||
//if (itemType == CH_GROUP) break;
|
|
||||||
}
|
|
||||||
else // Non-color channel
|
|
||||||
if (suffixCode == S_SAT || suffixCode == S_HUE) return -3;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} //Switch commands
|
||||||
|
|
||||||
|
//==================
|
||||||
|
|
||||||
|
if (driver) //New style modular code
|
||||||
|
{
|
||||||
|
int res = -1;
|
||||||
|
switch (cmd.getCmd())
|
||||||
|
{
|
||||||
|
case CMD_XON:
|
||||||
|
if (!chActive>0) //if channel was'nt active before CMD_XON
|
||||||
|
{
|
||||||
|
debugSerial<<F("Turning XON\n");
|
||||||
|
res = driver->Ctrl(cmd.Cmd(CMD_ON), suffixCode, subItem);
|
||||||
|
setCmd(CMD_XON);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ //cmd = CMD_ON;
|
||||||
|
debugSerial<<F("Already Active\n");
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CMD_HALT:
|
||||||
|
if (chActive>0) //if channel was active before CMD_HALT
|
||||||
|
{
|
||||||
|
res = driver->Ctrl(cmd.Cmd(CMD_OFF), suffixCode, subItem);
|
||||||
|
setCmd(CMD_HALT);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debugSerial<<F("Already Inactive\n");
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CMD_OFF:
|
||||||
|
if (getCmd() != CMD_HALT) //Halted, ignore OFF
|
||||||
|
{
|
||||||
|
res = driver->Ctrl(cmd.Cmd(CMD_OFF), suffixCode, subItem);
|
||||||
|
setCmd(CMD_OFF);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debugSerial<<F("Already Halted\n");
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
=========
|
case CMD_NUM:
|
||||||
int chActive = item->isActive();
|
res = driver->Ctrl(st, suffixCode, subItem);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: //another command
|
||||||
|
res = driver->Ctrl(cmd, suffixCode, subItem);
|
||||||
|
if (cmd.isCommand()) setCmd(cmd.getCmd());
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
// Legacy monolite core code
|
||||||
|
//==================
|
||||||
|
switch (itemType) {
|
||||||
|
case CH_GROUP://Group
|
||||||
|
{
|
||||||
|
if (itemArg->type == aJson_Array) {
|
||||||
|
aJsonObject *i = itemArg->child;
|
||||||
|
configLocked++;
|
||||||
|
while (i) {
|
||||||
|
if (i->type == aJson_String)
|
||||||
|
{
|
||||||
|
Item it(i->valuestring);
|
||||||
|
it.Ctrl(cmd, suffixCode,subItem);
|
||||||
|
}
|
||||||
|
i = i->next;
|
||||||
|
} //while
|
||||||
|
configLocked--;
|
||||||
|
} //if
|
||||||
|
} //case
|
||||||
|
} //switch
|
||||||
|
//=========
|
||||||
|
/*
|
||||||
bool toExecute = (chActive>0);
|
bool toExecute = (chActive>0);
|
||||||
long st;
|
|
||||||
if (cmd>0 && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it
|
if (cmd>0 && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it
|
||||||
|
|
||||||
|
|
||||||
@@ -919,6 +821,27 @@ bool send = isNotRetainingStatus() ;
|
|||||||
}
|
}
|
||||||
debugSerial<<F(")")<<endl;
|
debugSerial<<F(")")<<endl;
|
||||||
|
|
||||||
|
//======================//
|
||||||
|
itemCmd _itemCmd;
|
||||||
|
switch (n) {
|
||||||
|
case 0:
|
||||||
|
_itemCmd.Cmd(cmd);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1: _itemCmd.Percents((uint32_t)Parameters[0]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: _itemCmd.setH(Parameters[0]);
|
||||||
|
_itemCmd.setS(Parameters[1]);
|
||||||
|
_itemCmd.type=ST_HSV;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3: _itemCmd.HSV(Parameters[0],Parameters[1],Parameters[2]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
//=============//
|
||||||
|
|
||||||
if (itemType != CH_GROUP )
|
if (itemType != CH_GROUP )
|
||||||
{
|
{
|
||||||
//Check if subitem is some sort of command
|
//Check if subitem is some sort of command
|
||||||
@@ -1077,7 +1000,8 @@ bool send = isNotRetainingStatus() ;
|
|||||||
if ( cType == CH_RGB || cType == CH_RGBW || cType == CH_GROUP )
|
if ( cType == CH_RGB || cType == CH_RGBW || cType == CH_GROUP )
|
||||||
{
|
{
|
||||||
st.aslong = getVal();
|
st.aslong = getVal();
|
||||||
st.hsv_flag=1;
|
//st.hsv_flag=1;
|
||||||
|
setSubtype(ST_HSV);
|
||||||
switch (suffixCode)
|
switch (suffixCode)
|
||||||
{
|
{
|
||||||
case S_SAT:
|
case S_SAT:
|
||||||
@@ -1115,7 +1039,8 @@ bool send = isNotRetainingStatus() ;
|
|||||||
if (!chActive>0) //if channel was'nt active before CMD_XON
|
if (!chActive>0) //if channel was'nt active before CMD_XON
|
||||||
{
|
{
|
||||||
debugSerial<<F("Turning XON\n");
|
debugSerial<<F("Turning XON\n");
|
||||||
res = driver->Ctrl(CMD_ON, n, Par, suffixCode, subItem);
|
//res = driver->Ctrl(CMD_ON, n, Par, suffixCode, subItem);
|
||||||
|
res = driver->Ctrl(_itemCmd.Cmd(CMD_ON), suffixCode, subItem);
|
||||||
setCmd(CMD_XON);
|
setCmd(CMD_XON);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1127,7 +1052,7 @@ bool send = isNotRetainingStatus() ;
|
|||||||
case CMD_HALT:
|
case CMD_HALT:
|
||||||
if (chActive>0) //if channel was active before CMD_HALT
|
if (chActive>0) //if channel was active before CMD_HALT
|
||||||
{
|
{
|
||||||
res = driver->Ctrl(CMD_OFF, n, Par, suffixCode, subItem);
|
res = driver->Ctrl(_itemCmd.Cmd(CMD_OFF), suffixCode, subItem);
|
||||||
setCmd(CMD_HALT);
|
setCmd(CMD_HALT);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -1140,7 +1065,7 @@ bool send = isNotRetainingStatus() ;
|
|||||||
case CMD_OFF:
|
case CMD_OFF:
|
||||||
if (getCmd() != CMD_HALT) //Halted, ignore OFF
|
if (getCmd() != CMD_HALT) //Halted, ignore OFF
|
||||||
{
|
{
|
||||||
res = driver->Ctrl(cmd, n, Par, suffixCode, subItem);
|
res = driver->Ctrl(_itemCmd, suffixCode, subItem);
|
||||||
setCmd(CMD_OFF);
|
setCmd(CMD_OFF);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1155,7 +1080,7 @@ bool send = isNotRetainingStatus() ;
|
|||||||
break;
|
break;
|
||||||
*/
|
*/
|
||||||
default:
|
default:
|
||||||
res = driver->Ctrl(cmd, n, Par, suffixCode, subItem);
|
res = driver->Ctrl(_itemCmd, suffixCode, subItem);
|
||||||
if (cmd) setCmd(cmd);
|
if (cmd) setCmd(cmd);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
@@ -1180,7 +1105,7 @@ bool send = isNotRetainingStatus() ;
|
|||||||
case 1:
|
case 1:
|
||||||
|
|
||||||
st.v = Par[0]; //Volume only
|
st.v = Par[0]; //Volume only
|
||||||
if (st.hsv_flag)
|
if (getSubtype()==ST_HSV || getSubtype()==ST_RGB)
|
||||||
{
|
{
|
||||||
Par[0] = st.h;
|
Par[0] = st.h;
|
||||||
Par[1] = st.s;
|
Par[1] = st.s;
|
||||||
@@ -1191,14 +1116,16 @@ bool send = isNotRetainingStatus() ;
|
|||||||
st.h = Par[0];
|
st.h = Par[0];
|
||||||
st.s = Par[1];
|
st.s = Par[1];
|
||||||
Par[2] = st.v;
|
Par[2] = st.v;
|
||||||
st.hsv_flag = 1;
|
//st.hsv_flag = 1;
|
||||||
|
setSubtype(ST_HSV);
|
||||||
n = 3;
|
n = 3;
|
||||||
break;
|
break;
|
||||||
case 3: //complete triplet
|
case 3: //complete triplet
|
||||||
st.h = Par[0];
|
st.h = Par[0];
|
||||||
st.s = Par[1];
|
st.s = Par[1];
|
||||||
st.v = Par[2];
|
st.v = Par[2];
|
||||||
st.hsv_flag = 1;
|
//st.hsv_flag = 1;
|
||||||
|
setSubtype(ST_HSV);
|
||||||
}
|
}
|
||||||
setVal(st.aslong);
|
setVal(st.aslong);
|
||||||
if (!suffixCode)
|
if (!suffixCode)
|
||||||
@@ -2191,7 +2118,8 @@ int Item::SendStatus(int sendFlags) {
|
|||||||
snprintf(valstr, sizeof(valstr), "%d,%d,%d", st.h,st.s,st.v);
|
snprintf(valstr, sizeof(valstr), "%d,%d,%d", st.h,st.s,st.v);
|
||||||
break;
|
break;
|
||||||
case CH_GROUP:
|
case CH_GROUP:
|
||||||
if (st.hsv_flag)
|
//if (st.hsv_flag)
|
||||||
|
if (getSubtype()==ST_HSV)
|
||||||
snprintf(valstr, sizeof(valstr), "%d,%d,%d", st.h,st.s,st.v);
|
snprintf(valstr, sizeof(valstr), "%d,%d,%d", st.h,st.s,st.v);
|
||||||
else
|
else
|
||||||
snprintf(valstr, sizeof(valstr), "%d", st.v);
|
snprintf(valstr, sizeof(valstr), "%d", st.v);
|
||||||
@@ -2200,7 +2128,7 @@ int Item::SendStatus(int sendFlags) {
|
|||||||
sendFlags &= ~SEND_PARAMETERS; //No need to send value for relay
|
sendFlags &= ~SEND_PARAMETERS; //No need to send value for relay
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
snprintf(valstr, sizeof(valstr), "%d", st.aslong);
|
snprintf(valstr, sizeof(valstr), "%ld", st.aslong);
|
||||||
}//itemtype
|
}//itemtype
|
||||||
}
|
}
|
||||||
if (sendFlags & SEND_COMMAND)
|
if (sendFlags & SEND_COMMAND)
|
||||||
|
|||||||
129
lighthub/item.h
129
lighthub/item.h
@@ -20,10 +20,7 @@ e-mail anklimov@gmail.com
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "abstractout.h"
|
#include "abstractout.h"
|
||||||
|
#include "itemCmd.h"
|
||||||
#define POLLING_SLOW 1
|
|
||||||
#define POLLING_FAST 2
|
|
||||||
#define POLLING_INT 3
|
|
||||||
|
|
||||||
#define S_NOTFOUND 0
|
#define S_NOTFOUND 0
|
||||||
#define S_SETnCMD 0
|
#define S_SETnCMD 0
|
||||||
@@ -35,6 +32,7 @@ e-mail anklimov@gmail.com
|
|||||||
#define S_MODE 6
|
#define S_MODE 6
|
||||||
#define S_HUE 7
|
#define S_HUE 7
|
||||||
#define S_SAT 8
|
#define S_SAT 8
|
||||||
|
#define S_TEMP 9
|
||||||
#define S_ADDITIONAL 64
|
#define S_ADDITIONAL 64
|
||||||
|
|
||||||
#define CH_DIMMER 0 //DMX 1 ch
|
#define CH_DIMMER 0 //DMX 1 ch
|
||||||
@@ -58,64 +56,14 @@ e-mail anklimov@gmail.com
|
|||||||
|
|
||||||
#define CH_WHITE 127//
|
#define CH_WHITE 127//
|
||||||
|
|
||||||
#define CMD_NUM 0
|
|
||||||
#define CMD_UNKNOWN -1
|
|
||||||
#define CMD_JSON -2
|
|
||||||
//#define CMD_RGB -3
|
|
||||||
//#define CMD_HSV -4
|
|
||||||
|
|
||||||
typedef char cmdstr[9];
|
|
||||||
|
|
||||||
const cmdstr commands_P[] PROGMEM =
|
|
||||||
{
|
|
||||||
"","ON","OFF","REST","TOGGLE","HALT","XON","XOFF","INCREASE","DECREASE",
|
|
||||||
"HEAT","COOL","AUTO","FAN_ONLY","DRY","STOP","HIGH","MEDIUM","LOW",
|
|
||||||
"TRUE","FALSE","ENABLED","DISABLED","RGB","HSV"
|
|
||||||
};
|
|
||||||
#define commandsNum sizeof(commands_P)/sizeof(cmdstr)
|
|
||||||
|
|
||||||
#define CMD_ON 1
|
|
||||||
#define CMD_OFF 2
|
|
||||||
#define CMD_RESTORE 3 //on only if was turned off by CMD_HALT
|
|
||||||
#define CMD_TOGGLE 4
|
|
||||||
#define CMD_HALT 5 //just Off
|
|
||||||
#define CMD_XON 6 //just on
|
|
||||||
#define CMD_XOFF 7 //off only if was previously turned on by CMD_XON
|
|
||||||
#define CMD_UP 8 //increase
|
|
||||||
#define CMD_DN 9 //decrease
|
|
||||||
#define CMD_HEAT 0xa
|
|
||||||
#define CMD_COOL 0xb
|
|
||||||
#define CMD_AUTO 0xc
|
|
||||||
#define CMD_FAN 0xd
|
|
||||||
#define CMD_DRY 0xe
|
|
||||||
#define CMD_STOP 0xf
|
|
||||||
#define CMD_HIGH 0x10 //AC fan leve
|
|
||||||
#define CMD_MED 0x11
|
|
||||||
#define CMD_LOW 0x12
|
|
||||||
#define CMD_ENABLED 0x13
|
|
||||||
#define CMD_DISABLED 0x14
|
|
||||||
#define CMD_TRUE 0x15
|
|
||||||
#define CMD_FALSE 0x16
|
|
||||||
#define CMD_RGB 0x17
|
|
||||||
#define CMD_HSV 0x18
|
|
||||||
//#define CMD_CURTEMP 0xf
|
|
||||||
#define CMD_MASK 0xff
|
|
||||||
#define FLAG_MASK 0xff00
|
|
||||||
|
|
||||||
|
|
||||||
#define SEND_COMMAND 0x100
|
|
||||||
#define SEND_PARAMETERS 0x200
|
|
||||||
#define SEND_RETRY 0x400
|
|
||||||
#define SEND_DEFFERED 0x800
|
|
||||||
#define ACTION_NEEDED 0x1000
|
|
||||||
#define ACTION_IN_PROCESS 0x2000
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define POLLING_SLOW 1
|
||||||
|
#define POLLING_FAST 2
|
||||||
|
#define POLLING_INT 3
|
||||||
|
|
||||||
|
|
||||||
//#define CMD_REPORT 32
|
|
||||||
|
|
||||||
#define I_TYPE 0 //Type of item
|
#define I_TYPE 0 //Type of item
|
||||||
#define I_ARG 1 //Chanel-type depended argument or array of arguments (pin, address etc)
|
#define I_ARG 1 //Chanel-type depended argument or array of arguments (pin, address etc)
|
||||||
#define I_VAL 2 //Latest preset (int or array of presets)
|
#define I_VAL 2 //Latest preset (int or array of presets)
|
||||||
@@ -140,71 +88,6 @@ extern short thermoSetCurTemp(char *name, float t);
|
|||||||
|
|
||||||
int txt2cmd (char * payload);
|
int txt2cmd (char * payload);
|
||||||
|
|
||||||
enum itemStoreType {
|
|
||||||
ST_VOID = 0,
|
|
||||||
ST_PERCENTS = 1,
|
|
||||||
ST_HS = 2,
|
|
||||||
ST_HSV = 3,
|
|
||||||
ST_FLOAT_CELSIUS= 4,
|
|
||||||
ST_FLOAT_FARENHEIT= 5,
|
|
||||||
ST_RGB = 6,
|
|
||||||
ST_RGBW = 7,
|
|
||||||
ST_PERCENTS255 = 8,
|
|
||||||
ST_HSV255 = 9,
|
|
||||||
ST_INT32 = 10,
|
|
||||||
ST_UINT32 = 11,
|
|
||||||
ST_STRING = 12,
|
|
||||||
ST_FLOAT = 13,
|
|
||||||
ST_COMMAND = 15
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
long int aslong;
|
|
||||||
int32_t asInt32;
|
|
||||||
uint32_t asUint32;
|
|
||||||
char* asString;
|
|
||||||
float asfloat;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
uint8_t cmd_code;
|
|
||||||
uint8_t cmd_flag;
|
|
||||||
uint8_t cmd_effect;
|
|
||||||
uint8_t cmd_effect_param;
|
|
||||||
};
|
|
||||||
struct
|
|
||||||
{ uint8_t v;
|
|
||||||
uint8_t s;
|
|
||||||
uint16_t h:15;
|
|
||||||
uint16_t hsv_flag:1;
|
|
||||||
};
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
uint8_t r;
|
|
||||||
uint8_t g;
|
|
||||||
uint8_t b;
|
|
||||||
uint8_t w;//:7;
|
|
||||||
// uint8_t rgb_flag:1;
|
|
||||||
};
|
|
||||||
} itemStore;
|
|
||||||
|
|
||||||
class itemCmd
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
itemStoreType type;
|
|
||||||
itemStore param;
|
|
||||||
itemCmd Percents(int i);
|
|
||||||
itemCmd Int(int32_t i);
|
|
||||||
itemCmd Int(uint32_t i);
|
|
||||||
itemCmd Cmd(uint8_t i);
|
|
||||||
char * toString(char * Buffer, int bufLen);
|
|
||||||
short toCmd();
|
|
||||||
} ;
|
|
||||||
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
class Item
|
class Item
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -226,6 +109,7 @@ class Item
|
|||||||
int getArg(short n=0);
|
int getArg(short n=0);
|
||||||
//int getVal(short n); //From VAL array. Negative if no array
|
//int getVal(short n); //From VAL array. Negative if no array
|
||||||
long int getVal(); //From int val OR array
|
long int getVal(); //From int val OR array
|
||||||
|
uint8_t getSubtype();
|
||||||
uint8_t getCmd();
|
uint8_t getCmd();
|
||||||
long int getExt(); //From int val OR array
|
long int getExt(); //From int val OR array
|
||||||
void setExt(long int par);
|
void setExt(long int par);
|
||||||
@@ -236,6 +120,7 @@ class Item
|
|||||||
void setFlag (short flag);
|
void setFlag (short flag);
|
||||||
void clearFlag (short flag);
|
void clearFlag (short flag);
|
||||||
void setVal(long int par);
|
void setVal(long int par);
|
||||||
|
void setSubtype(uint8_t par);
|
||||||
int Poll(int cause);
|
int Poll(int cause);
|
||||||
int SendStatus(int sendFlags);
|
int SendStatus(int sendFlags);
|
||||||
int isActive();
|
int isActive();
|
||||||
|
|||||||
500
lighthub/itemCmd.cpp
Normal file
500
lighthub/itemCmd.cpp
Normal file
@@ -0,0 +1,500 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include "itemCmd.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "Streaming.h"
|
||||||
|
#include "item.h"
|
||||||
|
|
||||||
|
#ifdef ADAFRUIT_LED
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#else
|
||||||
|
#include "FastLED.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int txt2cmd(char *payload) {
|
||||||
|
int cmd = CMD_UNKNOWN;
|
||||||
|
if (!payload || !payload[0]) return cmd;
|
||||||
|
|
||||||
|
// Check for command
|
||||||
|
if (*payload == '-' || (*payload >= '0' && *payload <= '9')) cmd = CMD_NUM;
|
||||||
|
else if (*payload == '%') cmd = CMD_UP;
|
||||||
|
else if (*payload == '{') cmd = CMD_JSON;
|
||||||
|
else if (*payload == '#') cmd = CMD_RGB;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(uint8_t i=1; i<commandsNum ;i++)
|
||||||
|
if (strcmp_P(payload, commands_P[i]) == 0)
|
||||||
|
{
|
||||||
|
// debugSerial<< i << F(" ") << pgm_read_word_near(&serialModes_P[i].mode)<< endl;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
else if (strncmp_P(payload, HSV_P, strlen (HSV_P)) == 0) cmd = CMD_HSV;
|
||||||
|
else if (strncmp_P(payload, RGB_P, strlen (RGB_P)) == 0) cmd = CMD_RGB;
|
||||||
|
*/
|
||||||
|
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemCmd::itemCmd(itemStoreType _type)
|
||||||
|
{
|
||||||
|
type=_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemCmd itemCmd::setDefault()
|
||||||
|
{
|
||||||
|
switch (type){
|
||||||
|
case ST_FLOAT_CELSIUS: param.asfloat=20.;
|
||||||
|
break;
|
||||||
|
case ST_FLOAT_FARENHEIT: param.asfloat=75.;
|
||||||
|
break;
|
||||||
|
case ST_HSV: param.h=100; param.s=0; param.v=100;
|
||||||
|
break;
|
||||||
|
case ST_HSV255: param.h=100; param.s=0; param.v=255;
|
||||||
|
break;
|
||||||
|
case ST_PERCENTS: param.v=100;
|
||||||
|
break;
|
||||||
|
case ST_PERCENTS255: param.v=255;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
param.asInt32=0;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemCmd itemCmd::setH(uint16_t h)
|
||||||
|
{
|
||||||
|
int par=h;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ST_VOID:
|
||||||
|
type=ST_HSV;
|
||||||
|
case ST_HSV:
|
||||||
|
if (par>100) par=100;
|
||||||
|
case ST_HSV255:
|
||||||
|
if (par>255) par=255;
|
||||||
|
if (par<0) par=0;
|
||||||
|
param.h=par;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemCmd itemCmd::setS(uint8_t s)
|
||||||
|
{
|
||||||
|
int par=s;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ST_VOID:
|
||||||
|
type=ST_HSV;
|
||||||
|
case ST_HSV:
|
||||||
|
if (par>100) par=100;
|
||||||
|
case ST_HSV255:
|
||||||
|
if (par>255) par=255;
|
||||||
|
if (par<0) par=0;
|
||||||
|
param.s=par;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemCmd itemCmd::incrementPercents(int16_t dif)
|
||||||
|
{ int par=param.v;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ST_PERCENTS:
|
||||||
|
case ST_HSV:
|
||||||
|
par+=dif;
|
||||||
|
if (par>100) par=100;
|
||||||
|
if (par<0) par=0;
|
||||||
|
break;
|
||||||
|
case ST_PERCENTS255:
|
||||||
|
case ST_HSV255:
|
||||||
|
par+=dif;
|
||||||
|
if (par>255) par=255;
|
||||||
|
if (par<0) par=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
param.v=par;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemCmd itemCmd::incrementH(int16_t dif)
|
||||||
|
{ int par=param.h;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ST_HSV:
|
||||||
|
case ST_HSV255:
|
||||||
|
par+=dif;
|
||||||
|
if (par>365) par=0;
|
||||||
|
if (par<0) par=365;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
param.h=par;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemCmd itemCmd::incrementS(int16_t dif)
|
||||||
|
{int par=param.s;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ST_PERCENTS:
|
||||||
|
case ST_HSV:
|
||||||
|
par+=dif;
|
||||||
|
if (par>100) par=100;
|
||||||
|
if (par<0) par=0;
|
||||||
|
break;
|
||||||
|
case ST_PERCENTS255:
|
||||||
|
case ST_HSV255:
|
||||||
|
par+=dif;
|
||||||
|
if (par>255) par=255;
|
||||||
|
if (par<0) par=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
param.s=par;
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
itemCmd itemCmd::assignFrom(itemCmd from)
|
||||||
|
{
|
||||||
|
bool RGBW_flag = false;
|
||||||
|
bool HSV255_flag = false;
|
||||||
|
|
||||||
|
switch (type){ //Destination
|
||||||
|
case ST_HSV:
|
||||||
|
case ST_PERCENTS:
|
||||||
|
switch (from.type)
|
||||||
|
{
|
||||||
|
case ST_RGBW:
|
||||||
|
param.w=from.param.w;
|
||||||
|
case ST_RGB:
|
||||||
|
param.r=from.param.r;
|
||||||
|
param.g=from.param.g;
|
||||||
|
param.b=from.param.b;
|
||||||
|
type=from.type; //Changing if type
|
||||||
|
break;
|
||||||
|
case ST_HSV:
|
||||||
|
param.h=from.param.h;
|
||||||
|
param.s=from.param.s;
|
||||||
|
param.v=from.param.v;
|
||||||
|
break;
|
||||||
|
case ST_PERCENTS:
|
||||||
|
param.v=from.param.v;
|
||||||
|
break;
|
||||||
|
case ST_HSV255:
|
||||||
|
param.h=from.param.h;
|
||||||
|
param.s=map(from.param.s,0,255,0,100);
|
||||||
|
param.v=map(from.param.v,0,255,0,100);
|
||||||
|
break;
|
||||||
|
case ST_PERCENTS255:
|
||||||
|
param.v=map(from.param.v,0,255,0,100);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
debugSerial<<F("Wrong Assignment ")<<from.type<<F("->")<<type<<endl;
|
||||||
|
}
|
||||||
|
case ST_HSV255:
|
||||||
|
case ST_PERCENTS255:
|
||||||
|
switch (from.type)
|
||||||
|
{
|
||||||
|
case ST_RGBW:
|
||||||
|
param.w=from.param.w;
|
||||||
|
case ST_RGB:
|
||||||
|
param.r=from.param.r;
|
||||||
|
param.g=from.param.g;
|
||||||
|
param.b=from.param.b;
|
||||||
|
type=from.type;
|
||||||
|
break;
|
||||||
|
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);
|
||||||
|
break;
|
||||||
|
case ST_HSV255:
|
||||||
|
param.h=from.param.h;
|
||||||
|
param.s=from.param.s;
|
||||||
|
param.v=from.param.v;
|
||||||
|
break;
|
||||||
|
case ST_PERCENTS255:
|
||||||
|
param.v=from.param.v;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
debugSerial<<F("Wrong Assignment ")<<from.type<<F("->")<<type<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ST_VOID:
|
||||||
|
type=from.type;
|
||||||
|
|
||||||
|
case ST_INT32:
|
||||||
|
case ST_UINT32:
|
||||||
|
case ST_FLOAT:
|
||||||
|
case ST_FLOAT_CELSIUS:
|
||||||
|
case ST_FLOAT_FARENHEIT:
|
||||||
|
param.asInt32=from.param.asInt32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ST_RGBW:
|
||||||
|
RGBW_flag=true;
|
||||||
|
case ST_RGB:
|
||||||
|
switch (from.type)
|
||||||
|
{
|
||||||
|
case ST_RGBW:
|
||||||
|
case ST_RGB:
|
||||||
|
param.asInt32=from.param.asInt32;
|
||||||
|
break;
|
||||||
|
case ST_HSV255:
|
||||||
|
HSV255_flag=true;
|
||||||
|
case ST_HSV:
|
||||||
|
{ // HSV_XX to RGB_XX translation code
|
||||||
|
int rgbSaturation;
|
||||||
|
int rgbValue;
|
||||||
|
|
||||||
|
if (HSV255_flag)
|
||||||
|
{
|
||||||
|
rgbSaturation = from.param.s;
|
||||||
|
rgbValue = from.param.v;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rgbSaturation =map(from.param.s, 0, 100, 0, 255);
|
||||||
|
rgbValue = map(from.param.v, 0, 100, 0, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RGBW_flag)
|
||||||
|
{
|
||||||
|
if (rgbSaturation < 128) { // Using white
|
||||||
|
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);
|
||||||
|
if (rgbValue>255) rgbValue = 255;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rgbSaturation = map(rgbSaturation, 128, 255, 100, 255);
|
||||||
|
param.w=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef ADAFRUIT_LED
|
||||||
|
Adafruit_NeoPixel strip(0, 0, 0);
|
||||||
|
uint32_t rgb = strip.ColorHSV(map(from.param.h, 0, 365, 0, 65535), rgbSaturation, rgbValue);
|
||||||
|
param.r=(rgb >> 16)& 0xFF;
|
||||||
|
param.g=(rgb >> 8) & 0xFF;
|
||||||
|
param.b=rgb & 0xFF;
|
||||||
|
#else
|
||||||
|
CRGB rgb = CHSV(map(from.param.h, 0, 365, 0, 255), rgbSaturation, rgbValue);
|
||||||
|
param.r=rgb.r;
|
||||||
|
param.g=rgb.g;
|
||||||
|
param.b=rgb.b;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
debugSerial<<F("Wrong Assignment ")<<from.type<<F("->")<<type<<endl;
|
||||||
|
} //Translation to RGB_XX
|
||||||
|
break;
|
||||||
|
} //Destination
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool itemCmd::isCommand()
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case ST_COMMAND:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool itemCmd::isValue()
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
|
||||||
|
case ST_COMMAND:
|
||||||
|
case ST_VOID:
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long int itemCmd::getInt()
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
|
||||||
|
case ST_INT32:
|
||||||
|
case ST_PERCENTS:
|
||||||
|
case ST_UINT32:
|
||||||
|
case ST_PERCENTS255:
|
||||||
|
return param.aslong;
|
||||||
|
|
||||||
|
case ST_FLOAT:
|
||||||
|
case ST_FLOAT_CELSIUS:
|
||||||
|
case ST_FLOAT_FARENHEIT:
|
||||||
|
return int (param.asfloat);
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
short itemCmd::getPercents()
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
|
||||||
|
case ST_PERCENTS:
|
||||||
|
case ST_HSV:
|
||||||
|
return param.v;
|
||||||
|
|
||||||
|
case ST_PERCENTS255:
|
||||||
|
case ST_HSV255:
|
||||||
|
return map(param.v,0,255,0,100);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
short itemCmd::getPercents255()
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
|
||||||
|
case ST_PERCENTS:
|
||||||
|
case ST_HSV:
|
||||||
|
return map(param.v,0,100,0,255);
|
||||||
|
|
||||||
|
case ST_PERCENTS255:
|
||||||
|
case ST_HSV255:
|
||||||
|
return param.v;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
short itemCmd::getCmd()
|
||||||
|
{
|
||||||
|
if (type==ST_COMMAND) return param.cmd_code;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
short itemCmd::getCmdParam()
|
||||||
|
{
|
||||||
|
if (type==ST_COMMAND) return param.cmd_param;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemCmd itemCmd::Percents(int i)
|
||||||
|
{
|
||||||
|
type=ST_PERCENTS;
|
||||||
|
param.aslong=i;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemCmd itemCmd::Int(int32_t i)
|
||||||
|
{
|
||||||
|
type=ST_INT32;
|
||||||
|
param.asInt32=i;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
itemCmd itemCmd::HSV(uint16_t h, uint8_t s, uint8_t v)
|
||||||
|
{
|
||||||
|
type=ST_HSV;
|
||||||
|
param.h=h;
|
||||||
|
param.s=s;
|
||||||
|
param.v=v;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemCmd itemCmd::Int(uint32_t i)
|
||||||
|
{
|
||||||
|
type=ST_UINT32;
|
||||||
|
param.asUint32=i;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
itemCmd itemCmd::Cmd(uint8_t i)
|
||||||
|
{
|
||||||
|
type=ST_COMMAND;
|
||||||
|
param.cmd_code=i;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool itemCmd::loadItem(Item * item)
|
||||||
|
{
|
||||||
|
if (item && item->isValid())
|
||||||
|
{
|
||||||
|
param.asInt32=item->getVal();
|
||||||
|
type=(itemStoreType) item->getSubtype();
|
||||||
|
return (type!=ST_VOID);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool itemCmd::saveItem(Item * item)
|
||||||
|
{
|
||||||
|
if (item && item->isValid())
|
||||||
|
{
|
||||||
|
item->setVal(param.asInt32);
|
||||||
|
item->setSubtype(type);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char * itemCmd::toString(char * Buffer, int bufLen)
|
||||||
|
{
|
||||||
|
if (!Buffer) return NULL;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ST_VOID:
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
case ST_PERCENTS:
|
||||||
|
case ST_PERCENTS255:
|
||||||
|
case ST_UINT32:
|
||||||
|
snprintf(Buffer, bufLen, "%lu", param.asUint32);
|
||||||
|
break;
|
||||||
|
case ST_INT32:
|
||||||
|
snprintf(Buffer, bufLen, "%ld", param.asInt32);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ST_HSV:
|
||||||
|
case ST_HSV255:
|
||||||
|
snprintf(Buffer, 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);
|
||||||
|
break;
|
||||||
|
case ST_RGB:
|
||||||
|
snprintf(Buffer, 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);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ST_STRING:
|
||||||
|
strncpy(Buffer, param.asString,bufLen);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ST_COMMAND:
|
||||||
|
strncpy_P(Buffer, commands_P[param.cmd_code], bufLen);
|
||||||
|
}
|
||||||
|
return Buffer;
|
||||||
|
}
|
||||||
170
lighthub/itemCmd.h
Normal file
170
lighthub/itemCmd.h
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
/* Copyright © 2017-2020 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
Homepage: http://lazyhome.ru
|
||||||
|
GIT: https://github.com/anklimov/lighthub
|
||||||
|
e-mail anklimov@gmail.com
|
||||||
|
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
typedef char cmdstr[9];
|
||||||
|
|
||||||
|
const cmdstr commands_P[] PROGMEM =
|
||||||
|
{
|
||||||
|
"","ON","OFF","REST","TOGGLE","HALT","XON","XOFF","INCREASE","DECREASE",
|
||||||
|
"HEAT","COOL","AUTO","FAN_ONLY","DRY","STOP","HIGH","MEDIUM","LOW",
|
||||||
|
"TRUE","FALSE","ENABLED","DISABLED","RGB","HSV"
|
||||||
|
};
|
||||||
|
#define commandsNum sizeof(commands_P)/sizeof(cmdstr)
|
||||||
|
|
||||||
|
#define CMD_ON 1
|
||||||
|
#define CMD_OFF 2
|
||||||
|
#define CMD_RESTORE 3 //on only if was turned off by CMD_HALT
|
||||||
|
#define CMD_TOGGLE 4
|
||||||
|
#define CMD_HALT 5 //just Off
|
||||||
|
#define CMD_XON 6 //just on
|
||||||
|
#define CMD_XOFF 7 //off only if was previously turned on by CMD_XON
|
||||||
|
#define CMD_UP 8 //increase
|
||||||
|
#define CMD_DN 9 //decrease
|
||||||
|
#define CMD_HEAT 0xa
|
||||||
|
#define CMD_COOL 0xb
|
||||||
|
#define CMD_AUTO 0xc
|
||||||
|
#define CMD_FAN 0xd
|
||||||
|
#define CMD_DRY 0xe
|
||||||
|
#define CMD_STOP 0xf
|
||||||
|
#define CMD_HIGH 0x10 //AC fan leve
|
||||||
|
#define CMD_MED 0x11
|
||||||
|
#define CMD_LOW 0x12
|
||||||
|
#define CMD_ENABLED 0x13
|
||||||
|
#define CMD_DISABLED 0x14
|
||||||
|
#define CMD_TRUE 0x15
|
||||||
|
#define CMD_FALSE 0x16
|
||||||
|
#define CMD_RGB 0x17
|
||||||
|
#define CMD_HSV 0x18
|
||||||
|
//#define CMD_CURTEMP 0xf
|
||||||
|
#define CMD_MASK 0xff
|
||||||
|
#define FLAG_MASK 0xff00
|
||||||
|
|
||||||
|
#define CMD_NUM 0
|
||||||
|
#define CMD_UNKNOWN -1
|
||||||
|
#define CMD_JSON -2
|
||||||
|
//#define CMD_RGB -3
|
||||||
|
//#define CMD_HSV -4
|
||||||
|
|
||||||
|
#define SEND_COMMAND 0x100
|
||||||
|
#define SEND_PARAMETERS 0x200
|
||||||
|
#define SEND_RETRY 0x400
|
||||||
|
#define SEND_DEFFERED 0x800
|
||||||
|
#define ACTION_NEEDED 0x1000
|
||||||
|
#define ACTION_IN_PROCESS 0x2000
|
||||||
|
|
||||||
|
|
||||||
|
int txt2cmd (char * payload);
|
||||||
|
|
||||||
|
enum itemStoreType {
|
||||||
|
ST_VOID = 0,
|
||||||
|
ST_PERCENTS = 1,
|
||||||
|
ST_TENS = 2,
|
||||||
|
ST_HSV = 3,
|
||||||
|
ST_FLOAT_CELSIUS= 4,
|
||||||
|
ST_FLOAT_FARENHEIT= 5,
|
||||||
|
ST_RGB = 6,
|
||||||
|
ST_RGBW = 7,
|
||||||
|
ST_PERCENTS255 = 8,
|
||||||
|
ST_HSV255 = 9,
|
||||||
|
ST_INT32 = 10,
|
||||||
|
ST_UINT32 = 11,
|
||||||
|
ST_STRING = 12,
|
||||||
|
ST_FLOAT = 13,
|
||||||
|
ST_COMMAND = 15
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
long int aslong;
|
||||||
|
int32_t asInt32;
|
||||||
|
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;
|
||||||
|
uint16_t h:9;
|
||||||
|
uint16_t colorTemp:7;
|
||||||
|
};
|
||||||
|
struct
|
||||||
|
{ int8_t signed_v;
|
||||||
|
int8_t signed_s;
|
||||||
|
int16_t signed_h:9;
|
||||||
|
int16_t signed_colorTemp:7;
|
||||||
|
};
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint8_t r;
|
||||||
|
uint8_t g;
|
||||||
|
uint8_t b;
|
||||||
|
uint8_t w;
|
||||||
|
};
|
||||||
|
} itemStore;
|
||||||
|
class Item;
|
||||||
|
class itemCmd
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
itemStoreType type;
|
||||||
|
itemStore param;
|
||||||
|
|
||||||
|
itemCmd(itemStoreType _type=ST_VOID);
|
||||||
|
itemCmd assignFrom(itemCmd from);
|
||||||
|
|
||||||
|
bool loadItem(Item * item);
|
||||||
|
bool saveItem(Item * item);
|
||||||
|
|
||||||
|
itemCmd Int(int32_t i);
|
||||||
|
itemCmd Int(uint32_t i);
|
||||||
|
itemCmd Cmd(uint8_t i);
|
||||||
|
itemCmd HSV(uint16_t h, uint8_t s, uint8_t v);
|
||||||
|
itemCmd setH(uint16_t);
|
||||||
|
itemCmd setS(uint8_t);
|
||||||
|
itemCmd Percents(int i);
|
||||||
|
|
||||||
|
itemCmd incrementPercents(int16_t);
|
||||||
|
itemCmd incrementH(int16_t);
|
||||||
|
itemCmd incrementS(int16_t);
|
||||||
|
|
||||||
|
long int getInt();
|
||||||
|
short getPercents();
|
||||||
|
short getPercents255();
|
||||||
|
short getCmd();
|
||||||
|
short getCmdParam();
|
||||||
|
char * toString(char * Buffer, int bufLen);
|
||||||
|
|
||||||
|
bool isCommand();
|
||||||
|
bool isValue();
|
||||||
|
bool isHSV();
|
||||||
|
|
||||||
|
itemCmd setDefault();
|
||||||
|
};
|
||||||
|
|
||||||
|
#pragma pack(pop)
|
||||||
@@ -66,6 +66,7 @@ PWM Out
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "statusled.h"
|
||||||
|
|
||||||
#ifdef WIFI_ENABLE
|
#ifdef WIFI_ENABLE
|
||||||
WiFiClient ethClient;
|
WiFiClient ethClient;
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ void out_AC::InsertData(byte data[], size_t size){
|
|||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
|
|
||||||
publishTopic(item->itemArr->name,(long)set_tmp,"/set");
|
publishTopic(item->itemArr->name,(long)set_tmp,"/set");
|
||||||
publishTopic(item->itemArr->name, (long)cur_tmp, "/temp");
|
if (cur_tmp!=255) publishTopic(item->itemArr->name, (long)cur_tmp, "/temp");
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
s_mode[0]='\0';
|
s_mode[0]='\0';
|
||||||
|
|
||||||
@@ -148,6 +148,9 @@ void out_AC::InsertData(byte data[], size_t size){
|
|||||||
else if (mode == 0x04){
|
else if (mode == 0x04){
|
||||||
strcpy_P(s_mode,DRY_P);
|
strcpy_P(s_mode,DRY_P);
|
||||||
}
|
}
|
||||||
|
else if (mode == 109){
|
||||||
|
strcpy_P(s_mode,ERROR_P);
|
||||||
|
}
|
||||||
|
|
||||||
publishTopic(item->itemArr->name, (long) mode, "/mode");
|
publishTopic(item->itemArr->name, (long) mode, "/mode");
|
||||||
|
|
||||||
@@ -259,7 +262,8 @@ delay(100);
|
|||||||
return INTERVAL_POLLING;
|
return INTERVAL_POLLING;
|
||||||
};
|
};
|
||||||
|
|
||||||
int out_AC::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* subItem)
|
//int out_AC::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* subItem)
|
||||||
|
int out_AC::Ctrl(itemCmd cmd, int suffixCode, char* subItem)
|
||||||
{char s_mode[10];
|
{char s_mode[10];
|
||||||
// Some additional Subitems
|
// Some additional Subitems
|
||||||
if (strcmp_P(subItem, LOCK_P) == 0) suffixCode = S_LOCK;
|
if (strcmp_P(subItem, LOCK_P) == 0) suffixCode = S_LOCK;
|
||||||
@@ -267,12 +271,14 @@ int out_AC::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* su
|
|||||||
else if (strcmp_P(subItem, QUIET_P) == 0) suffixCode = S_QUIET;
|
else if (strcmp_P(subItem, QUIET_P) == 0) suffixCode = S_QUIET;
|
||||||
else if (strcmp_P(subItem, RAW_P) == 0) suffixCode = S_RAW;
|
else if (strcmp_P(subItem, RAW_P) == 0) suffixCode = S_RAW;
|
||||||
|
|
||||||
|
if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it
|
||||||
|
|
||||||
//data[B_POWER] = power;
|
//data[B_POWER] = power;
|
||||||
// debugSerial<<F(".");
|
// debugSerial<<F(".");
|
||||||
switch(suffixCode)
|
switch(suffixCode)
|
||||||
{
|
{
|
||||||
case S_SET:
|
case S_SET:
|
||||||
set_tmp = Parameters[0];
|
set_tmp = cmd.getInt();
|
||||||
if (set_tmp >= 10 && set_tmp <= 30)
|
if (set_tmp >= 10 && set_tmp <= 30)
|
||||||
{
|
{
|
||||||
data[B_SET_TMP] = set_tmp -16;
|
data[B_SET_TMP] = set_tmp -16;
|
||||||
@@ -282,7 +288,7 @@ int out_AC::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* su
|
|||||||
|
|
||||||
case S_CMD:
|
case S_CMD:
|
||||||
s_mode[0]='\0';
|
s_mode[0]='\0';
|
||||||
switch (cmd)
|
switch (cmd.getCmd())
|
||||||
{
|
{
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
case CMD_XON:
|
case CMD_XON:
|
||||||
@@ -340,7 +346,7 @@ int out_AC::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* su
|
|||||||
|
|
||||||
case S_FAN:
|
case S_FAN:
|
||||||
s_mode[0]='\0';
|
s_mode[0]='\0';
|
||||||
switch (cmd)
|
switch (cmd.getCmd())
|
||||||
{
|
{
|
||||||
case CMD_AUTO:
|
case CMD_AUTO:
|
||||||
data[B_FAN_SPD] = 3;
|
data[B_FAN_SPD] = 3;
|
||||||
@@ -359,18 +365,20 @@ int out_AC::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* su
|
|||||||
strcpy_P(s_mode,LOW_P);
|
strcpy_P(s_mode,LOW_P);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (n) data[B_FAN_SPD] = Parameters[0];
|
//if (n) data[B_FAN_SPD] = Parameters[0];
|
||||||
|
data[B_FAN_SPD] = cmd.getInt();
|
||||||
//TODO - mapping digits to speed
|
//TODO - mapping digits to speed
|
||||||
}
|
}
|
||||||
publishTopic(item->itemArr->name,s_mode,"/fan");
|
publishTopic(item->itemArr->name,s_mode,"/fan");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_MODE:
|
case S_MODE:
|
||||||
data[B_MODE] = Parameters[0];
|
//data[B_MODE] = Parameters[0];
|
||||||
|
data[B_MODE] = cmd.getInt();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_LOCK:
|
case S_LOCK:
|
||||||
switch (cmd)
|
switch (cmd.getCmd())
|
||||||
{
|
{
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
data[B_LOCK_REM] = 80;
|
data[B_LOCK_REM] = 80;
|
||||||
@@ -382,7 +390,7 @@ int out_AC::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* su
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case S_SWING:
|
case S_SWING:
|
||||||
switch (cmd)
|
switch (cmd.getCmd())
|
||||||
{
|
{
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
data[B_LOCK_REM] = 3;
|
data[B_LOCK_REM] = 3;
|
||||||
@@ -391,12 +399,13 @@ int out_AC::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* su
|
|||||||
data[B_LOCK_REM] = 0;
|
data[B_LOCK_REM] = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (n) data[B_SWING] = Parameters[0];
|
//if (n) data[B_SWING] = Parameters[0];
|
||||||
|
data[B_SWING] = cmd.getInt();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_QUIET:
|
case S_QUIET:
|
||||||
switch (cmd)
|
switch (cmd.getCmd())
|
||||||
{
|
{
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
data[B_POWER] |= 8;
|
data[B_POWER] |= 8;
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ public:
|
|||||||
int Stop() override;
|
int Stop() override;
|
||||||
int Status() override;
|
int Status() override;
|
||||||
int isActive() override;
|
int isActive() override;
|
||||||
int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) 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;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void InsertData(byte data[], size_t size);
|
void InsertData(byte data[], size_t size);
|
||||||
|
|||||||
226
lighthub/modules/out_dmx.cpp
Normal file
226
lighthub/modules/out_dmx.cpp
Normal file
@@ -0,0 +1,226 @@
|
|||||||
|
//#ifndef DMX_DISABLE
|
||||||
|
#ifdef XXXX
|
||||||
|
#include "modules/out_dmx.h"
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "options.h"
|
||||||
|
#include "Streaming.h"
|
||||||
|
|
||||||
|
#include "item.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
static int driverStatus = CST_UNKNOWN;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int out_dmx::Setup()
|
||||||
|
{
|
||||||
|
|
||||||
|
debugSerial<<F("DMX-Out Init")<<endl;
|
||||||
|
driverStatus = CST_INITIALIZED;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int out_SPILed::Stop()
|
||||||
|
{
|
||||||
|
debugSerial<<F("DMX-Out stop")<<endl;
|
||||||
|
driverStatus = CST_UNKNOWN;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int out_SPILed::Status()
|
||||||
|
{
|
||||||
|
return driverStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
int out_SPILed::isActive()
|
||||||
|
{
|
||||||
|
itemStore st;
|
||||||
|
st.aslong = item->getVal(); //Restore old params
|
||||||
|
debugSerial<< F(" val:")<<st.v<<endl;
|
||||||
|
return st.v;
|
||||||
|
}
|
||||||
|
|
||||||
|
int out_SPILed::Poll(short cause)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
int out_SPILed::getChanType()
|
||||||
|
{
|
||||||
|
if ((ledsType>>4) == (ledsType>>6))
|
||||||
|
return CH_RGB;
|
||||||
|
else
|
||||||
|
return CH_RGBW;
|
||||||
|
}
|
||||||
|
|
||||||
|
int out_SPILed::PixelCtrl(itemCmd cmd, int from, int to, bool show)
|
||||||
|
{
|
||||||
|
itemCmd st(ST_RGB);
|
||||||
|
|
||||||
|
#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
|
||||||
|
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<<F("Show")<<endl;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int out_SPILed::Ctrl(itemCmd cmd, int suffixCode, char* subItem)
|
||||||
|
{
|
||||||
|
int chActive = item->isActive();
|
||||||
|
bool toExecute = (chActive>0);
|
||||||
|
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<<F("Range:")<<subItem<<endl;
|
||||||
|
if (sscanf(subItem,"%d-%d",&from,&to) == 1) to=from;
|
||||||
|
}
|
||||||
|
debugSerial<<from<<F("-")<<to<<F(" cmd=")<<cmd.getCmd()<<endl;
|
||||||
|
|
||||||
|
|
||||||
|
switch(suffixCode)
|
||||||
|
{
|
||||||
|
case S_NOTFOUND:
|
||||||
|
// turn on and set
|
||||||
|
toExecute = true;
|
||||||
|
case S_SET:
|
||||||
|
case S_HSV:
|
||||||
|
//st.Int(item->getVal()); //Restore old params
|
||||||
|
st.loadItem(item);
|
||||||
|
st.assignFrom(cmd);
|
||||||
|
|
||||||
|
|
||||||
|
PixelCtrl(st,from,to,toExecute);
|
||||||
|
|
||||||
|
if (!subItem) //Whole strip
|
||||||
|
{
|
||||||
|
//item->setVal(st.getInt()); //Store
|
||||||
|
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;
|
||||||
|
//break;
|
||||||
|
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
|
||||||
|
st.loadItem(item);
|
||||||
|
|
||||||
|
if (subItem) // LED range, not whole strip
|
||||||
|
PixelCtrl(st.Cmd(CMD_ON),from,to);
|
||||||
|
else //whole strip
|
||||||
|
{
|
||||||
|
if (st.param.aslong && (st.param.v<MIN_VOLUME) /* && send */) st.Percents(INIT_VOLUME);
|
||||||
|
//item->setVal(st.getInt());
|
||||||
|
st.saveItem(item);
|
||||||
|
|
||||||
|
if (st.getInt() ) //Stored smthng
|
||||||
|
{
|
||||||
|
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
|
||||||
|
debugSerial<<F("Restored: ")<<st.param.h<<F(",")<<st.param.s<<F(",")<<st.param.v<<endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debugSerial<<st.param.aslong<<F(": No stored values - default\n");
|
||||||
|
st.setDefault();
|
||||||
|
//st.param.hsv_flag=1; ///tyta
|
||||||
|
// Store
|
||||||
|
//item->setVal(st.getInt());
|
||||||
|
st.saveItem(item);
|
||||||
|
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
|
||||||
|
}
|
||||||
|
|
||||||
|
PixelCtrl(st,from,to);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
item->SendStatus(SEND_COMMAND);
|
||||||
|
// if (send) item->publishTopic(item->itemArr->name,"OFF","/cmd");
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
} //switch cmd
|
||||||
|
|
||||||
|
break;
|
||||||
|
} //switch suffix
|
||||||
|
debugSerial<<F("Unknown cmd")<<endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
34
lighthub/modules/out_dmx.h
Normal file
34
lighthub/modules/out_dmx.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "options.h"
|
||||||
|
//#ifndef DMX_DISABLE
|
||||||
|
#ifdef XXXX
|
||||||
|
|
||||||
|
#include <abstractout.h>
|
||||||
|
#include <item.h>
|
||||||
|
|
||||||
|
#ifdef ADAFRUIT_LED
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#else
|
||||||
|
#include "FastLED.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class out_dmx : public abstractOut {
|
||||||
|
public:
|
||||||
|
|
||||||
|
out_dmx(Item * _item):abstractOut(_item){getConfig();};
|
||||||
|
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;
|
||||||
|
protected:
|
||||||
|
void getConfig();
|
||||||
|
};
|
||||||
|
#endif
|
||||||
@@ -338,14 +338,12 @@ int out_Modbus::getChanType()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int out_Modbus::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* subItem)
|
int out_Modbus::Ctrl(itemCmd cmd, int suffixCode, char* subItem)
|
||||||
{
|
{
|
||||||
int chActive = item->isActive();
|
int chActive = item->isActive();
|
||||||
bool toExecute = (chActive>0);
|
bool toExecute = (chActive>0);
|
||||||
long st;
|
itemCmd st(ST_UINT32);
|
||||||
if (cmd>0 && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it
|
if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it
|
||||||
|
|
||||||
//item->setFlag(ACTION_NEEDED);
|
|
||||||
|
|
||||||
switch(suffixCode)
|
switch(suffixCode)
|
||||||
{
|
{
|
||||||
@@ -354,12 +352,12 @@ case S_NOTFOUND:
|
|||||||
toExecute = true;
|
toExecute = true;
|
||||||
debugSerial<<F("Forced execution");
|
debugSerial<<F("Forced execution");
|
||||||
case S_SET:
|
case S_SET:
|
||||||
if (!Parameters || n==0) return 0;
|
if (!cmd.isValue()) return 0;
|
||||||
item->setVal(st=Parameters[0]); //Store
|
//////item->setVal(st=Parameters[0]); //Store
|
||||||
if (!suffixCode)
|
if (!suffixCode)
|
||||||
{
|
{
|
||||||
if (chActive>0 && !st) item->setCmd(CMD_OFF);
|
if (chActive>0 && !st.getInt()) item->setCmd(CMD_OFF);
|
||||||
if (chActive==0 && st) item->setCmd(CMD_ON);
|
if (chActive==0 && st.getInt()) item->setCmd(CMD_ON);
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED);
|
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED);
|
||||||
// if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
// if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
||||||
}
|
}
|
||||||
@@ -369,28 +367,29 @@ case S_SET:
|
|||||||
//break;
|
//break;
|
||||||
|
|
||||||
case S_CMD:
|
case S_CMD:
|
||||||
item->setCmd(cmd);
|
//item->setCmd(cmd.getCmd());
|
||||||
switch (cmd)
|
st.loadItem(item);
|
||||||
|
switch (cmd.getCmd())
|
||||||
{
|
{
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
//retrive stored values
|
//retrive stored values
|
||||||
st = item->getVal();
|
st.loadItem(item);
|
||||||
|
|
||||||
|
|
||||||
if (st && (st<MIN_VOLUME) /* && send */) st=INIT_VOLUME;
|
if (st.getPercents() && (st.getPercents()<MIN_VOLUME) /* && send */) st.Percents(INIT_VOLUME);
|
||||||
item->setVal(st);
|
st.saveItem(item);
|
||||||
|
|
||||||
if (st) //Stored smthng
|
if (st.getPercents()) //Stored smthng
|
||||||
{
|
{
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
|
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
|
||||||
debugSerial<<F("Restored: ")<<st<<endl;
|
debugSerial<<F("Restored: ")<<st.getPercents()<<endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debugSerial<<st<<F(": No stored values - default\n");
|
debugSerial<<F(": No stored values - default\n");
|
||||||
// Store
|
// Store
|
||||||
st=100;
|
st.setDefault();
|
||||||
item->setVal(st);
|
st.saveItem(item);
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
|
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
|
||||||
}
|
}
|
||||||
// if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
// if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ public:
|
|||||||
int Status() override;
|
int Status() override;
|
||||||
int isActive() override;
|
int isActive() override;
|
||||||
int getChanType() 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(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mbPersistent * store;
|
mbPersistent * store;
|
||||||
|
|||||||
@@ -211,12 +211,12 @@ int out_Motor::getChanType()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int out_Motor::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* subItem)
|
int out_Motor::Ctrl(itemCmd cmd, int suffixCode, char* subItem)
|
||||||
{
|
{
|
||||||
int chActive = item->isActive();
|
int chActive = item->isActive();
|
||||||
bool toExecute = (chActive>0);
|
bool toExecute = (chActive>0);
|
||||||
long st;
|
itemCmd st(ST_PERCENTS);
|
||||||
if (cmd>0 && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it
|
if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it
|
||||||
|
|
||||||
item->setFlag(ACTION_NEEDED);
|
item->setFlag(ACTION_NEEDED);
|
||||||
|
|
||||||
@@ -227,12 +227,14 @@ case S_NOTFOUND:
|
|||||||
toExecute = true;
|
toExecute = true;
|
||||||
debugSerial<<F("Forced execution");
|
debugSerial<<F("Forced execution");
|
||||||
case S_SET:
|
case S_SET:
|
||||||
if (!Parameters || n==0) return 0;
|
if (!cmd.isValue()) return 0;
|
||||||
item->setVal(st=Parameters[0]); //Store
|
st.assignFrom(cmd);
|
||||||
|
//Store
|
||||||
|
st.saveItem(item);
|
||||||
if (!suffixCode)
|
if (!suffixCode)
|
||||||
{
|
{
|
||||||
if (chActive>0 && !st) item->setCmd(CMD_OFF);
|
if (chActive>0 && !st.getPercents()) item->setCmd(CMD_OFF);
|
||||||
if (chActive==0 && st) item->setCmd(CMD_ON);
|
if (chActive==0 && st.getPercents()) item->setCmd(CMD_ON);
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED);
|
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED);
|
||||||
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
||||||
}
|
}
|
||||||
@@ -242,30 +244,32 @@ case S_SET:
|
|||||||
//break;
|
//break;
|
||||||
|
|
||||||
case S_CMD:
|
case S_CMD:
|
||||||
item->setCmd(cmd);
|
item->setCmd(cmd.getCmd());
|
||||||
switch (cmd)
|
switch (cmd.getCmd())
|
||||||
{
|
{
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
//retrive stored values
|
//retrive stored values
|
||||||
st = item->getVal();
|
if (st.loadItem(item))
|
||||||
|
|
||||||
|
|
||||||
if (st && (st<MIN_VOLUME) /* && send */) st=INIT_VOLUME;
|
|
||||||
item->setVal(st);
|
|
||||||
|
|
||||||
if (st) //Stored smthng
|
|
||||||
{
|
{
|
||||||
|
if (st.getPercents() && (st.getPercents()<MIN_VOLUME) /* && send */)
|
||||||
|
{ //Volume too low
|
||||||
|
st.Percents(INIT_VOLUME);
|
||||||
|
st.saveItem(item);
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
|
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
|
||||||
debugSerial<<F("Restored: ")<<st<<endl;
|
}
|
||||||
|
debugSerial<<F("Restored: ")<<st.getPercents()<<endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debugSerial<<st<<F(": No stored values - default\n");
|
debugSerial<<F(": No stored values - default\n");
|
||||||
// Store
|
// Store
|
||||||
st=100;
|
st.setDefault();
|
||||||
item->setVal(st);
|
st.saveItem(item);
|
||||||
|
//st=100;
|
||||||
|
//item->setVal(st);
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
|
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ public:
|
|||||||
int Status() override;
|
int Status() override;
|
||||||
int isActive() override;
|
int isActive() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) 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;
|
||||||
|
|
||||||
int8_t pinUp;
|
int8_t pinUp;
|
||||||
int8_t pinDown;
|
int8_t pinDown;
|
||||||
|
|||||||
@@ -108,35 +108,22 @@ int out_SPILed::getChanType()
|
|||||||
return CH_RGBW;
|
return CH_RGBW;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_SPILed::PixelCtrl(itemStore *st, short cmd, int from, int to, bool show, bool rgb)
|
int out_SPILed::PixelCtrl(itemCmd cmd, int from, int to, bool show)
|
||||||
{
|
{
|
||||||
//debugSerial<<F("cmd: ")<<cmd<<endl;
|
itemCmd st(ST_RGB);
|
||||||
|
|
||||||
#ifdef ADAFRUIT_LED
|
#ifdef ADAFRUIT_LED
|
||||||
uint32_t pixel;
|
uint32_t pixel;
|
||||||
#else
|
#else
|
||||||
CRGB pixel;
|
CRGB pixel;
|
||||||
#endif
|
#endif
|
||||||
if (!rgb)
|
|
||||||
{
|
|
||||||
int Saturation = map(st->s, 0, 100, 0, 255);
|
|
||||||
int Value = map(st->v, 0, 100, 0, 255);
|
|
||||||
|
|
||||||
#ifdef ADAFRUIT_LED
|
|
||||||
uint16_t Hue = map(st->h, 0, 365, 0, 65535);
|
|
||||||
pixel = leds->ColorHSV(Hue, Saturation, Value);
|
|
||||||
#else
|
|
||||||
int Hue = map(st->h, 0, 365, 0, 255);
|
|
||||||
pixel = CHSV(Hue, Saturation, Value);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
debugSerial<<F("hsv: ")<<st->h<<F(",")<<st->s<<F(",")<<st->v<<endl;
|
|
||||||
}
|
|
||||||
if (to>numLeds-1) to=numLeds-1;
|
if (to>numLeds-1) to=numLeds-1;
|
||||||
if (from<0) from=0;
|
if (from<0) from=0;
|
||||||
|
|
||||||
for (int i=from;i<=to;i++)
|
for (int i=from;i<=to;i++)
|
||||||
{
|
{
|
||||||
switch (cmd) {
|
switch (cmd.getCmd()) {
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
|
|
||||||
#ifdef ADAFRUIT_LED
|
#ifdef ADAFRUIT_LED
|
||||||
@@ -144,9 +131,8 @@ CRGB pixel;
|
|||||||
#else
|
#else
|
||||||
if (!leds[i].r && !leds[i].g &&!leds[i].b) leds[i] = CRGB::White;
|
if (!leds[i].r && !leds[i].g &&!leds[i].b) leds[i] = CRGB::White;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_OFF:
|
case CMD_OFF:
|
||||||
#ifdef ADAFRUIT_LED
|
#ifdef ADAFRUIT_LED
|
||||||
leds->setPixelColor(i, leds->Color(0, 0, 0));
|
leds->setPixelColor(i, leds->Color(0, 0, 0));
|
||||||
@@ -156,26 +142,18 @@ CRGB pixel;
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (rgb)
|
st.assignFrom(cmd);
|
||||||
{
|
|
||||||
#ifdef ADAFRUIT_LED
|
|
||||||
leds->setPixelColor(i, leds->Color(st->r,st->g,st->b));
|
|
||||||
#else
|
|
||||||
leds[i] = CRGB(st->r,st->g,st->b);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef ADAFRUIT_LED
|
|
||||||
leds->setPixelColor(i, pixel);
|
|
||||||
#else
|
|
||||||
leds[i] = pixel;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#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
|
} //for
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (show)
|
if (show)
|
||||||
{
|
{
|
||||||
#ifdef ADAFRUIT_LED
|
#ifdef ADAFRUIT_LED
|
||||||
@@ -189,12 +167,12 @@ CRGB pixel;
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_SPILed::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* subItem)
|
int out_SPILed::Ctrl(itemCmd cmd, int suffixCode, char* subItem)
|
||||||
{
|
{
|
||||||
int chActive = item->isActive();
|
int chActive = item->isActive();
|
||||||
bool toExecute = (chActive>0);
|
bool toExecute = (chActive>0);
|
||||||
itemStore st;
|
itemCmd st(ST_HSV);
|
||||||
if (cmd>0 && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it
|
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
|
int from=0, to=numLeds-1; //All LEDs on the strip by default
|
||||||
// retrive LEDs range from suffix
|
// retrive LEDs range from suffix
|
||||||
@@ -203,7 +181,7 @@ if (subItem)
|
|||||||
// debugSerial<<F("Range:")<<subItem<<endl;
|
// debugSerial<<F("Range:")<<subItem<<endl;
|
||||||
if (sscanf(subItem,"%d-%d",&from,&to) == 1) to=from;
|
if (sscanf(subItem,"%d-%d",&from,&to) == 1) to=from;
|
||||||
}
|
}
|
||||||
debugSerial<<from<<F("-")<<to<<F(" cmd=")<<cmd<<endl;
|
debugSerial<<from<<F("-")<<to<<F(" cmd=")<<cmd.getCmd()<<endl;
|
||||||
|
|
||||||
|
|
||||||
switch(suffixCode)
|
switch(suffixCode)
|
||||||
@@ -213,7 +191,10 @@ case S_NOTFOUND:
|
|||||||
toExecute = true;
|
toExecute = true;
|
||||||
case S_SET:
|
case S_SET:
|
||||||
case S_HSV:
|
case S_HSV:
|
||||||
st.aslong = item->getVal(); //Restore old params
|
//st.Int(item->getVal()); //Restore old params
|
||||||
|
st.loadItem(item);
|
||||||
|
st.assignFrom(cmd);
|
||||||
|
/*
|
||||||
switch (n) //How many parameters are passed?
|
switch (n) //How many parameters are passed?
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
@@ -236,21 +217,26 @@ case S_HSV:
|
|||||||
st.v = Parameters[2];
|
st.v = Parameters[2];
|
||||||
st.hsv_flag = 1;
|
st.hsv_flag = 1;
|
||||||
}
|
}
|
||||||
PixelCtrl(&st,0,from,to,toExecute);
|
*/
|
||||||
|
|
||||||
|
PixelCtrl(st,from,to,toExecute);
|
||||||
|
|
||||||
if (!subItem) //Whole strip
|
if (!subItem) //Whole strip
|
||||||
{
|
{
|
||||||
item->setVal(st.aslong); //Store
|
//item->setVal(st.getInt()); //Store
|
||||||
|
st.saveItem(item);
|
||||||
if (!suffixCode)
|
if (!suffixCode)
|
||||||
{
|
{
|
||||||
if (chActive>0 && !st.v) item->setCmd(CMD_OFF);
|
if (chActive>0 && !st.getPercents()) item->setCmd(CMD_OFF);
|
||||||
if (chActive==0 && st.v) item->setCmd(CMD_ON);
|
if (chActive==0 && st.getPercents()) item->setCmd(CMD_ON);
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED);
|
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED);
|
||||||
}
|
}
|
||||||
else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED);
|
else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
//break;
|
//break;
|
||||||
|
|
||||||
|
/*
|
||||||
case S_RGB:
|
case S_RGB:
|
||||||
st.r = Parameters[0];
|
st.r = Parameters[0];
|
||||||
st.g = Parameters[1];
|
st.g = Parameters[1];
|
||||||
@@ -267,59 +253,51 @@ if (!suffixCode)
|
|||||||
}
|
}
|
||||||
else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED);
|
else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED);
|
||||||
return 1;
|
return 1;
|
||||||
//break;
|
//break; */
|
||||||
case S_CMD:
|
case S_CMD:
|
||||||
item->setCmd(cmd);
|
item->setCmd(cmd.getCmd());
|
||||||
switch (cmd)
|
switch (cmd.getCmd())
|
||||||
{
|
{
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
|
|
||||||
/*
|
|
||||||
if (chActive>0 && send)
|
|
||||||
{
|
|
||||||
SendStatus(SEND_COMMAND);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//retrive stored values
|
//retrive stored values
|
||||||
st.aslong = item->getVal();
|
st.loadItem(item);
|
||||||
|
|
||||||
if (subItem) // LED range, not whole strip
|
if (subItem) // LED range, not whole strip
|
||||||
PixelCtrl(&st,CMD_ON,from,to);
|
PixelCtrl(st.Cmd(CMD_ON),from,to);
|
||||||
else //whole strip
|
else //whole strip
|
||||||
{
|
{
|
||||||
if (st.aslong && (st.v<MIN_VOLUME) /* && send */) st.v=INIT_VOLUME;
|
if (st.param.aslong && (st.param.v<MIN_VOLUME) /* && send */) st.Percents(INIT_VOLUME);
|
||||||
item->setVal(st.aslong);
|
//item->setVal(st.getInt());
|
||||||
|
st.saveItem(item);
|
||||||
|
|
||||||
if (st.aslong ) //Stored smthng
|
if (st.getInt() ) //Stored smthng
|
||||||
{
|
{
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
|
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
|
||||||
debugSerial<<F("Restored: ")<<st.h<<F(",")<<st.s<<F(",")<<st.v<<endl;
|
debugSerial<<F("Restored: ")<<st.param.h<<F(",")<<st.param.s<<F(",")<<st.param.v<<endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debugSerial<<st.aslong<<F(": No stored values - default\n");
|
debugSerial<<st.param.aslong<<F(": No stored values - default\n");
|
||||||
st.h = 100;
|
st.setDefault();
|
||||||
st.s = 0;
|
//st.param.hsv_flag=1; ///tyta
|
||||||
st.v = 100;
|
|
||||||
st.hsv_flag=1;
|
|
||||||
// Store
|
// Store
|
||||||
item->setVal(st.aslong);
|
//item->setVal(st.getInt());
|
||||||
|
st.saveItem(item);
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
|
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
|
||||||
}
|
}
|
||||||
|
|
||||||
PixelCtrl(&st,0,from,to);
|
PixelCtrl(st,from,to);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case CMD_OFF:
|
case CMD_OFF:
|
||||||
if (subItem) // LED range, not whole strip
|
if (subItem) // LED range, not whole strip
|
||||||
PixelCtrl(&st,CMD_OFF,from,to);
|
PixelCtrl(st.Cmd(CMD_OFF),from,to);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
st.v=0;
|
st.Percents(0);
|
||||||
PixelCtrl(&st,0,from,to);
|
PixelCtrl(st,from,to);
|
||||||
item->SendStatus(SEND_COMMAND);
|
item->SendStatus(SEND_COMMAND);
|
||||||
// if (send) item->publishTopic(item->itemArr->name,"OFF","/cmd");
|
// if (send) item->publishTopic(item->itemArr->name,"OFF","/cmd");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ public:
|
|||||||
int Status() override;
|
int Status() override;
|
||||||
int isActive() override;
|
int isActive() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||||
int PixelCtrl(itemStore *st, short cmd, int from =0 , int to = 1024, bool show = 1, bool rgb = 0);
|
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;
|
int numLeds;
|
||||||
int8_t pin;
|
int8_t pin;
|
||||||
int ledsType;
|
int ledsType;
|
||||||
|
|||||||
89
lighthub/statusled.cpp
Normal file
89
lighthub/statusled.cpp
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
Homepage: http://lazyhome.ru
|
||||||
|
GIT: https://github.com/anklimov/lighthub
|
||||||
|
e-mail anklimov@gmail.com
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "statusled.h"
|
||||||
|
|
||||||
|
|
||||||
|
statusLED::statusLED(uint8_t pattern)
|
||||||
|
{
|
||||||
|
#if defined (STATUSLED)
|
||||||
|
pinMode(pinRED, OUTPUT);
|
||||||
|
pinMode(pinGREEN, OUTPUT);
|
||||||
|
pinMode(pinBLUE, OUTPUT);
|
||||||
|
set(pattern);
|
||||||
|
timestamp=millis()+ledDelayms;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void statusLED::show (uint8_t pattern)
|
||||||
|
{
|
||||||
|
#if defined (STATUSLED)
|
||||||
|
digitalWrite(pinRED,(pattern & ledRED)?HIGH:LOW );
|
||||||
|
digitalWrite(pinGREEN,(pattern & ledGREEN)?HIGH:LOW);
|
||||||
|
digitalWrite(pinBLUE,(pattern & ledBLUE)?HIGH:LOW);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void statusLED::set (uint8_t pattern)
|
||||||
|
{
|
||||||
|
#if defined (STATUSLED)
|
||||||
|
short newStat = pattern & ledParams;
|
||||||
|
|
||||||
|
if (newStat!=(curStat & ledParams))
|
||||||
|
{
|
||||||
|
//if (!(curStat & ledHidden))
|
||||||
|
show(pattern);
|
||||||
|
curStat=newStat | (curStat & ~ledParams);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void statusLED::flash(uint8_t pattern)
|
||||||
|
{
|
||||||
|
#if defined (STATUSLED)
|
||||||
|
show(pattern);
|
||||||
|
curStat|=ledFlash;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void statusLED::poll()
|
||||||
|
{
|
||||||
|
#if defined (STATUSLED)
|
||||||
|
if (curStat & ledFlash)
|
||||||
|
{
|
||||||
|
curStat&=~ledFlash;
|
||||||
|
show(curStat);
|
||||||
|
}
|
||||||
|
if (millis()>timestamp)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (curStat & ledFASTBLINK) timestamp=millis()+ledFastDelayms;
|
||||||
|
else timestamp=millis()+ledDelayms;
|
||||||
|
|
||||||
|
if (( curStat & ledBLINK) || (curStat & ledFASTBLINK))
|
||||||
|
{
|
||||||
|
curStat^=ledHidden;
|
||||||
|
if (curStat & ledHidden)
|
||||||
|
show(0);
|
||||||
|
else show(curStat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
50
lighthub/statusled.h
Normal file
50
lighthub/statusled.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
Homepage: http://lazyhome.ru
|
||||||
|
GIT: https://github.com/anklimov/lighthub
|
||||||
|
e-mail anklimov@gmail.com
|
||||||
|
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#define ledRED 1
|
||||||
|
#define ledGREEN 2
|
||||||
|
#define ledBLUE 4
|
||||||
|
#define ledBLINK 8
|
||||||
|
#define ledFASTBLINK 16
|
||||||
|
#define ledParams (ledRED | ledGREEN | ledBLUE | ledBLINK | ledFASTBLINK)
|
||||||
|
|
||||||
|
#define ledFlash 32
|
||||||
|
#define ledHidden 64
|
||||||
|
|
||||||
|
#define pinRED 50
|
||||||
|
#define pinGREEN 51
|
||||||
|
#define pinBLUE 52
|
||||||
|
|
||||||
|
#define ledDelayms 1000UL
|
||||||
|
#define ledFastDelayms 300UL
|
||||||
|
|
||||||
|
class statusLED {
|
||||||
|
public:
|
||||||
|
statusLED(uint8_t pattern = 0);
|
||||||
|
void set (uint8_t pattern);
|
||||||
|
void show (uint8_t pattern);
|
||||||
|
void poll();
|
||||||
|
void flash(uint8_t pattern);
|
||||||
|
private:
|
||||||
|
uint8_t curStat;
|
||||||
|
uint32_t timestamp;
|
||||||
|
};
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "streamlog.h"
|
#include "streamlog.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "utils.h"
|
#include "statusled.h"
|
||||||
|
|
||||||
#if defined (STATUSLED)
|
#if defined (STATUSLED)
|
||||||
extern statusLED LED;
|
extern statusLED LED;
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ const char DRY_P[] PROGMEM = "DRY";
|
|||||||
const char HIGH_P[] PROGMEM = "HIGH";
|
const char HIGH_P[] PROGMEM = "HIGH";
|
||||||
const char MED_P[] PROGMEM = "MEDIUM";
|
const char MED_P[] PROGMEM = "MEDIUM";
|
||||||
const char LOW_P[] PROGMEM = "LOW";
|
const char LOW_P[] PROGMEM = "LOW";
|
||||||
|
const char ERROR_P[] PROGMEM = "ERR";
|
||||||
|
|
||||||
|
|
||||||
// SubTopics
|
// SubTopics
|
||||||
@@ -110,7 +110,7 @@ const char MODE_P[] PROGMEM = "mode";
|
|||||||
const char FAN_P[] PROGMEM = "fan";
|
const char FAN_P[] PROGMEM = "fan";
|
||||||
const char HUE_P[] PROGMEM = "hue";
|
const char HUE_P[] PROGMEM = "hue";
|
||||||
const char SAT_P[] PROGMEM = "sat";
|
const char SAT_P[] PROGMEM = "sat";
|
||||||
|
const char TEMP_P[] PROGMEM = "temp";
|
||||||
const char HSV_P[] PROGMEM = "HSV";
|
const char HSV_P[] PROGMEM = "HSV";
|
||||||
const char RGB_P[] PROGMEM = "RGB";
|
const char RGB_P[] PROGMEM = "RGB";
|
||||||
|
|
||||||
|
|||||||
@@ -630,73 +630,6 @@ itemCmd mapInt(int32_t arg, aJsonObject* map)
|
|||||||
return _itemCmd.Int(arg);
|
return _itemCmd.Int(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
statusLED::statusLED(uint8_t pattern)
|
|
||||||
{
|
|
||||||
#if defined (STATUSLED)
|
|
||||||
pinMode(pinRED, OUTPUT);
|
|
||||||
pinMode(pinGREEN, OUTPUT);
|
|
||||||
pinMode(pinBLUE, OUTPUT);
|
|
||||||
set(pattern);
|
|
||||||
timestamp=millis()+ledDelayms;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void statusLED::show (uint8_t pattern)
|
|
||||||
{
|
|
||||||
#if defined (STATUSLED)
|
|
||||||
digitalWrite(pinRED,(pattern & ledRED)?HIGH:LOW );
|
|
||||||
digitalWrite(pinGREEN,(pattern & ledGREEN)?HIGH:LOW);
|
|
||||||
digitalWrite(pinBLUE,(pattern & ledBLUE)?HIGH:LOW);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void statusLED::set (uint8_t pattern)
|
|
||||||
{
|
|
||||||
#if defined (STATUSLED)
|
|
||||||
short newStat = pattern & ledParams;
|
|
||||||
|
|
||||||
if (newStat!=(curStat & ledParams))
|
|
||||||
{
|
|
||||||
//if (!(curStat & ledHidden))
|
|
||||||
show(pattern);
|
|
||||||
curStat=newStat | (curStat & ~ledParams);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void statusLED::flash(uint8_t pattern)
|
|
||||||
{
|
|
||||||
#if defined (STATUSLED)
|
|
||||||
show(pattern);
|
|
||||||
curStat|=ledFlash;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void statusLED::poll()
|
|
||||||
{
|
|
||||||
#if defined (STATUSLED)
|
|
||||||
if (curStat & ledFlash)
|
|
||||||
{
|
|
||||||
curStat&=~ledFlash;
|
|
||||||
show(curStat);
|
|
||||||
}
|
|
||||||
if (millis()>timestamp)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (curStat & ledFASTBLINK) timestamp=millis()+ledFastDelayms;
|
|
||||||
else timestamp=millis()+ledDelayms;
|
|
||||||
|
|
||||||
if (( curStat & ledBLINK) || (curStat & ledFASTBLINK))
|
|
||||||
{
|
|
||||||
curStat^=ledHidden;
|
|
||||||
if (curStat & ledHidden)
|
|
||||||
show(0);
|
|
||||||
else show(curStat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma message(VAR_NAME_VALUE(debugSerial))
|
#pragma message(VAR_NAME_VALUE(debugSerial))
|
||||||
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
||||||
|
|||||||
@@ -65,32 +65,3 @@ bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t m
|
|||||||
bool executeCommand(aJsonObject* cmd, int8_t toggle = -1);
|
bool executeCommand(aJsonObject* cmd, int8_t toggle = -1);
|
||||||
bool executeCommand(aJsonObject* cmd, int8_t toggle, itemCmd _itemCmd);
|
bool executeCommand(aJsonObject* cmd, int8_t toggle, itemCmd _itemCmd);
|
||||||
itemCmd mapInt(int32_t arg, aJsonObject* map);
|
itemCmd mapInt(int32_t arg, aJsonObject* map);
|
||||||
|
|
||||||
#define ledRED 1
|
|
||||||
#define ledGREEN 2
|
|
||||||
#define ledBLUE 4
|
|
||||||
#define ledBLINK 8
|
|
||||||
#define ledFASTBLINK 16
|
|
||||||
#define ledParams (ledRED | ledGREEN | ledBLUE | ledBLINK | ledFASTBLINK)
|
|
||||||
|
|
||||||
#define ledFlash 32
|
|
||||||
#define ledHidden 64
|
|
||||||
|
|
||||||
#define pinRED 50
|
|
||||||
#define pinGREEN 51
|
|
||||||
#define pinBLUE 52
|
|
||||||
|
|
||||||
#define ledDelayms 1000UL
|
|
||||||
#define ledFastDelayms 300UL
|
|
||||||
|
|
||||||
class statusLED {
|
|
||||||
public:
|
|
||||||
statusLED(uint8_t pattern = 0);
|
|
||||||
void set (uint8_t pattern);
|
|
||||||
void show (uint8_t pattern);
|
|
||||||
void poll();
|
|
||||||
void flash(uint8_t pattern);
|
|
||||||
private:
|
|
||||||
uint8_t curStat;
|
|
||||||
uint32_t timestamp;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ default_envs =
|
|||||||
; mega2560-5500
|
; mega2560-5500
|
||||||
|
|
||||||
; LightHub controller HW revision 2.1 and above (Wiznet 5500 CS on pin 53)
|
; LightHub controller HW revision 2.1 and above (Wiznet 5500 CS on pin 53)
|
||||||
lighthub21
|
; lighthub21
|
||||||
|
|
||||||
; Arduino DUE + Ethernet shield Wiznet 5100
|
; Arduino DUE + Ethernet shield Wiznet 5100
|
||||||
; due-5100
|
; due-5100
|
||||||
|
|
||||||
; Generic DUE
|
; Generic DUE
|
||||||
; due
|
due
|
||||||
; Arduino DUE + Ethernet shield Wiznet 5500
|
; Arduino DUE + Ethernet shield Wiznet 5500
|
||||||
; due-5500
|
; due-5500
|
||||||
|
|
||||||
@@ -280,8 +280,8 @@ build_flags = !python get_build_flags.py due
|
|||||||
; Need to place arduinoOTA utility from Arduino IDE distribution to folder in your PATH
|
; Need to place arduinoOTA utility from Arduino IDE distribution to folder in your PATH
|
||||||
;fix address and password
|
;fix address and password
|
||||||
;upload_flags =
|
;upload_flags =
|
||||||
;upload_command = arduinoOTA -address 192.168.88.21 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE
|
upload_command = arduinoOTA -address 192.168.88.21 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE
|
||||||
;upload_protocol = custom
|
upload_protocol = custom
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
;DS2482_OneWire //UNCOMMENT for software 1-wire driver
|
;DS2482_OneWire //UNCOMMENT for software 1-wire driver
|
||||||
DHT sensor library for ESPx
|
DHT sensor library for ESPx
|
||||||
|
|||||||
Reference in New Issue
Block a user