diff --git a/mkdocs/api.md b/mkdocs/api.md index 6f8cd4f..3002cb9 100644 --- a/mkdocs/api.md +++ b/mkdocs/api.md @@ -110,7 +110,7 @@ bool config(AutoConnectConfig& config) bool config(const char* ap, const char* password = nullptr) ``` -Set SoftAP's WiFi configuration and static IP configuration. +Set SoftAP's WiFi configuration and static IP configuration.
**Parameters**
configReference to [**AutoConnectConfig**](apiconfig.md) containing SoftAP's parameters and static IP parameters.
@@ -121,6 +121,35 @@ Set SoftAP's WiFi configuration and static IP configuration.
falseConfiguration parameter is invalid, some values out of range.
+### enableMenu + +```cpp +void enableMenu(const uint16_t items) +``` + +Enable the [AutoConnect menu](menu.md) items specified by the items parameter with logical OR value using **AC_MENUITEM_t** constant. +
+
**Parameter**
+
itemsSpecify the combined value of **AC_MENUITEM_t** of the items applying to the AutoConnect menu. It provides the value calculated from the **logical OR** by the AC_MENUITEM_t value of each item applied as a menu. AC_MENUITEM_t is enumeration type to identify each menu item and it has the below values.
+: - **AC_MENUITEM_CONFIGNEW** : + [Configure new AP](menu.md#configure-new-ap) +: - **AC_MENUITEM_OPENSSIDS** : + [Open SSIDs](menu.md#open-ssids) +: - **AC_MENUITEM_DISCONNECT** : + [Disconnect](menu.md#disconnect) +: - **AC_MENUITEM_RESET** : + [Reset...](menu.md#reset) +: - **AC_MENUITEM_HOME** : + [HOME](menu.md#home) +: - **AC_MENUITEM_DEVINFO** : + [Device statistics](menu.md#where-the-from) as AutoConnect root page +
+ +!!! note "It is added, not replaced." + The initial configuration of the AutoConnect menu items: + `AC_MENUITEM_CONFIGNEW | AC_MENUITEM_OPENSSIDS | AC_MENUITEM_DISCONNECT | AC_MENUITEM_RESET | AC_MENUITEM_HOME` + The enableMenu function adds an indication of the specified items to the current. Therefore, use the [disableMenu](#disableMenu) to remove the specified item from the initial menu. + ### end ```cpp @@ -132,6 +161,19 @@ Stops AutoConnect captive portal service. Release ESP8266WebServer/WebServer and !!! warning "Attention to end" The end function releases the instance of ESP8266WebServer/WebServer and DNSServer. It can not process them after the end function. + +### disableMenu + +```cpp +void disableMenu(const uint16_t items) +``` + +Disable the [AutoConnect menu](menu.md) items specified by the items parameter with logical OR value using **AC_MENUITEM_t** constant. +
+
**Parameter**
+
itemsSpecify the combined value of **AC_MENUITEM_t** of the items deleting from the AutoConnect menu. It provides the value calculated from the **logical OR** by the AC_MENUITEM_t value of each item. Refer to the [enableMenu](#enablemenu) about AC_MENUITEM_t.
+
+ ### handleClient ```cpp diff --git a/mkdocs/apiconfig.md b/mkdocs/apiconfig.md index 758e010..330ffbb 100644 --- a/mkdocs/apiconfig.md +++ b/mkdocs/apiconfig.md @@ -40,9 +40,9 @@ Sets IP address for Soft AP in captive portal. When AutoConnect fails the initia
IPAddressThe default value is **172.217.28.1**
-### applyMenu +### menuItems -Configure applying items of the [AutoConnect menu](menu.md). You can arbitrarily combine valid menus by coordinating the applyMenu value. +Configure applying items of the [AutoConnect menu](menu.md). You can arbitrarily combine valid menus by coordinating the menuItems value.
**Type**
uint16_tIt provides the combined **AC_MENUITEM_t** value of the item to apply to the AutoConnect menu.
Specify the value calculated from the **logical OR** by the AC_MENUITEM_t value of each item applied as a menu. It affects not only disappear the items from the menu also invalidates the URI they have. As a consequence, even if it accesses the URL directly will occur a 404 error.
The default value is logical OR of AC_MENUITEM_CONFIGNEW, AC_MENUITEM_OPENSSIDS, AC_MENUITEM_DISCONNECT, AC_MENUITEM_RESET and AC_MENUITEM_HOME.
@@ -57,10 +57,10 @@ Configure applying items of the [AutoConnect menu](menu.md). You can arbitrarily
!!! info "How to specify the value of the menu items" - An applyMenu accepts the logical OR of AC_MENUITEM_t type value. For example, to enable only Open SSIDs and HOME items, specify: + An menuItems accepts the logical OR of AC_MENUITEM_t type value. For example, to enable only Open SSIDs and HOME items, specify: ```cpp AutoConnectConfig config; - config.applyMenu = AC_MENUITEM_OPENSSIDS | AC_MENUITEM_HOME; + config.menuItems = AC_MENUITEM_OPENSSIDS | AC_MENUITEM_HOME; ``` However, even if you specify like the above, the AutoConnectAux page items still display on the menu. To remove the AutoConnectAux items, use the [AutoConnectAux::menu](apiaux.md#menu) function. diff --git a/mkdocs/menu.md b/mkdocs/menu.md index 64556b6..c2a04fa 100644 --- a/mkdocs/menu.md +++ b/mkdocs/menu.md @@ -78,7 +78,7 @@ Also, you can change the HOME path using the AutoConnect API. The [**AutoConnect ## Applying the active menu items -Each of the above menu items can be configured with a Sketch. [AutoConnectConfig::applyMenu](apiconfig.md#applymenu) specifies the menu items that will be enabled at runtime. +Each of the above menu items can be configured with a Sketch. [AutoConnectConfig::menuItems](apiconfig.md#menuitems) specifies the menu items that will be enabled at runtime. You can also adjust available menu items using [AutoConnect::enableMenu](api.md#enablemenu) and [AutoConnect::disableMenu](api.md#disablemenu) function. It is an alternative to [AutoConnectConfig::menuItems](apiconfig.md#menuitems) and provides a shortcut to avoid using AutoConnectConfig. For example, by disabling the [Configure new AP](#configure-new-ap) and [Disconnect](#disconnect) item, you can prevent the configuration for unknown access points. ```cpp @@ -86,15 +86,27 @@ AutoConnect portal; AutoConnectConfig config; void setup() { - config.applyMenu = AC_MENUITEM_OPENSSIDS | AC_MENUITEM_RESET | AC_MENUITEM_HOME; + config.menuItems = AC_MENUITEM_OPENSSIDS | AC_MENUITEM_RESET | AC_MENUITEM_HOME; portal.config(config); } ``` + +The next is another way to achieve the same effect. + +```cpp +AutoConnect portal; + +void setup() { + portal.disableMenu(AC_MENUITEM_CONFIGNEW | AC_MENUITEM_DISCONNECT); + portal.config(config); +} +``` + The result of executing the above Sketch is as below: -Details for [AutoConnectConfig::applyMenu](apiconfig.md#applymenu). +Details for [AutoConnectConfig::menuItems](apiconfig.md#menuitems). ## Attaching to AutoConnect menu diff --git a/src/AutoConnect.h b/src/AutoConnect.h index 3594a73..11b5668 100644 --- a/src/AutoConnect.h +++ b/src/AutoConnect.h @@ -88,7 +88,7 @@ class AutoConnectConfig { immediateStart(false), retainPortal(false), portalTimeout(AUTOCONNECT_CAPTIVEPORTAL_TIMEOUT), - applyMenu(AC_MENUITEM_CONFIGNEW | AC_MENUITEM_OPENSSIDS | AC_MENUITEM_DISCONNECT | AC_MENUITEM_RESET | AC_MENUITEM_HOME), + menuItems(AC_MENUITEM_CONFIGNEW | AC_MENUITEM_OPENSSIDS | AC_MENUITEM_DISCONNECT | AC_MENUITEM_RESET | AC_MENUITEM_HOME), ticker(false), tickerPort(AUTOCONNECT_TICKER_PORT), tickerOn(LOW), @@ -121,7 +121,7 @@ class AutoConnectConfig { immediateStart(false), retainPortal(false), portalTimeout(portalTimeout), - applyMenu(AC_MENUITEM_CONFIGNEW | AC_MENUITEM_OPENSSIDS | AC_MENUITEM_DISCONNECT | AC_MENUITEM_RESET | AC_MENUITEM_HOME), + menuItems(AC_MENUITEM_CONFIGNEW | AC_MENUITEM_OPENSSIDS | AC_MENUITEM_DISCONNECT | AC_MENUITEM_RESET | AC_MENUITEM_HOME), ticker(false), tickerPort(AUTOCONNECT_TICKER_PORT), tickerOn(LOW), @@ -154,7 +154,7 @@ class AutoConnectConfig { immediateStart = o.immediateStart; retainPortal = o.retainPortal; portalTimeout = o.portalTimeout; - applyMenu = o.applyMenu; + menuItems = o.menuItems; ticker = o.ticker; tickerPort = o.tickerPort; tickerOn = o.tickerOn; @@ -186,7 +186,7 @@ class AutoConnectConfig { bool immediateStart; /**< Skips WiFi.begin(), start portal immediately */ bool retainPortal; /**< Even if the captive portal times out, it maintains the portal state. */ unsigned long portalTimeout; /**< Timeout value for stay in the captive portal */ - uint16_t applyMenu; /**< A compound value of the menu items to be attached */ + uint16_t menuItems; /**< A compound value of the menu items to be attached */ bool ticker; /**< Drives LED flicker according to WiFi connection status. */ uint8_t tickerPort; /**< GPIO for flicker */ uint8_t tickerOn; /**< A signal for flicker turn on */ @@ -221,6 +221,8 @@ class AutoConnect { void join(AutoConnectAuxVT auxVector); bool on(const String& uri, const AuxHandlerFunctionT handler, AutoConnectExitOrder_t order = AC_EXIT_AHEAD); String where(void) const { return _auxUri; } + inline void enableMenu(const uint16_t items) { _apConfig.menuItems |= items; } + inline void disableMenu(const uint16_t items) { _apConfig.menuItems &= (0xffff ^ items); } /** For AutoConnectAux described in JSON */ #ifdef AUTOCONNECT_USE_JSON diff --git a/src/AutoConnectPage.cpp b/src/AutoConnectPage.cpp index f6ac3f5..7436646 100644 --- a/src/AutoConnectPage.cpp +++ b/src/AutoConnectPage.cpp @@ -1369,7 +1369,7 @@ String AutoConnect::_attachMenuItem(const AC_MENUITEM_t item) { PGM_P link; PGM_P label; - switch (static_cast(_apConfig.applyMenu & static_cast(item))) { + switch (static_cast(_apConfig.menuItems & static_cast(item))) { case AC_MENUITEM_CONFIGNEW: id = PSTR(""); link = PSTR(AUTOCONNECT_URI_CONFIG); @@ -1455,7 +1455,7 @@ PageElement* AutoConnect::_setupPage(String& uri) { elm->addToken(String(FPSTR("CHIP_ID")), std::bind(&AutoConnect::_token_CHIP_ID, this, std::placeholders::_1)); elm->addToken(String(FPSTR("FREE_HEAP")), std::bind(&AutoConnect::_token_FREE_HEAP, this, std::placeholders::_1)); } - else if (uri == String(AUTOCONNECT_URI_CONFIG) && (_apConfig.applyMenu & AC_MENUITEM_CONFIGNEW)) { + else if (uri == String(AUTOCONNECT_URI_CONFIG) && (_apConfig.menuItems & AC_MENUITEM_CONFIGNEW)) { // Setup /auto/config elm->setMold(_PAGE_CONFIGNEW); @@ -1474,7 +1474,7 @@ PageElement* AutoConnect::_setupPage(String& uri) { elm->addToken(String(FPSTR("HIDDEN_COUNT")), std::bind(&AutoConnect::_token_HIDDEN_COUNT, this, std::placeholders::_1)); elm->addToken(String(FPSTR("CONFIG_IP")), std::bind(&AutoConnect::_token_CONFIG_STAIP, this, std::placeholders::_1)); } - else if (uri == String(AUTOCONNECT_URI_CONNECT) && (_apConfig.applyMenu & AC_MENUITEM_CONFIGNEW || _apConfig.applyMenu & AC_MENUITEM_OPENSSIDS)) { + else if (uri == String(AUTOCONNECT_URI_CONNECT) && (_apConfig.menuItems & AC_MENUITEM_CONFIGNEW || _apConfig.menuItems & AC_MENUITEM_OPENSSIDS)) { // Setup /auto/connect _menuTitle = FPSTR(AUTOCONNECT_MENUTEXT_CONNECTING); @@ -1488,7 +1488,7 @@ PageElement* AutoConnect::_setupPage(String& uri) { elm->addToken(String(FPSTR("MENU_POST")), std::bind(&AutoConnect::_token_MENU_POST, this, std::placeholders::_1)); elm->addToken(String(FPSTR("CUR_SSID")), std::bind(&AutoConnect::_token_CURRENT_SSID, this, std::placeholders::_1)); } - else if (uri == String(AUTOCONNECT_URI_OPEN) && (_apConfig.applyMenu & AC_MENUITEM_OPENSSIDS)) { + else if (uri == String(AUTOCONNECT_URI_OPEN) && (_apConfig.menuItems & AC_MENUITEM_OPENSSIDS)) { // Setup /auto/open elm->setMold(_PAGE_OPENCREDT); @@ -1502,7 +1502,7 @@ PageElement* AutoConnect::_setupPage(String& uri) { elm->addToken(String(FPSTR("MENU_POST")), std::bind(&AutoConnect::_token_MENU_POST, this, std::placeholders::_1)); elm->addToken(String(FPSTR("OPEN_SSID")), std::bind(&AutoConnect::_token_OPEN_SSID, this, std::placeholders::_1)); } - else if (uri == String(AUTOCONNECT_URI_DISCON) && (_apConfig.applyMenu & AC_MENUITEM_DISCONNECT)) { + else if (uri == String(AUTOCONNECT_URI_DISCON) && (_apConfig.menuItems & AC_MENUITEM_DISCONNECT)) { // Setup /auto/disc _menuTitle = FPSTR(AUTOCONNECT_MENUTEXT_DISCONNECT); @@ -1514,7 +1514,7 @@ PageElement* AutoConnect::_setupPage(String& uri) { elm->addToken(String(FPSTR("MENU_PRE")), std::bind(&AutoConnect::_token_MENU_PRE, this, std::placeholders::_1)); elm->addToken(String(FPSTR("MENU_POST")), std::bind(&AutoConnect::_token_MENU_POST, this, std::placeholders::_1)); } - else if (uri == String(AUTOCONNECT_URI_RESET) && (_apConfig.applyMenu & AC_MENUITEM_RESET)) { + else if (uri == String(AUTOCONNECT_URI_RESET) && (_apConfig.menuItems & AC_MENUITEM_RESET)) { // Setup /auto/reset elm->setMold(_PAGE_RESETTING);