mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
Adding onComplete event handler support for the asynchronous network scanning. (#2287)
This commit is contained in:
parent
f0e2c9f28b
commit
98fe5617eb
@ -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
|
||||
@ -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
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -319,4 +333,3 @@ void * ESP8266WiFiScanClass::_getScanInfoByIndex(int i) {
|
||||
}
|
||||
return reinterpret_cast<bss_info*>(ESP8266WiFiScanClass::_scanResult) + i;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user