LVGL Task handling

It would be nice if lvgl can “help” keep track of lvgl_tasks. Im sure there are ways but I’m not as familiar.

For example for someone to use an ongoing lvgl task to update a image/value on their active screen , they must:

  1. Initialize “lv_task_t * task” , then create it, create a call back (this makes sense)
  2. But say you must transition to another screen, in a coder’s perspective you would call this "lv_task_t pointer* to delete before moving to another screen which could cause a crash if not handled.

This can get more complex if you have 3-4 tasks doing independent things on a screen and say you have a variety of screens on the embedded application.

It might be cool similar to how LVGL animation widgets can check if there are any running animations " uint16_tlv_anim_count_running(void)" if lvgl tasks functions could do the same. A coder could add this as a case edge before moving onto the next screen, if so they would have some logic to remove which ever corresponding task is running based on what their outcome is.

Unless there is generally a preferred way to track tasks lvgl specifies I’m open to ideas! Thanks (:

Well I cannot imagine that it would be too difficult to figure out what is running or not You need to maintain an array of references to the tasks is how you would know if they are running or not. I use the term “running” very loosely. A “running” animation is not necessarily running. It’s actually waiting until it’s timer expires for the code to run again. LVGL is not thread safe so when you call lv_task_handler is when code gets executed for either a task, timer, animation or update of the display.

as an example. If you set a timer so that it it is supposed to call the callback every 20 milliseconds but you call lv_tack_handler every 500 seconds guess what?. That timer is not going to call the callback every 20 milliseconds.

That is why i use the term “running” very loosely.

when you create a task a reference to the object is returned. store that reference in an array. when the task ends then remove the reference from the array. Checking the array is how you will know what is running. Set up a structure that holds a reference to a screen and a reference to an array of tasks. when you want to change screens iterate over the tasks and delete them from both the array and also LVGL. then change the screens. That is probably the easiest solution in terms of keeping things organized.

1 Like