pull/11890/merge
glenn20 2024-04-23 13:18:44 +03:30 zatwierdzone przez GitHub
commit 0423ef463a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 33 dodań i 1 usunięć

Wyświetl plik

@ -170,6 +170,26 @@ Configuration
<https://docs.espressif.com/projects/esp-idf/en/v4.4.1/esp32/
api-reference/network/esp_wifi.html#_CPPv415wifi_phy_rate_t>`_.
*pm*: (ESP32 only) Set the ESPNOW wireless power saving parameters.
Usage: ``e.config(pm=(window, interval))``: every ``interval``
milliseconds the radio will be turned on for ``window`` milliseconds to
listen for incoming messages (``interval`` should be a multiple of
100ms). Incoming messages will be lost while the radio is off. Messages
may be sent at any time. By default, ESPNOW power saving is disabled and
the radio is turned on continuously. Examples::
e.config(pm=(75, 200)) # equivalent to WLAN.config(pm=WLAN.PM_PERFORMANCE)
e.config(pm=(75, 300)) # equivalent to WLAN.config(pm=WLAN.PM_POWERSAVE)
If the device is also connected to a wifi Access Point, the wifi power
saving mode will be used instead
(see `WLAN.config(pm=XX)<network.WLAN.config>`).
See `Config ESP-NOW Power-saving Parameter
<https://docs.espressif.com/projects/esp-idf/en/v5.0.2/esp32/
api-reference/network/
esp_now.html#config-esp-now-power-saving-parameter>`_.
.. data:: Returns:
``None`` or the value of the parameter being queried.

Wyświetl plik

@ -239,12 +239,13 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_active_obj, 1, 2, espnow_activ
// timeout: Default read timeout (default=300,000 milliseconds)
static mp_obj_t espnow_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
esp_espnow_obj_t *self = _get_singleton();
enum { ARG_get, ARG_rxbuf, ARG_timeout_ms, ARG_rate };
enum { ARG_get, ARG_rxbuf, ARG_timeout_ms, ARG_rate, ARG_pm };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_rxbuf, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
{ MP_QSTR_timeout_ms, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MIN} },
{ MP_QSTR_rate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
{ MP_QSTR_pm, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,
@ -261,6 +262,17 @@ static mp_obj_t espnow_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t
check_esp_err(esp_wifi_config_espnow_rate(ESP_IF_WIFI_STA, args[ARG_rate].u_int));
check_esp_err(esp_wifi_config_espnow_rate(ESP_IF_WIFI_AP, args[ARG_rate].u_int));
}
if (args[ARG_pm].u_obj != MP_OBJ_NULL) {
mp_obj_tuple_t *t = (mp_obj_tuple_t *)MP_OBJ_TO_PTR(args[ARG_pm].u_obj);
if (!mp_obj_is_type(t, &mp_type_tuple) || t->len < 1 || t->len > 2) {
mp_raise_TypeError(MP_ERROR_TEXT("pm should be set to tuple of length 2"));
}
check_esp_err(esp_now_set_wake_window(mp_obj_get_int(t->items[0])));
if (t->len == 2) {
check_esp_err(esp_wifi_connectionless_module_set_wake_interval(mp_obj_get_int(t->items[1])));
}
}
if (args[ARG_get].u_obj == MP_OBJ_NULL) {
return mp_const_none;
}