API simplificatoin ph1 (@send param remove

This commit is contained in:
2020-05-21 15:36:35 +03:00
parent cebb6fc486
commit 0687949bb7
17 changed files with 141 additions and 77 deletions

View File

@@ -26,7 +26,7 @@ int abstractCh::publishTopic(const char* topic, float value, const char* subtopi
int abstractCh::publishTopic(const char* topic, const char * value, const char* subtopic) int abstractCh::publishTopic(const char* topic, const char * value, const char* subtopic)
{ {
char addrstr[MQTT_TOPIC_LENGTH]; char addrstr[MQTT_TOPIC_LENGTH];
if (!isNotRetainingStatus()) return 0;
if (topic) if (topic)
{ {
strncpy(addrstr,topic,sizeof(addrstr)); strncpy(addrstr,topic,sizeof(addrstr));

View File

@@ -7,7 +7,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(short cmd, short n=0, int * Parameters=NULL, boolean send=true, int suffixCode=0, char* subItem=NULL) =0; virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, 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;}

View File

@@ -952,13 +952,13 @@ if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestri
Item it(item->valuestring); Item it(item->valuestring);
if (it.isValid()) { if (it.isValid()) {
if (newValue) { //send set command if (newValue) { //send set command
if (!scmd || scmd->type != aJson_String) it.Ctrl(CMD_ON, 0, NULL, true); if (!scmd || scmd->type != aJson_String) it.Ctrl(CMD_ON, 0, NULL);
else if (strlen(scmd->valuestring)) else if (strlen(scmd->valuestring))
it.Ctrl(scmd->valuestring, true); it.Ctrl(scmd->valuestring);
} else { //send reset command } else { //send reset command
if (!rcmd || rcmd->type != aJson_String) it.Ctrl(CMD_OFF, 0, NULL, true); if (!rcmd || rcmd->type != aJson_String) it.Ctrl(CMD_OFF, 0, NULL);
else if (strlen(rcmd->valuestring)) else if (strlen(rcmd->valuestring))
it.Ctrl(rcmd->valuestring, true); it.Ctrl(rcmd->valuestring);
} }
} }
} }

View File

@@ -456,9 +456,10 @@ return suffixCode;
#define MAXCTRLPAR 3 #define MAXCTRLPAR 3
// myhome/dev/item/subItem // myhome/dev/item/subItem
int Item::Ctrl(char * payload, boolean send, char * subItem){ int Item::Ctrl(char * payload, char * subItem){
if (!payload) return 0; if (!payload) return 0;
bool send = isNotRetainingStatus() ;
int suffixCode = 0; int suffixCode = 0;
//int setCommand = CMD_SET; //default SET behavior now - not turn on channels //int setCommand = CMD_SET; //default SET behavior now - not turn on channels
@@ -495,7 +496,7 @@ debugSerial<<F("Txt2Cmd:")<<cmd<<endl;
while (payload && i < 3) while (payload && i < 3)
Par[i++] = getInt((char **) &payload); Par[i++] = getInt((char **) &payload);
return Ctrl(setCommand, i, Par, send, suffixCode, subItem); return Ctrl(setCommand, i, Par, suffixCode, subItem);
} }
break; break;
@@ -515,14 +516,14 @@ debugSerial<<F("Txt2Cmd:")<<cmd<<endl;
Par[0] = map(hsv.h, 0, 255, 0, 365); Par[0] = map(hsv.h, 0, 255, 0, 365);
Par[1] = map(hsv.s, 0, 255, 0, 100); Par[1] = map(hsv.s, 0, 255, 0, 100);
Par[2] = map(hsv.v, 0, 255, 0, 100); Par[2] = map(hsv.v, 0, 255, 0, 100);
return Ctrl(setCommand, 3, Par, send, suffixCode, subItem); return Ctrl(setCommand, 3, Par, suffixCode, subItem);
} }
break; break;
} }
#endif #endif
#endif #endif
default: //some known command default: //some known command
return Ctrl(cmd, 0, NULL, send, suffixCode, subItem); return Ctrl(cmd, 0, NULL, suffixCode, subItem);
} //ctrl } //ctrl
return 0; return 0;
@@ -539,8 +540,8 @@ short Item::cmd2changeActivity(int lastActivity, short defaultCmd)
} }
*/ */
int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode, char *subItem) { int Item::Ctrl(short cmd, short n, int *Parameters, int suffixCode, char *subItem) {
bool send = isNotRetainingStatus() ;
if ((!subItem || !strlen(subItem)) && strlen(defaultSubItem)) if ((!subItem || !strlen(subItem)) && strlen(defaultSubItem))
subItem = defaultSubItem; /// possible problem here with truncated default subItem = defaultSubItem; /// possible problem here with truncated default
@@ -584,7 +585,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
int iaddr = getArg(); int iaddr = getArg();
int chActive =isActive(); int chActive =isActive();
CHstore st; itemStore st;
switch (cmd) { switch (cmd) {
int t; int t;
/* /*
@@ -756,7 +757,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
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, send, suffixCode, subItem); res = driver->Ctrl(CMD_ON, n, Par, suffixCode, subItem);
setCmd(CMD_XON); setCmd(CMD_XON);
} }
else else
@@ -768,7 +769,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
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, send, suffixCode, subItem); res = driver->Ctrl(CMD_OFF, n, Par, suffixCode, subItem);
setCmd(CMD_HALT); setCmd(CMD_HALT);
return res; return res;
} }
@@ -781,7 +782,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
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, send, suffixCode, subItem); res = driver->Ctrl(cmd, n, Par, suffixCode, subItem);
setCmd(CMD_OFF); setCmd(CMD_OFF);
} }
else else
@@ -796,7 +797,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
break; break;
*/ */
default: default:
res = driver->Ctrl(cmd, n, Par, send, suffixCode, subItem); res = driver->Ctrl(cmd, n, Par, suffixCode, subItem);
if (cmd) setCmd(cmd); if (cmd) setCmd(cmd);
} }
return res; return res;
@@ -1114,7 +1115,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
if (i->type == aJson_String) if (i->type == aJson_String)
{ {
Item it(i->valuestring); Item it(i->valuestring);
it.Ctrl(cmd, n, Par, send,suffixCode,subItem); //// was true it.Ctrl(cmd, n, Par, suffixCode,subItem); //// was true
} }
i = i->next; i = i->next;
} //while } //while
@@ -1197,7 +1198,7 @@ return 1;
} }
int Item::isActive() { int Item::isActive() {
CHstore st; itemStore st;
int val = 0; int val = 0;
@@ -1804,13 +1805,14 @@ void Item::sendDelayedStatus()
int Item::SendStatus(int sendFlags) { int Item::SendStatus(int sendFlags) {
int chancmd=getCmd();
if ((sendFlags & SEND_DEFFERED) || (lanStatus==RETAINING_COLLECTING)) { if ((sendFlags & SEND_DEFFERED) || (!isNotRetainingStatus() )) {
setFlag(sendFlags & (SEND_COMMAND | SEND_PARAMETERS)); setFlag(sendFlags & (SEND_COMMAND | SEND_PARAMETERS));
debugSerial<<F("Status deffered\n"); debugSerial<<F("Status deffered\n");
return -1; return -1;
} }
else { else {
int chancmd=getCmd();
sendFlags |= getFlag(SEND_COMMAND | SEND_PARAMETERS); //if some delayed status is pending sendFlags |= getFlag(SEND_COMMAND | SEND_PARAMETERS); //if some delayed status is pending
char addrstr[48]; char addrstr[48];
char valstr[16] = ""; char valstr[16] = "";
@@ -1819,7 +1821,7 @@ int Item::SendStatus(int sendFlags) {
if (sendFlags & SEND_PARAMETERS) if (sendFlags & SEND_PARAMETERS)
{ {
// Preparing parameters payload ////////// // Preparing parameters payload //////////
CHstore st; itemStore st;
int chanType = itemType; int chanType = itemType;
if (driver) chanType = driver->getChanType(); if (driver) chanType = driver->getChanType();
//retrive stored values //retrive stored values

View File

@@ -120,6 +120,20 @@ 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
};
#pragma pack(push, 1) #pragma pack(push, 1)
typedef union typedef union
{ {
@@ -136,10 +150,10 @@ typedef union
uint8_t r; uint8_t r;
uint8_t g; uint8_t g;
uint8_t b; uint8_t b;
uint8_t w:7; uint8_t w;//:7;
uint8_t rgb_flag:1; // uint8_t rgb_flag:1;
}; };
} CHstore; } itemStore;
/* /*
typedef union typedef union
@@ -164,8 +178,8 @@ class Item
boolean isValid (); boolean isValid ();
boolean Setup(); boolean Setup();
virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true, int suffixCode=0, char* subItem=NULL); int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL);
virtual int Ctrl(char * payload, boolean send=true, char * subItem=NULL); int Ctrl(char * payload, char * subItem=NULL);
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

View File

@@ -189,7 +189,7 @@ while (configLocked)
#ifdef _dmxin #ifdef _dmxin
DMXCheck(); DMXCheck();
#endif #endif
if (lanStatus != RETAINING_COLLECTING) pollingLoop(); if (isNotRetainingStatus()) pollingLoop();
thermoLoop(); thermoLoop();
inputLoop(); inputLoop();
} }
@@ -215,6 +215,10 @@ debugSerial<<F("Deleting conf. RAM was:")<<freeRam();
debugSerial<<F(" is ")<<freeRam()<<endl; debugSerial<<F(" is ")<<freeRam()<<endl;
} }
bool isNotRetainingStatus() {
return (lanStatus != RETAINING_COLLECTING);
}
void mqttCallback(char *topic, byte *payload, unsigned int length) { void mqttCallback(char *topic, byte *payload, unsigned int length) {
debugSerial<<F("\n[")<<topic<<F("] "); debugSerial<<F("\n[")<<topic<<F("] ");
if (!payload) return; if (!payload) return;
@@ -290,7 +294,7 @@ else
/* /*
if (item.itemType == CH_GROUP && (lanStatus == RETAINING_COLLECTING)) if (item.itemType == CH_GROUP && (lanStatus == RETAINING_COLLECTING))
return; //Do not restore group channels - they consist not relevant data */ return; //Do not restore group channels - they consist not relevant data */
item.Ctrl((char *)payload, !(lanStatus == RETAINING_COLLECTING),subItem); item.Ctrl((char *)payload,subItem);
} //valid item } //valid item
} }
@@ -1743,7 +1747,7 @@ void loop_main() {
if (items) { if (items) {
// #ifndef MODBUS_DISABLE // #ifndef MODBUS_DISABLE
if (lanStatus != RETAINING_COLLECTING) pollingLoop(); if (isNotRetainingStatus()) pollingLoop();
// #endif // #endif
//#ifdef _owire //#ifdef _owire
thermoLoop(); thermoLoop();

View File

@@ -186,6 +186,7 @@ typedef union {
uint8_t UID_Byte[20]; uint8_t UID_Byte[20];
} UID; } UID;
bool isNotRetainingStatus();
//void watchdogSetup(void); //void watchdogSetup(void);
void mqttCallback(char *topic, byte *payload, unsigned int length); void mqttCallback(char *topic, byte *payload, unsigned int length);

View File

@@ -258,7 +258,7 @@ delay(100);
return INTERVAL_POLLING; return INTERVAL_POLLING;
}; };
int out_AC::Ctrl(short cmd, short n, int * Parameters, boolean send, int suffixCode, char* subItem) int out_AC::Ctrl(short cmd, short n, int * Parameters, 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;
@@ -275,7 +275,7 @@ int out_AC::Ctrl(short cmd, short n, int * Parameters, boolean send, int suffixC
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;
if (send) publishTopic(item->itemArr->name,(long) set_tmp,"/set"); publishTopic(item->itemArr->name,(long) set_tmp,"/set");
} }
break; break;
@@ -288,7 +288,7 @@ int out_AC::Ctrl(short cmd, short n, int * Parameters, boolean send, int suffixC
data[B_POWER] = power; data[B_POWER] = power;
data[B_POWER] |= 1; data[B_POWER] |= 1;
SendData(on, sizeof(on)/sizeof(byte)); SendData(on, sizeof(on)/sizeof(byte));
if (send) publishTopic(item->itemArr->name,"ON","/cmd"); publishTopic(item->itemArr->name,"ON","/cmd");
return 1; return 1;
break; break;
case CMD_OFF: case CMD_OFF:
@@ -296,7 +296,7 @@ int out_AC::Ctrl(short cmd, short n, int * Parameters, boolean send, int suffixC
data[B_POWER] = power; data[B_POWER] = power;
data[B_POWER] &= ~1; data[B_POWER] &= ~1;
SendData(off, sizeof(off)/sizeof(byte)); SendData(off, sizeof(off)/sizeof(byte));
if (send) publishTopic(item->itemArr->name,"OFF","/cmd"); publishTopic(item->itemArr->name,"OFF","/cmd");
return 1; return 1;
break; break;
case CMD_AUTO: case CMD_AUTO:
@@ -334,7 +334,7 @@ int out_AC::Ctrl(short cmd, short n, int * Parameters, boolean send, int suffixC
return -1; return -1;
break; break;
} }
if (send) publishTopic(item->itemArr->name,s_mode,"/cmd"); publishTopic(item->itemArr->name,s_mode,"/cmd");
break; break;
case S_FAN: case S_FAN:
@@ -361,7 +361,7 @@ int out_AC::Ctrl(short cmd, short n, int * Parameters, boolean send, int suffixC
if (n) data[B_FAN_SPD] = Parameters[0]; if (n) data[B_FAN_SPD] = Parameters[0];
//TODO - mapping digits to speed //TODO - mapping digits to speed
} }
if (send) publishTopic(item->itemArr->name,s_mode,"/fan"); publishTopic(item->itemArr->name,s_mode,"/fan");
break; break;
case S_MODE: case S_MODE:

View File

@@ -29,7 +29,7 @@ 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, boolean send=true, 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:
void InsertData(byte data[], size_t size); void InsertData(byte data[], size_t size);

View File

@@ -58,7 +58,15 @@ const serial_t serialModes_P[] PROGMEM =
{ "8O1", SERIAL_8O1}, { "8O1", SERIAL_8O1},
{ "8O2", SERIAL_8O2}, { "8O2", SERIAL_8O2},
{ "8M1", SERIAL_8M1}, { "8M1", SERIAL_8M1},
{ "8S1", SERIAL_8S1} { "8S1", SERIAL_8S1},
{ "7E1", SERIAL_7E1},//(uint16_t) US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_EVEN },
{ "7N1", SERIAL_7N1},
{ "7E2", SERIAL_7E2},
{ "7N2", SERIAL_7N2},
{ "7O1", SERIAL_7O1},
{ "7O2", SERIAL_7O2},
{ "7M1", SERIAL_7M1},
{ "7S1", SERIAL_7S1}
} ; } ;
#define serialModesNum sizeof(serialModes_P)/sizeof(serial_t) #define serialModesNum sizeof(serialModes_P)/sizeof(serial_t)
@@ -275,7 +283,7 @@ int out_Modbus::getChanType()
int out_Modbus::Ctrl(short cmd, short n, int * Parameters, boolean send, int suffixCode, char* subItem) int out_Modbus::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* subItem)
{ {
int chActive = item->isActive(); int chActive = item->isActive();
bool toExecute = (chActive>0); bool toExecute = (chActive>0);
@@ -314,12 +322,12 @@ case S_CMD:
st = item->getVal(); st = item->getVal();
if (st && (st<MIN_VOLUME) && send) st=INIT_VOLUME; if (st && (st<MIN_VOLUME) /* && send */) st=INIT_VOLUME;
item->setVal(st); item->setVal(st);
if (st) //Stored smthng if (st) //Stored smthng
{ {
if (send) item->SendStatus(SEND_COMMAND | SEND_PARAMETERS); item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
debugSerial<<F("Restored: ")<<st<<endl; debugSerial<<F("Restored: ")<<st<<endl;
} }
else else
@@ -328,13 +336,13 @@ case S_CMD:
// Store // Store
st=100; st=100;
item->setVal(st); item->setVal(st);
if (send) 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:
if (send) 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;

View File

@@ -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(short cmd, short n=0, int * Parameters=NULL, boolean send=true, 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:

View File

@@ -210,7 +210,7 @@ int out_Motor::getChanType()
int out_Motor::Ctrl(short cmd, short n, int * Parameters, boolean send, int suffixCode, char* subItem) int out_Motor::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* subItem)
{ {
int chActive = item->isActive(); int chActive = item->isActive();
bool toExecute = (chActive>0); bool toExecute = (chActive>0);
@@ -249,12 +249,12 @@ case S_CMD:
st = item->getVal(); st = item->getVal();
if (st && (st<MIN_VOLUME) && send) st=INIT_VOLUME; if (st && (st<MIN_VOLUME) /* && send */) st=INIT_VOLUME;
item->setVal(st); item->setVal(st);
if (st) //Stored smthng if (st) //Stored smthng
{ {
if (send) item->SendStatus(SEND_COMMAND | SEND_PARAMETERS); item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
debugSerial<<F("Restored: ")<<st<<endl; debugSerial<<F("Restored: ")<<st<<endl;
} }
else else
@@ -263,13 +263,13 @@ case S_CMD:
// Store // Store
st=100; st=100;
item->setVal(st); item->setVal(st);
if (send) 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:
if (send) 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;

View File

@@ -25,7 +25,7 @@ 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, boolean send=true, int suffixCode=0, char* subItem=NULL) override; int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
int8_t pinUp; int8_t pinUp;
int8_t pinDown; int8_t pinDown;

View File

@@ -88,7 +88,7 @@ return driverStatus;
int out_SPILed::isActive() int out_SPILed::isActive()
{ {
CHstore st; itemStore st;
st.aslong = item->getVal(); //Restore old params st.aslong = item->getVal(); //Restore old params
debugSerial<< F(" val:")<<st.v<<endl; debugSerial<< F(" val:")<<st.v<<endl;
return st.v; return st.v;
@@ -107,7 +107,7 @@ int out_SPILed::getChanType()
return CH_RGBW; return CH_RGBW;
} }
int out_SPILed::PixelCtrl(CHstore *st, short cmd, int from, int to, bool show, bool rgb) int out_SPILed::PixelCtrl(itemStore *st, short cmd, int from, int to, bool show, bool rgb)
{ {
//debugSerial<<F("cmd: ")<<cmd<<endl; //debugSerial<<F("cmd: ")<<cmd<<endl;
#ifdef ADAFRUIT_LED #ifdef ADAFRUIT_LED
@@ -188,11 +188,11 @@ CRGB pixel;
return 1; return 1;
} }
int out_SPILed::Ctrl(short cmd, short n, int * Parameters, boolean send, int suffixCode, char* subItem) int out_SPILed::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* subItem)
{ {
int chActive = item->isActive(); int chActive = item->isActive();
bool toExecute = (chActive>0); bool toExecute = (chActive>0);
CHstore st; itemStore 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
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
@@ -287,12 +287,12 @@ case S_CMD:
PixelCtrl(&st,CMD_ON,from,to); PixelCtrl(&st,CMD_ON,from,to);
else //whole strip else //whole strip
{ {
if (st.aslong && (st.v<MIN_VOLUME) && send) st.v=INIT_VOLUME; if (st.aslong && (st.v<MIN_VOLUME) /* && send */) st.v=INIT_VOLUME;
item->setVal(st.aslong); item->setVal(st.aslong);
if (st.aslong ) //Stored smthng if (st.aslong ) //Stored smthng
{ {
if (send) 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.h<<F(",")<<st.s<<F(",")<<st.v<<endl;
} }
else else
@@ -304,7 +304,7 @@ case S_CMD:
st.hsv_flag=1; st.hsv_flag=1;
// Store // Store
item->setVal(st.aslong); item->setVal(st.aslong);
if (send) item->SendStatus(SEND_COMMAND | SEND_PARAMETERS ); item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
} }
PixelCtrl(&st,0,from,to); PixelCtrl(&st,0,from,to);
@@ -319,7 +319,7 @@ case S_CMD:
{ {
st.v=0; st.v=0;
PixelCtrl(&st,0,from,to); PixelCtrl(&st,0,from,to);
if (send) 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");
} }
return 1; return 1;

View File

@@ -21,8 +21,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, boolean send=true, 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(CHstore *st, short cmd, int from =0 , int to = 1024, bool show = 1, bool rgb = 0); int PixelCtrl(itemStore *st, short cmd, int from =0 , int to = 1024, bool show = 1, bool rgb = 0);
int numLeds; int numLeds;
int8_t pin; int8_t pin;
int ledsType; int ledsType;

View File

@@ -5,12 +5,15 @@ const char disconnected_P[] PROGMEM = "disconnected";
const char ready_P[] PROGMEM = "ready"; const char ready_P[] PROGMEM = "ready";
const char homie_P[] PROGMEM = "$homie"; const char homie_P[] PROGMEM = "$homie";
const char homiever_P[] PROGMEM = "2.1.0"; const char homiever_P[] PROGMEM = "3.0.1";
const char name_P[] PROGMEM = "$name"; const char name_P[] PROGMEM = "$name";
const char nameval_P[] PROGMEM = "LightHub "; const char nameval_P[] PROGMEM = "LightHub ";
const char nodes_P[] PROGMEM = "$nodes"; const char nodes_P[] PROGMEM = "$nodes";
const char properties_P[] PROGMEM = "$properties";
const char propertiesVal_P[] PROGMEM = "set,cmd";
const char settable_P[] PROGMEM = "settable";
const char localip_P[] PROGMEM = "$localip"; const char localip_P[] PROGMEM = "$localip";
const char mac_P[] PROGMEM = "$mac"; const char mac_P[] PROGMEM = "$mac";
const char fwname_P[] PROGMEM = "$fw/name"; const char fwname_P[] PROGMEM = "$fw/name";
@@ -37,6 +40,36 @@ const char statsval_P[] PROGMEM = "uptime,freeheap";
const char uptime_P[] PROGMEM = "uptime"; const char uptime_P[] PROGMEM = "uptime";
const char freeheap_P[] PROGMEM = "freeheap"; const char freeheap_P[] PROGMEM = "freeheap";
/*
{"name": "Спальня LED",
"command_topic": "myhome/in/bedr/cmd",
"state_topic": "myhome/s_out/bedr/cmd",
"hs_command_topic": "myhome/in/bedr/set",
"hs_state_topic": "myhome/s_out/bedr/set",
"hs_value_template": "{%set a=value.split(',')%} {% if a[1] -%} {{a[0]+','+a[1]}} {%- endif %}",
"brightness_scale": 100,
"brightness_command_topic": "myhome/in/bedr/set",
"brightness_state_topic": "myhome/s_out/bedr/set",
"brightness_value_template": "{{ value.split(',')[2] }}"
}
{
"~":"myhome"
"name": "Спальня LED",
"cmd_t": "~/in/bedr/cmd",
"tat_t": "~/s_out/bedr/cmd",
"hs_cmd_t": "~/in/bedr/set",
"hs_stat_t": "~/s_out/bedr/set",
"hs_val_tpl": "{%set a=value.split(',')%}{% if a[1] -%}{{a[0]+','+a[1]}}{%- endif %}",
"bri_scl": 100,
"bri_cmd_t": "~/in/bedr/set",
"bri_stat_t": "~/s_out/bedr/set",
"bri_val_tpl": "{{ value.split(',')[2] }}"
}
*/
//Commands //Commands
const char ON_P[] PROGMEM = "ON"; const char ON_P[] PROGMEM = "ON";

View File

@@ -541,28 +541,30 @@ switch (cmd->type)
case aJson_Object: case aJson_Object:
{ {
aJsonObject *item = aJson.getObjectItem(cmd, "item"); aJsonObject *item = aJson.getObjectItem(cmd, "item");
aJsonObject *icmd = aJson.getObjectItem(cmd, "icmd");
aJsonObject *emit = aJson.getObjectItem(cmd, "emit"); aJsonObject *emit = aJson.getObjectItem(cmd, "emit");
aJsonObject *ecmd = aJson.getObjectItem(cmd, "ecmd"); aJsonObject *icmd = NULL;
aJsonObject *ecmd = NULL;
switch (toggle)
aJsonObject *irev = NULL; {
aJsonObject *erev = NULL; case 0:
icmd = aJson.getObjectItem(cmd, "icmd");
if (toggle>0){ ecmd = aJson.getObjectItem(cmd, "ecmd");
aJsonObject *irev = aJson.getObjectItem(cmd, "irev"); break;
aJsonObject *erev = aJson.getObjectItem(cmd, "erev"); case 1:
} icmd = aJson.getObjectItem(cmd, "irev");
ecmd = aJson.getObjectItem(cmd, "erev");
//no *rev parameters - fallback
if (!icmd) icmd = aJson.getObjectItem(cmd, "icmd");
if (!ecmd) ecmd = aJson.getObjectItem(cmd, "ecmd");
}
char * itemCommand; char * itemCommand;
if (irev && toggle && irev->type == aJson_String) itemCommand = irev->valuestring; if(icmd && icmd->type == aJson_String) itemCommand = icmd->valuestring;
else if(icmd && icmd->type == aJson_String) itemCommand = icmd->valuestring;
else itemCommand = defCmd; else itemCommand = defCmd;
char * emitCommand; char * emitCommand;
if (erev && toggle && erev->type == aJson_String) emitCommand = erev->valuestring; if(ecmd && ecmd->type == aJson_String) emitCommand = ecmd->valuestring;
else if(ecmd && ecmd->type == aJson_String) emitCommand = ecmd->valuestring;
else emitCommand = defCmd; else emitCommand = defCmd;
//debugSerial << F("IN:") << (pin) << F(" : ") <<endl; //debugSerial << F("IN:") << (pin) << F(" : ") <<endl;
@@ -599,7 +601,7 @@ mqttClient.publish(addrstr, emitCommand , true);
if (item && itemCommand && item->type == aJson_String) { if (item && itemCommand && item->type == aJson_String) {
//debugSerial <<F("Controlled item:")<< item->valuestring <<endl; //debugSerial <<F("Controlled item:")<< item->valuestring <<endl;
Item it(item->valuestring); Item it(item->valuestring);
if (it.isValid()) it.Ctrl(itemCommand, true); if (it.isValid()) it.Ctrl(itemCommand);
} }
return true; return true;
} }