How to disable Tasks in determinated screen

Description

Hi, I’m developing an application with 2 screens, and about 5 lv_tasks on each screen. How can I pause/disable these tasks on screen that isn’t showing?

What MCU/Processor/Board and compiler are you using?

Stm32F4 with HAL and Keil

What LVGL version are you using?

lvgl V7

What do you want to achieve?

Pause/disable tasks on determinate screen

Thanks

Hi @Marcelocm1995,

For version 7 take a look at the docs here.

When you create the tasks be sure to save the pointer returned by the task_create() function in a static or global variable so you can gain access to the task later.

Use the void lv_task_set_prio(lv_task_t *task, lv_task_prio_t prio) function to set a value of LV_TASK_PRIO_OFF to suspend the tasks and when you want to restart the tasks set the original priority again.

Example code:

static lv_task_t *task1_ptr;
static lv_task_t *task2_ptr;

void create_tasks( void ) {

    task1_ptr = lv_task_t*lv_task_create( task1_cb, 100, LV_TASK_PRIO_MID, NULL);
    task2_ptr = lv_task_t*lv_task_create( task2_cb, 200, LV_TASK_PRIO_LOW, NULL);
}

void suspend_tasks( void ) {

    lv_task_set_prio( task1_ptr, LV_TASK_PRIO_OFF) ;
    lv_task_set_prio( task2_ptr, LV_TASK_PRIO_OFF) ;
}

void restart_tasks( void ) {

    lv_task_set_prio( task1_ptr, LV_TASK_PRIO_MID) ;
    lv_task_set_prio( task2_ptr, LV_TASK_PRIO_LOW) ;

}

Hope that helps.

Kind Regards,

Pete