multiClick automation slightly modified

Suffix calculaton bug fixed
HUE&SAT impact to non-color channels fixed
This commit is contained in:
2020-04-18 18:59:35 +03:00
parent c7bed971ba
commit ff6816b2e1
2 changed files with 33 additions and 20 deletions

View File

@@ -712,7 +712,15 @@ switch (store->state) //Timer based transitions
break; break;
case IS_PRESSED3: case IS_PRESSED3:
if (isTimeOver(store->timestamp16,millis() & 0xFFFF,T_LONG,0xFFFF)) changeState(IS_LONG3, cause); if (isTimeOver(store->timestamp16,millis() & 0xFFFF,T_LONG,0xFFFF))
{
if (!aJson.getObjectItem(inputObj, "lcmd3") && !aJson.getObjectItem(inputObj, "rpcmd3")) //No longpress handlers
{
if (aJson.getObjectItem(inputObj, "scmd3")) changeState(IS_WAITRELEASE, cause); //was used
else changeState(IS_PRESSED2, cause); // completely empty trippleClick section - fallback to first click handler
}
else changeState(IS_LONG3, cause);
}
break; break;
case IS_LONG3: case IS_LONG3:

View File

@@ -106,6 +106,9 @@ int subitem2cmd(char *payload) {
else if (strcmp_P(payload, AUTO_P) == 0) cmd = CMD_AUTO; 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, FAN_ONLY_P) == 0) cmd = CMD_FAN;
else if (strcmp_P(payload, DRY_P) == 0) cmd = CMD_DRY; else if (strcmp_P(payload, DRY_P) == 0) cmd = CMD_DRY;
//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;
return cmd; return cmd;
} }
@@ -394,12 +397,13 @@ int retrieveCode(char **psubItem)
{ {
int suffixCode; int suffixCode;
char* suffix; char* suffix;
//debugSerial<<F("*psubItem:")<<*psubItem<<endl;
if (suffix = strrchr(*psubItem, '/')) //Trying to retrieve right part if (suffix = strrchr(*psubItem, '/')) //Trying to retrieve right part
{ {
*suffix= 0; //Truncate subItem string *suffix= 0; //Truncate subItem string
suffix++; suffix++;
suffixCode = txt2subItem(suffix); suffixCode = txt2subItem(suffix);
debugSerial<<F("suffixCode:")<<suffixCode<<endl;
// myhome/dev/item/sub.....Item/suffix // myhome/dev/item/sub.....Item/suffix
} }
else else
@@ -436,10 +440,6 @@ if (subItem && strlen(subItem))
if (!suffixCode && defaultSuffixCode) if (!suffixCode && defaultSuffixCode)
suffixCode = defaultSuffixCode; suffixCode = defaultSuffixCode;
//if (!suffixCode)
// setCommand = 0; /// Old-style - turn ON by set value
int i=0; int i=0;
while (payload[i]) {payload[i]=toupper(payload[i]);i++;}; while (payload[i]) {payload[i]=toupper(payload[i]);i++;};
@@ -512,7 +512,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
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
if (subItem && strlen(subItem)) if (!suffixCode && subItem && strlen(subItem))
suffixCode = retrieveCode(&subItem); suffixCode = retrieveCode(&subItem);
if (!suffixCode && defaultSuffixCode) if (!suffixCode && defaultSuffixCode)
@@ -522,17 +522,6 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
debugSerial<<F("RAM=")<<freeRam()<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItem<<F(" Suff=")<<suffixCode<<F(" Cmd=")<<cmd<<F(" Par=("); debugSerial<<F("RAM=")<<freeRam()<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItem<<F(" Suff=")<<suffixCode<<F(" Cmd=")<<cmd<<F(" Par=(");
if (!itemArr) return -1; if (!itemArr) return -1;
if (itemType != CH_GROUP )
{
//Check if subitem is some sort of command
int subitemCmd = subitem2cmd(subItem);
if (subitemCmd && subitemCmd != getCmd())
{
debugSerial<<F("Ignored, stored cmd=")<<getCmd()<<endl;
return -1;
}
}
int Par[MAXCTRLPAR] = {0, 0, 0}; int Par[MAXCTRLPAR] = {0, 0, 0};
if (Parameters) if (Parameters)
for (short i=0;i<n && i<MAXCTRLPAR;i++){ for (short i=0;i<n && i<MAXCTRLPAR;i++){
@@ -540,8 +529,19 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
debugSerial<<F("<")<<Par[i]<<F(">"); debugSerial<<F("<")<<Par[i]<<F(">");
} }
debugSerial<<F(")")<<endl; debugSerial<<F(")")<<endl;
int itemCategory = itemType;
if (itemType != CH_GROUP )
{
//Check if subitem is some sort of command
int subitemCmd = subitem2cmd(subItem);
if (subitemCmd && subitemCmd != getCmd())
{
debugSerial<<F("Ignored, channel cmd=")<<getCmd()<<endl;
return -1;
}
}
//int itemCategory = itemType;
if (itemType == CH_GROUP && !send) if (itemType == CH_GROUP && !send)
{ {
@@ -616,6 +616,8 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
if (!n || !Par[0]) Par[0] = DEFAULT_INC_STEP; if (!n || !Par[0]) Par[0] = DEFAULT_INC_STEP;
if (cmd == CMD_DN) Par[0]=-Par[0]; if (cmd == CMD_DN) Par[0]=-Par[0];
st.aslong = getVal(); st.aslong = getVal();
int cType=getChanType();
debugSerial<<"from: h="<<st.h<<" s="<<st.s <<" v="<<st.v<<endl; debugSerial<<"from: h="<<st.h<<" s="<<st.s <<" v="<<st.v<<endl;
switch (suffixCode) switch (suffixCode)
{ {
@@ -628,8 +630,11 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
cmd=CMD_NUM; cmd=CMD_NUM;
debugSerial<<" to v="<<Par[0]<<endl; debugSerial<<" to v="<<Par[0]<<endl;
break; break;
case S_HUE:
case S_SAT:
if ( cType != CH_RGB && cType != CH_RGBW && cType != CH_GROUP) return 0; //HUE and SAT only applicable for RGBx channels
} }
int cType=getChanType();
if ( cType == CH_RGB || cType == CH_RGBW) if ( cType == CH_RGB || cType == CH_RGBW)
{ {
bool modified = false; bool modified = false;