开关机动画¶
Solution支持通过资源替换或接口配置两种方式自定义开关机动画,涵盖开机、关机、低电压、充电等多场景动画,适配不同分辨率与应用需求。
1. 自定义开关机动画¶
1.1 资源路径规范¶
开关机动画资源需按分辨率分类存放,默认路径为:resource/images/power_on/[目标分辨率目录]/
例如 410x494 分辨率的开机动画需放入 power_on/410x494/ 目录下。

1.2 支持资源类型¶
开关机动画资源可以支持如下几种类型:
单独一张图片,如png或jpg
png的序列帧,遵循序列帧规则
gif
1.3 接口说明¶
1.3.1 启动动画接口(power_on_anim_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)
动画类型枚举定义
/**
* @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的默认时长。
1.3.2 结束动画接口(power_on_anim_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)
1.4 资源与代码关联¶
动画资源通过anim_gif数组与类型枚举关联,枚举值顺序需与数组元素顺序严格一致。
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),
};
2. 动画替换方法¶
支持两种替换方式:直接替换资源文件(简单场景)、通过接口配置资源(灵活场景)。
2.1 直接替换资源文件¶
准备目标 资源,保持文件名与原资源一致(如替换开机动画需命名为gif_power_on.gif);
将资源放入对应分辨率的power_on目录下,覆盖原文件即可;
重新编译工程,动画会自动加载新资源。
2.2 接口配置资源替换¶
通过app_pm_anim_set_resource接口自定义动画资源(支持 JPG 等静态资源循环播放),需在gui_thread_entry运行前初始化。
2.2.1 步骤 1:定义动画资源结构¶
// 示例:将开机动画替换为welcome.jpg,播放300ms
static anim_img_t pm_anim_fn[] =
{
{APP_GET_JPG(welcome), 300, 0, 1}, // 资源句柄、单帧时长、循环次数、外部资源
};
2.2.1 步骤 2:初始化资源配置¶
根据应用类型选择初始化方式,确保在 GUI 线程启动前执行:
2.2.1.1 场景 1:动态应用(外置应用)¶
使用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__);
}
/* 必须在gui_thread_entry运行前初始化 */
#ifdef BSP_USING_PC_SIMULATOR
INIT_PRE_APP_EXPORT(xxx_init);
#else
DLMODULE_INIT_DEF(xxx_init);
#endif
2.2.1.2 场景 2:内置应用 / 系统模块¶
使用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__);
}
/* 必须在gui_thread_entry运行前初始化 */
INIT_PRE_APP_EXPORT(reader_init);
3. 动画播放完成如何跳转默认应用¶
开机动画播放结束后,系统会调用app_get_poweron_app函数获取默认应用,根据开机类型(恢复出厂开机 / 正常重启)的不同,跳转逻辑存在差异,可按需修改目标应用。
3.1 恢复出厂设置重开机¶
流程:开机动画 → 开机向导应用 → 跳转默认应用; 说明:首次开机或恢复出厂设置重开机触发,需完成开机向导(如语言设置、网络配置)后才进入目标应用。
3.2 正常重启开机¶
首先根据
app_get_reg_power_on_app获取开机跳转默认应用;如果不存在,则试图获取"Main"应用
3.3 修改默认跳转应用¶
修改函数
void app_get_poweron_app(void)的开机逻辑通过
app_set_reg_power_on_app设置新的跳转默认应用。参考如何调整开机后默认启动的应用