Skip to content

Commit

Permalink
Added ESP32 compatible methods for setting/getting sleep mode
Browse files Browse the repository at this point in the history
  • Loading branch information
drzony committed Mar 1, 2021
1 parent e3fe7a5 commit 455e998
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
33 changes: 33 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,39 @@ class ESP8266WiFiGenericClass {
uint8_t channel(void);

bool setSleepMode(WiFiSleepType_t type, uint8_t listenInterval = 0);
/**
* Set modem sleep mode (ESP32 compatibility)
* @param enable true to enable
* @return true if succeeded
*/
bool setSleep(bool enable)
{
if (enable)
{
return setSleepMode(WIFI_MODEM_SLEEP);
}
else
{
return setSleepMode(WIFI_NONE_SLEEP);
}
}
/**
* Set sleep mode (ESP32 compatibility)
* @param mode wifi_ps_type_t
* @return true if succeeded
*/
bool setSleep(wifi_ps_type_t mode)
{
return setSleepMode((WiFiSleepType_t)mode);
}
/**
* Get current sleep state (ESP32 compatibility)
* @return true if modem sleep is enabled
*/
bool getSleep()
{
return getSleepMode() == WIFI_MODEM_SLEEP;
}

WiFiSleepType_t getSleepMode();
uint8_t getListenInterval ();
Expand Down
7 changes: 7 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiType.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ typedef enum WiFiSleepType
WIFI_NONE_SLEEP = 0, WIFI_LIGHT_SLEEP = 1, WIFI_MODEM_SLEEP = 2
} WiFiSleepType_t;

// ESP32 compatibility
typedef enum wifi_ps_type
{
WIFI_PS_NONE = WIFI_NONE_SLEEP,
WIFI_PS_MIN_MODEM = WIFI_MODEM_SLEEP,
WIFI_PS_MAX_MODEM = WIFI_LIGHT_SLEEP,
} wifi_ps_type_t;

typedef enum WiFiEvent
{
Expand Down

0 comments on commit 455e998

Please sign in to comment.