From b66cc3479f363b61b53104aa40d841467062fe51 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 24 Dec 2019 17:10:50 +0100 Subject: [PATCH] Add support for user defined GUI button text Add commands ``WebButton1`` until ``WebButton16`` to support user defined GUI button text (#7166) --- RELEASENOTES.md | 1 + tasmota/CHANGELOG.md | 1 + tasmota/i18n.h | 1 + tasmota/settings.ino | 13 +++++----- tasmota/support_command.ino | 2 +- tasmota/tasmota.h | 9 +++---- tasmota/xdrv_01_webserver.ino | 47 +++++++++++++++++++++++++++++------ 7 files changed, 54 insertions(+), 20 deletions(-) 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("