Animation - custom start point

What do you want to achieve?

Set start point and start animation from my code

What have you tried so far?

I tried to find answers in this forum and in LVGL documentation

Screenshot or video

Pacanim

Others

  • SquareLine Studio version:
    1.5.0
  • Operating system:
    Win 10 x64
  • Target hardware:
    ESP32-S3

Hello, I have this animation and I would like to pass start value for the animation from my code, but I did not find way how to do it.

I did find similar issues for animation is SLS, but even I did find similar topic and solution frrom @Marian_M , I did not figure out how to bend it to my use case.

Is there way how can I simply pass start point to the animation via

(Set start and end values. E.g. 0, 150)
lv_anim_set_values(&a, start, end);

function in my code?

Many thanks for any help.

You self reply, create and test animation in SQ and after all is ready CTRL X into your code…

Thanks, @Marian_M for your reply.

I tried your suggestion and I copied the animation definition and code from ui.c file :

void PacmanRotation_Animation(lv_obj_t * TargetObject, int delay);
lv_obj_t * ui_ImgPacman;

and

void PacmanRotation_Animation(lv_obj_t * TargetObject, int delay)
{
    ui_anim_user_data_t * PropertyAnimation_0_user_data = lv_malloc(sizeof(ui_anim_user_data_t));
    PropertyAnimation_0_user_data->target = TargetObject;
    PropertyAnimation_0_user_data->val = -1;
    lv_anim_t PropertyAnimation_0;
    lv_anim_init(&PropertyAnimation_0);
    lv_anim_set_time(&PropertyAnimation_0, 30000);
    lv_anim_set_user_data(&PropertyAnimation_0, PropertyAnimation_0_user_data);
    lv_anim_set_custom_exec_cb(&PropertyAnimation_0, _ui_anim_callback_set_image_angle);
    lv_anim_set_values(&PropertyAnimation_0, 0, 3600);
    lv_anim_set_path_cb(&PropertyAnimation_0, lv_anim_path_linear);
    lv_anim_set_delay(&PropertyAnimation_0, delay + 0);
    lv_anim_set_deleted_cb(&PropertyAnimation_0, _ui_anim_callback_free_user_data);
    lv_anim_set_playback_time(&PropertyAnimation_0, 0);
    lv_anim_set_playback_delay(&PropertyAnimation_0, 0);
    lv_anim_set_repeat_count(&PropertyAnimation_0, LV_ANIM_REPEAT_INFINITE);
    lv_anim_set_repeat_delay(&PropertyAnimation_0, 0);
    lv_anim_set_early_apply(&PropertyAnimation_0, false);
    lv_anim_set_get_value_cb(&PropertyAnimation_0, &_ui_anim_callback_get_image_angle);
    lv_anim_start(&PropertyAnimation_0);
}

with this function call before end of the setup() function

PacmanRotation_Animation(ui_ImgPacman, 0);

but I get the following error:

I also tried to add extern to the ui.h file

extern void PacmanRotation_Animation(lv_obj_t * TargetObject, int delay);

but with this, I get this error:

Is it possible to fix my issue?

Many thanks for any help!

Your compiler takes this as error with its current setting, simply need to make this a warning, or even better: cast the malloc result to the target-type explicitly. like ui_anim_user_data_t * PropertyAnimation_0_user_data = (ui_anim_user_data_t*) lv_malloc( sizeof(ui_anim_user_data_t) );

1 Like

Primary good point is compile in C context as anim was in ui.c. You can do this in ino or cpp , but require extern “C” , not very readable. I create my own c file for lvgl parts (too i dont use ino …)
Secondary good point is rewrite anim func without user data and malloc. Squareline use it only for universality of callbacks.

int32_t your_anim_callback_get_image_angle(lv_anim_t * a)
{
    return lv_img_get_angle(ui_Pacmanimage);
}
void your_anim_callback_set_image_angle(lv_anim_t * a, int32_t v)
{
    lv_img_set_angle(ui_Pacmanimage, v);
}

void PacmanRotation_Animation(int delay)
{
    lv_anim_t PropertyAnimation_0;
    lv_anim_init(&PropertyAnimation_0);
    lv_anim_set_time(&PropertyAnimation_0, 30000);
    lv_anim_set_custom_exec_cb(&PropertyAnimation_0, your_anim_callback_set_image_angle);
    lv_anim_set_values(&PropertyAnimation_0, 0, 3600);
    lv_anim_set_path_cb(&PropertyAnimation_0, lv_anim_path_linear);
    lv_anim_set_delay(&PropertyAnimation_0, delay + 0);
    lv_anim_set_playback_time(&PropertyAnimation_0, 0);
    lv_anim_set_playback_delay(&PropertyAnimation_0, 0);
    lv_anim_set_repeat_count(&PropertyAnimation_0, LV_ANIM_REPEAT_INFINITE);
    lv_anim_set_repeat_delay(&PropertyAnimation_0, 0);
    lv_anim_set_early_apply(&PropertyAnimation_0, false);
    lv_anim_set_get_value_cb(&PropertyAnimation_0, &your_anim_callback_get_image_angle);
    lv_anim_start(&PropertyAnimation_0);
}

and here parameter is delay , but you can change to what you need. Warning anim is set as INFINITE then changing , stoping or other after call is ugly. Better is use normal anim.