mcu_ab568x/app/projects/AB5681F_240_32M/functions/func_sos.c
2025-05-30 18:03:10 +08:00

371 lines
13 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "include.h"
#include "func.h"
#include "app_variable.h"
#if TRACE_EN
#define TRACE(...) printf(__VA_ARGS__)
#else
#define TRACE(...)
#endif
#ifdef TJD_GUI_SOS_Show
//组件ID
enum {
COMPO_ID_TXT_BT = 1,
COMPO_ID_LOADING,
COMPO_ID_LOADING_TXT,
COMPO_ID_TXT_BT_NAME,
COMPO_ID_BTN_BT,
COMPO_ID_TXT_TIME,
COMPO_ID_TXT_NO_CONTACT,
COMPO_ID_PIC_NO_CONTACT,
COMPO_ID_TXT_NAME,
COMPO_ID_PIC_CALL,
COMPO_ID_PIC_CHANGE,
};
extern u8 get_call_book_cnt(void);
extern u8 get_sos_book_num(void);
extern void set_book_num(s32 n);
extern char call_name_str[LISTBOX_TEXT_LEN];
extern compo_listbox_custom_item_t tbl_call_txt_list[ADDRESS_BOOK_LIST_CNT];
static bool last_off_status = 0;
typedef struct f_sos_t_
{
compo_form_t *frm;
uint32_t tick;
} f_sos_t;
// 创建SOS窗体创建窗体中不要使用功能结构体 func_cb.f_cb
compo_form_t *func_sos_form_create(void)
{
compo_form_t *frm = compo_form_create(true);
char text_buf[TEXTBOX_TEXT_BUF_LEN] = {0};
/* 加载图标 */
compo_picturebox_t *btn_loading = compo_picturebox_create(frm, UI_BUF_SOS_LOADING_BIN);
compo_setid(btn_loading, COMPO_ID_LOADING);
compo_picturebox_set_pos(btn_loading, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y);
/* SOS加载中文字 */
compo_textbox_t *txt_loading = compo_textbox_create(frm, 150);
compo_textbox_set_location(txt_loading, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y + 69, 180, 30);
compo_setid(txt_loading, COMPO_ID_LOADING_TXT);
compo_textbox_set(txt_loading, i18n[STR_SOS_LOADING]);
//设置标题栏
compo_form_set_title(frm, i18n[STR_SOS]);
compo_form_set_mode(frm, COMPO_FORM_MODE_SHOW_TITLE | COMPO_FORM_MODE_SHOW_TIME);
//BT未连接
compo_textbox_t *txt = compo_textbox_create(frm, 30);
compo_setid(txt, COMPO_ID_TXT_BT);
compo_textbox_set_location(txt, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y - 15, GUI_SCREEN_WIDTH - 40, 30);
compo_textbox_set_autoroll_mode(txt, TEXT_AUTOROLL_MODE_SROLL_CIRC);
compo_textbox_set(txt, i18n[STR_POPUP_PLEASE_PAIR]);
compo_textbox_t *txt_name = compo_textbox_create(frm, 50);
compo_setid(txt_name, COMPO_ID_TXT_BT_NAME);
compo_textbox_set_location(txt_name, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y + 15, GUI_SCREEN_WIDTH - 40, 30);
compo_textbox_set_autoroll_mode(txt_name, TEXT_AUTOROLL_MODE_SROLL_CIRC);
sprintf(text_buf, "%s", bt_get_local_name());
compo_textbox_set(txt_name, text_buf);
compo_picturebox_t *btn = compo_picturebox_create(frm, UI_BUF_POPUP_POP_CLOSE_BIN);
compo_setid(btn, COMPO_ID_BTN_BT);
compo_picturebox_set_pos(btn, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y + 112);
//未同步紧急联系人
compo_textbox_t *txt_no = compo_textbox_create(frm, 100);
compo_setid(txt_no, COMPO_ID_TXT_NO_CONTACT);
compo_textbox_set_multiline(txt_no, true);
compo_textbox_set_location(txt_no, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y, GUI_SCREEN_WIDTH - 20, 80);
compo_textbox_set(txt_no, i18n[STR_SOS_NO_EME_CONTACT]);
/* sos添加按钮图标 */
compo_button_t *btn_add = compo_button_create_by_image(frm, UI_BUF_SOS_ADD_BIN);
compo_setid(btn_add, COMPO_ID_PIC_NO_CONTACT);
compo_button_set_pos(btn_add, GUI_SCREEN_CENTER_X, 269);
//紧急联系人
compo_textbox_t *call_name = compo_textbox_create(frm, 100);
/* 显示紧急联系人名字采用全字库 */
compo_textbox_set_font(call_name, UI_BUF_0FONT_FONT_20_BIN);
compo_setid(call_name, COMPO_ID_TXT_NAME);
compo_textbox_set_location(call_name, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y, GUI_SCREEN_WIDTH - 40, 30);
if(get_sos_book_num()){
compo_textbox_set(call_name, call_name_str);
}
else{
compo_textbox_set(call_name, "000");
}
compo_button_t *btn_call = compo_button_create_by_image(frm, UI_BUF_SOS_ANSWER_BIN);
compo_setid(btn_call, COMPO_ID_PIC_CALL);
compo_button_set_pos(btn_call, GUI_SCREEN_CENTER_X, 250);
compo_button_t *btn_set = compo_button_create_by_image(frm, UI_BUF_SOS_SET_BIN);
compo_setid(btn_set, COMPO_ID_PIC_CHANGE);
compo_button_set_pos(btn_set, 195, 264);
if(last_off_status == true)
{
compo_textbox_set_visible(txt_loading, true);
compo_picturebox_set_visible(btn_loading, true);
compo_textbox_set_visible(txt, false);
compo_textbox_set_visible(txt_name, false);
compo_picturebox_set_visible(btn, false);
compo_textbox_set_visible(txt_no, false);
compo_button_set_visible(btn_add, false);
compo_textbox_set_visible(call_name, false);
compo_button_set_visible(btn_call, false);
compo_button_set_visible(btn_set, false);
}
else
{
compo_textbox_set_visible(txt_loading, false);
compo_picturebox_set_visible(btn_loading, false);
if(bt_is_connected())
{
if(get_call_book_cnt()&&get_sos_book_num())
{
compo_textbox_set_visible(txt, false);
compo_textbox_set_visible(txt_name, false);
compo_picturebox_set_visible(btn, false);
compo_textbox_set_visible(txt_no, false);
compo_button_set_visible(btn_add, false);
compo_textbox_set_visible(call_name, true);
compo_button_set_visible(btn_call, true);
compo_button_set_visible(btn_set, true);
}
else{
compo_textbox_set_visible(txt, false);
compo_textbox_set_visible(txt_name, false);
compo_picturebox_set_visible(btn, false);
compo_textbox_set_visible(txt_no, true);
compo_button_set_visible(btn_add, true);
compo_textbox_set_visible(call_name, false);
compo_button_set_visible(btn_call, false);
compo_button_set_visible(btn_set, false);
}
}
else{
compo_textbox_set_visible(txt, true);
compo_textbox_set_visible(txt_name, true);
compo_picturebox_set_visible(btn, true);
compo_textbox_set_visible(txt_no, false);
compo_button_set_visible(btn_add, false);
compo_textbox_set_visible(call_name, false);
compo_button_set_visible(btn_call, false);
compo_button_set_visible(btn_set, false);
}
}
return frm;
}
//点进图标进入应用
void func_sos_address_book_icon_click(void)
{
compo_textbox_t *txt_no = compo_getobj_byid(COMPO_ID_PIC_NO_CONTACT);
compo_button_t *btn_call = compo_getobj_byid(COMPO_ID_PIC_CALL);
compo_button_t *btn_set = compo_getobj_byid(COMPO_ID_PIC_CHANGE);
pbap_pb_buf_t *pb_list = SysVariable.pb_list;
u8 i = 0;
int id = compo_get_button_id();
printf("---------------id =%d\n",id);
switch (id) {
case COMPO_ID_PIC_NO_CONTACT:
case COMPO_ID_PIC_CHANGE:
if(bt_is_connected())
func_switch_to_assign_screen(FUNC_SOS_BOOK, false);
else
func_directly_back_to();
break;
case COMPO_ID_PIC_CALL:
if(get_call_book_cnt()&&get_sos_book_num() && (last_off_status == FALSE)){
memset(sys_cb.outgoing_number, 0, 20);
for (i = 0; i < 20; i++) {
sys_cb.outgoing_number[i] = pb_list[get_sos_book_num()-1].num[i];
}
if(bt_is_connected()){
/* SOS拨号 如果通话音频关闭提示打开*/
if (!bt_hfp_is_connected()){
func_popup_new(POPUP_ID_HFP);
return;
}
bt_call_redial_number();
}
}
break;
default:
break;
}
}
// 刷新界面
static void func_sos_refresh(void)
{
f_sos_t *f_sos = (f_sos_t *)func_cb.f_cb;
compo_textbox_t *txt_loading = compo_getobj_byid(COMPO_ID_LOADING_TXT);
compo_picturebox_t *btn_loading = compo_getobj_byid(COMPO_ID_LOADING);
compo_textbox_t *txt = compo_getobj_byid(COMPO_ID_TXT_BT);
compo_textbox_t *txt_name = compo_getobj_byid(COMPO_ID_TXT_BT_NAME);
compo_picturebox_t *btn = compo_getobj_byid(COMPO_ID_BTN_BT);
compo_textbox_t *txt_no = compo_getobj_byid(COMPO_ID_TXT_NO_CONTACT);
compo_button_t *btn_add = compo_getobj_byid(COMPO_ID_PIC_NO_CONTACT);
compo_textbox_t *call_name = compo_getobj_byid(COMPO_ID_TXT_NAME);
compo_button_t *btn_call = compo_getobj_byid(COMPO_ID_PIC_CALL);
compo_button_t *btn_set = compo_getobj_byid(COMPO_ID_PIC_CHANGE);
if (tick_check_expire(f_sos->tick, 1500))
{
last_off_status = false;
if(bt_is_connected()&&get_call_book_cnt()==0)
func_switch_to_assign_screen(FUNC_SOS_BOOK, true);
}
if(last_off_status == true)
{
compo_textbox_set_visible(txt_loading, true);
compo_picturebox_set_visible(btn_loading, true);
compo_textbox_set_visible(txt, false);
compo_textbox_set_visible(txt_name, false);
compo_picturebox_set_visible(btn, false);
compo_textbox_set_visible(txt_no, false);
compo_button_set_visible(btn_add, false);
compo_textbox_set_visible(call_name, false);
compo_button_set_visible(btn_call, false);
compo_button_set_visible(btn_set, false);
}
else
{
compo_textbox_set_visible(txt_loading, false);
compo_picturebox_set_visible(btn_loading, false);
if(bt_is_connected())
{
if(get_call_book_cnt()&&get_sos_book_num())
{
compo_textbox_set_visible(txt, false);
compo_textbox_set_visible(txt_name, false);
compo_picturebox_set_visible(btn, false);
compo_textbox_set_visible(txt_no, false);
compo_button_set_visible(btn_add, false);
compo_textbox_set_visible(call_name, true);
compo_button_set_visible(btn_call, true);
compo_button_set_visible(btn_set, true);
}
else{
compo_textbox_set_visible(txt, false);
compo_textbox_set_visible(txt_name, false);
compo_picturebox_set_visible(btn, false);
compo_textbox_set_visible(txt_no, true);
compo_button_set_visible(btn_add, true);
compo_textbox_set_visible(call_name, false);
compo_button_set_visible(btn_call, false);
compo_button_set_visible(btn_set, false);
}
}
else{
compo_textbox_set_visible(txt, true);
compo_textbox_set_visible(txt_name, true);
compo_picturebox_set_visible(btn, true);
compo_textbox_set_visible(txt_no, false);
compo_button_set_visible(btn_add, false);
compo_textbox_set_visible(call_name, false);
compo_button_set_visible(btn_call, false);
compo_button_set_visible(btn_set, false);
}
}
}
// SOS功能消息处理
static void func_sos_process(void)
{
func_sos_refresh();
func_process();
}
static void func_sos_message(size_msg_t msg)
{
switch (msg)
{
case MSG_CTP_TOUCH:
break;
case MSG_CTP_CLICK:
func_sos_address_book_icon_click();
break;
case MSG_CTP_SHORT_UP:
case MSG_CTP_SHORT_DOWN:
case MSG_CTP_LONG:
break;
case MSG_QDEC_BACKWARD:
break;
case MSG_QDEC_FORWARD:
break;
default:
func_message(msg);
break;
}
}
// 进入SOS功能
static void func_sos_enter(void)
{
func_cb.f_cb = func_zalloc(sizeof(f_sos_t));
f_sos_t *f_sos = (f_sos_t *)func_cb.f_cb;
if(get_sos_book_num()){
for(int i = 0;i < ADDRESS_BOOK_LIST_CNT;i++)
{
if(strcmp(call_name_str,tbl_call_txt_list[i].str_txt) == 0)
{
set_book_num(i);
break;
}
else{
set_book_num(-1);
}
}
}
if(func_cb.last == FUNC_SET_SUB_OFF)
{
last_off_status = true;
f_sos->tick = tick_get();
}
if(bt_is_connected() && get_call_book_cnt()==0 && last_off_status == false)
func_switch_to_assign_screen(FUNC_SOS_BOOK, true);
func_cb.frm_main = func_sos_form_create();
}
// 退出SOS功能
static void func_sos_exit(void)
{
func_cb.last = FUNC_SOS;
}
// SOS功能
void func_sos(void)
{
printf("%s\n", __func__);
func_sos_enter();
while (func_cb.sta == FUNC_SOS) {
func_sos_process();
func_sos_message(msg_dequeue());
}
func_sos_exit();
}
#endif