Skip to content

Commit

Permalink
Add GUI sensor separators (#20495)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Jan 15, 2024
1 parent ee4bf86 commit 637fac5
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ All notable changes to this project will be documented in this file.
- SML support for IM350 (#20474)
- LVGL `lv.str_arr` (#20480)
- ESP32 MI BLE support for Xiaomi LYWSD02MMC (#20381)
- LVGL option to add `lv.keyboard` extra widget
- LVGL option to add `lv.keyboard` extra widget (#20496)
- GUI sensor separators (#20495)

### Breaking Changed

Expand Down
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
- Support for pipsolar inverter [#20408](https://github.com/arendst/Tasmota/issues/20408)
- Support for HardwareSerial invert [#15461](https://github.com/arendst/Tasmota/issues/15461)
- SML support for IM350 [#20474](https://github.com/arendst/Tasmota/issues/20474)
- GUI sensor separators [#20495](https://github.com/arendst/Tasmota/issues/20495)
- ESP32 used UART information
- ESP32 experimental support GPIOViewer when ``define USE_ESP32_GPIO_VIEWER`` is enabled
- ESP32 MI BLE support for Xiaomi LYWSD02MMC [#20381](https://github.com/arendst/Tasmota/issues/20381)
Expand All @@ -145,6 +146,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
- Berry `tasmota.webcolor` [#20454](https://github.com/arendst/Tasmota/issues/20454)
- Berry `debug.caller` [#20470](https://github.com/arendst/Tasmota/issues/20470)
- LVGL `lv.str_arr` [#20480](https://github.com/arendst/Tasmota/issues/20480)
- LVGL option to add `lv.keyboard` extra widget [#20496](https://github.com/arendst/Tasmota/issues/20496)
- HASPmota `haspmota.page_show()` to change page [#20333](https://github.com/arendst/Tasmota/issues/20333)
- HASPmota type `chart` [#20372](https://github.com/arendst/Tasmota/issues/20372)
- Matter support for password for remote Tasmota devices [#20296](https://github.com/arendst/Tasmota/issues/20296)
Expand Down
1 change: 1 addition & 0 deletions tasmota/include/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ const float kSpeedConversionFactor[] = {1, // none
// xdrv_02_webserver.ino
#ifdef USE_WEBSERVER
// {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
const char HTTP_SNS_HR[] PROGMEM = "<tr><td colspan=2><hr/>{e}";
const char HTTP_SNS_F_TEMP[] PROGMEM = "{s}%s " D_TEMPERATURE "{m}%*_f " D_UNIT_DEGREE "%c{e}";
const char HTTP_SNS_F_VOLTAGE[] PROGMEM = "{s}%s " D_VOLTAGE "{m}%*_f " D_UNIT_VOLT "{e}";
const char HTTP_SNS_F_CURRENT_MA[] PROGMEM = "{s}%s " D_CURRENT "{m}%*_f " D_UNIT_MILLIAMPERE "{e}";
Expand Down
26 changes: 24 additions & 2 deletions tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ void _WSContentSendBuffer(bool decimal, const char * formatP, va_list arg) {
int len = strlen(content);
if (0 == len) { return; } // No content

WSContentSeparator(2); // Print separator on next WSContentSeparator(1)

if (decimal && (D_DECIMAL_SEPARATOR[0] != '.')) {
for (uint32_t i = 0; i < len; i++) {
if ('.' == content[i]) {
Expand Down Expand Up @@ -982,6 +984,24 @@ void WSContentSpaceButton(uint32_t title_index, bool show=true) {
WSContentButton(title_index, show);
}

void WSContentSeparator(uint32_t state) {
// Send two column separator
static bool request = false;
switch (state) {
case 0: // Print separator (fall through to WSContentSeparator(1))
request = true;
case 1: // Print separator if needed
if (request) {
WSContentSend_P(HTTP_SNS_HR); // <tr><td colspan=2><hr/>{e}
request = false;
}
break;
case 2: // Print separator on next WSContentSeparator(1)
request = true;
break;
}
}

void WSContentSend_Temp(const char *types, float f_temperature) {
WSContentSend_PD(HTTP_SNS_F_TEMP, types, Settings->flag2.temperature_resolution, &f_temperature, TempUnit());
}
Expand Down Expand Up @@ -1467,12 +1487,14 @@ bool HandleRootStatusRefresh(void)
#else
WSContentBegin(200, CT_HTML);
#endif // USE_WEB_SSE
WSContentSend_P(PSTR("{t}"));

WSContentSend_P(PSTR("{t}")); // <table style='width:100%'>
WSContentSeparator(0); // Print separator
if (Settings->web_time_end) {
WSContentSend_P(PSTR("{s}" D_TIMER_TIME "{m}%s{e}"), GetDateAndTime(DT_LOCAL).substring(Settings->web_time_start, Settings->web_time_end).c_str());
WSContentSeparator(0); // Print separator
}
XsnsXdrvCall(FUNC_WEB_SENSOR);

WSContentSend_P(PSTR("</table>"));

if (TasmotaGlobal.devices_present) {
Expand Down
4 changes: 2 additions & 2 deletions tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ void EnergyShow(bool json) {
// {s}</th><th></th><th>Head1</th><th></th><th>Head2</th><th></th><td>{e}
// {s}</th><th></th><th>Head1</th><th></th><th>Head2</th><th></th><th>Head3</th><th></th><td>{e}
// {s}</th><th></th><th>Head1</th><th></th><th>Head2</th><th></th><th>Head3</th><th></th><th>Head4</th><th></th><td>{e}
WSContentSend_P(PSTR("</table><hr/>{t}{s}</th><th></th>")); // First column is empty ({t} = <table style='width:100%'>, {s} = <tr><th>)
WSContentSend_P(PSTR("</table>{t}{s}</th><th></th>")); // First column is empty ({t} = <table style='width:100%'>, {s} = <tr><th>)
bool label_o = voltage_common;
bool no_label = (1 == Energy->phase_count);
char number[4];
Expand Down Expand Up @@ -1448,7 +1448,7 @@ void EnergyShow(bool json) {
WSContentSend_PD(HTTP_SNS_EXPORT_ACTIVE, WebEnergyFmt(Energy->export_active, Settings->flag2.energy_resolution, single));
}
XnrgCall(FUNC_WEB_COL_SENSOR);
WSContentSend_P(PSTR("</table><hr/>{t}")); // {t} = <table style='width:100%'> - Define for next FUNC_WEB_SENSOR
WSContentSend_P(PSTR("</table>{t}")); // {t} = <table style='width:100%'> - Define for next FUNC_WEB_SENSOR
XnrgCall(FUNC_WEB_SENSOR);
#endif // USE_WEBSERVER
}
Expand Down
4 changes: 2 additions & 2 deletions tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ void EnergyShow(bool json) {
Energy->gui_count = relay_show - Energy->gui_offset;
if (Energy->gui_count > Energy->Settings.gui_cols) { Energy->gui_count = Energy->Settings.gui_cols; }

WSContentSend_P(PSTR("</table><hr/>")); // Close current table as we will use different column count
WSContentSend_P(PSTR("</table>")); // Close current table as we will use different column count
bool label_o = voltage_common;
if (ENERGY_DISPLAY_TABS == Energy->Settings.gui_display) {
uint32_t tabs = (relay_show -1 + Energy->Settings.gui_cols) / Energy->Settings.gui_cols;
Expand Down Expand Up @@ -1731,7 +1731,7 @@ void EnergyShow(bool json) {
}

XnrgCall(FUNC_WEB_COL_SENSOR);
WSContentSend_P(PSTR("</table><hr/>{t}")); // {t} = <table style='width:100%'> - Define for next FUNC_WEB_SENSOR
WSContentSend_P(PSTR("</table>{t}")); // {t} = <table style='width:100%'> - Define for next FUNC_WEB_SENSOR
XnrgCall(FUNC_WEB_SENSOR);
}
#endif // USE_WEBSERVER
Expand Down
4 changes: 2 additions & 2 deletions tasmota/tasmota_xdrv_driver/xdrv_86_esp32_sonoff_spm.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2283,7 +2283,7 @@ void SSPMEnergyShow(bool json) {
uint32_t offset = (Sspm->rotate >> 2) * 4;
uint32_t count = relay_show - offset;
if (count > 4) { count = 4; }
WSContentSend_P(PSTR("</table><hr/>")); // Close current table as we will use different column count
WSContentSend_P(PSTR("</table>")); // Close current table as we will use different column count
if (SPM_DISPLAY_TABS == Sspm->Settings.flag.display) {
uint32_t modules = relay_show / 4;
if (modules > 1) {
Expand Down Expand Up @@ -2317,7 +2317,7 @@ void SSPMEnergyShow(bool json) {
WSContentSend_PD(HTTP_SNS_ENERGY_TODAY, SSPMEnergyFormat(value_chr, Sspm->energy_today[0], Settings->flag2.energy_resolution, indirect, offset, count));
WSContentSend_PD(HTTP_SNS_ENERGY_YESTERDAY, SSPMEnergyFormat(value_chr, Sspm->Settings.energy_yesterday[0], Settings->flag2.energy_resolution, indirect, offset, count));
WSContentSend_PD(HTTP_SNS_ENERGY_TOTAL, SSPMEnergyFormat(value_chr, Sspm->energy_total[0], Settings->flag2.energy_resolution, indirect, offset, count));
WSContentSend_P(PSTR("</table><hr/>{t}")); // {t} = <table style='width:100%'> - Define for next FUNC_WEB_SENSOR
WSContentSend_P(PSTR("</table>{t}")); // {t} = <table style='width:100%'> - Define for next FUNC_WEB_SENSOR
}
#endif // USE_WEBSERVER
}
Expand Down
2 changes: 2 additions & 0 deletions tasmota/tasmota_xx2c_global/xdrv_interface.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,8 @@ bool XdrvCall(uint32_t function) {

result = xdrv_func_ptr[x](function);

if (FUNC_WEB_SENSOR == function) { WSContentSeparator(1); } // Show separator if needed

#ifdef USE_PROFILE_FUNCTION
#ifdef XFUNC_PTR_IN_ROM
uint32_t index = pgm_read_byte(kXdrvList + x);
Expand Down
2 changes: 2 additions & 0 deletions tasmota/tasmota_xx2c_global/xsns_interface.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,8 @@ bool XsnsCall(uint32_t function) {

result = xsns_func_ptr[x](function);

if (FUNC_WEB_SENSOR == function) { WSContentSeparator(1); } // Show separator if needed

#ifdef USE_PROFILE_FUNCTION
#ifdef XFUNC_PTR_IN_ROM
uint32_t index = pgm_read_byte(kXsnsList + x);
Expand Down

2 comments on commit 637fac5

@SteWers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arendst Are you sure to insert a separator at the beginning?

WSContentSend_P(PSTR("{t}"));        // <table style='width:100%'>
WSContentSeparator(0);               // Print separator | Remove thin line?
if (Settings->web_time_end) {
  WSContentSend_P(PSTR("{s}" D_TIMER_TIME "{m}%s{e}"), GetDateAndTime(DT_LOCAL).substring(Settings->web_time_start, Settings->web_time_end).c_str());
  WSContentSeparator(0);             // Print separator
}

In my opinion it looks better without.

@arendst
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. remove it.

Please sign in to comment.