From df2fdfb5a3b6b37472054e7f3567a7ff0aaed0aa Mon Sep 17 00:00:00 2001 From: Leah Date: Tue, 26 Oct 2021 03:38:36 +0200 Subject: [PATCH] feat: wifi power-save mode --- src/wifi.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/wifi.rs b/src/wifi.rs index 0c98ed39db0..2428805f616 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -216,6 +216,25 @@ pub struct EspWifi { shared: Box>, } +pub enum PowerSaveMode { + /// No power save + None, + /// Minimum modem power saving. In this mode, station wakes up to receive beacon every DTIM period + MinModem, + ///Maximum modem power saving. In this mode, interval to receive beacons is determined by the listen_interval parameter in wifi_sta_config_t + MaxModem, +} + +impl Into for PowerSaveMode { + fn into(self) -> wifi_ps_type_t { + match self { + PowerSaveMode::None => wifi_ps_type_t_WIFI_PS_NONE, + PowerSaveMode::MinModem => wifi_ps_type_t_WIFI_PS_MIN_MODEM, + PowerSaveMode::MaxModem => wifi_ps_type_t_WIFI_PS_MAX_MODEM, + } + } +} + impl EspWifi { pub fn new( netif_stack: Arc, @@ -301,6 +320,10 @@ impl EspWifi { Ok(wifi) } + pub fn set_power_save_mode(&mut self, mode: PowerSaveMode) -> Result<(), EspError> { + esp!(unsafe { esp_wifi_set_ps(mode.into()) }) + } + pub fn with_client_netif(&self, f: F) -> T where F: FnOnce(Option<&EspNetif>) -> T, @@ -828,7 +851,7 @@ impl Drop for EspWifi { fn drop(&mut self) { unsafe { TAKEN.lock(|taken| { - self.clear_all().unwrap(); + // self.clear_all().unwrap(); *taken = false; }); }