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

@@ -258,7 +258,7 @@ delay(100);
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];
// Some additional Subitems
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)
{
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;
@@ -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] |= 1;
SendData(on, sizeof(on)/sizeof(byte));
if (send) publishTopic(item->itemArr->name,"ON","/cmd");
publishTopic(item->itemArr->name,"ON","/cmd");
return 1;
break;
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] &= ~1;
SendData(off, sizeof(off)/sizeof(byte));
if (send) publishTopic(item->itemArr->name,"OFF","/cmd");
publishTopic(item->itemArr->name,"OFF","/cmd");
return 1;
break;
case CMD_AUTO:
@@ -334,7 +334,7 @@ int out_AC::Ctrl(short cmd, short n, int * Parameters, boolean send, int suffixC
return -1;
break;
}
if (send) publishTopic(item->itemArr->name,s_mode,"/cmd");
publishTopic(item->itemArr->name,s_mode,"/cmd");
break;
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];
//TODO - mapping digits to speed
}
if (send) publishTopic(item->itemArr->name,s_mode,"/fan");
publishTopic(item->itemArr->name,s_mode,"/fan");
break;
case S_MODE:

View File

@@ -29,7 +29,7 @@ public:
int Stop() override;
int Status() 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:
void InsertData(byte data[], size_t size);

View File

@@ -58,7 +58,15 @@ const serial_t serialModes_P[] PROGMEM =
{ "8O1", SERIAL_8O1},
{ "8O2", SERIAL_8O2},
{ "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)
@@ -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();
bool toExecute = (chActive>0);
@@ -314,12 +322,12 @@ case S_CMD:
st = item->getVal();
if (st && (st<MIN_VOLUME) && send) st=INIT_VOLUME;
if (st && (st<MIN_VOLUME) /* && send */) st=INIT_VOLUME;
item->setVal(st);
if (st) //Stored smthng
{
if (send) item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
debugSerial<<F("Restored: ")<<st<<endl;
}
else
@@ -328,13 +336,13 @@ case S_CMD:
// Store
st=100;
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
return 1;
case CMD_OFF:
if (send) item->SendStatus(SEND_COMMAND);
item->SendStatus(SEND_COMMAND);
// if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
return 1;

View File

@@ -31,7 +31,7 @@ public:
int Status() override;
int isActive() 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:

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();
bool toExecute = (chActive>0);
@@ -249,12 +249,12 @@ case S_CMD:
st = item->getVal();
if (st && (st<MIN_VOLUME) && send) st=INIT_VOLUME;
if (st && (st<MIN_VOLUME) /* && send */) st=INIT_VOLUME;
item->setVal(st);
if (st) //Stored smthng
{
if (send) item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
debugSerial<<F("Restored: ")<<st<<endl;
}
else
@@ -263,13 +263,13 @@ case S_CMD:
// Store
st=100;
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
return 1;
case CMD_OFF:
if (send) item->SendStatus(SEND_COMMAND);
item->SendStatus(SEND_COMMAND);
if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time
return 1;

View File

@@ -25,7 +25,7 @@ public:
int Status() override;
int isActive() 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 pinDown;

View File

@@ -88,7 +88,7 @@ return driverStatus;
int out_SPILed::isActive()
{
CHstore st;
itemStore st;
st.aslong = item->getVal(); //Restore old params
debugSerial<< F(" val:")<<st.v<<endl;
return st.v;
@@ -107,7 +107,7 @@ int out_SPILed::getChanType()
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;
#ifdef ADAFRUIT_LED
@@ -188,11 +188,11 @@ CRGB pixel;
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();
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
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);
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);
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;
}
else
@@ -304,7 +304,7 @@ case S_CMD:
st.hsv_flag=1;
// Store
item->setVal(st.aslong);
if (send) item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
}
PixelCtrl(&st,0,from,to);
@@ -319,7 +319,7 @@ case S_CMD:
{
st.v=0;
PixelCtrl(&st,0,from,to);
if (send) item->SendStatus(SEND_COMMAND);
item->SendStatus(SEND_COMMAND);
// if (send) item->publishTopic(item->itemArr->name,"OFF","/cmd");
}
return 1;

View File

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