Refresh screen when needed

Description

Hi, I have two questions described below.

Refresh Screen time

I know the refresh is handled by “_lv_disp_refr_task”
When we register the disp_drv, the fresh task will be created.
LV_DISP_DEF_REFR_PERIOD = 30

disp->refr_task = lv_task_create(_lv_disp_refr_task, LV_DISP_DEF_REFR_PERIOD, LV_REFR_TASK_PRIO, disp);

I assume that “_lv_disp_refr_task” will be called every 30ms and check if there is any update. (I’ve called task_handler every 1ms)
In my observation, the task is triggered only when something needs to be updated. (I print something in the function to check.)
I wonder what stops the task being called in code. (sorry for my poor technique…)

Refresh Screen when needed

I study the above question since I want to refresh the screen manually.
One way to achieve this is to call “lv_task_handler” whenever I want to refresh. (supposed I do not call the function periodically).

Is there a better way to achieve this?

I would greatly appreciate it if you kindly give me some guidance.
Many thanks.

The refresh task is enabled whenever any object area gets invalidated.

It is then disabled again at the start of a refresh. If an invalidation is triggered for whatever reason during a refresh, the task will be re-enabled and runs a second time. Otherwise it is suspended pending another invalidation.

This approach has 2 caveats to be aware of:

  • You also need to call it upon input from the user, otherwise their input will be ignored until the screen refreshes.
  • Animations won’t work properly with this approach (since they are processed when lv_task_handler is called).

Could you explain why you want to only refresh the screen at certain times? Maybe there is a cleaner way to solve your problem.

Hi embeddedt,

Thank you so much for your help.

In my case, I would have many tasks that will draw on the screen.
I want to refresh(update) the screen only when some events happen. (event-triggered)
Currently, I think I don’t need animations.

Do you think that there is a better way for me in this situation?

LVGL already tracks drawn areas and only refreshes the screen if something changes (you can test this by checking when flush_cb is called, you’ll see that it doesn’t get called unless you touch the screen, etc). That means you should be able to call lv_task_handler as many times as you like, and rendering will only happen if one of your events changed an object’s value, for example. Otherwise, it just returns immediately (and occasionally processes input).

I’ve been working on a similar issue which also involved pushing a screen refresh manually and i found that calling lv_refr_now(NULL); was the key to my puzzle…