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

Adding onComplete event handler #2287

Merged
merged 1 commit into from
Jul 18, 2016
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
15 changes: 14 additions & 1 deletion libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ bool ESP8266WiFiScanClass::_scanComplete = false;
size_t ESP8266WiFiScanClass::_scanCount = 0;
void* ESP8266WiFiScanClass::_scanResult = 0;

std::function<void(int)> ESP8266WiFiScanClass::_onComplete;

/**
* Start scan WiFi networks available
* @param async run in async mode
Expand Down Expand Up @@ -102,6 +104,15 @@ int8_t ESP8266WiFiScanClass::scanNetworks(bool async, bool show_hidden) {

}

/**
* Starts scanning WiFi networks available in async mode
* @param onComplete the event handler executed when the scan is done
* @param show_hidden show hidden networks
*/
void ESP8266WiFiScanClass::scanNetworksAsync(std::function<void(int)> onComplete, bool show_hidden) {
_onComplete = onComplete;
scanNetworks(true, show_hidden);
}

/**
* called to get the scan state in Async mode
Expand Down Expand Up @@ -305,6 +316,9 @@ void ESP8266WiFiScanClass::_scanDone(void* result, int status) {

if(!ESP8266WiFiScanClass::_scanAsync) {
esp_schedule();
} else if (ESP8266WiFiScanClass::_onComplete) {
ESP8266WiFiScanClass::_onComplete(ESP8266WiFiScanClass::_scanCount);
ESP8266WiFiScanClass::_onComplete = nullptr;
}
}

Expand All @@ -319,4 +333,3 @@ void * ESP8266WiFiScanClass::_getScanInfoByIndex(int i) {
}
return reinterpret_cast<bss_info*>(ESP8266WiFiScanClass::_scanResult) + i;
}

3 changes: 3 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ESP8266WiFiScanClass {
public:

int8_t scanNetworks(bool async = false, bool show_hidden = false);
void scanNetworksAsync(std::function<void(int)> onComplete, bool show_hidden = false);

int8_t scanComplete();
void scanDelete();
Expand All @@ -59,6 +60,8 @@ class ESP8266WiFiScanClass {
static size_t _scanCount;
static void* _scanResult;

static std::function<void(int)> _onComplete;

static void _scanDone(void* result, int status);
static void * _getScanInfoByIndex(int i);

Expand Down