Limiting feedback_cb on specific type of objects?


I am trying to use indev_drv.feedback_cb to give user audible feedback when a button is touched.
However when I test it it gives feedback where ever I touch on screen regardless of if it is a button or empty space.

How can i limit the feedback if user is touched only on specific type of objects like buttons, images or label etc?


//Give feedback to the user
void feedback_audio(_lv_indev_drv_t *, uint8_t event) {

    if (event == LV_EVENT_PRESSED) {
      Serial.println("LV EVENT PRESSED DETECTED");

    if (event == LV_EVENT_RELEASED) {
      Serial.println("LV EVENT RELEASED DETECTED");

//Initialize the input device driver
  static lv_indev_drv_t indev_drv;
  lv_indev_drv_init(&indev_drv);                                 //Basic initialization
  indev_drv.type = LV_INDEV_TYPE_POINTER;                        //Touch pad is a pointer-like device
  indev_drv.read_cb = touchpad_read;                             //Set your driver function
  indev_drv.feedback_cb = feedback_audio;                           //Set your driver function
  lv_indev_t * disp_indev = lv_indev_drv_register(&indev_drv);   //Register the driver in LVGL and save the created input device object


In the feedback_audio handler you could get the target object with lv_obj_t * obj = lv_event_get_current_target(event); and then check if it’s of a given class with bool lv_obj_check_type(const lv_obj_t * obj, const lv_obj_class_t * class_p).

For buttons it can be something like:

void feedback_audio(_lv_indev_drv_t *, uint8_t event)
lv_obj_t * obj = lv_event_get_current_target(event);

if ((lv_obj_check_type(obj, &lv_button_class)) && (event == LV_EVENT_PRESSED))
    /* Audio feedback when button is pressed */


Give it a try, I don’t have hardware to test it.