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

171 lines
4.7 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 200
#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_ {
} f_scan_t;
void *barcode_creat(void *parent, char *str, int x, int y, int h, u8 length, bool dir);
static bool Refresh = false;
static u8 click_num = 0;
//创建扫一扫窗体
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_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_create(frm, QRCODE_TYPE_2D, QR_CODE_MAX);
if (qrbox->qrcode) {
compo_qrcodebox_set(qrbox, (const char *)p_qrCode);
compo_qrcodebox_set_bitwid_by_qrwid(qrbox, 140);
compo_qrcodebox_pos(qrbox, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y - 10);
}
func_free(p_qrCode);
compo_textbox_t *txt = compo_textbox_create(frm, TEXTBOX_TEXT_BUF_LEN);
compo_textbox_set_location(txt, GUI_SCREEN_CENTER_X, 260, 220, 48);
compo_textbox_set(txt, i18n[STR_SETTING_ABOUT_QRCODE]);
return frm;
}
//扫一扫功能事件处理
static void func_scan_process(void)
{
if(tick_check_expire(func_cb.enter_tick, 3000))
{
func_cb.enter_tick = tick_get();
click_num = 0;
printf("func_scan_process click_num = %d\n",click_num);
}
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)
{
switch (msg) {
case MSG_CTP_SHORT_UP:
break;
case MSG_CTP_SHORT_DOWN:
break;
case MSG_CTP_CLICK:
/* APP已连接下不允许进入工厂模式 */
click_num ++;
printf("func_scan_message click_num = %d\n",click_num);
if(click_num >= 5)
{
click_num = 0;
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();
click_num = 0;
}
//退出扫一扫功能
static void func_scan_exit(void)
{
Refresh = false;
func_cb.last = FUNC_SCAN;
}
//扫一扫功能
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();
}