Hello everyone. I am doing my first steps with LVGL and, even if documentation is well written, I have some problems to reach my trivial target: switch among views of a tabview simply using an hardware button.
I have two sections of code, one referring to the external button and one to the tabview:
I can correctly see tabview on my screen (obviously only the first view) and detect the my button state using the button_read callback. Simply I don’t understand how to link these two sections.
Moreover there is no call to btn_event_cb callback (cannot see “pressed” string) when I press my external button.
Could you give me any suggestion, maybe using a simple snippet of code?
Finally, i would prefer to use the “feeback_cb” instead of my read_cb in order to don’t stress CPU but, again, cannot find any example.
Thank you for your time
You might want to change your input device to KEYPAD or ENCODER (Depending on your use case) instead of BUTTON. BUTTON requires you to specify the x and y points to where you want to click, which may not be ideal for what you want to achieve.
indev_drv.type = LV_INDEV_TYPE_KEYPAD;
You need to create a group and set it with your input device.
group = lv_group_create();
lv_indev_set_group(indev, group);
Add the tabview obj to your group
lv_group_add_obj(group, tabview);
You need to return a key state to lv_indev_data_t *data. For tabview navigation, it’s LEFT/RIGHT keys to select tabs and ENTER to click.
Thank you for your reply @nwb. I could consider keypad/encoder for navigation. Let’s consider that I need to move just in one direction (view1 -> view2 -> view3 -> view1 ->…) . Don’t you think button as input device is enough? Even if it requires a specific point (x,y), it can be whatever you want on the screen and it will be always the same.
I solved the problem I had on btn_event_cb. Now this is my code:
Not sure what is your exact full use case but if its purely just to click an UI button to navigate through the tabs, it should suffice.
Based on my understanding, wouldn’t you need to read the input device data to trigger an action? Not confident on this, but I dont think your intent is possible.
The total flow if both read_cb and feedback_cb is implemented.
LVGL constantly polls for input device data -> HW Physically pressed -> read_cb triggers, input device state changes to PRESSED -> UI Button state changes to PRESSED -> input driv feedback_cb triggered.
As written in the official documentation, feedback_cb should be an alternative to read_cb and feedback_cb should be “event driven” instead of using polling. Maybe I completely misunderstood its use.
feedback_cb is not intended to be used as a replacement to read_cb.
feedback_cb is a mechanism for LVGL to provide data to the input device, so it can find out about events it is sending to objects. It cannot be used to read data from the input device.
The intended use case is to provide the user with feedback when a touch, etc. occurs, such as an audible click.