Can not figure out esp_event_base , and event_id are known in default event loop example

noweare
Posts: 74
Joined: Tue Jul 02, 2019 11:35 am

Can not figure out esp_event_base , and event_id are known in default event loop example

Postby noweare » Fri Nov 19, 2021 4:32 pm

Hello,

I am going through the example default_event_loop example from the examples directory
and I don't understand how esp_event_base and event_id variables are chosen in the example.

I would think that there was a list of each variable for each esp32 component, but I can
not find one.

I guess I am trying to figure out what links actual events to these variables ?

These variables are used in both registering a callback and the handler itself.

For example, to register an instance of a handler function this function is used

Code: Select all


esp_err_t esp_event_handler_instance_register(esp_event_base_t event_base,
                                              int32_t event_id,
                                              esp_event_handler_t event_handler,
                                              void *event_handler_arg,
                                              esp_event_handler_instance_t *context)




noweare
Posts: 74
Joined: Tue Jul 02, 2019 11:35 am

Re: Can not figure out esp_event_base , and event_id are known in default event loop example

Postby noweare » Sat Nov 20, 2021 12:53 am

So I am understanding the event loop stuff a little better.
I was pretty confused about it and not out of the woods yet.

For event_base and event_id I was looking for documented events like the uart has i.e. UART_DATA, UART_BREAK etc...
but after spending time on the default event loop and user event loop examples the event_base and event_id are user defined.

Thanks for gathering the documentation. I had read them but it just didn't sink in.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Can not figure out esp_event_base , and event_id are known in default event loop example

Postby chegewara » Sat Nov 20, 2021 11:52 am

It is not easy, but its what for you have docs and IDEs with different tools.
For example i am using VS code, which has search across all files tool. When i searched ESP_EVENT_DECLARE_BASE there was some amount results, then i had to remove docs and example files and finally i found 13 declarations of different base_id.
noweare wrote: For event_base and event_id I was looking for documented events like the uart has i.e. UART_DATA, UART_BREAK etc...
but after spending time on the default event loop and user event loop examples the event_base and event_id are user defined.
This is another case, because not all events belongs to event loops. UART is not handling events with with event loop, but its using Queue.
https://github.com/espressif/esp-idf/bl ... main.c#L46

And again, you can find all events used by UART in docs:
https://docs.espressif.com/projects/esp ... ent_type_t


This is simple snippet code you can use to learn base_id for all events handled in your app (any app):

Code: Select all

static void evt_handler(void* arg, esp_event_base_t event_base,
                                    int32_t event_id, void* event_data)
{
    ESP_LOGW("", "ANY base: %s, event: %d\n", event_base, event_id);
}


void app_main()
{
...
// remember to create default event loop before this line
// esp_event_loop_create_default()
    esp_event_handler_instance_t instance_any_id;
    esp_event_handler_instance_register(ESP_EVENT_ANY_BASE, ESP_EVENT_ANY_ID, evt_handler, NULL, &instance_any_id);
...
}

noweare
Posts: 74
Joined: Tue Jul 02, 2019 11:35 am

Re: Can not figure out esp_event_base , and event_id are known in default event loop example

Postby noweare » Sat Nov 20, 2021 9:06 pm

Yeah, not easy but the documentation is very good. Just a lot of it. The examples are really good too.

The event loop library gives us the freedom of making up our own events and what we name them.

The idf has components with built-in events like the uart so I thought the library was for built-in system events.
The example got me thinking correctly about it, though. That's not to mean I know when best to use the event loop library in my application. Hopefully that will be more clear the longer i spend learning this system.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 111 guests