pub unsafe extern "C" fn esp_event_handler_register(
    event_base: esp_event_base_t,
    event_id: i32,
    event_handler: esp_event_handler_t,
    event_handler_arg: *mut c_void
) -> esp_err_t
Expand description

@brief Register an event handler to the system event loop (legacy).

This function can be used to register a handler for either: (1) specific events, (2) all events of a certain event base, or (3) all events known by the system event loop.

  • specific events: specify exact event_base and event_id
  • all events of a certain base: specify exact event_base and use ESP_EVENT_ANY_ID as the event_id
  • all events known by the loop: use ESP_EVENT_ANY_BASE for event_base and ESP_EVENT_ANY_ID as the event_id

Registering multiple handlers to events is possible. Registering a single handler to multiple events is also possible. However, registering the same handler to the same event multiple times would cause the previous registrations to be overwritten.

@param[in] event_base the base ID of the event to register the handler for @param[in] event_id the ID of the event to register the handler for @param[in] event_handler the handler function which gets called when the event is dispatched @param[in] event_handler_arg data, aside from event data, that is passed to the handler when it is called

@note the event loop library does not maintain a copy of event_handler_arg, therefore the user should ensure that event_handler_arg still points to a valid location by the time the handler gets called

@return

  • ESP_OK: Success
  • ESP_ERR_NO_MEM: Cannot allocate memory for the handler
  • ESP_ERR_INVALID_ARG: Invalid combination of event base and event ID
  • Others: Fail