From 6cd19c0e5990857a9383f0902dd0b0c19f07ff92 Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Tue, 29 Apr 2025 14:04:29 +0200 Subject: [PATCH] WebUI status line left and renamed events 'FUNC_WEB_STATUS_left' and 'FUNC_WEB_STATUS_RIGHT' (#23354) --- CHANGELOG.md | 1 + .../berry_tasmota/src/be_webserver_lib.c | 3 ++ tasmota/include/tasmota.h | 2 +- .../xdrv_01_9_webserver.ino | 35 ++++++------------- .../tasmota_xdrv_driver/xdrv_02_9_mqtt.ino | 7 ++-- .../xdrv_52_3_berry_webserver.ino | 15 ++++++++ .../tasmota_xdrv_driver/xdrv_52_9_berry.ino | 7 ++-- 7 files changed, 39 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9502e716a..1fdcb14da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. - WebUI status line for MQTT and TLS, added `FUNC_WEB_STATUS` event (#23326) - Wireguard VPN (#23347) - Optional Wifi strength indicator in WebUI status line +- WebUI status line left and renamed events `FUNC_WEB_STATUS_left` and `FUNC_WEB_STATUS_RIGHT` ### Breaking Changed diff --git a/lib/libesp32/berry_tasmota/src/be_webserver_lib.c b/lib/libesp32/berry_tasmota/src/be_webserver_lib.c index 49aa105ff..34caf01af 100644 --- a/lib/libesp32/berry_tasmota/src/be_webserver_lib.c +++ b/lib/libesp32/berry_tasmota/src/be_webserver_lib.c @@ -27,6 +27,7 @@ extern int w_webserver_content_flush(bvm *vm); extern int w_webserver_content_stop(bvm *vm); extern int w_webserver_content_close(bvm *vm); extern int w_webserver_content_button(bvm *vm); +extern int w_webserver_content_status_sticker(bvm *vm); extern int w_webserver_html_escape(bvm *vm); @@ -157,6 +158,8 @@ module webserver (scope: global) { content_close, func(w_webserver_content_close) content_button, func(w_webserver_content_button) + content_status_sticker, func(w_webserver_content_status_sticker) + html_escape, func(w_webserver_html_escape) arg_size, func(w_webserver_argsize) diff --git a/tasmota/include/tasmota.h b/tasmota/include/tasmota.h index a0bf27851..86ce99b83 100644 --- a/tasmota/include/tasmota.h +++ b/tasmota/include/tasmota.h @@ -442,7 +442,7 @@ enum XsnsFunctions { FUNC_SETTINGS_OVERRIDE, FUNC_SETUP_RING1, FUNC_SETUP_RING2, FUNC_WEB_GET_ARG, FUNC_WEB_ADD_HANDLER, FUNC_SET_SCHEME, FUNC_HOTPLUG_SCAN, FUNC_TIME_SYNCED, FUNC_DEVICE_GROUP_ITEM, FUNC_NETWORK_UP, FUNC_NETWORK_DOWN, - FUNC_WEB_STATUS, + FUNC_WEB_STATUS_LEFT, FUNC_WEB_STATUS_RIGHT, FUNC_return_result = 200, // Insert function WITHOUT return results before here. Following functions return results FUNC_PIN_STATE, FUNC_MODULE_INIT, FUNC_ADD_BUTTON, FUNC_ADD_SWITCH, FUNC_BUTTON_PRESSED, FUNC_BUTTON_MULTI_PRESSED, FUNC_SET_DEVICE_POWER, diff --git a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino index e3370b7e1..e36dfb288 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino @@ -1175,26 +1175,12 @@ void WSContentStop(void) { // // Convert seconds to a string representing days, hours or minutes. // The string will contain the most coarse time only, rounded down (61m == 01h, 01h37m == 01h). -void WSContentStatusSticker(const char *msg, int32_t seconds) +void WSContentStatusSticker(const char *msg, const char *attr = NULL); +void WSContentStatusSticker(const char *msg, const char *attr) { - char title_attr[64] = ""; - - if (seconds > 0) { - static const uint32_t conversions[4] = {24 * 3600, 3600, 60, 1}; - static const char units[4] = { 'd', 'h', 'm', 's'}; // day, hour, minute - - char unit; - int32_t time_unit = seconds; - for(uint32_t i = 0; i < 4; ++i) { - unit = units[i]; - if (time_unit >= conversions[i]) { // always pass even if 00m - time_unit = seconds / conversions[i]; - break; - } - } - ext_snprintf_P(title_attr, sizeof(title_attr), PSTR(" title='Connected for %i%c'"), time_unit, unit); - } - WSContentSend_P(HTTP_STATUS_STICKER, 0xAAAAAA, title_attr, msg); + if (msg == NULL) { return; } + if (attr == NULL) { attr = ""; } + WSContentSend_P(HTTP_STATUS_STICKER, 0xAAAAAA, attr, msg); } #endif // USE_WEB_STATUS_LINE @@ -1932,25 +1918,26 @@ bool HandleRootStatusRefresh(void) { } #ifdef USE_WEB_STATUS_LINE -#ifdef USE_WEB_STATUS_LINE_WIFI // create a first DIV for the upper left status bar, positioned left-justified // we use the same string literal for both lines to reduce Flash WSContentSend_P(PSTR("