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
4387f903
Commit
4387f903
authored
Nov 03, 2015
by
dnc40085
Browse files
Added function wifi.sleep
parent
38b494c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/wifi.c
View file @
4387f903
...
@@ -18,6 +18,11 @@
...
@@ -18,6 +18,11 @@
static
int
wifi_smart_succeed
=
LUA_NOREF
;
static
int
wifi_smart_succeed
=
LUA_NOREF
;
static
uint8
getap_output_format
=
0
;
static
uint8
getap_output_format
=
0
;
//wifi.sleep variables
#define FPM_SLEEP_MAX_TIME 0xFFFFFFF
bool
FLAG_wifi_force_sleep_enabled
=
0
;
//variables for wifi event monitor
//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
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
;
static
volatile
os_timer_t
wifi_sta_status_timer
;
...
@@ -319,6 +324,47 @@ static int wifi_getphymode( lua_State* L )
...
@@ -319,6 +324,47 @@ static int wifi_getphymode( lua_State* L )
return
1
;
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()
// Lua: mac = wifi.xx.getmac()
static
int
wifi_getmac
(
lua_State
*
L
,
uint8_t
mode
)
static
int
wifi_getmac
(
lua_State
*
L
,
uint8_t
mode
)
{
{
...
@@ -1329,6 +1375,7 @@ const LUA_REG_TYPE wifi_map[] =
...
@@ -1329,6 +1375,7 @@ const LUA_REG_TYPE wifi_map[] =
{
LSTRKEY
(
"getchannel"
),
LFUNCVAL
(
wifi_getchannel
)
},
{
LSTRKEY
(
"getchannel"
),
LFUNCVAL
(
wifi_getchannel
)
},
{
LSTRKEY
(
"setphymode"
),
LFUNCVAL
(
wifi_setphymode
)
},
{
LSTRKEY
(
"setphymode"
),
LFUNCVAL
(
wifi_setphymode
)
},
{
LSTRKEY
(
"getphymode"
),
LFUNCVAL
(
wifi_getphymode
)
},
{
LSTRKEY
(
"getphymode"
),
LFUNCVAL
(
wifi_getphymode
)
},
{
LSTRKEY
(
"sleep"
),
LFUNCVAL
(
wifi_sleep
)
},
{
LSTRKEY
(
"startsmart"
),
LFUNCVAL
(
wifi_start_smart
)
},
{
LSTRKEY
(
"startsmart"
),
LFUNCVAL
(
wifi_start_smart
)
},
{
LSTRKEY
(
"stopsmart"
),
LFUNCVAL
(
wifi_exit_smart
)
},
{
LSTRKEY
(
"stopsmart"
),
LFUNCVAL
(
wifi_exit_smart
)
},
{
LSTRKEY
(
"sleeptype"
),
LFUNCVAL
(
wifi_sleeptype
)
},
{
LSTRKEY
(
"sleeptype"
),
LFUNCVAL
(
wifi_sleeptype
)
},
...
...
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