Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function wifi.sleep #725

Merged
merged 3 commits into from
Nov 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion app/modules/wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
static int wifi_smart_succeed = LUA_NOREF;
static uint8 getap_output_format=0;

//wifi.sleep variables
#define FPM_SLEEP_MAX_TIME 0xFFFFFFF
static bool FLAG_wifi_force_sleep_enabled=0;


//variables for wifi event monitor
static sint32_t wifi_status_cb_ref[6] = {LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF};
static volatile os_timer_t wifi_sta_status_timer;
Expand Down Expand Up @@ -319,6 +324,47 @@ static int wifi_getphymode( lua_State* L )
return 1;
}

//wifi.sleep()
static int wifi_sleep(lua_State* L)
{
uint8 desired_sleep_state=2;
if(lua_isnumber(L, 1))
{
if(luaL_checknumber(L, 1)==0)
{
desired_sleep_state=FALSE;
}
else if(luaL_checknumber(L, 1)==1)
{
desired_sleep_state=TRUE;
}
}
if (!FLAG_wifi_force_sleep_enabled && desired_sleep_state==1)
{
FLAG_wifi_force_sleep_enabled=TRUE;
uint8 wifi_current_opmode=wifi_get_opmode();
if (wifi_current_opmode==1||wifi_current_opmode==3)
{
wifi_station_disconnect();
}
// set WiFi mode to null mode
wifi_set_opmode(NULL_MODE);
// set force sleep type
wifi_fpm_set_sleep_type(MODEM_SLEEP_T);
wifi_fpm_open();
wifi_fpm_do_sleep(FPM_SLEEP_MAX_TIME);
}
else if(FLAG_wifi_force_sleep_enabled && desired_sleep_state==0)
{
FLAG_wifi_force_sleep_enabled=FALSE;
// wake up to use WiFi again
wifi_fpm_do_wakeup();
wifi_fpm_close();
}
lua_pushnumber(L, FLAG_wifi_force_sleep_enabled);
return 1;
}

// Lua: mac = wifi.xx.getmac()
static int wifi_getmac( lua_State* L, uint8_t mode )
{
Expand Down Expand Up @@ -1329,14 +1375,15 @@ const LUA_REG_TYPE wifi_map[] =
{ LSTRKEY( "getchannel" ), LFUNCVAL( wifi_getchannel ) },
{ LSTRKEY( "setphymode" ), LFUNCVAL( wifi_setphymode ) },
{ LSTRKEY( "getphymode" ), LFUNCVAL( wifi_getphymode ) },
{ LSTRKEY( "sleep" ), LFUNCVAL( wifi_sleep ) },
{ LSTRKEY( "startsmart" ), LFUNCVAL( wifi_start_smart ) },
{ LSTRKEY( "stopsmart" ), LFUNCVAL( wifi_exit_smart ) },
{ LSTRKEY( "sleeptype" ), LFUNCVAL( wifi_sleeptype ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "sta" ), LROVAL( wifi_station_map ) },
{ LSTRKEY( "ap" ), LROVAL( wifi_ap_map ) },

// { LSTRKEY( "NULLMODE" ), LNUMVAL( NULL_MODE ) },
{ LSTRKEY( "NULLMODE" ), LNUMVAL( NULL_MODE ) },
{ LSTRKEY( "STATION" ), LNUMVAL( STATION_MODE ) },
{ LSTRKEY( "SOFTAP" ), LNUMVAL( SOFTAP_MODE ) },
{ LSTRKEY( "STATIONAP" ), LNUMVAL( STATIONAP_MODE ) },
Expand Down