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

199 lines
5.6 KiB
C

#include "include.h"
#include "func.h"
#include "ble_protocol_msg.h"
#include "app_variable.h"
#if TRACE_EN
#define TRACE(...) printf(__VA_ARGS__)
#else
#define TRACE(...)
#endif
#define QR_CODE_MAX 100
#if(APP_CHOOSE==APP_CHOOSE_LEFUN)
#if defined(KEY_DEFINED_BY_XG_CUSTOM)
#define STR_URL_EN "http://app.waashine.com/Lefun/download.html"
#else
#define STR_URL_EN "http://dw.ss-tjd.com/download/en4.html"
#endif
#define STR_URL_CN "http://dw.ss-tjd.com/download/index4.html"
#elif(APP_CHOOSE==APP_CHOOSE_TFit)
#if defined(TJD_GUI_W17_SWATCH_MODIFY) && !defined(TJD_HUAYING_MODIFY)
#define STR_URL "http://download.microwear.com/mactiveapk.html"
#else
#define STR_URL "http://dw.ss-tjd.com/DownLoad/TFitzh.html"
#endif
#endif
typedef struct f_scan_t_ {
page_tp_move_t *ptm;
} f_scan_t;
void *barcode_creat(void *parent, char *str, int x, int y, int h, u8 length, bool dir);
static bool Refresh = false;
//创建扫一扫窗体
compo_form_t *func_scan_form_create(void)
{
u8 *p_qrCode = func_zalloc(160);
//新建窗体
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_SETTING_QR_CODE]);
compo_textbox_t *txt = compo_textbox_create(frm, 80);
compo_textbox_set_location(txt, GUI_SCREEN_CENTER_X, 260 + 15, 120, 60);
compo_textbox_set_multiline(txt, true);
compo_textbox_set(txt, i18n[STR_SCAN_REMIND]);
compo_textbox_set_autoroll_mode(txt, TEXT_AUTOROLL_MODE_SROLL_CIRC);
//创建按键
//compo_button_t *btn = compo_button_create_by_image(frm, UI_BUF_ICON_SCAN_BIN);
//compo_button_set_pos(btn, 160, 180);
u8 mac_addr[20]={0};
u8 mac_buf[20]={0};
ble_get_local_bd_addr((void *)mac_addr);
sprintf((char*)mac_buf,"%02x%02x%02x%02x%02x%02x",mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
#if(APP_CHOOSE==APP_CHOOSE_LEFUN)
#if defined(__LANGUAGE_SM_CHINESE__)
if(SysVariable.deviceInfo.language==LANGUAGE_TYPE_Chinese){
sprintf((char*)p_qrCode,"%s?name=%s&mac=%s", STR_URL_CN, xcfg_cb.le_name, mac_buf);
}else
#endif
{
sprintf((char*)p_qrCode,"%s?name=%s&mac=%s", STR_URL_EN, xcfg_cb.le_name, mac_buf);
}
#elif(APP_CHOOSE==APP_CHOOSE_TFit)
#if defined(TJD_GUI_BASE_SW_BIULD)
sprintf((char*)p_qrCode,"%s?name=%s&mac=%s", STR_URL, ble_name, mac_buf);
#else
sprintf((char*)p_qrCode,"%s?name=%s&mac=%s", STR_URL, BLE_GAP_DEVICE_NAME, mac_buf);
#endif
#endif
compo_qrcodebox_t *qrbox = compo_qrcodebox_y_create(frm, QRCODE_TYPE_2D, QR_CODE_MAX, 30);
compo_qrcodebox_set(qrbox, (const char*)p_qrCode);
compo_qrcodebox_set_bitwid_by_qrwid(qrbox, 100);
//barcode_creat(frm->page_body, "123896\0", GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y, 80, 6, false);
func_free(p_qrCode);
return frm;
}
//扫一扫功能事件处理
static void func_scan_process(void)
{
f_scan_t *f_scan = (f_scan_t *)func_cb.f_cb;
compo_page_move_process(f_scan->ptm);
if (Refresh && !sco_is_connected()) {
Refresh = false;
compo_form_t *frm = func_cb.frm_main;
compo_form_destroy(frm);
func_cb.frm_main = func_scan_form_create();
}
func_process();
}
//扫一扫功能消息处理
static void func_scan_message(size_msg_t msg)
{
f_scan_t *f_scan = (f_scan_t *)func_cb.f_cb;
switch (msg) {
case MSG_CTP_TOUCH:
compo_page_move_touch_handler(f_scan->ptm);
break;
case MSG_CTP_CLICK:
break;
case MSG_CTP_SHORT_UP:
break;
case MSG_CTP_SHORT_DOWN:
break;
case MSG_QDEC_BACKWARD:
if (func_cb.flag_sort) { //快捷应用状态下不滚动页面
func_message(msg);
} else {
compo_page_move_set_by_pages(f_scan->ptm, -1);
}
break;
case MSG_QDEC_FORWARD:
if (func_cb.flag_sort) {
func_message(msg);
} else {
compo_page_move_set_by_pages(f_scan->ptm, 1);
}
break;
case MSG_CTP_LONG:
/* APP已连接下不允许进入工厂模式 */
if (!ble_is_connected()) {
func_switch_to_assign_screen(FUNC_FACTORY_TEST, false);
}
break;
default:
func_message(msg);
break;
}
}
//进入扫一扫功能
static void func_scan_enter(void)
{
if (sco_is_connected()) {
Refresh = true;
}
func_cb.f_cb = func_zalloc(sizeof(f_scan_t));
func_cb.frm_main = func_scan_form_create();
func_cb.enter_tick = tick_get();
f_scan_t *f_scan = (f_scan_t *)func_cb.f_cb;
f_scan->ptm = (page_tp_move_t *)func_zalloc(sizeof(page_tp_move_t));
page_move_info_t info = {
.title_used = FALSE,
.page_size = 330, //除标题外页面总长度
.page_count = 1,
.up_over_perc = 10,
.down_over_perc = 10,
};
compo_page_move_init(f_scan->ptm, func_cb.frm_main->page_body, &info);
}
//退出扫一扫功能
static void func_scan_exit(void)
{
f_scan_t *f_scan = (f_scan_t *)func_cb.f_cb;
Refresh = false;
func_cb.last = FUNC_SCAN;
if (f_scan->ptm) {
func_free(f_scan->ptm);
}
}
//扫一扫功能
void func_scan(void)
{
printf("%s\n", __func__);
func_scan_enter();
while (func_cb.sta == FUNC_SCAN) {
func_scan_process();
func_scan_message(msg_dequeue());
}
func_scan_exit();
}