esp8266: Added wifi_mode() to read and set WiFi operating mode.

This commit is contained in:
Bill Owens 2015-06-10 12:14:10 -07:00 committed by Paul Sokolovsky
parent a160b70ced
commit a66a99bfd8
2 changed files with 22 additions and 0 deletions

View File

@ -509,6 +509,16 @@ void error_check(bool status, const char *msg) {
} }
} }
STATIC mp_obj_t esp_wifi_mode(mp_uint_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
return mp_obj_new_int(wifi_get_opmode());
} else {
wifi_set_opmode(mp_obj_get_int(args[0]));
return mp_const_none;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_wifi_mode_obj, 0, 1, esp_wifi_mode);
STATIC mp_obj_t esp_phy_mode(mp_uint_t n_args, const mp_obj_t *args) { STATIC mp_obj_t esp_phy_mode(mp_uint_t n_args, const mp_obj_t *args) {
if (n_args == 0) { if (n_args == 0) {
return mp_obj_new_int(wifi_get_phy_mode()); return mp_obj_new_int(wifi_get_phy_mode());
@ -565,6 +575,7 @@ STATIC const mp_map_elem_t esp_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_mac), (mp_obj_t)&esp_mac_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_mac), (mp_obj_t)&esp_mac_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&esp_getaddrinfo_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&esp_getaddrinfo_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_wifi_mode), (mp_obj_t)&esp_wifi_mode_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_phy_mode), (mp_obj_t)&esp_phy_mode_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_phy_mode), (mp_obj_t)&esp_phy_mode_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep_type), (mp_obj_t)&esp_sleep_type_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_type), (mp_obj_t)&esp_sleep_type_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_deepsleep), (mp_obj_t)&esp_deepsleep_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_deepsleep), (mp_obj_t)&esp_deepsleep_obj },
@ -585,6 +596,13 @@ STATIC const mp_map_elem_t esp_module_globals_table[] = {
MP_OBJ_NEW_SMALL_INT(LIGHT_SLEEP_T) }, MP_OBJ_NEW_SMALL_INT(LIGHT_SLEEP_T) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP_MODEM), { MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP_MODEM),
MP_OBJ_NEW_SMALL_INT(MODEM_SLEEP_T) }, MP_OBJ_NEW_SMALL_INT(MODEM_SLEEP_T) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_STA_MODE),
MP_OBJ_NEW_SMALL_INT(STATION_MODE)},
{ MP_OBJ_NEW_QSTR(MP_QSTR_AP_MODE),
MP_OBJ_NEW_SMALL_INT(SOFTAP_MODE)},
{ MP_OBJ_NEW_QSTR(MP_QSTR_STA_AP_MODE),
MP_OBJ_NEW_SMALL_INT(STATIONAP_MODE)},
#endif #endif
}; };

View File

@ -56,6 +56,7 @@ Q(esp)
Q(socket) Q(socket)
Q(connect) Q(connect)
Q(disconnect) Q(disconnect)
Q(wifi_mode)
Q(phy_mode) Q(phy_mode)
Q(sleep_type) Q(sleep_type)
Q(deepsleep) Q(deepsleep)
@ -89,6 +90,9 @@ Q(MODE_11N)
Q(SLEEP_NONE) Q(SLEEP_NONE)
Q(SLEEP_LIGHT) Q(SLEEP_LIGHT)
Q(SLEEP_MODEM) Q(SLEEP_MODEM)
Q(STA_MODE)
Q(AP_MODE)
Q(STA_AP_MODE)
// network module // network module
Q(network) Q(network)