Add function `wifi.nullmodesleep()` (#1475)

Enable auto sleep in NULL_MODE by default.
This commit is contained in:
dnc40085 2016-08-27 02:46:24 -07:00 committed by Marcel Stör
parent cd6862f738
commit 3328c66f2c
3 changed files with 44 additions and 0 deletions

View File

@ -372,6 +372,26 @@ static int wifi_sleep(lua_State* L)
return 2;
}
//wifi.nullmodesleep()
static int wifi_null_mode_auto_sleep(lua_State* L)
{
if (!lua_isnone(L, 1))
{
bool auto_sleep_setting=lua_toboolean(L, 1);
if (auto_sleep_setting!=(bool) get_fpm_auto_sleep_flag())
{
wifi_fpm_auto_sleep_set_in_null_mode((uint8)auto_sleep_setting);
//if esp is already in NULL_MODE, auto sleep setting won't take effect until next wifi_set_opmode(NULL_MODE) call.
if(wifi_get_opmode()==NULL_MODE)
{
wifi_set_opmode_current(NULL_MODE);
}
}
}
lua_pushboolean(L, (bool) get_fpm_auto_sleep_flag());
return 1;
}
// Lua: mac = wifi.xx.getmac()
static int wifi_getmac( lua_State* L, uint8_t mode )
{
@ -1268,6 +1288,7 @@ static const LUA_REG_TYPE wifi_map[] = {
{ LSTRKEY( "setphymode" ), LFUNCVAL( wifi_setphymode ) },
{ LSTRKEY( "getphymode" ), LFUNCVAL( wifi_getphymode ) },
{ LSTRKEY( "sleep" ), LFUNCVAL( wifi_sleep ) },
{ LSTRKEY( "nullmodesleep" ), LFUNCVAL( wifi_null_mode_auto_sleep ) },
#ifdef WIFI_SMART_ENABLE
{ LSTRKEY( "startsmart" ), LFUNCVAL( wifi_start_smart ) },
{ LSTRKEY( "stopsmart" ), LFUNCVAL( wifi_exit_smart ) },
@ -1349,6 +1370,12 @@ void wifi_change_default_host_name(void)
int luaopen_wifi( lua_State *L )
{
wifi_fpm_auto_sleep_set_in_null_mode(1);
//if esp is already in NULL_MODE, auto sleep setting won't take effect until next wifi_set_opmode(NULL_MODE) call.
if(wifi_get_opmode()==NULL_MODE)
{
wifi_set_opmode_current(NULL_MODE);
}
#if defined(WIFI_SDK_EVENT_MONITOR_ENABLE)
wifi_eventmon_init();
#endif

View File

@ -128,6 +128,21 @@ physical mode after setup
#### See also
[`wifi.getphymode()`](#wifigetphymode)
## wifi.nullmodesleep()
Configures whether or not WiFi automatically goes to sleep in NULL_MODE. Enabled by default.
#### Syntax
`wifi.nullmodesleep(enable)`
#### Parameters
- `enable`
- true: Enable WiFi auto sleep in NULL_MODE. (Default setting)
- false: Disable WiFi auto sleep in NULL_MODE.
#### Returns
Current/new NULL_MODE sleep setting.
## wifi.sleeptype()
Configures the WiFi modem sleep type.

View File

@ -4,5 +4,7 @@
#include_next "user_interface.h"
bool wifi_softap_deauth(uint8 mac[6]);
uint8 get_fpm_auto_sleep_flag(void);
#endif /* SDK_OVERRIDES_INCLUDE_USER_INTERFACE_H_ */