diff --git a/src/lv_api_map.h b/src/lv_api_map.h index 12a77a906..d5406b240 100644 --- a/src/lv_api_map.h +++ b/src/lv_api_map.h @@ -31,6 +31,11 @@ extern "C" { * V6.0 COMPATIBILITY *--------------------*/ +static inline void lv_task_once(lv_task_t *task) +{ + lv_task_set_repeat_count(task, 1); +} + #if LV_USE_CHART #define lv_chart_get_point_cnt lv_chart_get_point_count diff --git a/src/lv_misc/lv_async.c b/src/lv_misc/lv_async.c index 4d6e7b095..4336ff09a 100644 --- a/src/lv_misc/lv_async.c +++ b/src/lv_misc/lv_async.c @@ -57,7 +57,7 @@ lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data) /* Set the task's user data */ task->user_data = info; - lv_task_once(task); + lv_task_set_repeat_count(task, 1); return LV_RES_OK; } diff --git a/src/lv_misc/lv_task.c b/src/lv_misc/lv_task.c index 8e97ede22..3cdccd0db 100644 --- a/src/lv_misc/lv_task.c +++ b/src/lv_misc/lv_task.c @@ -236,7 +236,7 @@ lv_task_t * lv_task_create_basic(void) new_task->task_cb = NULL; new_task->prio = DEF_PRIO; - new_task->once = 0; + new_task->repeat_count = -1; new_task->last_run = lv_tick_get(); new_task->user_data = NULL; @@ -341,12 +341,13 @@ void lv_task_ready(lv_task_t * task) } /** - * Delete the lv_task after one call + * Set the number of times a task will repeat. * @param task pointer to a lv_task. + * @param repeat_count -1 : infinity; 0 : stop ; n>0: residual times */ -void lv_task_once(lv_task_t * task) +void lv_task_set_repeat_count(lv_task_t * task, int32_t repeat_count) { - task->once = 1; + task->repeat_count = repeat_count; } /** @@ -398,9 +399,12 @@ static bool lv_task_exec(lv_task_t * task) /*Delete if it was a one shot lv_task*/ if(task_deleted == false) { /*The task might be deleted by itself as well*/ - if(task->once != 0) { - lv_task_del(task); + if(task->repeat_count > 0) { + task->repeat_count--; } + if(task->repeat_count == 0) { + lv_task_del(task); + } } exec = true; } diff --git a/src/lv_misc/lv_task.h b/src/lv_misc/lv_task.h index ab7ba3b71..f7184ed58 100644 --- a/src/lv_misc/lv_task.h +++ b/src/lv_misc/lv_task.h @@ -64,8 +64,8 @@ typedef struct _lv_task_t { void * user_data; /**< Custom user data */ + int32_t repeat_count; /**< 1: Task times; -1 : infinity; 0 : stop ; n>0: residual times */ uint8_t prio : 3; /**< Task priority */ - uint8_t once : 1; /**< 1: one shot task */ } lv_task_t; /********************** @@ -140,10 +140,11 @@ void lv_task_set_period(lv_task_t * task, uint32_t period); void lv_task_ready(lv_task_t * task); /** - * Delete the lv_task after one call + * Set the number of times a task will repeat. * @param task pointer to a lv_task. + * @param repeat_count -1 : infinity; 0 : stop ; n>0: residual times */ -void lv_task_once(lv_task_t * task); +void lv_task_set_repeat_count(lv_task_t * task, int32_t repeat_count); /** * Reset a lv_task.