开关机动画

如何自定义开关机动画

资源路径

开关机动画的gif放在工程/resource/images/power_on目录对应分辨率下:

open

开关机动画open接口,用于启动播放动画。

/**
    This function starts playing the startup animation.
    Note:
    When calling this function, it must be in the task of lv_task (or lv_timer) and must be blocked by power_on_anim_close,
    as this function starts a high priority thread and plays animations every 30ms (adjustable).
    The function that plays animations directly calls the refresh function.
    If not blocked, the refresh function will experience reentry, leading to unpredictable consequences.
 */
int power_on_anim_open(power_on_anim_type_t anim_type, uint32_t play_time)

anim_type,动画类型:

/**
 * @brief  The type of Power on and Power off animation.
 */
typedef enum
{
    LOW_VOLT_CHARGING_ANIM,     /**< charging animation icon of low voltage                         */
    LOW_VOLT_NOTIFY_ANIM,       /**< notification(event) animation icon when low voltage satified   */
    POWER_ON_ANIM,              /**< power on animation when power on                               */
    POWER_OFF_ANIM,             /**< power off animation when power off                             */
} power_on_anim_type_t;

play_time,播放时长,如果为0,则表示gif的默认时长。

close

开关机动画close接口,用于动画播放结束释放资源,open_lcd,是否打开lcd。

/**
    Block the current lv_task (or lv_timer) task and wait for the animation to finish playing.
 */
int power_on_anim_close(bool open_lcd)

资源代码路径

static const anim_gif_t anim_gif[] =
{
    (lv_img_dsc_t *) APP_GET_GIF_FROM_APP(switch_anim, gif_charging),
    (lv_img_dsc_t *) APP_GET_GIF_FROM_APP(switch_anim, gif_charge_flash),
    (lv_img_dsc_t *) APP_GET_GIF(gif_power_on),
    (lv_img_dsc_t *) APP_GET_GIF(gif_power_off),
};

替换动画

修改/resource/images/power_on下的资源进行替换。

更换资源路径的gif,保持gif名称不变即可。

通过app_pm_anim_set_resource接口进行资源替换

  1. 如以下代码修改开机动画为welcome.jpg,播放时长300ms,播放30ms,资源来自于动态应用:

static anim_img_t pm_anim_fn[] =
{
    {APP_GET_JPG(welcome), 300, 0, 1},
};

app_pm_anim_set_resource((anim_img_t *)pm_anim_fn, sizeof(pm_anim_fn) / sizeof(anim_img_t));
  1. 可以通过在pm_anim_fn定义4个结构来改变4个类型的动画;

  2. 调用app_pm_anim_set_resource需要在gui_thread_entry运行以前。

    • 动态应用:可以用过DLMODULE_INIT_DEF来实现;

static void xxx_init(void)
{
    app_pm_anim_set_resource((anim_img_t *)pm_anim_fn, sizeof(pm_anim_fn) / sizeof(anim_img_t));
    epbub_decoder_img_init();
    LOG_I("%s", __func__);
}

/* It must be initialized before the gui_thread_entry runs. */
#ifdef BSP_USING_PC_SIMULATOR
    INIT_PRE_APP_EXPORT(xxx_init);
#else
    DLMODULE_INIT_DEF(xxx_init);
#endif
   - 其他:则可以通过INIT_PRE_APP_EXPORT来实现。
static void reader_init(void)
{
    app_pm_anim_set_resource((anim_img_t *)pm_anim_fn, sizeof(pm_anim_fn) / sizeof(anim_img_t));
    epbub_decoder_img_init();
    LOG_I("%s", __func__);
}

/* It must be initialized before the gui_thread_entry runs. */
INIT_PRE_APP_EXPORT(reader_init);

注意事项

power_on_anim_type_t值的顺序需要和anim_gif数组的顺序匹配!

动画播放完成如何跳转默认应用

开机动画默认跳转的Main app,开机分为reset开机和正常重启开机,reset会先走开机向导应用,开机向导应用完成后才会跳转默认应用,如下: 正常开机代码如下 改变跳转默认app,只需要将上面截图的gui_app_run(“Main”) 改成gui_app_run需要跳转的app即可。