diff --git a/RELEASENOTES.md b/RELEASENOTES.md index c9293bb95381..6be1dfa9fb7d 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -56,6 +56,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Change Smoother ``Fade`` using 100Hz instead of 20Hz animation (#7179) - Change number of rule ``Var``s and ``Mem``s from 5 to 16 (#4933) - Change number of ``FriendlyName``s from 4 to 8 +- Add commands ``WebButton1`` until ``WebButton16`` to support user defined GUI button text (#7166) - Add support for max 150 characters in most command parameter strings (#3686, #4754) - Add support for GPS as NTP server by Christian Baars and Adrian Scillato - Add support for ``AdcParam`` parameters to control ADC0 Moisture formula by Federico Leoni (#7309) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index d6b1d0ab73fc..0c12ed15cfbc 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -6,6 +6,7 @@ - Change number of ``FriendlyName``s from 4 to 8 - Add Zigbee better support for Xiaomi Double Switch and Xiaomi Vibration sensor - Add support for ``AdcParam`` parameters to control ADC0 Moisture formula by Federico Leoni (#7309) +- Add commands ``WebButton1`` until ``WebButton16`` to support user defined GUI button text (#7166) ### 8.0.0.1 20191221 diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 1ae20dcde2ff..e726fdf5d96b 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -334,6 +334,7 @@ #define D_CMND_WEBREFRESH "WebRefresh" #define D_CMND_WEBSEND "WebSend" #define D_CMND_WEBCOLOR "WebColor" +#define D_CMND_WEBBUTTON "WebButton" #define D_CMND_WEBSENSOR "WebSensor" #define D_CMND_EMULATION "Emulation" #define D_CMND_SENDMAIL "Sendmail" diff --git a/tasmota/settings.ino b/tasmota/settings.ino index ce6c33ff41be..6412d3fc975f 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -551,13 +551,14 @@ bool SettingsUpdateText(uint32_t index, const char* replace_me) char* SettingsText(uint32_t index) { - if (index >= SET_MAX) { - return nullptr; // Setting not supported - internal error - } - char* position = Settings.text_pool; - for (;index > 0; index--) { - while (*position++ != '\0') { } + + if (index >= SET_MAX) { + position += settings_text_size -1; // Setting not supported - internal error - return empty string + } else { + for (;index > 0; index--) { + while (*position++ != '\0') { } + } } return position; } diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 265926b59bc1..f6413dd57d34 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -1311,7 +1311,7 @@ void CmndFriendlyname(void) } else { snprintf_P(stemp1, sizeof(stemp1), PSTR(FRIENDLY_NAME "%d"), XdrvMailbox.index); } - SettingsUpdateText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1, (SC_DEFAULT == Shortcut()) ? stemp1 : XdrvMailbox.data); + SettingsUpdateText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1, ('"' == XdrvMailbox.data[0]) ? "" : (SC_DEFAULT == Shortcut()) ? stemp1 : XdrvMailbox.data); } ResponseCmndIdxChar(SettingsText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1)); } diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 2e539bb49140..c0231d3c9908 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -73,8 +73,9 @@ const uint8_t MAX_RULE_SETS = 3; // Max number of rule sets of size 5 const uint16_t MAX_RULE_SIZE = 512; // Max number of characters in rules // Changes to the following MAX_ defines need to be in line with enum SettingsTextIndex -const uint8_t MAX_FRIENDLYNAMES = 8; // Max number of Friendly names const uint8_t MAX_RULE_MEMS = 16; // Max number of saved vars +const uint8_t MAX_FRIENDLYNAMES = 8; // Max number of Friendly names +const uint8_t MAX_BUTTON_TEXT = 16; // Max number of GUI button labels const uint8_t MAX_HUE_DEVICES = 15; // Max number of Philips Hue device per emulation @@ -290,10 +291,8 @@ enum SettingsTextIndex { SET_OTAURL, SET_MEM9, SET_MEM10, SET_MEM11, SET_MEM12, SET_MEM13, SET_MEM14, SET_MEM15, SET_MEM16, SET_FRIENDLYNAME1, SET_FRIENDLYNAME2, SET_FRIENDLYNAME3, SET_FRIENDLYNAME4, SET_FRIENDLYNAME5, SET_FRIENDLYNAME6, SET_FRIENDLYNAME7, SET_FRIENDLYNAME8, - SET_BUTTON1, SET_BUTTON2, SET_BUTTON3, SET_BUTTON4, - SET_BUTTON5, SET_BUTTON6, SET_BUTTON7, SET_BUTTON8, - SET_BUTTON9, SET_BUTTON10, SET_BUTTON11, SET_BUTTON12, - SET_BUTTON13, SET_BUTTON14, SET_BUTTON15, SET_BUTTON16, + SET_BUTTON1, SET_BUTTON2, SET_BUTTON3, SET_BUTTON4, SET_BUTTON5, SET_BUTTON6, SET_BUTTON7, SET_BUTTON8, + SET_BUTTON9, SET_BUTTON10, SET_BUTTON11, SET_BUTTON12, SET_BUTTON13, SET_BUTTON14, SET_BUTTON15, SET_BUTTON16, SET_MAX }; enum CommandSource { SRC_IGNORE, SRC_MQTT, SRC_RESTART, SRC_BUTTON, SRC_SWITCH, SRC_BACKLOG, SRC_SERIAL, SRC_WEBGUI, SRC_WEBCOMMAND, SRC_WEBCONSOLE, SRC_PULSETIMER, diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index c25cdc3f6d44..d86562bb358b 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1014,7 +1014,7 @@ void HandleRoot(void) AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_MAIN_MENU); - char stemp[10]; + char stemp[33]; WSContentStart_P(S_MAIN_MENU); #ifdef USE_SCRIPT_WEB_DISPLAY @@ -1106,14 +1106,19 @@ void HandleRoot(void) WSContentSend_P(PSTR("")); #ifdef USE_SONOFF_IFAN if (IsModuleIfan()) { - WSContentSend_P(HTTP_DEVICE_CONTROL, 36, 1, D_BUTTON_TOGGLE, ""); + WSContentSend_P(HTTP_DEVICE_CONTROL, 36, 1, + (strlen(SettingsText(SET_BUTTON1))) ? SettingsText(SET_BUTTON1) : D_BUTTON_TOGGLE, + ""); for (uint32_t i = 0; i < MaxFanspeed(); i++) { snprintf_P(stemp, sizeof(stemp), PSTR("%d"), i); - WSContentSend_P(HTTP_DEVICE_CONTROL, 16, i +2, stemp, ""); + WSContentSend_P(HTTP_DEVICE_CONTROL, 16, i +2, + (strlen(SettingsText(SET_BUTTON2 + i))) ? SettingsText(SET_BUTTON2 + i) : stemp, + ""); } } else { #endif // USE_SONOFF_IFAN 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; @@ -1124,13 +1129,17 @@ void HandleRoot(void) } } if (shutter_used) { - WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx, (idx % 2) ? "▲" : "▼" , ""); + WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx, + (set_button) ? SettingsText(SET_BUTTON1 + idx -1) : (idx % 2) ? "▲" : "▼", + ""); continue; } } #endif // USE_SHUTTER snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), idx); - WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx, (devices_present < 5) ? D_BUTTON_TOGGLE : "", (devices_present > 1) ? stemp : ""); + WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx, + (set_button) ? SettingsText(SET_BUTTON1 + idx -1) : (devices_present < 5) ? D_BUTTON_TOGGLE : "", + (set_button) ? "" : (devices_present > 1) ? stemp : ""); } #ifdef USE_SONOFF_IFAN } @@ -1146,7 +1155,9 @@ void HandleRoot(void) if (idx > 0) { WSContentSend_P(PSTR("")); } for (uint32_t j = 0; j < 4; j++) { idx++; - WSContentSend_P(PSTR(""), idx, idx); // &k is related to WebGetArg("k", tmp, sizeof(tmp)); + snprintf_P(stemp, sizeof(stemp), PSTR("%d"), idx); + WSContentSend_P(PSTR(""), idx, // &k is related to WebGetArg("k", tmp, sizeof(tmp)); + (strlen(SettingsText(SET_BUTTON1 + idx -1))) ? SettingsText(SET_BUTTON1 + idx -1) : stemp); } } WSContentSend_P(PSTR("")); @@ -2733,7 +2744,8 @@ const char kWebCommands[] PROGMEM = "|" // No prefix #ifdef USE_SENDMAIL D_CMND_SENDMAIL "|" #endif - D_CMND_WEBSERVER "|" D_CMND_WEBPASSWORD "|" D_CMND_WEBLOG "|" D_CMND_WEBREFRESH "|" D_CMND_WEBSEND "|" D_CMND_WEBCOLOR "|" D_CMND_WEBSENSOR "|" D_CMND_CORS; + D_CMND_WEBSERVER "|" D_CMND_WEBPASSWORD "|" D_CMND_WEBLOG "|" D_CMND_WEBREFRESH "|" D_CMND_WEBSEND "|" D_CMND_WEBCOLOR "|" + D_CMND_WEBSENSOR "|" D_CMND_WEBBUTTON "|" D_CMND_CORS; void (* const WebCommand[])(void) PROGMEM = { #ifdef USE_EMULATION @@ -2742,7 +2754,8 @@ void (* const WebCommand[])(void) PROGMEM = { #ifdef USE_SENDMAIL &CmndSendmail, #endif - &CmndWebServer, &CmndWebPassword, &CmndWeblog, &CmndWebRefresh, &CmndWebSend, &CmndWebColor, &CmndWebSensor, &CmndCors }; + &CmndWebServer, &CmndWebPassword, &CmndWeblog, &CmndWebRefresh, &CmndWebSend, &CmndWebColor, + &CmndWebSensor, &CmndWebButton, &CmndCors }; /*********************************************************************************************\ * Commands @@ -2863,6 +2876,24 @@ void CmndWebSensor(void) ResponseJsonEnd(); } +void CmndWebButton(void) +{ + if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_BUTTON_TEXT)) { + if (!XdrvMailbox.usridx) { + mqtt_data[0] = '\0'; + for (uint32_t i = 0; i < MAX_BUTTON_TEXT; i++) { + ResponseAppend_P(PSTR("%c\"WebButton%d\":\"%s\""), (i) ? ',' : '{', i +1, SettingsText(SET_BUTTON1 +i)); + } + ResponseJsonEnd(); + } else { + if (XdrvMailbox.data_len > 0) { + SettingsUpdateText(SET_BUTTON1 + XdrvMailbox.index -1, ('"' == XdrvMailbox.data[0]) ? "" : XdrvMailbox.data); + } + ResponseCmndIdxChar(SettingsText(SET_BUTTON1 + XdrvMailbox.index -1)); + } + } +} + void CmndCors(void) { if (XdrvMailbox.data_len > 0) {