Passing in additional parameters to Event Handler functions
Posted: Sun Jun 19, 2022 12:57 am
I am trying to get access to a class member variable to expose whether the class is connected to Wifi or not.
I am currently registering the handler as shown below with the assumption that "this" will get passed into the handler in place of "event_data".
When when this code runs it crashed and causes a LoadProhibited error.
Still quite new to embedded programming so I would really appreciate an explanation as to why this would happen/how to fix it.
I am currently registering the handler as shown below with the assumption that "this" will get passed into the handler in place of "event_data".
- esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, WifiEventHandler, this);
- void WifiModule::WifiEventHandler(void *event_handler_arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
- {
- auto ThisWifiModuleReference = (WifiModule*)(event_data);
- std::cout << ThisWifiModuleReference->m_sSSID << std::endl;
- switch (event_id)
- {
- case WIFI_EVENT_STA_START:
- printf("WiFi connecting ... \n");
- //ThisWifiModuleReference->m_bWifiConnected = false;
- break;
- case WIFI_EVENT_STA_CONNECTED:
- printf("WiFi connected ... \n");
- //ThisWifiModuleReference->m_bWifiConnected = false;
- break;
- case WIFI_EVENT_STA_DISCONNECTED:
- printf("WiFi lost connection ... \n");
- //ThisWifiModuleReference->m_bWifiConnected = false;
- break;
- case IP_EVENT_STA_GOT_IP:
- printf("WiFi got IP ... \n\n");
- //ThisWifiModuleReference->m_bWifiConnected = true;
- break;
- default:
- break;
- }
- }