第 7 章 模式管理接口说明

1、模式管理接口说明

模式管理接口为应用层 app 模式提供切换、查询等操作,保证各个应用情景有序切换及响应。

2、接口介绍

//切换到前一个有效模式void app_task_switch_prev();
//切换到下一个有效模式
void app_task_switch_next();
//返回到之前的模式
int app_task_switch_back();
//切换到指定模式
int app_task_switch_to(u8 app_task);
//获取当前模式 id
u8 app_get_curr_task();
//通过 id 检查是否是当前模式
u8 app_check_curr_task(u8 app);
//模式切换退出检测u8 app_task_exitting();

3、模式切换表

模式配置表,这里可以配置切换模式的顺序,方案根据需求定义,如图7.1所示

../_images/图片15.png

图7.1

4、按键映射

按键驱动检测到按键之后, 会在 notify 按键事件之前对按键进行映射,映射处理如图7.2所示:(根据不同的按键类型进行映射)

../_images/图片24.png

图7.2

5、模式消息收发接口

//app 自定义消息发送接口
int app_task_put_usr_msg(int msg, int arg_num, ...);
//app 消息获取接口(block 参数为 0 表示内部 pend,1 直接返回) void app_task_get_msg(int *msg, int msg_size, int block);
//app 按键消息发送接口
int app_task_put_key_msg(int msg , int value);

应用流程消息发送接 ,消息枚举在 key_event_deal.h 中定义,在各自模式的按键事件中响应(SYS_KEY_EVENT),如图 7.3所示:

key 消息发送

app_task_put_key_msg(KEY_MUSIC_PLAYER_START, 0);

key 消息响应

../_images/图片33.png

图7.3

消息扩展

在没有特殊需求情况下,不建议使用 app_task_put_usr_msg,针对需要传送多参数才使用,消息枚举在app_task.h 中定义如图7.4所示:

../_images/图片43.png

图7.4

自定义消息获取处理,在所在模式中的消息获取中增加 case 进行响应,如图7.5所示:

../_images/图片53.png

图7.5