mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
Suspend the animation task if there are no running animations
This commit is contained in:
parent
4cb5ab4a03
commit
5cbff436b4
@ -26,6 +26,7 @@
|
||||
*********************/
|
||||
#define LV_ANIM_RESOLUTION 1024
|
||||
#define LV_ANIM_RES_SHIFT 10
|
||||
#define LV_ANIM_TASK_PRIO LV_TASK_PRIO_MID
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
@ -35,6 +36,7 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void anim_task(lv_task_t * param);
|
||||
static void anim_mark_list_change(void);
|
||||
static bool anim_ready_handler(lv_anim_t * a);
|
||||
|
||||
/**********************
|
||||
@ -42,6 +44,7 @@ static bool anim_ready_handler(lv_anim_t * a);
|
||||
**********************/
|
||||
static uint32_t last_task_run;
|
||||
static bool anim_list_changed;
|
||||
static lv_task_t * _lv_anim_task;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@ -58,7 +61,9 @@ void lv_anim_core_init(void)
|
||||
{
|
||||
lv_ll_init(&LV_GC_ROOT(_lv_anim_ll), sizeof(lv_anim_t));
|
||||
last_task_run = lv_tick_get();
|
||||
lv_task_create(anim_task, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, NULL);
|
||||
_lv_anim_task = lv_task_create(anim_task, LV_DISP_DEF_REFR_PERIOD, LV_ANIM_TASK_PRIO, NULL);
|
||||
anim_mark_list_change(); /*Turn off the animation task*/
|
||||
anim_list_changed = false; /*The list has not actaully changed*/
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,7 +107,7 @@ void lv_anim_create(lv_anim_t * a)
|
||||
|
||||
/* Creating an animation changed the linked list.
|
||||
* It's important if it happens in a ready callback. (see `anim_task`)*/
|
||||
anim_list_changed = true;
|
||||
anim_mark_list_change();
|
||||
|
||||
LV_LOG_TRACE("animation created")
|
||||
}
|
||||
@ -127,7 +132,7 @@ bool lv_anim_del(void * var, lv_anim_exec_xcb_t exec_cb)
|
||||
if(a->var == var && (a->exec_cb == exec_cb || exec_cb == NULL)) {
|
||||
lv_ll_remove(&LV_GC_ROOT(_lv_anim_ll), a);
|
||||
lv_mem_free(a);
|
||||
anim_list_changed = true; /*Read by `anim_task`. It need to know if a delete occurred in
|
||||
anim_mark_list_change(); /*Read by `anim_task`. It need to know if a delete occurred in
|
||||
the linked list*/
|
||||
del = true;
|
||||
}
|
||||
@ -446,7 +451,8 @@ static bool anim_ready_handler(lv_anim_t * a)
|
||||
memcpy(&a_tmp, a, sizeof(lv_anim_t));
|
||||
lv_ll_remove(&LV_GC_ROOT(_lv_anim_ll), a);
|
||||
lv_mem_free(a);
|
||||
anim_list_changed = true;
|
||||
/*Flag that the list has changed */
|
||||
anim_mark_list_change();
|
||||
|
||||
/* Call the callback function at the end*/
|
||||
if(a_tmp.ready_cb != NULL) a_tmp.ready_cb(&a_tmp);
|
||||
@ -471,4 +477,12 @@ static bool anim_ready_handler(lv_anim_t * a)
|
||||
|
||||
return anim_list_changed;
|
||||
}
|
||||
static void anim_mark_list_change(void)
|
||||
{
|
||||
anim_list_changed = true;
|
||||
if(lv_ll_get_head(&LV_GC_ROOT(_lv_anim_ll)) == NULL)
|
||||
lv_task_set_prio(_lv_anim_task, LV_TASK_PRIO_OFF);
|
||||
else
|
||||
lv_task_set_prio(_lv_anim_task, LV_ANIM_TASK_PRIO);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user