How to set different event_cb for each button in a button matrix?

Important: posts that do not use this template will be ignored or closed.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the relevant part of the documentation. We will not respond in detail to posts where you haven’t read the relevant documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

how to set different event_cb for each button in a button matrix?

What MCU/Processor/Board and compiler are you using?

What do you want to achieve?

For example, I create a button matrix, and create 2 buttons. If I clicked the first button, it calls event_cb_function1, and if I clicked the second button, it calls event_cb_function2, how can I make it come true?

What have you tried so far?

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

It can’t set differenct event_cb for each button of a button matrix,
however you can check which button of the button matrix is clicked, by

the button matrix’s event LV_EVENT_VALUE_CHANGED is received
in the button matrix’s event_cb, and check which button is clicked by

void btnm_event_cb(lv_obj_t *btnm, lv_event_t event){
    if( event != LV_EVENT_VALUE_CHANGED) return;
    const char* button_name = lv_btnm_get_active_btn_text(btnm);
    // .... your code ...
}
2 Likes

thanks, i will try it.