Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
5e95f48a
Commit
5e95f48a
authored
Nov 05, 2015
by
dnc40085
Browse files
Update function wifi.sleep to return any error codes to user
parent
10c4ac14
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/wifi.c
View file @
5e95f48a
...
@@ -327,23 +327,23 @@ static int wifi_getphymode( lua_State* L )
...
@@ -327,23 +327,23 @@ static int wifi_getphymode( lua_State* L )
//wifi.sleep()
//wifi.sleep()
static
int
wifi_sleep
(
lua_State
*
L
)
static
int
wifi_sleep
(
lua_State
*
L
)
{
{
uint8
desired_sleep_state
=
2
;
uint8
desired_sleep_state
=
2
;
sint8
wifi_fpm_do_sleep_return_value
=
1
;
if
(
lua_isnumber
(
L
,
1
))
if
(
lua_isnumber
(
L
,
1
))
{
{
if
(
luaL_checknumber
(
L
,
1
)
==
0
)
if
(
luaL_checknumber
(
L
,
1
)
==
0
)
{
{
desired_sleep_state
=
FALSE
;
desired_sleep_state
=
0
;
}
}
else
if
(
luaL_checknumber
(
L
,
1
)
==
1
)
else
if
(
luaL_checknumber
(
L
,
1
)
==
1
)
{
{
desired_sleep_state
=
TRUE
;
desired_sleep_state
=
1
;
}
}
}
}
if
(
!
FLAG_wifi_force_sleep_enabled
&&
desired_sleep_state
==
1
)
if
(
!
FLAG_wifi_force_sleep_enabled
&&
desired_sleep_state
==
1
)
{
{
FLAG_wifi_force_sleep_enabled
=
TRUE
;
uint8
wifi_current_opmode
=
wifi_get_opmode
();
uint8
wifi_current_opmode
=
wifi_get_opmode
();
if
(
wifi_current_opmode
==
1
||
wifi_current_opmode
==
3
)
if
(
wifi_current_opmode
==
1
||
wifi_current_opmode
==
3
)
{
{
wifi_station_disconnect
();
wifi_station_disconnect
();
}
}
...
@@ -352,17 +352,37 @@ static int wifi_sleep(lua_State* L)
...
@@ -352,17 +352,37 @@ static int wifi_sleep(lua_State* L)
// set force sleep type
// set force sleep type
wifi_fpm_set_sleep_type
(
MODEM_SLEEP_T
);
wifi_fpm_set_sleep_type
(
MODEM_SLEEP_T
);
wifi_fpm_open
();
wifi_fpm_open
();
wifi_fpm_do_sleep
(
FPM_SLEEP_MAX_TIME
);
wifi_fpm_do_sleep_return_value
=
wifi_fpm_do_sleep
(
FPM_SLEEP_MAX_TIME
);
if
(
wifi_fpm_do_sleep_return_value
==
0
)
{
FLAG_wifi_force_sleep_enabled
=
TRUE
;
}
else
if
(
wifi_fpm_do_sleep_return_value
!=
0
)
{
wifi_fpm_close
();
FLAG_wifi_force_sleep_enabled
=
FALSE
;
}
}
}
else
if
(
FLAG_wifi_force_sleep_enabled
&&
desired_sleep_state
==
0
)
else
if
(
FLAG_wifi_force_sleep_enabled
&&
desired_sleep_state
==
0
)
{
{
FLAG_wifi_force_sleep_enabled
=
FALSE
;
FLAG_wifi_force_sleep_enabled
=
FALSE
;
// wake up to use WiFi again
// wake up to use WiFi again
wifi_fpm_do_wakeup
();
wifi_fpm_do_wakeup
();
wifi_fpm_close
();
wifi_fpm_close
();
}
}
lua_pushnumber
(
L
,
FLAG_wifi_force_sleep_enabled
);
return
1
;
if
(
desired_sleep_state
==
1
&&
FLAG_wifi_force_sleep_enabled
==
FALSE
)
{
lua_pushnil
(
L
);
lua_pushnumber
(
L
,
wifi_fpm_do_sleep_return_value
);
}
else
{
lua_pushnumber
(
L
,
FLAG_wifi_force_sleep_enabled
);
lua_pushnil
(
L
);
}
return
2
;
}
}
// Lua: mac = wifi.xx.getmac()
// Lua: mac = wifi.xx.getmac()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment