10000 esp32/modnetwork: Add interface to the WIFI power save functions of E… · micropython/micropython@cc360a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc360a2

Browse files
committed
esp32/modnetwork: Add interface to the WIFI power save functions of ESP-IDF.
New function WLAN.wifi_ps() with zero or one parameter. New constants in network: WIFI_PS_NONE WIFI_PS_MIN_MODEM WIFI_PS_MAX_MODEM When called without parameter, the function returns the current WIFI power save mode. When called with one parameter, the power save mode is set to the value of the parameter and the previous power save mode is returned. esp32/modnetwork: code formatting
1 parent f7aafc0 commit cc360a2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

ports/esp32/modnetwork.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,19 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
724724
}
725725
MP_DEFINE_CONST_FUN_OBJ_KW(esp_config_obj, 1, esp_config);
726726

727+
STATIC mp_obj_t esp_wifi_ps(size_t n_args, const mp_obj_t *args) {
728+
wifi_ps_type_t ps_type_old, ps_type_new;
729+
// wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
730+
731+
ESP_EXCEPTIONS(esp_wifi_get_ps(&ps_type_old));
732+
if (n_args == 2) {
733+
ps_type_new = (wifi_ps_type_t)mp_obj_get_int(args[1]);
734+
ESP_EXCEPTIONS(esp_wifi_set_ps(ps_type_new));
735+
}
736+
return MP_OBJ_NEW_SMALL_INT(ps_type_old);
737+
}
738+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_wifi_ps_obj, 1, 2, esp_wifi_ps);
739+
727740
STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
728741
{ MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&esp_active_obj) },
729742
{ MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&esp_connect_obj) },
@@ -733,6 +746,8 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
733746
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&esp_isconnected_obj) },
734747
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&esp_config_obj) },
735748
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) },
749+
// wifi power save functions
750+
{ MP_ROM_QSTR(MP_QSTR_wifi_ps), MP_ROM_PTR(&esp_wifi_ps_obj) },
736751
};
737752

738753
STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);
@@ -797,6 +812,10 @@ STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
797812
{ MP_ROM_QSTR(MP_QSTR_STAT_BEACON_TIMEOUT), MP_ROM_INT(WIFI_REASON_BEACON_TIMEOUT)},
798813
{ MP_ROM_QSTR(MP_QSTR_STAT_ASSOC_FAIL), MP_ROM_INT(WIFI_REASON_ASSOC_FAIL)},
799814
{ MP_ROM_QSTR(MP_QSTR_STAT_HANDSHAKE_TIMEOUT), MP_ROM_INT(WIFI_REASON_HANDSHAKE_TIMEOUT)},
815+
// wifi power save constants
816+
{ MP_ROM_QSTR(MP_QSTR_WIFI_PS_NONE), MP_ROM_INT(WIFI_PS_NONE)},
817+
{ MP_ROM_QSTR(MP_QSTR_WIFI_PS_MIN_MODEM), MP_ROM_INT(WIFI_PS_MIN_MODEM)},
818+
{ MP_ROM_QSTR(MP_QSTR_WIFI_PS_MAX_MODEM), MP_ROM_INT(WIFI_PS_MAX_MODEM)},
800819
#endif
801820
};
802821

0 commit comments

Comments
 (0)
0