diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index ee165063..90efbe71 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -120,6 +120,12 @@ static bool espWiFiStop(){ // ------------------------------------------------- Generic WiFi function ----------------------------------------------- // ----------------------------------------------------------------------------------------------------------------------- +typedef struct { + WiFiEventCb cb; + WiFiEventFullCb fcb; + system_event_id_t event; +} WiFiEventCbList_t; + // arduino dont like std::vectors move static here static std::vector cbEventList; @@ -143,6 +149,19 @@ void WiFiGenericClass::onEvent(WiFiEventCb cbEvent, system_event_id_t event) } WiFiEventCbList_t newEventHandler; newEventHandler.cb = cbEvent; + newEventHandler.fcb = NULL; + newEventHandler.event = event; + cbEventList.push_back(newEventHandler); +} + +void WiFiGenericClass::onEvent(WiFiEventFullCb cbEvent, system_event_id_t event) +{ + if(!cbEvent) { + return; + } + WiFiEventCbList_t newEventHandler; + newEventHandler.cb = NULL; + newEventHandler.fcb = cbEvent; newEventHandler.event = event; cbEventList.push_back(newEventHandler); } @@ -166,6 +185,20 @@ void WiFiGenericClass::removeEvent(WiFiEventCb cbEvent, system_event_id_t event) } } +void WiFiGenericClass::removeEvent(WiFiEventFullCb cbEvent, system_event_id_t event) +{ + if(!cbEvent) { + return; + } + + for(uint32_t i = 0; i < cbEventList.size(); i++) { + WiFiEventCbList_t entry = cbEventList[i]; + if(entry.fcb == cbEvent && entry.event == event) { + cbEventList.erase(cbEventList.begin() + i); + } + } +} + /** * callback for WiFi events * @param arg @@ -208,9 +241,13 @@ esp_err_t WiFiGenericClass::_eventCallback(void *arg, system_event_t *event) for(uint32_t i = 0; i < cbEventList.size(); i++) { WiFiEventCbList_t entry = cbEventList[i]; - if(entry.cb) { + if(entry.cb || entry.fcb) { if(entry.event == (system_event_id_t) event->event_id || entry.event == SYSTEM_EVENT_MAX) { - entry.cb((system_event_id_t) event->event_id); + if(entry.cb){ + entry.cb((system_event_id_t) event->event_id); + } else { + entry.fcb((system_event_id_t) event->event_id, (system_event_info_t) event->event_info); + } } } } diff --git a/libraries/WiFi/src/WiFiGeneric.h b/libraries/WiFi/src/WiFiGeneric.h index 95b85b16..356f44e7 100644 --- a/libraries/WiFi/src/WiFiGeneric.h +++ b/libraries/WiFi/src/WiFiGeneric.h @@ -28,11 +28,7 @@ #include typedef void (*WiFiEventCb)(system_event_id_t event); - -typedef struct { - WiFiEventCb cb; - system_event_id_t event; -} WiFiEventCbList_t; +typedef void (*WiFiEventFullCb)(system_event_id_t event, system_event_info_t info); class WiFiGenericClass { @@ -41,7 +37,9 @@ public: WiFiGenericClass(); void onEvent(WiFiEventCb cbEvent, system_event_id_t event = SYSTEM_EVENT_MAX); + void onEvent(WiFiEventFullCb cbEvent, system_event_id_t event = SYSTEM_EVENT_MAX); void removeEvent(WiFiEventCb cbEvent, system_event_id_t event = SYSTEM_EVENT_MAX); + void removeEvent(WiFiEventFullCb cbEvent, system_event_id_t event = SYSTEM_EVENT_MAX); int32_t channel(void);