Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ESP32 compatible methods for setting/getting sleep mode #7901

Merged
merged 4 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
d-a-v marked this conversation as resolved.
Show resolved Hide resolved
}
}
/**
* 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