Merge pull request #7464 from to-scho/hotfix/shutterbutton_webbuttons

Fix labeling of web buttons for shutters
This commit is contained in:
Theo Arends 2020-01-09 09:45:28 +01:00 committed by GitHub
commit 49607b9747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 18 deletions

View File

@ -502,6 +502,8 @@
#define D_CMND_SHUTTER_CLOSE "Close"
#define D_CMND_SHUTTER_UP "Up"
#define D_CMND_SHUTTER_DOWN "Down"
#define D_CMND_SHUTTER_TOGGLEUP "ToggleUp"
#define D_CMND_SHUTTER_TOGGLEDOWN "ToggleDown"
#define D_CMND_SHUTTER_STOP "Stop"
#define D_CMND_SHUTTER_POSITION "Position"
#define D_CMND_SHUTTER_OPENTIME "OpenDuration"

View File

@ -1120,20 +1120,12 @@ void HandleRoot(void)
for (uint32_t idx = 1; idx <= devices_present; idx++) {
bool set_button = ((idx <= MAX_BUTTON_TEXT) && strlen(SettingsText(SET_BUTTON1 + idx -1)));
#ifdef USE_SHUTTER
if (Settings.flag3.shutter_mode) { // SetOption80 - Enable shutter support
bool shutter_used = false;
for (uint32_t i = 0; i < MAX_SHUTTERS; i++) {
if (Settings.shutter_startrelay[i] == (((idx -1) & 0xFFFFFFFE) +1)) {
shutter_used = true;
break;
}
}
if (shutter_used) {
WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx,
(set_button) ? SettingsText(SET_BUTTON1 + idx -1) : (idx % 2) ? "" : "",
"");
continue;
}
int32_t ShutterWebButton;
if (ShutterWebButton = IsShutterWebButton(idx)) {
WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx,
(set_button) ? SettingsText(SET_BUTTON1 + idx -1) : (ShutterWebButton>0) ? "" : "",
"");
continue;
}
#endif // USE_SHUTTER
snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), idx);
@ -1216,7 +1208,18 @@ bool HandleRootStatusRefresh(void)
}
} else {
#endif // USE_SONOFF_IFAN
ExecuteCommandPower(device, POWER_TOGGLE, SRC_IGNORE);
#ifdef USE_SHUTTER
int32_t ShutterWebButton;
if (ShutterWebButton = IsShutterWebButton(device)) {
snprintf_P(svalue, sizeof(svalue), PSTR("ShutterPosition%d %s"), abs(ShutterWebButton), (ShutterWebButton>0) ? PSTR(D_CMND_SHUTTER_TOGGLEUP) : PSTR(D_CMND_SHUTTER_TOGGLEDOWN));
AddLog_P2(LOG_LEVEL_INFO, PSTR("SHT: WebButton %d, %s"), ShutterWebButton, svalue);
ExecuteWebCommand(svalue, SRC_WEBGUI);
} else {
#endif // USE_SHUTTER
ExecuteCommandPower(device, POWER_TOGGLE, SRC_IGNORE);
#ifdef USE_SHUTTER
}
#endif // USE_SHUTTER
#ifdef USE_SONOFF_IFAN
}
#endif // USE_SONOFF_IFAN
@ -1301,6 +1304,22 @@ bool HandleRootStatusRefresh(void)
return true;
}
#ifdef USE_SHUTTER
int32_t IsShutterWebButton(uint32_t idx) {
/* 0: Not a shutter, 1..4: shutter up idx, -1..-4: shutter down idx */
int32_t ShutterWebButton = 0;
if (Settings.flag3.shutter_mode) { // SetOption80 - Enable shutter support
for (uint32_t i = 0; i < MAX_SHUTTERS; i++) {
if (Settings.shutter_startrelay[i] && ((Settings.shutter_startrelay[i] == idx) || (Settings.shutter_startrelay[i] == (idx-1)))) {
ShutterWebButton = (Settings.shutter_startrelay[i] == idx) ? (i+1): (-1-i);
break;
}
}
}
return ShutterWebButton;
}
#endif // USE_SHUTTER
/*-------------------------------------------------------------------------------------------*/
#ifndef FIRMWARE_MINIMAL

View File

@ -667,15 +667,15 @@ void CmndShutterPosition(void)
// value 0 with data_len > 0 can mean Open
if ((XdrvMailbox.data_len > 1) && (XdrvMailbox.payload <= 0)) {
//UpperCase(XdrvMailbox.data, XdrvMailbox.data);
if (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_UP) || !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_OPEN)) {
if (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_UP) || !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_OPEN) || ((Shutter.direction[index]==0) && !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_TOGGLEUP))) {
CmndShutterOpen();
return;
}
if (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_DOWN) || !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_CLOSE)) {
if (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_DOWN) || !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_CLOSE) || ((Shutter.direction[index]==0) && !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_TOGGLEDOWN))) {
CmndShutterClose();
return;
}
if (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_STOP)) {
if (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_STOP) || ((Shutter.direction[index]) && (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_TOGGLEUP) || !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_TOGGLEDOWN)))) {
XdrvMailbox.payload = -99;
CmndShutterStop();
return;