290 lines
8.6 KiB
C
290 lines
8.6 KiB
C
#include "include.h"
|
|
#include "func.h"
|
|
#include "app_variable.h"
|
|
|
|
#if TRACE_EN
|
|
#define TRACE(...) printf(__VA_ARGS__)
|
|
#else
|
|
#define TRACE(...)
|
|
#endif
|
|
|
|
//组件ID
|
|
enum {
|
|
//图像
|
|
COMPO_ID_PIC_VOICE = 1,
|
|
COMPO_ID_BTN_VOICE,
|
|
|
|
COMPO_ID_TEXT,
|
|
};
|
|
|
|
//卡片/按钮id
|
|
enum{
|
|
DIR_FORWARD = 1,
|
|
DIR_BACKWARD = 2,
|
|
};
|
|
|
|
#define VOICE_RESIZE_MIN 68
|
|
#define VOICE_RESIZE_MAX 80
|
|
#define VOICE_RESIZE_STEP 4
|
|
|
|
typedef struct f_voice_t_ {
|
|
u16 resize;
|
|
u16 dir;
|
|
u32 tick;
|
|
u16 num;
|
|
u32 sleep_temp;//用来临时存储系统 熄屏时间
|
|
// s16 icon_deg;
|
|
} f_voice_t;
|
|
|
|
//创建语音助手窗体
|
|
compo_form_t *func_voice_form_create(void)
|
|
{
|
|
//新建窗体
|
|
compo_form_t *frm = compo_form_create(true);
|
|
|
|
//设置标题栏
|
|
compo_form_set_mode(frm, COMPO_FORM_MODE_SHOW_TITLE | COMPO_FORM_MODE_SHOW_TIME);
|
|
compo_form_set_title(frm, i18n[STR_VOICE]);
|
|
|
|
//创建 图片 按钮
|
|
compo_button_t *btn = compo_button_create(frm);
|
|
compo_setid(btn, COMPO_ID_BTN_VOICE);
|
|
compo_button_set_location(btn, GUI_SCREEN_CENTER_X, 161+34, 70, 70);
|
|
|
|
//创建 文本框
|
|
compo_textbox_t *txt = compo_textbox_create(frm, 50);
|
|
compo_setid(txt, COMPO_ID_TEXT);
|
|
compo_textbox_set_location(txt, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y, GUI_SCREEN_WIDTH-40, 50);
|
|
compo_textbox_set_multiline(txt,true);
|
|
compo_textbox_set_autoroll_mode(txt, TEXT_AUTOROLL_MODE_SROLL_CIRC);
|
|
compo_textbox_set(txt, "HI");
|
|
|
|
//创建动画
|
|
compo_picturebox_t *animation = compo_picturebox_create(frm, UI_BUF_VOICE_ASSISTANT_BIN);
|
|
compo_picturebox_set_pos(animation, GUI_SCREEN_CENTER_X, 161+34);
|
|
compo_setid(animation, COMPO_ID_PIC_VOICE);
|
|
// compo_animation_set_rotation(animation, 5);
|
|
// compo_animation_set_rotation_center(animation, GUI_SCREEN_CENTER_X, 213+34);
|
|
|
|
return frm;
|
|
}
|
|
|
|
|
|
//动画滚动
|
|
static void func_voice_animation_roll(void)
|
|
{
|
|
f_voice_t *f_voice = (f_voice_t *)func_cb.f_cb;
|
|
compo_picturebox_t *animation = compo_getobj_byid(COMPO_ID_PIC_VOICE);
|
|
compo_textbox_t *txt = compo_getobj_byid(COMPO_ID_TEXT);
|
|
|
|
if (tick_check_expire(f_voice->tick, 300)){
|
|
f_voice->tick = tick_get();
|
|
|
|
if(f_voice->num != 0)
|
|
{
|
|
f_voice->num ++;
|
|
}
|
|
|
|
if((f_voice->num < 24)&&(f_voice->num != 0)){
|
|
if(f_voice->dir == DIR_FORWARD)
|
|
{
|
|
f_voice->resize += VOICE_RESIZE_STEP;
|
|
if(f_voice->resize >= VOICE_RESIZE_MAX)
|
|
{
|
|
f_voice->resize = VOICE_RESIZE_MAX;
|
|
f_voice->dir = DIR_BACKWARD;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
f_voice->resize -= VOICE_RESIZE_STEP;
|
|
if(f_voice->resize <= VOICE_RESIZE_MIN)
|
|
{
|
|
f_voice->resize = VOICE_RESIZE_MIN;
|
|
f_voice->dir = DIR_FORWARD;
|
|
}
|
|
}
|
|
compo_picturebox_set_size(animation, f_voice->resize, f_voice->resize);
|
|
|
|
if(txt)
|
|
{
|
|
compo_textbox_set(txt, i18n[STR_SIRI_REMIND]);
|
|
}
|
|
}
|
|
else{
|
|
f_voice->num = 0;
|
|
if(txt)
|
|
{
|
|
compo_textbox_set(txt, "HI");
|
|
//如果系统熄屏时间超过上限,说明修改过系统休眠时间,复原
|
|
if(SysVariable.sleep_time > 10000)
|
|
{
|
|
SysVariable.sleep_time = f_voice->sleep_temp;
|
|
SysVariable.guioff_delay = SysVariable.sleep_time;
|
|
SysVariable.sleep_delay = SysVariable.sleep_time;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//语音助手功能事件处理
|
|
static void func_voice_process(void)
|
|
{
|
|
func_voice_animation_roll();
|
|
func_process();
|
|
}
|
|
|
|
//按键事件处理
|
|
static void func_f_voice_click(void)
|
|
{
|
|
f_voice_t *f_voice = (f_voice_t *)func_cb.f_cb;
|
|
compo_picturebox_t *animation = compo_getobj_byid(COMPO_ID_PIC_VOICE);
|
|
|
|
int id = compo_get_button_id();
|
|
switch (id) {
|
|
case COMPO_ID_BTN_VOICE:
|
|
{
|
|
//如果蓝牙已连接且 siri未唤出
|
|
if(bt_is_connected())
|
|
{
|
|
if (bt_get_siri_status() != 1)
|
|
{
|
|
bt_hfp_siri_switch();
|
|
f_voice->dir = DIR_FORWARD;
|
|
f_voice->num = 1;
|
|
//把系统休眠时长放在临时数据后,将系统休眠时间改为无限长
|
|
f_voice->sleep_temp = SysVariable.sleep_time;
|
|
SysVariable.sleep_time = -1;
|
|
SysVariable.sleep_delay = SysVariable.sleep_time;
|
|
SysVariable.guioff_delay = SysVariable.sleep_time;
|
|
}
|
|
else
|
|
{
|
|
f_voice->num = 0;
|
|
compo_picturebox_set_size(animation, VOICE_RESIZE_MIN, VOICE_RESIZE_MIN);
|
|
bt_hfp_siri_switch();
|
|
//如果系统熄屏时间超过上限,说明修改过系统休眠时间,复原
|
|
if(SysVariable.sleep_time > 10000)
|
|
{
|
|
SysVariable.sleep_time = f_voice->sleep_temp;
|
|
SysVariable.guioff_delay = SysVariable.sleep_time;
|
|
SysVariable.sleep_delay = SysVariable.sleep_time;
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
func_popup_new(POPUP_ID_BT_REMIND);
|
|
}
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
//语音助手功能消息处理
|
|
static void func_voice_message(size_msg_t msg)
|
|
{
|
|
f_voice_t *f_voice = (f_voice_t *)func_cb.f_cb;
|
|
compo_picturebox_t *animation = compo_getobj_byid(COMPO_ID_PIC_VOICE);
|
|
|
|
switch (msg) {
|
|
case MSG_CTP_CLICK:
|
|
func_f_voice_click();
|
|
break;
|
|
|
|
case MSG_CTP_SHORT_UP:
|
|
break;
|
|
|
|
case MSG_CTP_SHORT_DOWN:
|
|
break;
|
|
|
|
case MSG_CTP_LONG:
|
|
break;
|
|
|
|
case KU_BACK:
|
|
if (bt_get_siri_status()) {
|
|
f_voice->num = 0;
|
|
compo_picturebox_set_size(animation, VOICE_RESIZE_MIN, VOICE_RESIZE_MIN);
|
|
bt_hfp_siri_switch();
|
|
//如果系统熄屏时间超过上限,说明修改过系统休眠时间,复原
|
|
if(SysVariable.sleep_time > 10000)
|
|
{
|
|
SysVariable.sleep_time = f_voice->sleep_temp;
|
|
SysVariable.guioff_delay = SysVariable.sleep_time;
|
|
SysVariable.sleep_delay = SysVariable.sleep_time;
|
|
}
|
|
} else {
|
|
func_back_to();
|
|
}
|
|
break;
|
|
case MSG_CTP_SHORT_RIGHT:
|
|
if (bt_get_siri_status()) {
|
|
f_voice->num = 0;
|
|
compo_picturebox_set_size(animation, VOICE_RESIZE_MIN, VOICE_RESIZE_MIN);
|
|
bt_hfp_siri_switch();
|
|
//如果系统熄屏时间超过上限,说明修改过系统休眠时间,复原
|
|
if(SysVariable.sleep_time > 10000)
|
|
{
|
|
SysVariable.sleep_time = f_voice->sleep_temp;
|
|
SysVariable.guioff_delay = SysVariable.sleep_time;
|
|
SysVariable.sleep_delay = SysVariable.sleep_time;
|
|
}
|
|
} else {
|
|
func_message(msg);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
func_message(msg);
|
|
break;
|
|
}
|
|
}
|
|
|
|
//进入语音助手功能
|
|
static void func_voice_enter(void)
|
|
{
|
|
func_cb.f_cb = func_zalloc(sizeof(f_voice_t));
|
|
f_voice_t *f_voice = (f_voice_t *)func_cb.f_cb;
|
|
func_cb.frm_main = func_voice_form_create();
|
|
f_voice->resize = 68 ;
|
|
f_voice->num = 0;
|
|
f_voice->sleep_temp = SysVariable.sleep_time;
|
|
}
|
|
|
|
//退出语音助手功能
|
|
static void func_voice_exit(void)
|
|
{
|
|
f_voice_t *f_voice = (f_voice_t *)func_cb.f_cb;
|
|
|
|
/* 关闭语言助手 */
|
|
if (bt_get_siri_status()) {
|
|
bt_hfp_siri_switch();
|
|
}
|
|
|
|
//如果系统熄屏时间超过上限,说明修改过系统休眠时间,复原
|
|
if(SysVariable.sleep_time > 10000)
|
|
{
|
|
SysVariable.sleep_time = f_voice->sleep_temp;
|
|
SysVariable.guioff_delay = SysVariable.sleep_time;
|
|
SysVariable.sleep_delay = SysVariable.sleep_time;
|
|
}
|
|
func_cb.last = FUNC_VOICE;
|
|
}
|
|
|
|
//语音助手功能
|
|
void func_voice(void)
|
|
{
|
|
printf("%s\n", __func__);
|
|
func_voice_enter();
|
|
while (func_cb.sta == FUNC_VOICE) {
|
|
func_voice_process();
|
|
func_voice_message(msg_dequeue());
|
|
}
|
|
func_voice_exit();
|
|
}
|