开发板:
ART-PI
开发环境:
rtthread studio
之前分享的在lvgl中显示中文的文章中有一张显示图片中呈现了一个二维码显示,有小伙伴问我是如何实现的,这里就将过程分享进去。
LVGL是否间接生成二维码显示呢?这个答案是必定的,曾经有大佬开源了相干的库,本人试了一下,颇为不便。这里将过程分享进去。
首先要下载库,地址如下:https://github.com/littlevgl/...
下载实现之后,把压缩包解压进去的文件夹整个复制到工程目录下,这里是我的目录。
而后要增加编译门路,点击小扳手
而后增加includes门路
抉择方才解压的文件夹
而后,就能够到lvgl的samples中增加相干的代码了。
要在代码的后面增加include信息,蕴含头文件
而后我这里的做法是在页面中新建一个容器cont,而后在容器内新建一个二维码。二维码的数据内容是Hello World! This is a QR_Code Test!
这就是理论显示成果,通过手机扫描二维码失去的就是方才编辑的信息内容
上面是我的代码:
static void table_system_create(lv_obj_t* parent){ lv_page_set_scrl_layout(parent, LV_LAYOUT_PRETTY_TOP); lv_disp_size_t disp_size = lv_disp_get_size_category(NULL); lv_coord_t grid_h = lv_page_get_height_grid(parent, 1, 1); lv_coord_t grid_w = lv_page_get_width_grid(parent, 1, 1); lv_coord_t grid_h2 = lv_page_get_height_grid(parent, 2, 1); lv_coord_t grid_w2 = lv_page_get_width_grid(parent, 2, 1); // 显示二维码 lv_obj_t* qr_code = lv_cont_create(parent, NULL); lv_cont_set_layout(qr_code, LV_LAYOUT_PRETTY_MID); lv_obj_add_style(qr_code, LV_CONT_PART_MAIN, &style_box); lv_obj_set_drag_parent(qr_code, true); //lv_obj_set_style_local_value_str(qr_code, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, "Time"); lv_cont_set_fit2(qr_code, LV_FIT_NONE, LV_FIT_TIGHT); lv_obj_set_width(qr_code, grid_w2); lv_obj_set_height(qr_code, grid_w2); lv_obj_set_style_local_value_str(qr_code, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, "QR_Code"); const char* data = "Hello World! This is a QR_Code Test!"; //Create a 100x100 QR code lv_obj_t* qr = lv_qrcode_create(qr_code, grid_w2 - LV_DPX(30), LV_THEME_DEFAULT_COLOR_PRIMARY, lv_color_hex3(0xeef)); //Set data lv_qrcode_update(qr, data, strlen(data)); lv_obj_t* sys_info = lv_cont_create(parent, qr_code); lv_obj_set_style_local_value_str(sys_info, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, "System Information"); static lv_obj_t* lable_sys_info; // lable lable_sys_info = lv_label_create(sys_info, NULL); lv_obj_set_style_local_text_font(lable_sys_info, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &myFont); lv_label_set_text(lable_sys_info, "你好!\n这里是汉字显示例程!");}