How to get the current value of lv_animimg?

Description

I want to get the lv_animimg’s current value.

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

IMXRT1050EVK

What LVGL version are you using?

V8

What have you tried so far?

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/
	lv_animimg_set_src(ui->animimg, (lv_img_dsc_t**) imgs, 30);
	lv_animimg_set_duration(ui->animimg, 1000);
	lv_animimg_set_repeat_count(ui->animimg, 0);
	lv_animimg_start(ui->animimg);

## Screenshot and/or video
If possible, add screenshots and/or videos about the current state.

I want to get the lv_animimg’s current value.

you can see current in lv_anim_t struct.

typedef struct _lv_anim_t {
void * var; /<Variable to animate*/
lv_anim_exec_xcb_t exec_cb; /
< Function to execute to animate*/
lv_anim_start_cb_t start_cb; /< Call it when the animation is starts (considering delay)*/
lv_anim_ready_cb_t ready_cb; /
< Call it when the animation is ready*/
lv_anim_get_value_cb_t get_value_cb; /< Get the current value in relative mode*/
#if LV_USE_USER_DATA
void * user_data; /
< Custom user data*/
#endif
lv_anim_path_cb_t path_cb; /< Describe the path (curve) of animations*/
int32_t start_value; /
< Start value*/
int32_t current_value; /< Current value*/
int32_t end_value; /
< End value*/
int32_t time; /< Animation time in ms*/
int32_t act_time; /
< Current time in animation. Set to negative to make delay./
uint32_t playback_delay; /**< Wait before play back
/
uint32_t playback_time; /< Duration of playback animation*/
uint32_t repeat_delay; /
< Wait before repeat*/
uint16_t repeat_cnt; /< Repeat count for the animation*/
uint8_t early_apply : 1; /
< 1: Apply start value immediately even is there is delay*/

/*Animation system use these - user shouldn't set*/
uint8_t playback_now : 1; /**< Play back is in progress*/
uint8_t run_round : 1;    /**< Indicates the animation has run in this round*/
uint8_t start_cb_called : 1;    /**< Indicates that the `start_cb` was already called*/
uint32_t time_orig;

} lv_anim_t;

The “int32_t current_value” is always 0 while the lv_animimg is running.

Did you use lv_anim_get() ?
For ex,
lv_anim_t * anim_status = lv_anim_get( obj, callback );
then check anim_status->current

Thanks ,
I have no experience to do this . Can you say the details?

For me, It would be like this.
Set and Start an animation.

lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, obj_for_anim);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)callback_for_anim);
lv_anim_set_values(&a, 0, 100);
lv_anim_set_time(&a, 4000);
lv_anim_set_playback_time(&a, 1000);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_start(&a);

When you want to check current value of animation

lv_anim_t *anim_status = lv_anim_get( obj_for_anim, callback_for_anim);
printf("%d\r\n", anim_status->current);

Thanks,
It is lv_animimg , not lv_anim. Same or not?

I have not ever used lv_animimg_xxx(), but in these delay, repeat, etc. functions, it will be set to lv_anim_t. So I think you can use this way to get current.
btw, I am using lvgl ver 7.10.1

OK, i will try. Thanks a lot . If work , i will tell you.

I used the follow functions. The “v” is the current value , but the animation shows error code.

static void anim_useimgs_set_src(void * src,int32_t v)
{
lv_img_set_src(src,imgs + v);
}

void lv_anim_useimgs(lv_obj_t * var,int8_t start,int8_t end)
{
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, var);
lv_anim_set_exec_cb(&a, anim_useimgs_set_src);
lv_anim_set_values(&a, start, end);
if(end >= start)
{
lv_anim_set_time(&a, (end - start) * 33);
}
else
{
lv_anim_set_time(&a, (start - end) * 33);
}
lv_anim_set_repeat_count(&a, 0);
lv_anim_start(&a);
}

I’m not sure if the current of lv_anim_t works in this case.
If your need look like below lv_animimg example
I think you can check current image via pic_count.
Refer lv_animimg_constructor() and index_change() callback in lv_animimg.c

https://docs.lvgl.io/8.2/widgets/extra/animimg.html#example

Thanks ,
Worked!

I changed “imgs + v” to “imgs[v]”.

static void anim_useimgs_set_src(void * src,int32_t v)
{
lv_img_set_src(src,imgs[v]);
}