Skip to content

Commit

Permalink
Refactor GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Dec 13, 2024
1 parent f135f46 commit ab5208d
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ ESP8266WebServer *Webserver;
struct WEB {
String chunk_buffer = ""; // Could be max 2 * CHUNKED_BUFFER_SIZE
uint32_t upload_size = 0;
uint32_t light_shutter_button_mask;
uint32_t buttons_non_light_non_shutter;
uint32_t slider_update_time = 0;
int slider[LST_MAX];
int8_t shutter_slider[16]; // MAX_SHUTTERS_ESP32
Expand Down Expand Up @@ -1257,9 +1259,9 @@ int32_t IsShutterWebButton(uint32_t idx) {

/*-------------------------------------------------------------------------------------------*/

void WebGetDeviceCounts(uint32_t &buttons_non_light_non_shutter, uint32_t &light_shutter_button_mask) {
buttons_non_light_non_shutter = TasmotaGlobal.devices_present;
light_shutter_button_mask = 0; // Bitmask for each light and/or shutter button
void WebGetDeviceCounts(void) {
Web.buttons_non_light_non_shutter = TasmotaGlobal.devices_present;
Web.light_shutter_button_mask = 0; // Bitmask for each light and/or shutter button

#ifdef USE_LIGHT
// Chk for reduced toggle buttons used by lights
Expand All @@ -1268,8 +1270,8 @@ void WebGetDeviceCounts(uint32_t &buttons_non_light_non_shutter, uint32_t &light
uint32_t light_device = LightDevice();
uint32_t light_devices = LightDevices();
for (uint32_t button_idx = light_device; button_idx < (light_device + light_devices); button_idx++) {
buttons_non_light_non_shutter--;
light_shutter_button_mask |= (1 << (button_idx -1)); // Set button bit in bitmask
Web.buttons_non_light_non_shutter--;
Web.light_shutter_button_mask |= (1 << (button_idx -1)); // Set button bit in bitmask
}
}
#endif // USE_LIGHT
Expand All @@ -1280,14 +1282,14 @@ void WebGetDeviceCounts(uint32_t &buttons_non_light_non_shutter, uint32_t &light
// Find and skip dedicated shutter buttons
for (uint32_t button_idx = 1; button_idx <= TasmotaGlobal.devices_present; button_idx++) {
if (IsShutterWebButton(button_idx) != 0) {
buttons_non_light_non_shutter--;
light_shutter_button_mask |= (1 << (button_idx -1)); // Set button bit in bitmask
Web.buttons_non_light_non_shutter--;
Web.light_shutter_button_mask |= (1 << (button_idx -1)); // Set button bit in bitmask
}
}
}
#endif // USE_SHUTTER

// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("HTP: DP %d, BNLNS %d, SB %08X"), TasmotaGlobal.devices_present, buttons_non_light_non_shutter, light_shutter_button_mask);
// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("HTP: DP %d, BNLNS %d, SB %08X"), TasmotaGlobal.devices_present, Web.buttons_non_light_non_shutter, Web.light_shutter_button_mask);
}

#ifdef USE_LIGHT
Expand Down Expand Up @@ -1370,12 +1372,10 @@ void HandleRoot(void) {
#ifndef FIRMWARE_MINIMAL

if (TasmotaGlobal.devices_present) {
uint32_t buttons_non_light_non_shutter;
uint32_t light_shutter_button_mask;
WebGetDeviceCounts(buttons_non_light_non_shutter, light_shutter_button_mask);
uint32_t button_idx = 1;
WebGetDeviceCounts();

if (buttons_non_light_non_shutter) { // Any non light AND non shutter button - Show toggle buttons
uint32_t button_idx = 1;
if (Web.buttons_non_light_non_shutter) { // Any non light AND non shutter button - Show toggle buttons
WSContentSend_P(HTTP_TABLE100); // "<table style='width:100%%'>"
WSContentSend_P(PSTR("<tr>"));

Expand All @@ -1394,14 +1394,14 @@ void HandleRoot(void) {
#endif // USE_SONOFF_IFAN

const uint32_t max_columns = 8;
uint32_t rows = buttons_non_light_non_shutter / max_columns;
if (buttons_non_light_non_shutter % max_columns) { rows++; }
uint32_t cols = buttons_non_light_non_shutter / rows;
if (buttons_non_light_non_shutter % rows) { cols++; }
uint32_t rows = Web.buttons_non_light_non_shutter / max_columns;
if (Web.buttons_non_light_non_shutter % max_columns) { rows++; }
uint32_t cols = Web.buttons_non_light_non_shutter / rows;
if (Web.buttons_non_light_non_shutter % rows) { cols++; }

uint32_t button_ptr = 0;
for (button_idx = 1; button_idx <= TasmotaGlobal.devices_present; button_idx++) {
if (bitRead(light_shutter_button_mask, button_idx -1)) { continue; } // Skip non-sequential light and/or shutter button
if (bitRead(Web.light_shutter_button_mask, button_idx -1)) { continue; } // Skip non-sequential light and/or shutter button
bool set_button = ((button_idx <= MAX_BUTTON_TEXT) && strlen(GetWebButton(button_idx -1)));
snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), button_idx);
WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / cols, button_idx, button_idx,
Expand Down Expand Up @@ -1563,7 +1563,7 @@ void HandleRoot(void) {
WSContentSend_P(PSTR("</tr>"));
}
} else { // Settings->flag3.pwm_multi_channels - SetOption68 1 - Enable multi-channels PWM instead of Color PWM
stemp[0] = 'e'; stemp[1] = '0'; stemp[2] = '\0'; // d0
stemp[0] = 'e'; stemp[1] = '0'; stemp[2] = '\0'; // e0
for (uint32_t i = 0; i < light_devices; i++) {
bool set_button = ((button_idx <= MAX_BUTTON_TEXT) && strlen(GetWebButton(button_idx -1)));
char first[2];
Expand Down Expand Up @@ -1684,7 +1684,7 @@ bool HandleRootStatusRefresh(void) {
char svalue[32]; // Command and number parameter
char webindex[5]; // WebGetArg name

WebGetArg(PSTR("o"), tmp, sizeof(tmp)); // 1 - 16 Device number for button Toggle or Fanspeed
WebGetArg(PSTR("o"), tmp, sizeof(tmp)); // 1 - 32 Device number for button Toggle or Fanspeed
if (strlen(tmp)) {
ShowWebSource(SRC_WEBGUI);
uint32_t device = atoi(tmp);
Expand Down Expand Up @@ -1900,16 +1900,12 @@ bool HandleRootStatusRefresh(void) {
} else {
#endif // USE_SONOFF_IFAN

uint32_t buttons_non_light_non_shutter;
uint32_t light_shutter_button_mask;
WebGetDeviceCounts(buttons_non_light_non_shutter, light_shutter_button_mask);

if (buttons_non_light_non_shutter <= 8) { // Any non light AND non shutter button
if (Web.buttons_non_light_non_shutter <= 8) { // Any non light AND non shutter button
WSContentSend_P(PSTR("{t}<tr>"));
uint32_t cols = buttons_non_light_non_shutter;
uint32_t cols = Web.buttons_non_light_non_shutter;
uint32_t fontsize = (cols < 5) ? 70 - (cols * 8) : 32;
for (uint32_t idx = 1; idx <= TasmotaGlobal.devices_present; idx++) {
if (bitRead(light_shutter_button_mask, idx -1)) { continue; } // Skip non-sequential shutter button
for (uint32_t idx = 1; idx <= Web.buttons_non_light_non_shutter; idx++) {
if (bitRead(Web.light_shutter_button_mask, idx -1)) { continue; } // Skip non-sequential shutter button
snprintf_P(svalue, sizeof(svalue), PSTR("%d"), bitRead(TasmotaGlobal.power, idx -1));
WSContentSend_P(HTTP_DEVICE_STATE, 100 / cols, (bitRead(TasmotaGlobal.power, idx -1)) ? PSTR("bold") : PSTR("normal"), fontsize,
(cols < 5) ? GetStateText(bitRead(TasmotaGlobal.power, idx -1)) : svalue);
Expand Down

0 comments on commit ab5208d

Please sign in to comment.