Images as animation

Hello,
I’m a hobbyist and just found littlevgl thanks for sharing.
I have a nanopi neo2 with a 1.8" ST7735 LCD setup as /dev/fb0
I managed to display some text and image on the lcd using the library.

The library is overkill for what I wanted to do with my nanopi since I have
a tiny screen but it’s working for me. I have a 5 images that I would like
to animate in a loop sort of like an animated gif. If it is possible, how can I do it?
I have converted all 5 images to C array with the online converter.

This code should do what you’re looking for. It uses the task system which calls my_image_looper over and over every second. You can adjust the frequency if you wish.


static int img_index = 0;
static void my_image_looper(void *custom_ptr)
{
    lv_img_set_src(img_obj, <your image>); /* Set the next image */
    img_index++;
    if(img_index == 5)
         img_index = 0;
}
lv_task_create(my_image_looper, 1000, LV_TASK_PRIO_LOWEST, NULL);

Thanks. I’m going to try it, but I’m not clear with
setting the next image. The images are in separate C files.
Do I need to create an array of image descriptor and cycle through it?

What I really want to do is make something like a preloader.
Like when I read a sensor and it takes time, analogous to “hour glass” on pc :).

@mhel Yes. I would make an array of pointers to the images like this:

LV_IMG_DECLARE(img1)
LV_IMG_DECLARE(img2)

lv_img_t * const my_images[] = {
    &img1,
    &img2
};

...

lv_img_set_src(img_obj, my_images[index]);

Thanks again. I will try it.

Edit:
I’ve tried it works for a few seconds then it freezes,
with 100% CPU usage.

I’m using the dev-6.0 of the library, I figured if it’s going to be released soon I might as well use that version.
I couldn’t find the definition of lv_img_t but
I found this lv_img_dsc_t

Hi,How about your project,I have same project which need Images as animation,I edit my code like up,But it works for a few seconds then it freezes, I do not know where is wrong?(I use the dev-5.3 of the library)

Sorry for the delay… the forum doesn’t tell me that you edited your post.

I haven’t gotten a chance to verify my own medicine yet. :wink: Chances are I did something wrong. It seems like both of you have the exact same problem.

I’ll test it as soon as possible.

Thanks,embeddedt,if you have any result,please tell us.

Unfortunately I still haven’t figured out what’s wrong.
I’m still learning.

I tested this variant and it seems to work fine for me. Does this code work for you?

static int img_index = 0;
static lv_obj_t *img_obj;

lv_img_dsc_t * const my_images[] = {
    (lv_img_dsc_t *)LV_SYMBOL_AUDIO,
    (lv_img_dsc_t *)LV_SYMBOL_VIDEO,
    (lv_img_dsc_t *)LV_SYMBOL_UP,
    (lv_img_dsc_t *)LV_SYMBOL_DOWN,
    (lv_img_dsc_t *)LV_SYMBOL_LEFT
};

static void my_image_looper(void *custom_ptr)
{
        printf("looping %d\n", img_index);
    lv_img_set_src(img_obj, my_images[img_index]); /* Set the next image */
    img_index++;
    if(img_index == 5)
         img_index = 0;
}

Obviously you’ll need to create the img_obj elsewhere in your code.

Thanks I’ll get back to you on that.
I’m recompiling the kernel to go back to fbtft, I tried to tinker
with tinydrm but couldn’t get it to work.
It’s going to take a while, I think my nanopi neo2 is faster than my pc :slight_smile:

Maybe @oldersu can try it?

Are you running it on Linux? If so, you could try debugging it to see where it’s hanging while you wait. Up to you. :slight_smile:

Yes I am, my platform is OpenWrt. I’m cross compiling.
I’m just tinkering and hoping to come up with something.

Is this correct?

static void img_looper(lv_task_t *param) {

(void)param;

lv_img_dsc_t const *my_images[] = {
	&img1,
	&img2,
	&img3,
	&img4,
	&img5
};
 
static int img_index = 0;
lv_obj_t * img_loop = lv_img_create(lv_scr_act(), NULL); /*Create an image object*/
lv_obj_set_pos(my_images, 60, 50);     

lv_img_set_src(img_loop, my_images[img_index]); /* Set the next image */

img_index++;
    if(img_index == 5)
     img_index = 0;	
   }

I think I’m doing it wrong.
The parameter for the creation of task seems different from 5.3 to 6.0.
If I use void *ptr for the callback parameter the compiler complains and says
I should be using lv_task_t pointer type. And so I did. Then of-course I don’t know what to do with that :frowning:

It doesn’t really matter for this, but it should be lv_img_dsc_t * const not lv_img_dsc_t const *. There is a difference.

You can just ignore the parameter. It’s not used in my_image_looper.

Does it still crash?

I had gcc catch all warning as error that’s why I moved it :blush:
Thanks for the link, I now know more.

But yes, it still crash. I just downloaded the simulator and will try to get it going and check from there.

Sorry for the delay…My project can work normally,it is myself problem,I malloc some memory for every img,but i forget free them, so after it works some time, it freeze.So you can check your code if these is the same problem.

My project uses littlevgl 5.3,I do not konw if it works normally with 6.0.

I don’t think there shouldn’t be much of a difference between 5.3 and 6.0 in regards to this specific use case.

@mhel Can you show me the full contents of your main function? Maybe I can spot the issue for you faster.

I’ve just tried it in the simulator and it’s the same thing.
It works for a few seconds and it freezes.
I had to do it in the console via make, eclipse is not cooperating with me.

@oldersu I didn’t do any malloc, I just have my images as arrays converted online.