From 8b3036f89c4a9b23664794f934ecc1a155673277 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Mon, 11 Mar 2019 12:13:03 +0900 Subject: [PATCH] Supports AutoConnectLabels --- mkdocs/advancedusage.md | 13 +++++++++ src/AutoConnect.cpp | 2 +- src/AutoConnectLabels.h | 65 +++++++++++++++++++++++++++++++++++++++++ src/AutoConnectPage.cpp | 15 +++++----- src/AutoConnectPage.h | 2 ++ 5 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 src/AutoConnectLabels.h diff --git a/mkdocs/advancedusage.md b/mkdocs/advancedusage.md index 58c0e02..e62e905 100644 --- a/mkdocs/advancedusage.md +++ b/mkdocs/advancedusage.md @@ -191,6 +191,19 @@ Executing the above sketch will rewrite the menu title for the **FSBrowser** as
+### Change the menu labels + +You can change the label of the AutoConnect menu item by rewriting the default label letter in [AutoConnectLabels.h](https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectLabels.h) macros. However, changing menu items letter influences all the sketch's build scenes. + +```cpp +#define AUTOCONNECT_MENULABEL_CONFIGNEW "Configure new AP" +#define AUTOCONNECT_MENULABEL_OPENSSIDS "Open SSIDs" +#define AUTOCONNECT_MENULABEL_DISCONNECT "Disconnect" +#define AUTOCONNECT_MENULABEL_RESET "Reset..." +#define AUTOCONNECT_MENULABEL_HOME "HOME" +#define AUTOCONNECT_BUTTONLABEL_RESET "RESET" +``` + ### Combination with mDNS With [mDNS library](https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266mDNS), you can access to ESP8266 by name instead of IP address after connection. The sketch can start the MDNS responder after [*AutoConnect::begin*](api.md#begin). diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index 2feb7eb..b30fbf3 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -668,7 +668,7 @@ void AutoConnect::_handleNotFound(void) { String AutoConnect::_induceReset(PageArgument& args) { AC_UNUSED(args); _rfReset = true; - return String(F("Reset in progress...")); + return String(F(AUTOCONNECT_BUTTONLABEL_RESET " in progress...")); } /** diff --git a/src/AutoConnectLabels.h b/src/AutoConnectLabels.h new file mode 100644 index 0000000..1591ed4 --- /dev/null +++ b/src/AutoConnectLabels.h @@ -0,0 +1,65 @@ +/** + * AutoConnect proper menu label constant definition. + * @file AutoConnectLabels.h + * @author hieromon@gmail.com + * @version 0.9.8 + * @date 2019-03-11 + * @copyright MIT license. + */ + +#ifndef _AUTOCONNECTLABELS_H_ +#define _AUTOCONNECTLABELS_H_ + +/** + * The upper row of each of the following definition items is the + * default value. The lower row is an alternative label string as + * a sample and can be changed you wish. + * + * Notes: + * You can find some tokens for the PageBuilder if you parse + * AutoConnectPage.cpp. Some of the tokens are valid at the time + * the AutoConnect menu will generate. For example, the token + * `{{CUR_SSID}}` returns the SSID of the currently participating + * AP by AutoConnect::_token_CURRENT_SSID function. + * You can use these tokens to display dynamic menus showing the + * current situation, but you need to know the internal structure + * of AutoConnect in order to display the appropriate menu. + */ + +// Menu item: Configure new AP +#ifndef AUTOCONNECT_MENULABEL_CONFIGNEW +#define AUTOCONNECT_MENULABEL_CONFIGNEW "Configure new AP" +//#define AUTOCONNECT_MENULABEL_CONFIGNEW "Establish a new AP" +#endif // !AUTOCONNECT_MENULABEL_CONFIGNEW + +// Menu item: Open SSIDs +#ifndef AUTOCONNECT_MENULABEL_OPENSSIDS +#define AUTOCONNECT_MENULABEL_OPENSSIDS "Open SSIDs" +//#define AUTOCONNECT_MENULABEL_OPENSSIDS "Open credentials" +#endif // !AUTOCONNECT_MENULABEL_OPENSSIDS + +// Menu item: Disconnect +#ifndef AUTOCONNECT_MENULABEL_DISCONNECT +#define AUTOCONNECT_MENULABEL_DISCONNECT "Disconnect" +//#define AUTOCONNECT_MENULABEL_DISCONNECT "Leave {{CUR_SSID}}" +#endif // !AUTOCONNECT_MENULABEL_DISCONNECT + +// Menu item: Reset... +#ifndef AUTOCONNECT_MENULABEL_RESET +#define AUTOCONNECT_MENULABEL_RESET "Reset..." +//#define AUTOCONNECT_MENULABEL_RESET "Reboot..." +#endif // !AUTOCONNECT_MENULABEL_RESET + +// Menu item: HOME +#ifndef AUTOCONNECT_MENULABEL_HOME +#define AUTOCONNECT_MENULABEL_HOME "HOME" +//#define AUTOCONNECT_MENULABEL_HOME "Main" +#endif // !AUTOCONNECT_MENULABEL_HOME + +// Button label: RESET +#ifndef AUTOCONNECT_BUTTONLABEL_RESET +#define AUTOCONNECT_BUTTONLABEL_RESET "RESET" +//#define AUTOCONNECT_BUTTONLABEL_RESET "Reboot" +#endif // !AUTOCONNECT_BUTTONLABEL_RESET + +#endif diff --git a/src/AutoConnectPage.cpp b/src/AutoConnectPage.cpp index 84796b7..6e983a5 100644 --- a/src/AutoConnectPage.cpp +++ b/src/AutoConnectPage.cpp @@ -525,10 +525,10 @@ const char AutoConnect::_ELM_MENU_PRE[] PROGMEM = { "MENU_TITLE" "" "" - "
  • Configure new AP
  • " - "
  • Open SSIDs
  • " - "
  • Disconnect
  • " - "
  • Reset...
  • " + "
  • " AUTOCONNECT_MENULABEL_CONFIGNEW "
  • " + "
  • " AUTOCONNECT_MENULABEL_OPENSSIDS "
  • " + "
  • " AUTOCONNECT_MENULABEL_DISCONNECT "
  • " + "
  • " AUTOCONNECT_MENULABEL_RESET "
  • " }; const char AutoConnect::_ELM_MENU_AUX[] PROGMEM = { @@ -536,11 +536,11 @@ const char AutoConnect::_ELM_MENU_AUX[] PROGMEM = { }; const char AutoConnect::_ELM_MENU_POST[] PROGMEM = { - "
  • HOME
  • " + "
  • " AUTOCONNECT_MENULABEL_HOME "
  • " "" "" "
    " - "" + "" "
    " "" }; @@ -906,10 +906,9 @@ String AutoConnect::_token_HEAD(PageArgument& args) { } String AutoConnect::_token_MENU_PRE(PageArgument& args) { - AC_UNUSED(args); String currentMenu = FPSTR(_ELM_MENU_PRE); currentMenu.replace(String(F("MENU_TITLE")), _menuTitle); - // currentMenu.replace(String(F("HOME_URI")), _apConfig.homeUri); + currentMenu.replace(String(F("{{CUR_SSID}}")), _token_ESTAB_SSID(args)); return currentMenu; } diff --git a/src/AutoConnectPage.h b/src/AutoConnectPage.h index b48e43d..e07f56e 100644 --- a/src/AutoConnectPage.h +++ b/src/AutoConnectPage.h @@ -10,6 +10,8 @@ #ifndef _AUTOCONNECTPAGE_H_ #define _AUTOCONNECTPAGE_H_ +#include "AutoConnectLabels.h" + #define AUTOCONNECT_PARAMID_SSID "SSID" #define AUTOCONNECT_PARAMID_PASS "Passphrase" #define AUTOCONNECT_PARAMID_CRED "Credential"