Using of LV_EVENT_VALUE_CHANGED with tabview

Hi,
my idea is to use one tab like home screen. If someone change tab to other than home tab, after some timeout without activity, it should automatically go back to home tab.

So, what I need at this point is a callback function that will be called every time actual tab is changed.
I will refresh some return timeout inside this function.

Documentation says:

Besides the Generic events the following Special events are sent by the Slider:
LV_EVENT_VALUE_CHANGED Sent when a new tab is selected by sliding or clicking the tab button

I tried this without luck:

static void tabview_slider_cb(lv_obj_t * slider, lv_event_t event)
{
	if(event != LV_EVENT_VALUE_CHANGED)
        return;
}

void gui_screen_init(void)
{
    tv = lv_tabview_create(lv_scr_act(), NULL);

    t1 = lv_tabview_add_tab(tv, QB_SYMBOL_INFO);
    t2 = lv_tabview_add_tab(tv, QB_SYMBOL_LOCK);
    t3 = lv_tabview_add_tab(tv, QB_SYMBOL_CLOCK);
    t4 = lv_tabview_add_tab(tv, QB_SYMBOL_LIST);

    lv_tabview_set_tab_act(tv, 2, LV_ANIM_ON);

    lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tv);
    lv_obj_set_event_cb(ext->indic, tabview_slider_cb);
}

Function tabview_slider_cb is never called even if click to tabview buttons.
How can I set proper callback for this purpose?

Hi Peter, I’m still new to LVGL, but we needed the same functionality and accomplished it using this command:

lv_tabview_set_tab_act(maintabview, 0, LV_ANIM_OFF);

Thanks

Hi,
I think this function set tab only once. It will not do automatic return after timeout. But I already partially accomplished what I need to do. Documentation page just confuse me before because there was mentioned “slider” object. Correct callback function is configured simply for whole tabview object, not for slider object.

static lv_obj_t * tv;
static lv_obj_t * t1;
static lv_obj_t * t2;
static lv_obj_t * t3;
static lv_obj_t * t4;
static lv_task_t * home_task = NULL;

static void tab1_create(lv_obj_t * parent)
{
}

static void tab2_create(lv_obj_t * parent)
{
}

static void tab3_create(lv_obj_t * parent)
{
}

static void tab4_create(lv_obj_t * parent)
{
}

static void home_task_cb(lv_task_t * task)
{
    lv_tabview_set_tab_act(tv, 2, LV_ANIM_ON);
    lv_task_del(task);
    home_task = NULL;
}

static void tabview_cb(lv_obj_t * obj, lv_event_t event)
{
    if(event != LV_EVENT_VALUE_CHANGED)
        return;

    if(home_task)
        lv_task_reset(home_task);
    else
        home_task = lv_task_create(home_task_cb, 5000, LV_TASK_PRIO_MID, NULL);
}

void gui_screen_init(void)
{
    tv = lv_tabview_create(lv_scr_act(), NULL);

    t1 = lv_tabview_add_tab(tv, "1");
    t2 = lv_tabview_add_tab(tv, "2");
    t3 = lv_tabview_add_tab(tv, "3");
    t4 = lv_tabview_add_tab(tv, "4");

    tab1_create(t1);
    tab2_create(t2);
    tab3_create(t3);
    tab4_create(t4);

    lv_tabview_set_tab_act(tv, 2, LV_ANIM_ON);

    lv_obj_set_event_cb(tv, tabview_cb);
}

But it still isn’t exactly what I expected. I probably have to refresh my 5000ms return timeout every time touchscreen is pressed and not only if tab is changed. I can easily do this outside of LVGL, but it is dirty solution.

Is there a way how to get global touchscreen pressed status for whole screen, not only for one active object?

Hi, according to what you said, you can only monitor the changes of tabs, but not other operations on the screen. If you want to monitor the touch operation of the full screen, I think it is easier to achieve in the hardware layer, such as interrupts.

Exception: I made a change to the ‘lv_ex_tabview_1()’ example in response to your problem. The effect is shown below

lv_obj_set_event_cb(tabview, tabview_val_changed_cb);

 no_operation_monitor_handle = lv_task_create(no_operation_monitor_cb, 100, LV_TASK_PRIO_LOW, NULL);

static void no_operation_monitor_cb(lv_task_t* task)
{
    
    uint16_t act_id = lv_tabview_get_tab_act(tabview);
    if (act_id != 0) 
    {
        time_count++;
        if (time_count >= 20)
        {

            lv_tabview_set_tab_act(tabview, 0, LV_ANIM_ON);
            printf("the ui have no operation in %d ms,have return to main page.\r\n", time_count*100);
            time_count = 0;
        }
    }
}
void tabview_val_changed_cb(lv_obj_t *obj,lv_event_t event)
{
    if (event == LV_EVENT_VALUE_CHANGED)
    {
        time_count = 0;
        printf("tab %d active\r\n", lv_tabview_get_tab_act(obj));
    }
}