diff --git a/tasmota/include/tasmota.h b/tasmota/include/tasmota.h index 1df0aa1f0..708e015d9 100644 --- a/tasmota/include/tasmota.h +++ b/tasmota/include/tasmota.h @@ -122,7 +122,7 @@ const uint8_t MAX_STATE_TEXT = 4; // Max number of State names (OFF, O const uint8_t MAX_NTP_SERVERS = 3; // Max number of NTP servers 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_BUTTON_TEXT = 32; // Max number of GUI button labels const uint8_t MAX_GROUP_TOPICS = 4; // Max number of Group Topics const uint8_t MAX_DEV_GROUP_NAMES = 4; // Max number of Device Group names @@ -484,7 +484,12 @@ enum SettingsTextIndex { SET_OTAURL, SET_SHD_PARAM, SET_RGX_SSID, SET_RGX_PASSWORD, SET_INFLUXDB_HOST, SET_INFLUXDB_PORT, SET_INFLUXDB_ORG, SET_INFLUXDB_TOKEN, SET_INFLUXDB_BUCKET, SET_INFLUXDB_RP, - SET_MAX }; + SET_MAX, // limit of texts stored in Settings + // Index above are not stored in Settings and should be handled specifically in SettingText() + SET_BUTTON17, SET_BUTTON18, SET_BUTTON19, SET_BUTTON20, SET_BUTTON21, SET_BUTTON22, SET_BUTTON23, SET_BUTTON24, + SET_BUTTON25, SET_BUTTON26, SET_BUTTON27, SET_BUTTON28, SET_BUTTON29, SET_BUTTON30, SET_BUTTON31, SET_BUTTON32, + SET_FINAL_MAX + }; enum SpiInterfaces { SPI_NONE, SPI_MOSI, SPI_MISO, SPI_MOSI_MISO }; diff --git a/tasmota/tasmota_support/settings.ino b/tasmota/tasmota_support/settings.ino index 46173d79e..61bf2c58f 100644 --- a/tasmota/tasmota_support/settings.ino +++ b/tasmota/tasmota_support/settings.ino @@ -682,7 +682,11 @@ bool SettingsUpdateText(uint32_t index, const char* replace_me) { char* SettingsText(uint32_t index) { char* position = Settings->text_pool; - if (index >= SET_MAX) { + if (index >= SET_MAX) { // Index above SET_MAX are not stored in Settings +#ifdef USE_WEBSERVER + if (SET_BUTTON17 <= index && index <= SET_BUTTON32) + return (char*)GetWebButton(index-SET_BUTTON17+16); +#endif position += settings_text_size -1; // Setting not supported - internal error - return empty string } else { SettingsUpdateFinished(); diff --git a/tasmota/tasmota_support/support_command.ino b/tasmota/tasmota_support/support_command.ino index 1d62ec9db..e5c627414 100644 --- a/tasmota/tasmota_support/support_command.ino +++ b/tasmota/tasmota_support/support_command.ino @@ -305,6 +305,7 @@ void ResponseCmndAll(uint32_t text_index, uint32_t count) { #ifdef MQTT_DATA_STRING for (uint32_t i = 0; i < count; i++) { if ((SET_MQTT_GRP_TOPIC == text_index) && (1 == i)) { real_index = SET_MQTT_GRP_TOPIC2 -1; } + if ((SET_BUTTON1 == text_index) && (16 == i)) { real_index = SET_BUTTON17 -16; } ResponseAppend_P(PSTR("%c\"%s%d\":\"%s\""), (i)?',':'{', XdrvMailbox.command, i +1, EscapeJSONString(SettingsText(real_index +i)).c_str()); } ResponseJsonEnd(); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino index af0cfa588..d9124dbe7 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino @@ -1266,18 +1266,18 @@ void HandleRoot(void) #endif // USE_SONOFF_IFAN uint32_t cols = WebDeviceColumns(); for (uint32_t idx = 1; idx <= TasmotaGlobal.devices_present; idx++) { - bool set_button = ((idx <= MAX_BUTTON_TEXT) && strlen(SettingsText(SET_BUTTON1 + idx -1))); + bool set_button = ((idx <= MAX_BUTTON_TEXT) && strlen(GetWebButton(idx -1))); #ifdef USE_SHUTTER int32_t ShutterWebButton; if (ShutterWebButton = IsShutterWebButton(idx)) { WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / cols, idx, - (set_button) ? SettingsText(SET_BUTTON1 + idx -1) : ((ShutterGetOptions(abs(ShutterWebButton)-1) & 2) /* is locked */ ? "-" : ((ShutterGetOptions(abs(ShutterWebButton)-1) & 8) /* invert web buttons */ ? ((ShutterWebButton>0) ? "▼" : "▲") : ((ShutterWebButton>0) ? "▲" : "▼"))), + (set_button) ? GetWebButton(idx -1) : ((ShutterGetOptions(abs(ShutterWebButton)-1) & 2) /* is locked */ ? "-" : ((ShutterGetOptions(abs(ShutterWebButton)-1) & 8) /* invert web buttons */ ? ((ShutterWebButton>0) ? "▼" : "▲") : ((ShutterWebButton>0) ? "▲" : "▼"))), ""); } else { #endif // USE_SHUTTER snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), idx); WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / cols, idx, - (set_button) ? SettingsText(SET_BUTTON1 + idx -1) : (cols < 5) ? PSTR(D_BUTTON_TOGGLE) : "", + (set_button) ? GetWebButton(idx -1) : (cols < 5) ? PSTR(D_BUTTON_TOGGLE) : "", (set_button) ? "" : (TasmotaGlobal.devices_present > 1) ? stemp : ""); #ifdef USE_SHUTTER } @@ -3696,6 +3696,32 @@ void CmndWebSensor(void) ResponseJsonEnd(); } +String *WebButton1732[16] = {0,}; + +void SetWebButton(uint8_t button_index, const char *text) { + if (button_index < 16) + SettingsUpdateText(SET_BUTTON1 + button_index, text); + else if (button_index < MAX_BUTTON_TEXT) { + button_index -= 16; + if (!WebButton1732[button_index]) + WebButton1732[button_index] = new String(text); + else + *WebButton1732[button_index] = text; + } +} + +const char* GetWebButton(uint8_t button_index) { + static char empty[1] = {0}; + if (button_index < 16) + return SettingsText(SET_BUTTON1 + button_index); + else if (button_index < MAX_BUTTON_TEXT) { + button_index -= 16; + if (WebButton1732[button_index]) + return WebButton1732[button_index]->c_str(); + } + return empty; +} + void CmndWebButton(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_BUTTON_TEXT)) { @@ -3703,9 +3729,9 @@ void CmndWebButton(void) ResponseCmndAll(SET_BUTTON1, MAX_BUTTON_TEXT); } else { if (XdrvMailbox.data_len > 0) { - SettingsUpdateText(SET_BUTTON1 + XdrvMailbox.index -1, ('"' == XdrvMailbox.data[0]) ? "" : XdrvMailbox.data); + SetWebButton(XdrvMailbox.index -1, ('"' == XdrvMailbox.data[0]) ? "" : XdrvMailbox.data); } - ResponseCmndIdxChar(SettingsText(SET_BUTTON1 + XdrvMailbox.index -1)); + ResponseCmndIdxChar(GetWebButton(XdrvMailbox.index -1)); } } } diff --git a/tasmota/tasmota_xdrv_driver/xdrv_06_snfbridge.ino b/tasmota/tasmota_xdrv_driver/xdrv_06_snfbridge.ino index cf62932b4..9b34c497d 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_06_snfbridge.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_06_snfbridge.ino @@ -516,7 +516,7 @@ void SonoffBridgeAddButton(void) { for (uint32_t j = 0; j < 4; j++) { idx++; WSContentSend_P(PSTR("