From d521cea2322e4ad61e94144b5a72d46c33ca9a53 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Mon, 28 Dec 2015 17:55:38 +0100 Subject: [PATCH] reorder part 3 --- libraries/ESP8266WiFi/src/ESP8266WiFi.cpp | 15 ++++- libraries/ESP8266WiFi/src/ESP8266WiFi.h | 72 ++++++++++++++++++----- 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp index ee52e8ab4..0207f2ea8 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp @@ -106,12 +106,21 @@ static bool softap_config_equal(const softap_config& lhs, const softap_config& r // ---------------------------------------------------- ESP8266WiFiClass ------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------------- -ESP8266WiFiClass::ESP8266WiFiClass() : - _smartConfigStarted(false), _smartConfigDone(false), _useStaticIp(false), _persistent(true) { +ESP8266WiFiClass::ESP8266WiFiClass() { + + _useStaticIp = false; + uint8 m = wifi_get_opmode(); - _useClientMode = (m & WIFI_STA); _useApMode = (m & WIFI_AP); + _useClientMode = (m & WIFI_STA); + + _persistent = true; + + _smartConfigStarted = false; + _smartConfigDone = false; + wifi_set_event_handler_cb((wifi_event_handler_cb_t) &ESP8266WiFiClass::_eventCallback); + } /** diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFi.h b/libraries/ESP8266WiFi/src/ESP8266WiFi.h index 9a9e433ac..bd2696213 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFi.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFi.h @@ -52,12 +52,25 @@ typedef enum { } WiFiSleepType_t; class ESP8266WiFiClass { + + // ---------------------------------------------------------------------------------------------- + // -------------------------------------- ESP8266WiFiClass -------------------------------------- + // ---------------------------------------------------------------------------------------------- + public: + ESP8266WiFiClass(); + protected: + + static void _eventCallback(void *event); + // ---------------------------------------------------------------------------------------------- // ---------------------------------------- STA function ---------------------------------------- // ---------------------------------------------------------------------------------------------- + + public: + int begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL); int begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL); int begin(); @@ -94,9 +107,16 @@ class ESP8266WiFiClass { int32_t RSSI(); + protected: + + bool _useStaticIp; + // ---------------------------------------------------------------------------------------------- // ----------------------------------------- AP function ---------------------------------------- // ---------------------------------------------------------------------------------------------- + + public: + void softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0); void softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet); int softAPdisconnect(bool wifioff = false); @@ -106,10 +126,14 @@ class ESP8266WiFiClass { uint8_t* softAPmacAddress(uint8_t* mac); String softAPmacAddress(void); + protected: + // ---------------------------------------------------------------------------------------------- // ----------------------------------------- scan function -------------------------------------- // ---------------------------------------------------------------------------------------------- + public: + int8_t scanNetworks(bool async = false, bool show_hidden = false); int8_t scanComplete(); @@ -126,10 +150,24 @@ class ESP8266WiFiClass { int32_t channel(uint8_t networkItem); bool isHidden(uint8_t networkItem); + protected: + + static bool _scanAsync; + static bool _scanStarted; + static bool _scanComplete; + + static size_t _scanCount; + static void* _scanResult; + + static void _scanDone(void* result, int status); + void * _getScanInfoByIndex(int i); + // ---------------------------------------------------------------------------------------------- // -------------------------------------- Generic WiFi function --------------------------------- // ---------------------------------------------------------------------------------------------- + public: + int32_t channel(void); bool setSleepMode(WiFiSleepType_t type); @@ -142,49 +180,51 @@ class ESP8266WiFiClass { void mode(WiFiMode); WiFiMode getMode(); + protected: + bool _useApMode; + bool _useClientMode; + bool _persistent; + void _mode(WiFiMode); + // ---------------------------------------------------------------------------------------------- // ------------------------------------ Generic Network function -------------------------------- // ---------------------------------------------------------------------------------------------- + public: + int hostByName(const char* aHostname, IPAddress& aResult); + protected: // ---------------------------------------------------------------------------------------------- // ------------------------------------ STA remote configure ----------------------------------- // ---------------------------------------------------------------------------------------------- + public: + bool beginWPSConfig(void); void beginSmartConfig(); bool smartConfigDone(); void stopSmartConfig(); + protected: + + bool _smartConfigStarted; + bool _smartConfigDone; + static void _smartConfigCallback(uint32_t status, void* result); // ---------------------------------------------------------------------------------------------- // ------------------------------------------- Debug -------------------------------------------- // ---------------------------------------------------------------------------------------------- + public: + void printDiag(Print& dest); friend class WiFiClient; friend class WiFiServer; - protected: - void _mode(WiFiMode); - static void _scanDone(void* result, int status); - void * _getScanInfoByIndex(int i); - static void _smartConfigCallback(uint32_t status, void* result); - static void _eventCallback(void *event);bool _smartConfigStarted;bool _smartConfigDone; - - bool _useApMode;bool _useClientMode;bool _useStaticIp;bool _persistent; - - static bool _scanAsync; - static bool _scanStarted; - static bool _scanComplete; - - static size_t _scanCount; - static void* _scanResult; - }; extern ESP8266WiFiClass WiFi;