From 3328c66f2c1c4b83f96b3c869b2167bb2ab183a2 Mon Sep 17 00:00:00 2001 From: dnc40085 Date: Sat, 27 Aug 2016 02:46:24 -0700 Subject: [PATCH] Add function `wifi.nullmodesleep()` (#1475) Enable auto sleep in NULL_MODE by default. --- app/modules/wifi.c | 27 ++++++++++++++++++++++++++ docs/en/modules/wifi.md | 15 ++++++++++++++ sdk-overrides/include/user_interface.h | 2 ++ 3 files changed, 44 insertions(+) diff --git a/app/modules/wifi.c b/app/modules/wifi.c index af9beeb4..c130dfda 100644 --- a/app/modules/wifi.c +++ b/app/modules/wifi.c @@ -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 diff --git a/docs/en/modules/wifi.md b/docs/en/modules/wifi.md index 39310d3a..dd2b9874 100644 --- a/docs/en/modules/wifi.md +++ b/docs/en/modules/wifi.md @@ -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. diff --git a/sdk-overrides/include/user_interface.h b/sdk-overrides/include/user_interface.h index 2fe4da29..b288f995 100644 --- a/sdk-overrides/include/user_interface.h +++ b/sdk-overrides/include/user_interface.h @@ -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_ */