@@ -170,12 +170,18 @@ static bool espWiFiStop(){
170
170
// ------------------------------------------------- Generic WiFi function -----------------------------------------------
171
171
// -----------------------------------------------------------------------------------------------------------------------
172
172
173
- typedef struct {
173
+ typedef struct WiFiEventCbList {
174
+ static wifi_event_id_t current_id;
175
+ wifi_event_id_t id;
174
176
WiFiEventCb cb;
175
- WiFiEventFullCb fcb;
177
+ WiFiEventFuncCb fcb;
176
178
WiFiEventSysCb scb;
177
179
system_event_id_t event;
180
+
181
+ WiFiEventCbList () : id(current_id++) {}
178
182
} WiFiEventCbList_t;
183
+ wifi_event_id_t WiFiEventCbList::current_id = 1 ;
184
+
179
185
180
186
// arduino dont like std::vectors move static here
181
187
static std::vector<WiFiEventCbList_t> cbEventList;
@@ -193,43 +199,46 @@ WiFiGenericClass::WiFiGenericClass()
193
199
* @param cbEvent WiFiEventCb
194
200
* @param event optional filter (WIFI_EVENT_MAX is all events)
195
201
*/
196
- void WiFiGenericClass::onEvent (WiFiEventCb cbEvent, system_event_id_t event)
202
+ wifi_event_id_t WiFiGenericClass::onEvent (WiFiEventCb cbEvent, system_event_id_t event)
197
203
{
198
204
if (!cbEvent) {
199
- return ;
205
+ return 0 ;
200
206
}
201
207
WiFiEventCbList_t newEventHandler;
202
208
newEventHandler.cb = cbEvent;
203
209
newEventHandler.fcb = NULL ;
204
210
newEventHandler.scb = NULL ;
205
211
newEventHandler.event = event;
206
212
cbEventList.push_back (newEventHandler);
213
+ return newEventHandler.id ;
207
214
}
208
215
209
- void WiFiGenericClass::onEvent (WiFiEventFullCb cbEvent, system_event_id_t event)
216
+ wifi_event_id_t WiFiGenericClass::onEvent (WiFiEventFuncCb cbEvent, system_event_id_t event)
210
217
{
211
218
if (!cbEvent) {
212
- return ;
219
+ return 0 ;
213
220
}
214
221
WiFiEventCbList_t newEventHandler;
215
222
newEventHandler.cb = NULL ;
216
223
newEventHandler.fcb = cbEvent;
217
224
newEventHandler.scb = NULL ;
218
225
newEventHandler.event = event;
219
226
cbEventList.push_back (newEventHandler);
227
+ return newEventHandler.id ;
220
228
}
221
229
222
- void WiFiGenericClass::onEvent (WiFiEventSysCb cbEvent, system_event_id_t event)
230
+ wifi_event_id_t WiFiGenericClass::onEvent (WiFiEventSysCb cbEvent, system_event_id_t event)
223
231
{
224
232
if (!cbEvent) {
225
- return ;
233
+ return 0 ;
226
234
}
227
235
WiFiEventCbList_t newEventHandler;
228
236
newEventHandler.cb = NULL ;
229
237
newEventHandler.fcb = NULL ;
230
238
newEventHandler.scb = cbEvent;
231
239
newEventHandler.event = event;
232
240
cbEventList.push_back (newEventHandler);
241
+ return newEventHandler.id ;
233
242
}
234
243
235
244
/* *
@@ -251,29 +260,25 @@ void WiFiGenericClass::removeEvent(WiFiEventCb cbEvent, system_event_id_t event)
251
260
}
252
261
}
253
262
254
- void WiFiGenericClass::removeEvent (WiFiEventFullCb cbEvent, system_event_id_t event)
263
+ void WiFiGenericClass::removeEvent (WiFiEventSysCb cbEvent, system_event_id_t event)
255
264
{
256
265
if (!cbEvent) {
257
266
return ;
258
267
}
259
268
260
269
for (uint32_t i = 0 ; i < cbEventList.size (); i++) {
261
270
WiFiEventCbList_t entry = cbEventList[i];
262
- if (entry.fcb == cbEvent && entry.event == event) {
271
+ if (entry.scb == cbEvent && entry.event == event) {
263
272
cbEventList.erase (cbEventList.begin () + i);
264
273
}
265
274
}
266
275
}
267
276
268
- void WiFiGenericClass::removeEvent (WiFiEventSysCb cbEvent, system_event_id_t event )
277
+ void WiFiGenericClass::removeEvent (wifi_event_id_t id )
269
278
{
270
- if (!cbEvent) {
271
- return ;
272
- }
273
-
274
279
for (uint32_t i = 0 ; i < cbEventList.size (); i++) {
275
280
WiFiEventCbList_t entry = cbEventList[i];
276
- if (entry.scb == cbEvent && entry. event == event ) {
281
+ if (entry.id == id ) {
277
282
cbEventList.erase (cbEventList.begin () + i);
278
283
}
279
284
}
@@ -329,9 +334,9 @@ esp_err_t WiFiGenericClass::_eventCallback(void *arg, system_event_t *event)
329
334
WiFiEventCbList_t entry = cbEventList[i];
330
335
if (entry.cb || entry.fcb || entry.scb ) {
331
336
if (entry.event == (system_event_id_t ) event->event_id || entry.event == SYSTEM_EVENT_MAX) {
332
- if (entry.cb ){
337
+ if (entry.cb ) {
333
338
entry.cb ((system_event_id_t ) event->event_id );
334
- } else if (entry.fcb ){
339
+ } else if (entry.fcb ) {
335
340
entry.fcb ((system_event_id_t ) event->event_id , (system_event_info_t ) event->event_info );
336
341
} else {
337
342
entry.scb (event);
0 commit comments