BigW Consortium Gitlab

Commit fa6eb2fc by Gabor Kiss-Vamosi

lv_anim: delete unused global variable

parent c547d2cf
...@@ -36,7 +36,6 @@ static bool anim_ready_handler(lv_anim_t * a); ...@@ -36,7 +36,6 @@ static bool anim_ready_handler(lv_anim_t * a);
**********************/ **********************/
static lv_ll_t anim_ll; static lv_ll_t anim_ll;
static uint32_t last_task_run; static uint32_t last_task_run;
static bool anim_del_global_flag = false;
/********************** /**********************
* MACROS * MACROS
...@@ -51,9 +50,9 @@ static bool anim_del_global_flag = false; ...@@ -51,9 +50,9 @@ static bool anim_del_global_flag = false;
*/ */
void lv_anim_init(void) void lv_anim_init(void)
{ {
lv_ll_init(&anim_ll, sizeof(lv_anim_t)); lv_ll_init(&anim_ll, sizeof(lv_anim_t));
last_task_run = lv_tick_get(); last_task_run = lv_tick_get();
lv_task_create(anim_task, LV_REFR_PERIOD, LV_TASK_PRIO_MID, NULL); lv_task_create(anim_task, LV_REFR_PERIOD, LV_TASK_PRIO_MID, NULL);
} }
/** /**
...@@ -65,16 +64,16 @@ void lv_anim_create(lv_anim_t * anim_p) ...@@ -65,16 +64,16 @@ void lv_anim_create(lv_anim_t * anim_p)
/* Do not let two animations for the same 'var' with the same 'fp'*/ /* Do not let two animations for the same 'var' with the same 'fp'*/
if(anim_p->fp != NULL) lv_anim_del(anim_p->var, anim_p->fp); /*fp == NULL would delete all animations of var*/ if(anim_p->fp != NULL) lv_anim_del(anim_p->var, anim_p->fp); /*fp == NULL would delete all animations of var*/
/*Add the new animation to the animation linked list*/ /*Add the new animation to the animation linked list*/
lv_anim_t * new_anim = lv_ll_ins_head(&anim_ll); lv_anim_t * new_anim = lv_ll_ins_head(&anim_ll);
lv_mem_assert(new_anim); lv_mem_assert(new_anim);
/*Initialize the animation descriptor*/ /*Initialize the animation descriptor*/
anim_p->playback_now = 0; anim_p->playback_now = 0;
memcpy(new_anim, anim_p, sizeof(lv_anim_t)); memcpy(new_anim, anim_p, sizeof(lv_anim_t));
/*Set the start value*/ /*Set the start value*/
if(new_anim->fp != NULL) new_anim->fp(new_anim->var, new_anim->start); if(new_anim->fp != NULL) new_anim->fp(new_anim->var, new_anim->start);
} }
/** /**
...@@ -86,25 +85,24 @@ void lv_anim_create(lv_anim_t * anim_p) ...@@ -86,25 +85,24 @@ void lv_anim_create(lv_anim_t * anim_p)
*/ */
bool lv_anim_del(void * var, lv_anim_fp_t fp) bool lv_anim_del(void * var, lv_anim_fp_t fp)
{ {
bool del = false; bool del = false;
lv_anim_t * a; lv_anim_t * a;
lv_anim_t * a_next; lv_anim_t * a_next;
a = lv_ll_get_head(&anim_ll); a = lv_ll_get_head(&anim_ll);
while(a != NULL) { while(a != NULL) {
/*'a' might be deleted, so get the next object while 'a' is valid*/ /*'a' might be deleted, so get the next object while 'a' is valid*/
a_next = lv_ll_get_next(&anim_ll, a); a_next = lv_ll_get_next(&anim_ll, a);
if(a->var == var && (a->fp == fp || fp == NULL)) { if(a->var == var && (a->fp == fp || fp == NULL)) {
lv_ll_rem(&anim_ll, a); lv_ll_rem(&anim_ll, a);
lv_mem_free(a); lv_mem_free(a);
del = true; del = true;
anim_del_global_flag = true; }
}
a = a_next;
a = a_next; }
}
return del;
return del;
} }
/** /**
...@@ -116,14 +114,14 @@ bool lv_anim_del(void * var, lv_anim_fp_t fp) ...@@ -116,14 +114,14 @@ bool lv_anim_del(void * var, lv_anim_fp_t fp)
*/ */
uint16_t lv_anim_speed_to_time(uint16_t speed, int32_t start, int32_t end) uint16_t lv_anim_speed_to_time(uint16_t speed, int32_t start, int32_t end)
{ {
int32_t d = LV_MATH_ABS((int32_t) start - end); int32_t d = LV_MATH_ABS((int32_t) start - end);
uint16_t time = (int32_t)((int32_t)(d * 1000) / speed); uint16_t time = (int32_t)((int32_t)(d * 1000) / speed);
if(time == 0) { if(time == 0) {
time++; time++;
} }
return time; return time;
} }
/** /**
...@@ -174,39 +172,39 @@ static void anim_task (void * param) ...@@ -174,39 +172,39 @@ static void anim_task (void * param)
{ {
(void)param; (void)param;
volatile uint32_t elaps; volatile uint32_t elaps;
elaps = lv_tick_elaps(last_task_run); elaps = lv_tick_elaps(last_task_run);
lv_anim_t * a; lv_anim_t * a;
lv_anim_t * a_next; lv_anim_t * a_next;
a = lv_ll_get_head(&anim_ll); a = lv_ll_get_head(&anim_ll);
while(a != NULL) { while(a != NULL) {
/*'a' might be deleted, so get the next object while 'a' is valid*/ /*'a' might be deleted, so get the next object while 'a' is valid*/
a_next = lv_ll_get_next(&anim_ll, a); a_next = lv_ll_get_next(&anim_ll, a);
a->act_time += elaps; a->act_time += elaps;
if(a->act_time >= 0) { if(a->act_time >= 0) {
if(a->act_time > a->time) a->act_time = a->time; if(a->act_time > a->time) a->act_time = a->time;
int32_t new_value; int32_t new_value;
new_value = a->path(a); new_value = a->path(a);
if(a->fp != NULL) a->fp(a->var, new_value); /*Apply the calculated value*/ if(a->fp != NULL) a->fp(a->var, new_value); /*Apply the calculated value*/
/*If the time is elapsed the animation is ready*/ /*If the time is elapsed the animation is ready*/
if(a->act_time >= a->time) { if(a->act_time >= a->time) {
bool invalid; bool invalid;
invalid = anim_ready_handler(a); invalid = anim_ready_handler(a);
if(invalid != false) { if(invalid != false) {
a_next = lv_ll_get_head(&anim_ll); /*a_next might be invalid if animation delete occurred*/ a_next = lv_ll_get_head(&anim_ll); /*a_next might be invalid if animation delete occurred*/
} }
} }
} }
a = a_next; a = a_next;
} }
last_task_run = lv_tick_get(); last_task_run = lv_tick_get();
} }
/** /**
...@@ -217,43 +215,42 @@ static void anim_task (void * param) ...@@ -217,43 +215,42 @@ static void anim_task (void * param)
* */ * */
static bool anim_ready_handler(lv_anim_t * a) static bool anim_ready_handler(lv_anim_t * a)
{ {
bool invalid = false; bool invalid = false;
/*Delete the animation if /*Delete the animation if
* - no repeat and no play back (simple one shot animation) * - no repeat and no play back (simple one shot animation)
* - no repeat, play back is enabled and play back is ready */ * - no repeat, play back is enabled and play back is ready */
if((a->repeat == 0 && a->playback == 0) || if((a->repeat == 0 && a->playback == 0) ||
(a->repeat == 0 && a->playback == 1 && a->playback_now == 1)) { (a->repeat == 0 && a->playback == 1 && a->playback_now == 1)) {
void (*cb) (void *) = a->end_cb; void (*cb) (void *) = a->end_cb;
void * p = a->var; void * p = a->var;
lv_ll_rem(&anim_ll, a); lv_ll_rem(&anim_ll, a);
lv_mem_free(a); lv_mem_free(a);
/*Call the callback function at the end*/ /*Call the callback function at the end*/
/* Check if an animation is deleted in the cb function /* Check if an animation is deleted in the cb function
* if yes then the caller function has to know this*/ * if yes then the caller function has to know this*/
anim_del_global_flag = false; if(cb != NULL) cb(p);
if(cb != NULL) cb(p); invalid = true;
invalid = anim_del_global_flag; }
} /*If the animation is not deleted then restart it*/
/*If the animation is not deleted then restart it*/ else {
else { a->act_time = - a->repeat_pause; /*Restart the animation*/
a->act_time = - a->repeat_pause; /*Restart the animation*/ /*Swap the start and end values in play back mode*/
/*Swap the start and end values in play back mode*/ if(a->playback != 0) {
if(a->playback != 0) { /*If now turning back use the 'playback_pause*/
/*If now turning back use the 'playback_pause*/ if(a->playback_now == 0) a->act_time = - a->playback_pause;
if(a->playback_now == 0) a->act_time = - a->playback_pause;
/*Toggle the play back state*/
/*Toggle the play back state*/ a->playback_now = a->playback_now == 0 ? 1: 0;
a->playback_now = a->playback_now == 0 ? 1: 0; /*Swap the start and end values*/
/*Swap the start and end values*/ int32_t tmp;
int32_t tmp; tmp = a->start;
tmp = a->start; a->start = a->end;
a->start = a->end; a->end = tmp;
a->end = tmp; }
} }
}
return invalid;
return invalid;
} }
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment