mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
Refactoring/smoke tested
This commit is contained in:
@@ -8,7 +8,7 @@ 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(itemCmd cmd, char* subItem=NULL) =0;
|
virtual int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) =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;}
|
||||||
|
|||||||
@@ -16,16 +16,30 @@ short colorChannel::getChannelAddr(short n)
|
|||||||
return item->getArg(n);
|
return item->getArg(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
int colorChannel::Ctrl(itemCmd cmd, char* subItem)
|
int colorChannel::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
|
||||||
{
|
{
|
||||||
|
debugSerial<<F("clrCtr: ");
|
||||||
int chActive = item->isActive();
|
cmd.debugOut();
|
||||||
bool toExecute = (chActive>0); // execute if channel is active now
|
//int chActive = item->isActive();
|
||||||
|
//bool toExecute = (chActive>0); // execute if channel is active now
|
||||||
int suffixCode = cmd.getSuffix();
|
int suffixCode = cmd.getSuffix();
|
||||||
itemCmd st(ST_HSV,CMD_VOID);
|
/*
|
||||||
|
// 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 (!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
|
if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command recognized , but w/o correct cmd suffix - threat it as command
|
||||||
|
*/
|
||||||
|
|
||||||
switch(suffixCode)
|
switch(suffixCode)
|
||||||
{
|
{
|
||||||
@@ -34,62 +48,32 @@ case S_NOTFOUND:
|
|||||||
toExecute = true;
|
toExecute = true;
|
||||||
case S_SET:
|
case S_SET:
|
||||||
case S_HSV:
|
case S_HSV:
|
||||||
st.loadItem(item);
|
PixelCtrl(cmd, subItem, toExecute);
|
||||||
st.assignFrom(cmd);
|
|
||||||
PixelCtrl(st, subItem, toExecute);
|
|
||||||
st.saveItem(item);
|
|
||||||
|
|
||||||
if (!suffixCode)
|
|
||||||
{
|
|
||||||
if (chActive>0 && !st.getPercents()) item->setCmd(CMD_OFF);
|
|
||||||
if (chActive==0 && st.getPercents()) item->setCmd(CMD_ON);
|
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED);
|
|
||||||
}
|
|
||||||
else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED);
|
|
||||||
return 1;
|
return 1;
|
||||||
/*
|
|
||||||
case S_HUE:
|
|
||||||
st.setH(uint16_t);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case S_SAT:
|
|
||||||
st.setS(uint8_t);
|
|
||||||
break;
|
|
||||||
*/
|
|
||||||
case S_CMD:
|
case S_CMD:
|
||||||
item->setCmd(cmd.getCmd());
|
item->setCmd(cmd.getCmd());
|
||||||
switch (cmd.getCmd())
|
switch (cmd.getCmd())
|
||||||
{
|
{
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
//retrive stored values
|
PixelCtrl(cmd,subItem, true);
|
||||||
if (st.loadItem(item))
|
|
||||||
{
|
|
||||||
if (st.param.aslong && (st.param.v<MIN_VOLUME)) {
|
|
||||||
st.Percents(INIT_VOLUME);
|
|
||||||
}
|
|
||||||
|
|
||||||
debugSerial<<F("Restored: ")<<st.param.h<<F(",")<<st.param.s<<F(",")<<st.param.v<<endl;
|
|
||||||
}
|
|
||||||
else // Not restored
|
|
||||||
{
|
|
||||||
st.setDefault();
|
|
||||||
debugSerial<<st.param.aslong<<F(": No stored values - default\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
st.saveItem(item, true);
|
|
||||||
PixelCtrl(st);
|
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
|
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case CMD_OFF:
|
case CMD_OFF:
|
||||||
st.Percents(0);
|
cmd.Percents(0);
|
||||||
PixelCtrl(st, subItem, true);
|
PixelCtrl(cmd, subItem, true);
|
||||||
item->SendStatus(SEND_COMMAND);
|
item->SendStatus(SEND_COMMAND);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
default:
|
||||||
|
debugSerial<<F("Unknown cmd ")<<cmd.getCmd()<<endl;
|
||||||
} //switch cmd
|
} //switch cmd
|
||||||
|
|
||||||
|
default:
|
||||||
|
debugSerial<<F("Unknown suffix ")<<suffixCode<<endl;
|
||||||
} //switch suffix
|
} //switch suffix
|
||||||
|
|
||||||
debugSerial<<F("Unknown cmd")<<endl;
|
cmd.debugOut();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public:
|
|||||||
if (iaddr<0) iaddr=-iaddr;
|
if (iaddr<0) iaddr=-iaddr;
|
||||||
numArgs = item->getArgCount(); // and how many addresses is configured
|
numArgs = item->getArgCount(); // and how many addresses is configured
|
||||||
};
|
};
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
|
||||||
virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true ) =0;
|
virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true ) =0;
|
||||||
short getChannelAddr(short n =0);
|
short getChannelAddr(short n =0);
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "itemCmd.h""
|
#include "itemCmd.h"
|
||||||
|
|
||||||
#ifndef DHT_DISABLE
|
#ifndef DHT_DISABLE
|
||||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -39,17 +39,48 @@ int txt2cmd(char *payload) {
|
|||||||
|
|
||||||
itemCmd::itemCmd(uint8_t _type, uint8_t _code)
|
itemCmd::itemCmd(uint8_t _type, uint8_t _code)
|
||||||
{
|
{
|
||||||
|
cmd.aslong=0;
|
||||||
|
param.aslong=0;
|
||||||
|
|
||||||
cmd.itemArgType=_type;
|
cmd.itemArgType=_type;
|
||||||
cmd.cmdCode=_code;
|
cmd.cmdCode=_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
itemCmd::itemCmd(float val)
|
itemCmd::itemCmd(float val)
|
||||||
{
|
{
|
||||||
cmd.cmdCode=0;
|
cmd.aslong=0;
|
||||||
|
param.aslong=0;
|
||||||
|
|
||||||
cmd.itemArgType=ST_FLOAT;
|
cmd.itemArgType=ST_FLOAT;
|
||||||
param.asfloat=val;
|
param.asfloat=val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemCmd itemCmd::setChanType(short chanType)
|
||||||
|
{
|
||||||
|
switch (chanType)
|
||||||
|
{
|
||||||
|
case CH_RGB:
|
||||||
|
case CH_RGBW:
|
||||||
|
case CH_SPILED:
|
||||||
|
cmd.itemArgType=ST_HSV;
|
||||||
|
break;
|
||||||
|
case CH_AC:
|
||||||
|
case CH_THERMO:
|
||||||
|
case CH_VCTEMP:
|
||||||
|
cmd.itemArgType=ST_FLOAT_CELSIUS;
|
||||||
|
break;
|
||||||
|
case CH_DIMMER:
|
||||||
|
case CH_MOTOR:
|
||||||
|
case CH_PWM:
|
||||||
|
case CH_RELAY:
|
||||||
|
cmd.itemArgType=ST_PERCENTS;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cmd.itemArgType=ST_PERCENTS;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
itemCmd itemCmd::setDefault()
|
itemCmd itemCmd::setDefault()
|
||||||
{
|
{
|
||||||
switch (cmd.itemArgType){
|
switch (cmd.itemArgType){
|
||||||
@@ -71,7 +102,7 @@ itemCmd itemCmd::setDefault()
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
itemCmd itemCmd::setH(uint16_t h)
|
bool itemCmd::setH(uint16_t h)
|
||||||
{
|
{
|
||||||
int par=h;
|
int par=h;
|
||||||
switch (cmd.itemArgType)
|
switch (cmd.itemArgType)
|
||||||
@@ -79,16 +110,20 @@ itemCmd itemCmd::setH(uint16_t h)
|
|||||||
case ST_VOID:
|
case ST_VOID:
|
||||||
cmd.itemArgType=ST_HSV;
|
cmd.itemArgType=ST_HSV;
|
||||||
case ST_HSV:
|
case ST_HSV:
|
||||||
if (par>100) par=100;
|
|
||||||
case ST_HSV255:
|
case ST_HSV255:
|
||||||
if (par>255) par=255;
|
if (par>365) par=365;
|
||||||
if (par<0) par=0;
|
if (par<0) par=0;
|
||||||
param.h=par;
|
param.h=par;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// debugSerial<<F("Can't assign HUE to type ")<<cmd.itemArgType<<endl;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return *this;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
itemCmd itemCmd::setS(uint8_t s)
|
bool itemCmd::setS(uint8_t s)
|
||||||
{
|
{
|
||||||
int par=s;
|
int par=s;
|
||||||
switch (cmd.itemArgType)
|
switch (cmd.itemArgType)
|
||||||
@@ -97,15 +132,31 @@ itemCmd itemCmd::setS(uint8_t s)
|
|||||||
cmd.itemArgType=ST_HSV;
|
cmd.itemArgType=ST_HSV;
|
||||||
case ST_HSV:
|
case ST_HSV:
|
||||||
if (par>100) par=100;
|
if (par>100) par=100;
|
||||||
|
param.s=par;
|
||||||
|
break;
|
||||||
case ST_HSV255:
|
case ST_HSV255:
|
||||||
if (par>255) par=255;
|
if (par>255) par=255;
|
||||||
if (par<0) par=0;
|
if (par<0) par=0;
|
||||||
param.s=par;
|
param.s=par;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// debugSerial<<F("Can't assign saturation to type ")<<cmd.itemArgType<<endl;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return *this;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
itemCmd itemCmd::incrementPercents(int16_t dif)
|
uint16_t itemCmd::getH()
|
||||||
|
{
|
||||||
|
return param.h;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t itemCmd::getS()
|
||||||
|
{
|
||||||
|
return param.s;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool itemCmd::incrementPercents(int16_t dif)
|
||||||
{ int par=param.v;
|
{ int par=param.v;
|
||||||
switch (cmd.itemArgType)
|
switch (cmd.itemArgType)
|
||||||
{
|
{
|
||||||
@@ -121,12 +172,13 @@ itemCmd itemCmd::incrementPercents(int16_t dif)
|
|||||||
if (par>255) par=255;
|
if (par>255) par=255;
|
||||||
if (par<0) par=0;
|
if (par<0) par=0;
|
||||||
break;
|
break;
|
||||||
|
default: return false;
|
||||||
}
|
}
|
||||||
param.v=par;
|
param.v=par;
|
||||||
return *this;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
itemCmd itemCmd::incrementH(int16_t dif)
|
bool itemCmd::incrementH(int16_t dif)
|
||||||
{ int par=param.h;
|
{ int par=param.h;
|
||||||
switch (cmd.itemArgType)
|
switch (cmd.itemArgType)
|
||||||
{
|
{
|
||||||
@@ -136,30 +188,33 @@ itemCmd itemCmd::incrementH(int16_t dif)
|
|||||||
if (par>365) par=0;
|
if (par>365) par=0;
|
||||||
if (par<0) par=365;
|
if (par<0) par=365;
|
||||||
break;
|
break;
|
||||||
|
default: return false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
param.h=par;
|
param.h=par;
|
||||||
return *this;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
itemCmd itemCmd::incrementS(int16_t dif)
|
bool itemCmd::incrementS(int16_t dif)
|
||||||
{int par=param.s;
|
{int par=param.s;
|
||||||
switch (cmd.itemArgType)
|
switch (cmd.itemArgType)
|
||||||
{
|
{
|
||||||
case ST_PERCENTS:
|
//case ST_PERCENTS:
|
||||||
case ST_HSV:
|
case ST_HSV:
|
||||||
par+=dif;
|
par+=dif;
|
||||||
if (par>100) par=100;
|
if (par>100) par=100;
|
||||||
if (par<0) par=0;
|
if (par<0) par=0;
|
||||||
break;
|
break;
|
||||||
case ST_PERCENTS255:
|
//case ST_PERCENTS255:
|
||||||
case ST_HSV255:
|
case ST_HSV255:
|
||||||
par+=dif;
|
par+=dif;
|
||||||
if (par>255) par=255;
|
if (par>255) par=255;
|
||||||
if (par<0) par=0;
|
if (par<0) par=0;
|
||||||
break;
|
break;
|
||||||
|
default: return false;
|
||||||
}
|
}
|
||||||
param.s=par;
|
param.s=par;
|
||||||
return *this;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,6 +223,7 @@ itemCmd itemCmd::assignFrom(itemCmd from)
|
|||||||
{
|
{
|
||||||
bool RGBW_flag = false;
|
bool RGBW_flag = false;
|
||||||
bool HSV255_flag = false;
|
bool HSV255_flag = false;
|
||||||
|
cmd.suffixCode=from.cmd.suffixCode;
|
||||||
|
|
||||||
switch (cmd.itemArgType){ //Destination
|
switch (cmd.itemArgType){ //Destination
|
||||||
case ST_HSV:
|
case ST_HSV:
|
||||||
@@ -201,6 +257,7 @@ itemCmd itemCmd::assignFrom(itemCmd from)
|
|||||||
default:
|
default:
|
||||||
debugSerial<<F("Wrong Assignment ")<<from.cmd.itemArgType<<F("->")<<cmd.itemArgType<<endl;
|
debugSerial<<F("Wrong Assignment ")<<from.cmd.itemArgType<<F("->")<<cmd.itemArgType<<endl;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case ST_HSV255:
|
case ST_HSV255:
|
||||||
case ST_PERCENTS255:
|
case ST_PERCENTS255:
|
||||||
switch (from.cmd.itemArgType)
|
switch (from.cmd.itemArgType)
|
||||||
@@ -232,7 +289,7 @@ itemCmd itemCmd::assignFrom(itemCmd from)
|
|||||||
default:
|
default:
|
||||||
debugSerial<<F("Wrong Assignment ")<<from.cmd.itemArgType<<F("->")<<cmd.itemArgType<<endl;
|
debugSerial<<F("Wrong Assignment ")<<from.cmd.itemArgType<<F("->")<<cmd.itemArgType<<endl;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case ST_VOID:
|
case ST_VOID:
|
||||||
cmd.itemArgType=from.cmd.itemArgType;
|
cmd.itemArgType=from.cmd.itemArgType;
|
||||||
|
|
||||||
@@ -298,6 +355,7 @@ itemCmd itemCmd::assignFrom(itemCmd from)
|
|||||||
param.g=rgb.g;
|
param.g=rgb.g;
|
||||||
param.b=rgb.b;
|
param.b=rgb.b;
|
||||||
#endif
|
#endif
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
debugSerial<<F("Wrong Assignment ")<<from.cmd.itemArgType<<F("->")<<cmd.itemArgType<<endl;
|
debugSerial<<F("Wrong Assignment ")<<from.cmd.itemArgType<<F("->")<<cmd.itemArgType<<endl;
|
||||||
@@ -388,7 +446,7 @@ uint8_t itemCmd::getArgType()
|
|||||||
|
|
||||||
itemCmd itemCmd::setArgType(uint8_t type)
|
itemCmd itemCmd::setArgType(uint8_t type)
|
||||||
{
|
{
|
||||||
cmd.itemArgType=type;
|
cmd.itemArgType=type & 0xF;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -514,11 +572,17 @@ itemCmd itemCmd::setSuffix(uint8_t suffix)
|
|||||||
bool itemCmd::loadItem(Item * item, bool includeCommand)
|
bool itemCmd::loadItem(Item * item, bool includeCommand)
|
||||||
{
|
{
|
||||||
if (item && item->isValid())
|
if (item && item->isValid())
|
||||||
|
{
|
||||||
|
short subtype =item->getSubtype();
|
||||||
|
if (subtype)
|
||||||
{
|
{
|
||||||
param.asInt32=item->getVal();
|
param.asInt32=item->getVal();
|
||||||
cmd.itemArgType=item->getSubtype();
|
cmd.itemArgType= subtype;
|
||||||
if (includeCommand) cmd.cmdCode=item->getCmd();
|
if (includeCommand) cmd.cmdCode=item->getCmd();
|
||||||
return (cmd.itemArgType!=ST_VOID);
|
debugSerial<<F("Loaded :");
|
||||||
|
debugOut();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -530,6 +594,8 @@ bool itemCmd::saveItem(Item * item, bool includeCommand)
|
|||||||
item->setVal(param.asInt32);
|
item->setVal(param.asInt32);
|
||||||
item->setSubtype(cmd.itemArgType);
|
item->setSubtype(cmd.itemArgType);
|
||||||
if (includeCommand) item->setCmd(cmd.cmdCode);
|
if (includeCommand) item->setCmd(cmd.cmdCode);
|
||||||
|
debugSerial<<F("Saved :");
|
||||||
|
debugOut();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -537,13 +603,13 @@ return false;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
char * itemCmd::toString(char * Buffer, int bufLen)
|
char * itemCmd::toString(char * Buffer, int bufLen, int sendFlags )
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!Buffer || !bufLen) return NULL;
|
if (!Buffer || !bufLen) return NULL;
|
||||||
*Buffer=0;
|
*Buffer=0;
|
||||||
char * argPtr=Buffer;
|
char * argPtr=Buffer;
|
||||||
if (isCommand())
|
if (isCommand() && (sendFlags & SEND_COMMAND))
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
strncpy_P(Buffer, commands_P[cmd.cmdCode], bufLen);
|
strncpy_P(Buffer, commands_P[cmd.cmdCode], bufLen);
|
||||||
@@ -552,12 +618,14 @@ char * itemCmd::toString(char * Buffer, int bufLen)
|
|||||||
argPtr+=len;
|
argPtr+=len;
|
||||||
bufLen-=len;
|
bufLen-=len;
|
||||||
}
|
}
|
||||||
|
if (sendFlags & SEND_PARAMETERS)
|
||||||
switch (cmd.itemArgType)
|
switch (cmd.itemArgType)
|
||||||
{
|
{
|
||||||
|
|
||||||
case ST_PERCENTS:
|
case ST_PERCENTS:
|
||||||
case ST_PERCENTS255:
|
case ST_PERCENTS255:
|
||||||
|
snprintf(argPtr, bufLen, "%u", param.v);
|
||||||
|
break;
|
||||||
case ST_UINT32:
|
case ST_UINT32:
|
||||||
snprintf(argPtr, bufLen, "%lu", param.asUint32);
|
snprintf(argPtr, bufLen, "%lu", param.asUint32);
|
||||||
break;
|
break;
|
||||||
@@ -592,3 +660,10 @@ char * itemCmd::toString(char * Buffer, int bufLen)
|
|||||||
}
|
}
|
||||||
return Buffer;
|
return Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void itemCmd::debugOut()
|
||||||
|
{
|
||||||
|
char buf[32];
|
||||||
|
toString(buf,sizeof(buf));
|
||||||
|
debugSerial<<buf<<F(" AT:")<<getArgType()<<F(" Suff:")<<getSuffix()<<endl;
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ e-mail anklimov@gmail.com
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
///#include "item.h"
|
||||||
|
|
||||||
typedef char cmdstr[9];
|
typedef char cmdstr[9];
|
||||||
|
|
||||||
@@ -98,16 +99,17 @@ ST_FLOAT = 13//,
|
|||||||
#define ST_PERCENTS 1
|
#define ST_PERCENTS 1
|
||||||
#define ST_TENS 2
|
#define ST_TENS 2
|
||||||
#define ST_HSV 3
|
#define ST_HSV 3
|
||||||
#define ST_FLOAT_CELSIUS 4
|
#define ST_HSVW 4
|
||||||
#define ST_FLOAT_FARENHEIT 5
|
#define ST_FLOAT_CELSIUS 5
|
||||||
#define ST_RGB 6
|
#define ST_FLOAT_FARENHEIT 6
|
||||||
#define ST_RGBW 7
|
#define ST_RGB 7
|
||||||
#define ST_PERCENTS255 8
|
#define ST_RGBW 8
|
||||||
#define ST_HSV255 9
|
#define ST_PERCENTS255 9
|
||||||
#define ST_INT32 10
|
#define ST_HSV255 10
|
||||||
#define ST_UINT32 11
|
#define ST_INT32 11
|
||||||
#define ST_STRING 12
|
#define ST_UINT32 12
|
||||||
#define ST_FLOAT 13
|
#define ST_STRING 13
|
||||||
|
#define ST_FLOAT 14
|
||||||
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
@@ -122,12 +124,18 @@ typedef union
|
|||||||
uint8_t cmdCode;
|
uint8_t cmdCode;
|
||||||
union {
|
union {
|
||||||
uint8_t cmdFlag;
|
uint8_t cmdFlag;
|
||||||
|
/*
|
||||||
struct
|
struct
|
||||||
{ uint8_t suffixCode:4;
|
{ uint8_t suffixCode:4;
|
||||||
uint8_t itemArgType:4;
|
uint8_t itemArgType:4;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
uint8_t cmdEffect;
|
struct
|
||||||
|
{ uint8_t suffixCode:4;
|
||||||
|
uint8_t itemArgType:4;
|
||||||
|
};
|
||||||
|
// uint8_t cmdEffect;
|
||||||
uint8_t cmdParam;
|
uint8_t cmdParam;
|
||||||
};
|
};
|
||||||
} itemCmdStore;
|
} itemCmdStore;
|
||||||
@@ -181,8 +189,10 @@ public:
|
|||||||
itemCmd HSV(uint16_t h, uint8_t s, uint8_t v);
|
itemCmd HSV(uint16_t h, uint8_t s, uint8_t v);
|
||||||
itemCmd RGB(uint8_t r, uint8_t g, uint8_t b);
|
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);
|
itemCmd RGBW(uint8_t r, uint8_t g, uint8_t b, uint8_t w);
|
||||||
itemCmd setH(uint16_t);
|
bool setH(uint16_t);
|
||||||
itemCmd setS(uint8_t);
|
bool setS(uint8_t);
|
||||||
|
uint16_t getH();
|
||||||
|
uint16_t getS();
|
||||||
itemCmd setArgType(uint8_t);
|
itemCmd setArgType(uint8_t);
|
||||||
itemCmd Percents(int i);
|
itemCmd Percents(int i);
|
||||||
itemCmd Percents255(int i);
|
itemCmd Percents255(int i);
|
||||||
@@ -190,9 +200,9 @@ public:
|
|||||||
uint8_t getSuffix();
|
uint8_t getSuffix();
|
||||||
itemCmd setSuffix(uint8_t suffix);
|
itemCmd setSuffix(uint8_t suffix);
|
||||||
|
|
||||||
itemCmd incrementPercents(int16_t);
|
bool incrementPercents(int16_t);
|
||||||
itemCmd incrementH(int16_t);
|
bool incrementH(int16_t);
|
||||||
itemCmd incrementS(int16_t);
|
bool incrementS(int16_t);
|
||||||
|
|
||||||
long int getInt();
|
long int getInt();
|
||||||
short getPercents(bool inverse=false);
|
short getPercents(bool inverse=false);
|
||||||
@@ -200,13 +210,15 @@ public:
|
|||||||
uint8_t getCmd();
|
uint8_t getCmd();
|
||||||
uint8_t getArgType();
|
uint8_t getArgType();
|
||||||
uint8_t getCmdParam();
|
uint8_t getCmdParam();
|
||||||
char * toString(char * Buffer, int bufLen);
|
char * toString(char * Buffer, int bufLen, int sendFlags = SEND_COMMAND | SEND_PARAMETERS );
|
||||||
|
|
||||||
bool isCommand();
|
bool isCommand();
|
||||||
bool isValue();
|
bool isValue();
|
||||||
bool isHSV();
|
bool isHSV();
|
||||||
|
|
||||||
itemCmd setDefault();
|
itemCmd setDefault();
|
||||||
|
itemCmd setChanType(short chanType);
|
||||||
|
void debugOut();
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ 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, char* subItem)
|
int out_AC::Ctrl(itemCmd cmd, char* subItem , bool toExecute)
|
||||||
{char s_mode[10];
|
{char s_mode[10];
|
||||||
int suffixCode = cmd.getSuffix();
|
int suffixCode = cmd.getSuffix();
|
||||||
// Some additional Subitems
|
// Some additional Subitems
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public:
|
|||||||
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, char* subItem=NULL) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void InsertData(byte data[], size_t size);
|
void InsertData(byte data[], size_t size);
|
||||||
|
|||||||
@@ -338,11 +338,11 @@ int out_Modbus::getChanType()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int out_Modbus::Ctrl(itemCmd cmd, char* subItem)
|
int out_Modbus::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
|
||||||
{
|
{
|
||||||
int chActive = item->isActive();
|
//int chActive = item->isActive();
|
||||||
bool toExecute = (chActive>0);
|
//bool toExecute = (chActive>0);
|
||||||
itemCmd st(ST_UINT32,CMD_VOID);
|
//itemCmd st(ST_UINT32,CMD_VOID);
|
||||||
int suffixCode = cmd.getSuffix();
|
int suffixCode = cmd.getSuffix();
|
||||||
|
|
||||||
if (cmd.isCommand() && !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
|
||||||
@@ -355,58 +355,30 @@ toExecute = true;
|
|||||||
debugSerial<<F("Forced execution");
|
debugSerial<<F("Forced execution");
|
||||||
case S_SET:
|
case S_SET:
|
||||||
if (!cmd.isValue()) return 0;
|
if (!cmd.isValue()) return 0;
|
||||||
//////item->setVal(st=Parameters[0]); //Store
|
|
||||||
if (!suffixCode)
|
|
||||||
{
|
|
||||||
if (chActive>0 && !st.getInt()) item->setCmd(CMD_OFF);
|
|
||||||
if (chActive==0 && st.getInt()) item->setCmd(CMD_ON);
|
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED);
|
|
||||||
// if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
|
||||||
}
|
|
||||||
else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED);
|
|
||||||
|
|
||||||
|
//TODO
|
||||||
return 1;
|
return 1;
|
||||||
//break;
|
//break;
|
||||||
|
|
||||||
case S_CMD:
|
case S_CMD:
|
||||||
//item->setCmd(cmd.getCmd());
|
|
||||||
st.loadItem(item);
|
|
||||||
switch (cmd.getCmd())
|
switch (cmd.getCmd())
|
||||||
{
|
{
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
//retrive stored values
|
|
||||||
st.loadItem(item);
|
|
||||||
|
|
||||||
|
|
||||||
if (st.getPercents() && (st.getPercents()<MIN_VOLUME) /* && send */) st.Percents(INIT_VOLUME);
|
|
||||||
st.saveItem(item);
|
|
||||||
|
|
||||||
if (st.getPercents()) //Stored smthng
|
|
||||||
{
|
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
|
|
||||||
debugSerial<<F("Restored: ")<<st.getPercents()<<endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
debugSerial<<F(": No stored values - default\n");
|
|
||||||
// Store
|
|
||||||
st.setDefault();
|
|
||||||
st.saveItem(item);
|
|
||||||
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
|
|
||||||
}
|
|
||||||
// if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case CMD_OFF:
|
case CMD_OFF:
|
||||||
item->SendStatus(SEND_COMMAND);
|
|
||||||
// if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
} //switch cmd
|
default:
|
||||||
|
debugSerial<<F("Unknown cmd ")<<cmd.getCmd()<<endl;
|
||||||
|
} //switch cmd
|
||||||
|
|
||||||
break;
|
default:
|
||||||
|
debugSerial<<F("Unknown suffix ")<<suffixCode<<endl;
|
||||||
} //switch suffix
|
} //switch suffix
|
||||||
debugSerial<<F("Unknown cmd")<<endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
int Status() override;
|
int Status() override;
|
||||||
int isActive() override;
|
int isActive() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) 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;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -211,12 +211,12 @@ int out_Motor::getChanType()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int out_Motor::Ctrl(itemCmd cmd, char* subItem)
|
int out_Motor::Ctrl(itemCmd cmd, char* subItem , bool toExecute)
|
||||||
{
|
{
|
||||||
int chActive = item->isActive();
|
//int chActive = item->isActive();
|
||||||
bool toExecute = (chActive>0);
|
//bool toExecute = (chActive>0);
|
||||||
int suffixCode = cmd.getSuffix();
|
int suffixCode = cmd.getSuffix();
|
||||||
itemCmd st(ST_PERCENTS,CMD_VOID);
|
//itemCmd st(ST_PERCENTS,CMD_VOID);
|
||||||
if (cmd.isCommand() && !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);
|
||||||
@@ -229,6 +229,8 @@ toExecute = true;
|
|||||||
debugSerial<<F("Forced execution");
|
debugSerial<<F("Forced execution");
|
||||||
case S_SET:
|
case S_SET:
|
||||||
if (!cmd.isValue()) return 0;
|
if (!cmd.isValue()) return 0;
|
||||||
|
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
||||||
|
/*
|
||||||
st.assignFrom(cmd);
|
st.assignFrom(cmd);
|
||||||
//Store
|
//Store
|
||||||
st.saveItem(item);
|
st.saveItem(item);
|
||||||
@@ -240,7 +242,7 @@ case S_SET:
|
|||||||
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
||||||
}
|
}
|
||||||
else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED);
|
else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED);
|
||||||
|
*/
|
||||||
return 1;
|
return 1;
|
||||||
//break;
|
//break;
|
||||||
|
|
||||||
@@ -249,10 +251,12 @@ case S_CMD:
|
|||||||
switch (cmd.getCmd())
|
switch (cmd.getCmd())
|
||||||
{
|
{
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
|
|
||||||
|
/*
|
||||||
//retrive stored values
|
//retrive stored values
|
||||||
if (st.loadItem(item))
|
if (st.loadItem(item))
|
||||||
{
|
{
|
||||||
if (st.getPercents() && (st.getPercents()<MIN_VOLUME) /* && send */)
|
if (st.getPercents() && (st.getPercents()<MIN_VOLUME))
|
||||||
{ //Volume too low
|
{ //Volume too low
|
||||||
st.Percents(INIT_VOLUME);
|
st.Percents(INIT_VOLUME);
|
||||||
st.saveItem(item);
|
st.saveItem(item);
|
||||||
@@ -270,12 +274,12 @@ case S_CMD:
|
|||||||
//item->setVal(st);
|
//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;
|
||||||
|
|
||||||
case CMD_OFF:
|
case CMD_OFF:
|
||||||
item->SendStatus(SEND_COMMAND);
|
////item->SendStatus(SEND_COMMAND);
|
||||||
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public:
|
|||||||
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, char* subItem=NULL) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
|
||||||
|
|
||||||
int8_t pinUp;
|
int8_t pinUp;
|
||||||
int8_t pinDown;
|
int8_t pinDown;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
@@ -581,8 +581,8 @@ framework = arduino
|
|||||||
board = due
|
board = due
|
||||||
build_flags = !python get_build_flags.py lighthub21
|
build_flags = !python get_build_flags.py lighthub21
|
||||||
;upload_command = arduinoOTA -address 192.168.11.172 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE
|
;upload_command = arduinoOTA -address 192.168.11.172 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE
|
||||||
;upload_command = arduinoOTA -address 192.168.88.34 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE
|
upload_command = arduinoOTA -address 192.168.88.28 -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