From b3c93d9abdfdc20d1338e928ab0dd710659308e8 Mon Sep 17 00:00:00 2001 From: xiehongyan Date: Tue, 26 Dec 2023 18:19:04 +0800 Subject: [PATCH] =?UTF-8?q?BUG:10646=20=E5=88=87=E6=8D=A2=E8=BF=90?= =?UTF-8?q?=E8=90=A5=E5=95=86=E5=90=8E=E6=98=BE=E7=A4=BA=E5=B9=B6=E7=AD=89?= =?UTF-8?q?=E5=BE=85=E4=B8=89=E7=A7=92=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UIFlowLVGL/UIFlowMenuCommonItem/MenuQR.c | 29 +++++--- .../UIFlowMenuCommonOptionEventCallback.c | 15 ++++ code/lib/source/lvgl/Makefile | 10 +-- .../lvgl/lvgl/src/lv_lib_qrcode/lv_qrcode.c | 74 ++++++++++++++++++- .../lvgl/lvgl/src/lv_lib_qrcode/lv_qrcode.h | 17 +++++ .../lvgl/lvgl/src/lv_lib_qrcode/qrcodegen.c | 2 +- 6 files changed, 131 insertions(+), 16 deletions(-) diff --git a/code/application/source/cardv/SrcCode/UIWnd/LVGL_SPORTCAM/UIFlowLVGL/UIFlowMenuCommonItem/MenuQR.c b/code/application/source/cardv/SrcCode/UIWnd/LVGL_SPORTCAM/UIFlowLVGL/UIFlowMenuCommonItem/MenuQR.c index 17adf2d29..60c8954d3 100644 --- a/code/application/source/cardv/SrcCode/UIWnd/LVGL_SPORTCAM/UIFlowLVGL/UIFlowMenuCommonItem/MenuQR.c +++ b/code/application/source/cardv/SrcCode/UIWnd/LVGL_SPORTCAM/UIFlowLVGL/UIFlowMenuCommonItem/MenuQR.c @@ -425,6 +425,7 @@ static void network_scan_task_cb(lv_task_t* task) } else { + lv_label_set_text(plabel, "\n\nSearching..."); if(!sf_file_IsExsit(NETMSGPATH)) { SF_MESSAGE_BUF_S stMessageBuf = {0}; @@ -527,11 +528,26 @@ static void network_select_task_cb(lv_task_t* task) { case 0x00:/*CMD_SUCCESS*/ lv_label_set_text(plabel, "\n\nCompleted"); + sf_cardv_set_operationSelectResp(0xff); + SF_MESSAGE_BUF_S stMessageBuf = {0}; + stMessageBuf.arg1 = SF_DEV_CMD_ESIM_OPERATION_SELECT; + stMessageBuf.arg2 = SF_CONTROL_TYPE_LOCAL; + stMessageBuf.arg3 = ProfileFocused; + stMessageBuf.cmdId = CMD_DEV; + sf_com_message_send_to_app(&stMessageBuf); Countdown = 3; break; case 0x34:/*NETWORK_NOT_NEED_SET*/ lv_label_set_text(plabel, "\n\nProfile is enabled"); Countdown = 3; + while (Countdown > 0) + { + Countdown--; + usleep(1000*1000); + } + network_select_task_end(); + lv_plugin_scr_close(obj, gen_nvtmsg_data(NVTRET_ENTER_MENU, 0)); + hidde_Network_Selection_page(); break; case 0xff: break; @@ -607,7 +623,7 @@ void Option_Network_Selection_Key(lv_obj_t* obj, uint32_t key) } else { - ProfileFocused = 0; + ProfileFocused = ProfileTotal-1; } update_Network_Selection_msg(obj); } @@ -623,13 +639,7 @@ void Option_Network_Selection_Key(lv_obj_t* obj, uint32_t key) { lv_obj_set_hidden(container_main_menu_scr_uiflowmenucommonoption, true); lv_label_set_text(plabel, "\n\nNetwork Switching..."); - sf_cardv_set_operationSelectResp(0xff); - SF_MESSAGE_BUF_S stMessageBuf = {0}; - stMessageBuf.arg1 = SF_DEV_CMD_ESIM_OPERATION_SELECT; - stMessageBuf.arg2 = SF_CONTROL_TYPE_LOCAL; - stMessageBuf.arg3 = ProfileFocused; - stMessageBuf.cmdId = CMD_DEV; - sf_com_message_send_to_app(&stMessageBuf); + if(network_select_task == NULL){ Countdown = 0; network_select_task = lv_task_create(network_select_task_cb, 1000, LV_TASK_PRIO_MID, (void*)obj); @@ -711,7 +721,8 @@ static void qr_page_task_cb(lv_task_t* task){ /*Create a 100x100 QR code*/ printf("[qr_page_task_cb]qr code create...\n"); - qr = lv_qrcode_create(obj, 115, (lv_color_t) { .full = 0x02}, (lv_color_t) { .full = 0x23});//23 + + qr = lv_qrcode_create(obj, 120, (lv_color_t) { .full = 0x02}, (lv_color_t) { .full = 0x23});//23 lv_obj_set_pos(qr, 42, 75); lv_qrcode_update(qr, qr_date, strlen(qr_date)); diff --git a/code/application/source/cardv/SrcCode/UIWnd/LVGL_SPORTCAM/UIFlowLVGL/UIFlowMenuCommonOption/UIFlowMenuCommonOptionEventCallback.c b/code/application/source/cardv/SrcCode/UIWnd/LVGL_SPORTCAM/UIFlowLVGL/UIFlowMenuCommonOption/UIFlowMenuCommonOptionEventCallback.c index 9ff95343d..0ea6b2679 100755 --- a/code/application/source/cardv/SrcCode/UIWnd/LVGL_SPORTCAM/UIFlowLVGL/UIFlowMenuCommonOption/UIFlowMenuCommonOptionEventCallback.c +++ b/code/application/source/cardv/SrcCode/UIWnd/LVGL_SPORTCAM/UIFlowLVGL/UIFlowMenuCommonOption/UIFlowMenuCommonOptionEventCallback.c @@ -475,6 +475,12 @@ static void LV_MenuCommonOption_UpdateContent(TM_MENU *pMenu) ui_hidden = false; break; } + default: + { + itemIconId = LV_PLUGIN_IMG_ID_SF_LIST_SELECTED;//√ + lv_obj_set_pos(image_option2_scr_uiflowmenucommonoption, 272, 0); + break; + } } } @@ -1163,6 +1169,15 @@ static void UIFlowMenuCommonOption_ScrClose(lv_obj_t* obj) message_item_close(); UIMenuStoreInfo *puiPara = sf_ui_para_get(); printf("camera mode = %d\n", puiPara->CamMode); + UINT16 itemIconId = LV_PLUGIN_IMG_ID_SF_LIST_SELECTED;//√ + lv_obj_set_pos(image_option1_scr_uiflowmenucommonoption, 272, 0); + lv_obj_set_pos(image_option2_scr_uiflowmenucommonoption, 272, 0); + lv_obj_set_pos(image_option3_scr_uiflowmenucommonoption, 272, 0); + lv_obj_set_pos(image_option4_scr_uiflowmenucommonoption, 272, 0); + lv_plugin_menu_set_item_img_id(menu_option, 0, LV_PLUGIN_MENU_ITEM_VISIBLE_STATE_NUM, itemIconId); + lv_plugin_menu_set_item_img_id(menu_option, 1, LV_PLUGIN_MENU_ITEM_VISIBLE_STATE_NUM, itemIconId); + lv_plugin_menu_set_item_img_id(menu_option, 2, LV_PLUGIN_MENU_ITEM_VISIBLE_STATE_NUM, itemIconId); + lv_plugin_menu_set_item_img_id(menu_option, 3, LV_PLUGIN_MENU_ITEM_VISIBLE_STATE_NUM, itemIconId); } static void UIFlowMenuCommonOption_ChildScrClose(lv_obj_t* obj) diff --git a/code/lib/source/lvgl/Makefile b/code/lib/source/lvgl/Makefile index c9bb4a4d3..052b3b3bb 100755 --- a/code/lib/source/lvgl/Makefile +++ b/code/lib/source/lvgl/Makefile @@ -28,7 +28,7 @@ EXTRA_INCLUDE += \ -I$(NVT_HDAL_DIR)/vendor/media/include \ #--------- ENVIRONMENT SETTING -------------------- -WARNING = -Wall -Wundef -Wsign-compare -Wno-missing-braces -Wstrict-prototypes -Werror +WARNING = -Wall -Wundef -Wno-missing-braces -Wstrict-prototypes -Werror COMPILE_OPTS = -I. -O2 -fPIC -ffunction-sections -fdata-sections -DSOCKLEN_T=socklen_t -D__LINUX_USER__ -D_TODO_=0 C_PREDEFINED = -D_NVT_CONSOLE_ C_CFLAGS = $(PLATFORM_CFLAGS) $(COMPILE_OPTS) $(WARNING) $(EXTRA_INCLUDE) $(C_PREDEFINED) @@ -186,7 +186,7 @@ EXTRA_INCLUDE += \ -I$(NVT_HDAL_DIR)/vendor/media/include \ -I$(NVT_HDAL_DIR)/include \ -C_CFLAGS = $(PLATFORM_CFLAGS) $(EXTRA_INCLUDE) -DDEBUG -Wno-format -D_TODO_=0 -Wno-inline +C_CFLAGS = $(PLATFORM_CFLAGS) $(EXTRA_INCLUDE) -DDEBUG -Wno-format -Wno-sign-compare -D_TODO_=0 -Wno-inline SRC = \ lvgl/src/lv_font/lv_font.c \ @@ -291,9 +291,9 @@ SRC = \ lvgl/src/lv_hal/lv_hal_indev.c \ lvgl/src/lv_hal/lv_hal_tick.c \ lvgl/src/lv_gpu/lv_gpu_nvt_dma2d.c \ - lvgl/src/lv_lib_qrcode/lv_qrcode.c \ - lvgl/src/lv_lib_qrcode/qrcodegen.c \ - + lvgl/src/lv_lib_qrcode/lv_qrcode.c \ + lvgl/src/lv_lib_qrcode/qrcodegen.c \ + copy = if [ ! -z "$(1)" -a "$(1)" != " " ]; then cp -avf $(1) $(2); fi OBJ = $(SRC:.c=.o) diff --git a/code/lib/source/lvgl/lvgl/src/lv_lib_qrcode/lv_qrcode.c b/code/lib/source/lvgl/lvgl/src/lv_lib_qrcode/lv_qrcode.c index 315b29096..0e9e42ba8 100755 --- a/code/lib/source/lvgl/lvgl/src/lv_lib_qrcode/lv_qrcode.c +++ b/code/lib/source/lvgl/lvgl/src/lv_lib_qrcode/lv_qrcode.c @@ -73,6 +73,77 @@ lv_obj_t * lv_qrcode_create(lv_obj_t * parent, lv_coord_t size, lv_color_t dark_ } +lv_coord_t lv_qrcode_base_size(const void * data, uint32_t data_len) +{ + uint8_t* qr0 = NULL; + uint8_t* data_tmp = NULL; + lv_res_t ret = LV_RES_OK; + + if(data_len > qrcodegen_BUFFER_LEN_MAX){ + ret = LV_RES_INV; + goto EXIT; + } + + qr0 = (uint8_t*)lv_mem_alloc(qrcodegen_BUFFER_LEN_MAX); + if(qr0 == NULL){ + ret = LV_RES_INV; + goto EXIT; + } + + data_tmp = (uint8_t*)lv_mem_alloc(qrcodegen_BUFFER_LEN_MAX); + if(data_tmp == NULL){ + ret = LV_RES_INV; + goto EXIT; + } + + memcpy(data_tmp, data, data_len); + + bool ok = qrcodegen_encodeBinary(data_tmp, data_len, + qr0, qrcodegen_Ecc_MEDIUM, + qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, + qrcodegen_Mask_AUTO, true); + + if (!ok) { + ret = LV_RES_INV; + goto EXIT; + } + + int qr_size = qrcodegen_getSize(qr0); + + EXIT: + + if(qr0){ + lv_mem_free(qr0); + } + + if(data_tmp){ + lv_mem_free(data_tmp); + } + + if(ret == LV_RES_INV) + return -1; + else + return qr_size; +} + +lv_coord_t lv_qrcode_evaluate_size(lv_coord_t target_size, uint8_t border_ratio, const void * data, uint32_t data_len) +{ + lv_coord_t qr_size = lv_qrcode_base_size(data, data_len); + + if(qr_size <= 0){ + return -1; + } + + /* size with no border */ + target_size = target_size - (target_size % qr_size); + + lv_coord_t scale = target_size / qr_size; + lv_coord_t scaled = qr_size * scale; + lv_coord_t border = (scaled * border_ratio) / 100; + + return (target_size + (border * 2)); +} + /** * Set the data of a QR code object * @param qrcode pointer to aQ code object @@ -125,6 +196,7 @@ lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_le int scale = obj_w / qr_size; int scaled = qr_size * scale; int margin = (obj_w - scaled) / 2; + lv_img_dsc_t * img = lv_canvas_get_img(qrcode); uint8_t * buf_u8 = (uint8_t *)img->data + 8; /*+8 skip the palette*/ /* Copy the qr code canvas: @@ -167,7 +239,7 @@ lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_le } /*The Qr is probably scaled so simply to the repeated rows*/ - int s; + uint32_t s; const uint8_t * row_ori = buf_u8 + row_byte_cnt * y; for(s = 1; s < scale; s++) { memcpy((uint8_t*)buf_u8 + row_byte_cnt * (y + s), row_ori, row_byte_cnt); diff --git a/code/lib/source/lvgl/lvgl/src/lv_lib_qrcode/lv_qrcode.h b/code/lib/source/lvgl/lvgl/src/lv_lib_qrcode/lv_qrcode.h index ac6460ede..c7d77730c 100755 --- a/code/lib/source/lvgl/lvgl/src/lv_lib_qrcode/lv_qrcode.h +++ b/code/lib/source/lvgl/lvgl/src/lv_lib_qrcode/lv_qrcode.h @@ -55,6 +55,23 @@ lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_le */ void lv_qrcode_delete(lv_obj_t * qrcode); + +/** + * Calculate best fit size with border ratio. + * Please use this API before lv_qrcode_create + * + * lv_coord_t target_size = 100; + * lv_coord_t evaluate_size = lv_qrcode_evaluate_size(target_size, 5, data, data_len); + * lv_obj_t * qr = lv_qrcode_create(parent, evaluate_size, dark_color, light_color); + * + * @param target_size + * @param margin_ratio 0-100, 5 means qrcode keeps 5% margin of scaled size , 0 is no margin + * @param data data to display + * @param data_len length of data in bytes + * @return best fit size + */ +lv_coord_t lv_qrcode_evaluate_size(lv_coord_t target_size, uint8_t border_ratio, const void * data, uint32_t data_len); + /********************** * MACROS **********************/ diff --git a/code/lib/source/lvgl/lvgl/src/lv_lib_qrcode/qrcodegen.c b/code/lib/source/lvgl/lvgl/src/lv_lib_qrcode/qrcodegen.c index cbe134e1d..67c191739 100755 --- a/code/lib/source/lvgl/lvgl/src/lv_lib_qrcode/qrcodegen.c +++ b/code/lib/source/lvgl/lvgl/src/lv_lib_qrcode/qrcodegen.c @@ -853,7 +853,7 @@ testable int calcSegmentBitLength(enum qrcodegen_Mode mode, size_t numChars) { return -1; } assert(result >= 0); - if (result > (long)INT16_MAX) + if (result > (unsigned int)INT16_MAX) return -1; return (int)result; }