Add AutoConnect::enableMenu

pull/197/head
Hieromon Ikasamo 4 years ago
parent ac8b2e7f01
commit 8e4390c808
  1. 44
      mkdocs/api.md
  2. 8
      mkdocs/apiconfig.md
  3. 18
      mkdocs/menu.md
  4. 10
      src/AutoConnect.h
  5. 12
      src/AutoConnectPage.cpp

@ -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.
<dl class="apidl">
<dt>**Parameters**</dt>
<dd><span class="apidef">config</span><span class="apidesc">Reference to [**AutoConnectConfig**](apiconfig.md) containing SoftAP's parameters and static IP parameters.</span></dd>
@ -121,6 +121,35 @@ Set SoftAP's WiFi configuration and static IP configuration.
<dd><span class="apidef">false</span><span class="aidesc">Configuration parameter is invalid, some values out of range.</span></dd>
</dl>
### <i class="fa fa-caret-right"></i> 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.
<dl class="apidl">
<dt>**Parameter**</dt>
<dd><span class="apidef">items</span><span class="apidesc">Specify 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.</span></dd>
: - **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
</dl>
!!! 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.
### <i class="fa fa-caret-right"></i> 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.
### <i class="fa fa-caret-right"></i> 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.
<dl class="apidl">
<dt>**Parameter**</dt>
<dd><span class="apidef">items</span><span class="apidesc">Specify 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.</span></dd>
</dl>
### <i class="fa fa-caret-right"></i> handleClient
```cpp

@ -40,9 +40,9 @@ Sets IP address for Soft AP in captive portal. When AutoConnect fails the initia
<dd><span class="apidef">IPAddress</span><span class="apidesc">The default value is **172.217.28.1**</span></dd>
</dl>
### <i class="fa fa-caret-right"></i> applyMenu
### <i class="fa fa-caret-right"></i> 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.
<dl class="apidl">
<dt>**Type**</dt>
<dd><span class="apidef">uint16_t</span><span class="apidesc">It provides the combined **AC_MENUITEM_t** value of the item to apply to the AutoConnect menu.<br>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.<br>The default value is logical OR of AC_MENUITEM_CONFIGNEW, AC_MENUITEM_OPENSSIDS, AC_MENUITEM_DISCONNECT, AC_MENUITEM_RESET and AC_MENUITEM_HOME.</span></dd>
@ -57,10 +57,10 @@ Configure applying items of the [AutoConnect menu](menu.md). You can arbitrarily
</dl>
!!! 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.

@ -78,7 +78,7 @@ Also, you can change the HOME path using the AutoConnect API. The [**AutoConnect
## <i class="fa fa-bars"></i> 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:
<img src="images/applymenu.png" style="border-style:solid;border-width:1px;border-color:lightgrey;width:280px;" />
Details for [AutoConnectConfig::applyMenu](apiconfig.md#applymenu).
Details for [AutoConnectConfig::menuItems](apiconfig.md#menuitems).
## <i class="fa fa-bars"></i> Attaching to AutoConnect menu

@ -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

@ -1369,7 +1369,7 @@ String AutoConnect::_attachMenuItem(const AC_MENUITEM_t item) {
PGM_P link;
PGM_P label;
switch (static_cast<AC_MENUITEM_t>(_apConfig.applyMenu & static_cast<uint16_t>(item))) {
switch (static_cast<AC_MENUITEM_t>(_apConfig.menuItems & static_cast<uint16_t>(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);

Loading…
Cancel
Save