Improved String buffer consumption

pull/197/head
Hieromon Ikasamo 5 years ago
parent 1e1e221fef
commit 3951fe57b6
  1. 6
      src/AutoConnectLabels.h
  2. 51
      src/AutoConnectPage.cpp

@ -62,9 +62,9 @@
#endif // !AUTOCONNECT_MENULABEL_UPDATE #endif // !AUTOCONNECT_MENULABEL_UPDATE
// Menu item: Device Info // Menu item: Device Info
#ifndef AUTOCONNECT_MENULABEL_DEVICEINFO #ifndef AUTOCONNECT_MENULABEL_DEVINFO
#define AUTOCONNECT_MENULABEL_DEVICEINFO "Device info" #define AUTOCONNECT_MENULABEL_DEVINFO "Device info"
#endif // !AUTOCONNECT_MENULABEL_DEVICEINFO #endif // !AUTOCONNECT_MENULABEL_DEVINFO
// Button label: RESET // Button label: RESET
#ifndef AUTOCONNECT_BUTTONLABEL_RESET #ifndef AUTOCONNECT_BUTTONLABEL_RESET

@ -1366,35 +1366,52 @@ String AutoConnect::_token_CURRENT_SSID(PageArgument& args) {
* @return HTML string of a li tag with the menu item. * @return HTML string of a li tag with the menu item.
*/ */
String AutoConnect::_attachMenuItem(const AC_MENUITEM_t item) { String AutoConnect::_attachMenuItem(const AC_MENUITEM_t item) {
AC_MENUITEM_t liItem = static_cast<AC_MENUITEM_t>(_apConfig.attachMenu & static_cast<uint16_t>(item)); static const char _liTempl[] PROGMEM = "<li class=\"lb-item\"%s><a href=\"%s\">%s</a></li>";
String li = String(F("<li class=\"lb-item\"")); PGM_P id;
if (liItem == AC_MENUITEM_RESET) PGM_P link;
li += String(F(" id=\"reset\"><a href=\"#rdlg\">" AUTOCONNECT_MENULABEL_RESET)); PGM_P label;
else {
li += String(F("><a href=\"")); switch (static_cast<AC_MENUITEM_t>(_apConfig.attachMenu & static_cast<uint16_t>(item))) {
switch (liItem) {
case AC_MENUITEM_CONFIGNEW: case AC_MENUITEM_CONFIGNEW:
li += String(F(AUTOCONNECT_URI_CONFIG "\">" AUTOCONNECT_MENULABEL_CONFIGNEW)); id = PSTR("");
link = PSTR(AUTOCONNECT_URI_CONFIG);
label = PSTR(AUTOCONNECT_MENULABEL_CONFIGNEW);
break; break;
case AC_MENUITEM_OPENSSIDS: case AC_MENUITEM_OPENSSIDS:
li += String(F(AUTOCONNECT_URI_OPEN "\">" AUTOCONNECT_MENULABEL_OPENSSIDS)); id = PSTR("");
link = PSTR(AUTOCONNECT_URI_OPEN);
label = PSTR(AUTOCONNECT_MENULABEL_OPENSSIDS);
break; break;
case AC_MENUITEM_DISCONNECT: case AC_MENUITEM_DISCONNECT:
li += String(F(AUTOCONNECT_URI_DISCON "\">" AUTOCONNECT_MENULABEL_DISCONNECT)); id = PSTR("");
link = PSTR(AUTOCONNECT_URI_DISCON);
label = PSTR(AUTOCONNECT_MENULABEL_DISCONNECT);
break; break;
case AC_MENUITEM_DEVINFO: case AC_MENUITEM_RESET:
li += String(F(AUTOCONNECT_URI "\">" AUTOCONNECT_MENULABEL_DEVICEINFO)); id = PSTR(" id=\"reset\"");
link = PSTR("#rdlg");
label = PSTR(AUTOCONNECT_MENULABEL_RESET);
break; break;
case AC_MENUITEM_HOME: case AC_MENUITEM_HOME:
li += String(F("HOME_URI\">" AUTOCONNECT_MENULABEL_HOME)); id = PSTR("");
link = PSTR("HOME_URI");
label = PSTR(AUTOCONNECT_MENULABEL_HOME);
break;
case AC_MENUITEM_DEVINFO:
id = PSTR("");
link = PSTR(AUTOCONNECT_URI);
label = PSTR(AUTOCONNECT_MENULABEL_DEVINFO);
break; break;
default: default:
li = _emptyString; id = nullptr;
link = nullptr;
label = nullptr;
break; break;
} }
} char li[128] = { '\0' };
li += String(F("</a></li>")); if (!!id && !!link && !!label)
return li; snprintf(li, sizeof(li), (PGM_P)_liTempl, id, link, label);
return String(li);
} }
/** /**

Loading…
Cancel
Save