Skip to content

add setSleepMode + getSleepMode and setPhyMode + getPhyMode to WiFi #1306

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

Merged
merged 1 commit into from
Dec 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 37 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,43 @@ void ESP8266WiFiClass::_smartConfigCallback(uint32_t st, void* result)
}
}


//--------------------------------------------------------------

/**
* set Sleep mode
* @param type sleep_type_t
* @return bool
*/
bool ESP8266WiFiClass::setSleepMode(WiFiSleepType_t type) {
return wifi_set_sleep_type((sleep_type_t)type);
}

/**
* get Sleep mode
* @return sleep_type_t
*/
WiFiSleepType_t ESP8266WiFiClass::getSleepMode() {
return (WiFiSleepType_t)wifi_get_sleep_type();
}

/**
* set phy Mode
* @param mode phy_mode_t
* @return bool
*/
bool ESP8266WiFiClass::setPhyMode(WiFiPhyMode_t mode) {
return wifi_set_phy_mode((phy_mode_t)mode);
}

/**
* get phy Mode
* @return phy_mode_t
*/
WiFiPhyMode_t ESP8266WiFiClass::getPhyMode() {
return (WiFiPhyMode_t)wifi_get_phy_mode();
}

//--------------------------------------------------------------

void ESP8266WiFiClass::_eventCallback(void* arg)
Expand Down
39 changes: 39 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,21 @@ extern "C" {
#define WIFI_SCAN_RUNNING (-1)
#define WIFI_SCAN_FAILED (-2)


// Note:
// this enums need to be in sync with the SDK!

enum WiFiMode { WIFI_OFF = 0, WIFI_STA = 1, WIFI_AP = 2, WIFI_AP_STA = 3 };

typedef enum {
WIFI_PHY_MODE_11B = 1, WIFI_PHY_MODE_11G = 2, WIFI_PHY_MODE_11N = 3
} WiFiPhyMode_t;

typedef enum {
WIFI_NONE_SLEEP = 0, WIFI_LIGHT_SLEEP = 2, WIFI_MODEM_SLEEP = 3
} WiFiSleepType_t;


class ESP8266WiFiClass
{
public:
Expand Down Expand Up @@ -375,6 +388,32 @@ class ESP8266WiFiClass
friend class WiFiClient;
friend class WiFiServer;

/**
* set Sleep mode
* @param type WiFiPhyMode_t
* @return bool
*/
bool setSleepMode(WiFiSleepType_t type);

/**
* get Sleep mode
* @return sleep_type_t
*/
WiFiSleepType_t getSleepMode();

/**
* set phy Mode
* @param mode phy_mode_t
* @return bool
*/
bool setPhyMode(WiFiPhyMode_t mode);

/**
* get phy Mode
* @return phy_mode_t
*/
WiFiPhyMode_t getPhyMode();

protected:
void _mode(WiFiMode);
static void _scanDone(void* result, int status);
Expand Down
20 changes: 10 additions & 10 deletions tools/sdk/include/user_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,30 +333,30 @@ void wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb);

void wifi_promiscuous_set_mac(const uint8_t *address);

enum phy_mode {
typedef enum {
PHY_MODE_11B = 1,
PHY_MODE_11G = 2,
PHY_MODE_11N = 3
};
} phy_mode_t;

enum phy_mode wifi_get_phy_mode(void);
bool wifi_set_phy_mode(enum phy_mode mode);
phy_mode_t wifi_get_phy_mode(void);
bool wifi_set_phy_mode(phy_mode_t mode);

enum sleep_type {
typedef enum {
NONE_SLEEP_T = 0,
LIGHT_SLEEP_T,
MODEM_SLEEP_T
};
} sleep_type_t;

bool wifi_set_sleep_type(enum sleep_type type);
enum sleep_type wifi_get_sleep_type(void);
bool wifi_set_sleep_type(sleep_type_t type);
sleep_type_t wifi_get_sleep_type(void);

void wifi_fpm_open(void);
void wifi_fpm_close(void);
void wifi_fpm_do_wakeup(void);
sint8 wifi_fpm_do_sleep(uint32 sleep_time_in_us);
void wifi_fpm_set_sleep_type(enum sleep_type type);
enum sleep_type wifi_fpm_get_sleep_type(void);
void wifi_fpm_set_sleep_type(sleep_type_t type);
sleep_type_t wifi_fpm_get_sleep_type(void);

enum {
EVENT_STAMODE_CONNECTED = 0,
Expand Down