834 lines
30 KiB
C
Executable File
834 lines
30 KiB
C
Executable File
#include "lvgl_app.h"
|
||
#include <ft2build.h>
|
||
#include "src/misc/lv_fs.h" // 引入 POSIX 文件系统驱动
|
||
#include "lvgl/lvgl.h"
|
||
|
||
extern lv_group_t *Key_Matrix_Group;
|
||
void lv_example_btn_1(void)
|
||
{
|
||
lv_obj_t * label;
|
||
|
||
|
||
|
||
// 创建按钮 1
|
||
lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
|
||
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40);
|
||
lv_obj_set_size(btn1, 400, 300);
|
||
|
||
// 设置按钮 1 背景颜色为红色
|
||
// lv_obj_set_style_bg_color(btn1, lv_color_hex(0xFF0000), 0); // 红色
|
||
|
||
// 创建标签并设置文本
|
||
label = lv_label_create(btn1);
|
||
lv_label_set_text(label, "Button");
|
||
lv_obj_center(label);
|
||
|
||
// 创建按钮 2
|
||
lv_obj_t * btn2 = lv_btn_create(lv_scr_act());
|
||
lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 40);
|
||
lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
|
||
lv_obj_set_height(btn2, LV_SIZE_CONTENT);
|
||
|
||
// 创建标签并设置文本
|
||
label = lv_label_create(btn2);
|
||
lv_label_set_text(label, "Toggle");
|
||
lv_obj_center(label);
|
||
|
||
// 将按钮添加到组中
|
||
lv_group_add_obj(Key_Matrix_Group, btn1);
|
||
lv_group_add_obj(Key_Matrix_Group, btn2);
|
||
}
|
||
|
||
static void Lock_screen_event_callback(lv_event_t* event)
|
||
{
|
||
if (event == NULL)
|
||
{
|
||
printf("[%s:%d] event is NULL\n", __FUNCTION__, __LINE__);
|
||
return ;
|
||
}
|
||
lv_event_code_t event_code = lv_event_get_code(event);
|
||
lv_obj_t * target = lv_event_get_target(event);
|
||
|
||
if(event_code == LV_EVENT_KEY)
|
||
{
|
||
lv_group_remove_obj(Lock_screen.screen);
|
||
lv_group_add_obj(Key_Matrix_Group ,Bar_screen.screen);
|
||
lv_obj_add_event_cb(Bar_screen.screen, Bar_screen.event_cb, LV_EVENT_ALL, NULL);
|
||
lv_obj_add_flag(Lock_screen.screen, LV_OBJ_FLAG_HIDDEN);
|
||
lv_obj_clear_flag(Bar_screen.screen, LV_OBJ_FLAG_HIDDEN);
|
||
}
|
||
if(event_code <= LV_EVENT_HIT_TEST)
|
||
{
|
||
LV_LOG_USER("Clicked:%d",event_code);
|
||
}
|
||
|
||
}
|
||
|
||
static void Bar_screen_event_callback(lv_event_t* event)
|
||
{
|
||
if (event == NULL)
|
||
{
|
||
printf("[%s:%d] event is NULL\n", __FUNCTION__, __LINE__);
|
||
return ;
|
||
}
|
||
lv_event_code_t event_code = lv_event_get_code(event);
|
||
|
||
if(event_code == LV_EVENT_KEY)
|
||
{
|
||
lv_group_remove_obj(Bar_screen.screen);
|
||
lv_group_add_obj(Key_Matrix_Group ,Lock_screen.screen);
|
||
lv_obj_add_event_cb(Bar_screen.screen, Bar_screen.event_cb, LV_EVENT_ALL, NULL);
|
||
lv_obj_add_flag(Bar_screen.screen, LV_OBJ_FLAG_HIDDEN);
|
||
lv_obj_clear_flag(Lock_screen.screen, LV_OBJ_FLAG_HIDDEN);
|
||
}
|
||
if(event_code <= LV_EVENT_HIT_TEST)
|
||
{
|
||
LV_LOG_USER("Clicked:%d",event_code);
|
||
}
|
||
}
|
||
|
||
lv_obj_t* Main_Scr;//主屏幕
|
||
lv_obj_t* Set_Scr;//设置界面
|
||
lv_obj_t* Net_Scr;//网络界面
|
||
lv_obj_t* Columnlab_Scr;//列标签
|
||
//lv_obj_t* Lock_screen;//锁屏界面
|
||
|
||
config_lv_page_t Lock_screen ={
|
||
.event_cb = Lock_screen_event_callback,
|
||
};
|
||
|
||
config_lv_page_t Bar_screen ={
|
||
.event_cb = Bar_screen_event_callback,
|
||
};
|
||
static const char * btnm_map[] = {"Home","\n",
|
||
"Set","\n",
|
||
"System","\n",
|
||
"Net",""};
|
||
lv_obj_t* Menulable;
|
||
|
||
config_lv_btn_t Button_Group[2][10]={
|
||
|
||
{
|
||
{
|
||
.flag = true,
|
||
.src_left = "A:/root/nfs_tools/lvgl_imgs/Home Kit.bin",
|
||
.event_num = HOME_BUTTON,
|
||
},
|
||
{
|
||
.flag = true,
|
||
.src_left = "A:/root/nfs_tools/lvgl_imgs/Setting.bin",
|
||
.event_num = SETING_BUTTON,
|
||
},
|
||
{
|
||
.flag = true,
|
||
.src_left = "A:/root/nfs_tools/lvgl_imgs/Terminal.bin",
|
||
.event_num = SETING_BUTTON,
|
||
},
|
||
{
|
||
.flag = true,
|
||
.src_left = "A:/root/nfs_tools/lvgl_imgs/file.bin",
|
||
.event_num = SETING_BUTTON,
|
||
},
|
||
{
|
||
.flag = true,
|
||
.src_left = "A:/root/nfs_tools/lvgl_imgs/Time.bin",
|
||
.event_num = SETING_BUTTON,
|
||
}
|
||
},
|
||
{
|
||
|
||
}
|
||
};
|
||
|
||
lv_obj_t* container;
|
||
|
||
void lv_example_freetype_1(lv_obj_t * parent)
|
||
{
|
||
/*Create a font*/
|
||
static lv_ft_info_t info;
|
||
/*FreeType uses C standard file system, so no driver letter is required.*/
|
||
info.name = "/root/fontfile/MHEIGB181.TTF";
|
||
info.weight = 32;
|
||
info.style = FT_FONT_STYLE_NORMAL;
|
||
info.mem = NULL;
|
||
if(!lv_ft_font_init(&info)) {
|
||
LV_LOG_ERROR("create failed.");
|
||
}
|
||
|
||
/*Create style with the new font*/
|
||
static lv_style_t style;
|
||
lv_style_init(&style);
|
||
lv_style_set_text_font(&style, info.font);
|
||
lv_style_set_text_align(&style, LV_TEXT_ALIGN_RIGHT);
|
||
/*Create a label with the new style*/
|
||
lv_obj_t * label = lv_label_create(parent);
|
||
lv_obj_add_style(label, &style, 0);
|
||
lv_label_set_text(label, "你好世界\nI'm a font created with FreeType");
|
||
lv_obj_center(label);
|
||
|
||
}
|
||
|
||
lv_ft_info_t MHEIGB_Info[128];
|
||
|
||
void lv_font_open_Init(uint8_t Type_size)
|
||
{
|
||
MHEIGB_Info[Type_size].name = "/root/fontfile/MHEIGB181.TTF";
|
||
MHEIGB_Info[Type_size].weight = Type_size;
|
||
MHEIGB_Info[Type_size].style = FT_FONT_STYLE_NORMAL;
|
||
MHEIGB_Info[Type_size].mem = NULL;
|
||
if(!lv_ft_font_init(&MHEIGB_Info[Type_size])) {
|
||
LV_LOG_ERROR("create failed.");
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* @brief 处理按钮事件的回调函数
|
||
* @param event
|
||
*/
|
||
static void button_event_cb(lv_event_t* event)
|
||
{
|
||
lv_obj_t* current_btn = lv_event_get_current_target(event);
|
||
uint32_t current_btn_index = lv_obj_get_index(current_btn);
|
||
uint32_t mid_btn_index = (lv_obj_get_child_cnt(Columnlab_Scr) - 1) / 2;
|
||
static uint8_t btn_index = 0;
|
||
if (event->code == LV_EVENT_FOCUSED)
|
||
{
|
||
if (current_btn_index > mid_btn_index)
|
||
{
|
||
LV_LOG_USER("btn_index:%d > %d %d\n",current_btn_index , mid_btn_index,btn_index);
|
||
lv_obj_scroll_to_view(lv_obj_get_child(Columnlab_Scr, mid_btn_index - 1), LV_ANIM_ON);
|
||
lv_obj_scroll_to_view(lv_obj_get_child(Columnlab_Scr, mid_btn_index), LV_ANIM_ON);
|
||
lv_obj_move_to_index(lv_obj_get_child(Columnlab_Scr, 0), -1);
|
||
}
|
||
else if (current_btn_index < mid_btn_index)
|
||
{
|
||
LV_LOG_USER("btn_index:%d < %d\n",current_btn_index , mid_btn_index);
|
||
lv_obj_scroll_to_view(lv_obj_get_child(Columnlab_Scr, mid_btn_index + 1), LV_ANIM_OFF);
|
||
lv_obj_scroll_to_view(lv_obj_get_child(Columnlab_Scr, mid_btn_index), LV_ANIM_ON);
|
||
lv_obj_move_to_index(lv_obj_get_child(Columnlab_Scr, -1), 0);
|
||
}
|
||
}
|
||
else if (event->code == LV_EVENT_CLICKED)
|
||
{
|
||
/**/
|
||
}
|
||
}
|
||
static uint8_t btn_index = 0;
|
||
static void event_handler(lv_event_t * e)
|
||
{
|
||
lv_event_code_t code = lv_event_get_code(e);
|
||
|
||
if(code == LV_EVENT_CLICKED && btn_index<4) {
|
||
LV_LOG_USER("Clicked");
|
||
btn_index++;
|
||
lv_obj_scroll_to_view(lv_obj_get_child(Columnlab_Scr, btn_index), LV_ANIM_ON);
|
||
//lv_obj_move_to_index(lv_obj_get_child(Columnlab_Scr, 0), -1);
|
||
}
|
||
else if(code == LV_EVENT_VALUE_CHANGED) {
|
||
LV_LOG_USER("Toggled");
|
||
}
|
||
}
|
||
|
||
static void event_handlerdown(lv_event_t * e)
|
||
{
|
||
lv_event_code_t code = lv_event_get_code(e);
|
||
|
||
if(code == LV_EVENT_CLICKED && btn_index>0) {
|
||
LV_LOG_USER("Clicked");
|
||
btn_index--;
|
||
lv_obj_scroll_to_view(lv_obj_get_child(Columnlab_Scr, btn_index), LV_ANIM_ON);
|
||
//lv_obj_move_to_index(lv_obj_get_child(Columnlab_Scr, -1), 0);
|
||
}
|
||
else if(code == LV_EVENT_VALUE_CHANGED) {
|
||
LV_LOG_USER("Toggled");
|
||
}
|
||
}
|
||
|
||
void screen_Navigation_bar(lv_obj_t * parent)
|
||
{
|
||
Bar_screen.screen = lv_obj_create(lv_scr_act());
|
||
lv_obj_set_style_bg_color(Bar_screen.screen, lv_color_hex(0xF5F5F5), 0); // 设置背景颜色
|
||
lv_obj_set_size(Bar_screen.screen,480,320);
|
||
lv_obj_set_align(Bar_screen.screen,LV_ALIGN_CENTER);
|
||
|
||
}
|
||
|
||
void Load_Physical_screen(lv_disp_t * disp)
|
||
{
|
||
lv_disp_set_default(disp);
|
||
}
|
||
|
||
#define CANVAS_WIDTH 200
|
||
#define CANVAS_HEIGHT 200
|
||
static lv_obj_t * canvas;
|
||
/*Create colors with the indices of the palette*/
|
||
static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_INDEXED_1BIT(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||
lv_color_t c0;
|
||
lv_color_t c1;
|
||
|
||
static lv_point_t points[1000]; // 存储点的数组
|
||
static uint32_t point_count = 0; // 当前点的数量
|
||
|
||
static void touch_event_cb(lv_event_t * e)
|
||
{
|
||
lv_event_code_t code = lv_event_get_code(e);
|
||
lv_obj_t * obj = lv_event_get_target(e);
|
||
|
||
if(code == LV_EVENT_PRESSED) {
|
||
// 用户按下触摸屏
|
||
point_count = 0; // 重置点的数量
|
||
printf("点击\r\n");
|
||
/*Create a buffer for the canvas*/
|
||
|
||
|
||
|
||
}
|
||
else if(code == LV_EVENT_PRESSING) {
|
||
// 用户按住并移动触摸屏
|
||
lv_point_t touch_point;
|
||
lv_indev_get_point(lv_indev_get_act(), &touch_point); // 获取触摸点位置
|
||
|
||
// 将当前点存储到数组中
|
||
if(point_count < sizeof(points) / sizeof(points[0])) {
|
||
points[point_count] = touch_point;
|
||
point_count++;
|
||
}
|
||
// printf("滑动:%d,%d\n",touch_point.x,touch_point.y);
|
||
|
||
|
||
|
||
lv_canvas_set_px_color(canvas, touch_point.x, touch_point.y, c0);
|
||
/*Create hole on the canvas*/
|
||
// uint32_t x;
|
||
// uint32_t y;
|
||
// for( y = 10; y < 30; y++) {
|
||
// for( x = 5; x < 20; x++) {
|
||
// lv_canvas_set_px_color(canvas, x, y, c0);
|
||
// }
|
||
// }
|
||
|
||
}
|
||
else if(code == LV_EVENT_RELEASED) {
|
||
// 用户松开触摸
|
||
// 可选:可以在这里添加保存绘图的操作
|
||
}
|
||
}
|
||
|
||
|
||
void Drawing_board_screen(lv_disp_t * disp)
|
||
{
|
||
lv_disp_set_default(disp);
|
||
if(disp == disp_480x320)
|
||
{
|
||
lv_obj_t* screen = lv_obj_create(lv_scr_act());
|
||
lv_obj_set_size(screen,480,320);
|
||
canvas = lv_canvas_create(lv_scr_act());
|
||
|
||
/*Create a canvas and initialize its palette*/
|
||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_INDEXED_1BIT);
|
||
lv_canvas_set_palette(canvas, 0, LV_COLOR_CHROMA_KEY);
|
||
lv_canvas_set_palette(canvas, 1, lv_palette_main(LV_PALETTE_RED));
|
||
|
||
c0.full = 0;
|
||
c1.full = 1;
|
||
/*Red background (There is no dedicated alpha channel in indexed images so LV_OPA_COVER is ignored)*/
|
||
lv_canvas_fill_bg(canvas, c1, LV_OPA_COVER);
|
||
}else{
|
||
lv_obj_t* screen = lv_obj_create(lv_scr_act());
|
||
lv_obj_set_size(screen,300,240);
|
||
lv_obj_add_event_cb(screen, touch_event_cb, LV_EVENT_ALL, NULL);
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
extern void lv_example_scroll_3();
|
||
|
||
static void btn_event_cb(lv_event_t * e)
|
||
{
|
||
lv_obj_t * btn = lv_event_get_target(e); // 获取触发事件的按钮
|
||
uint32_t i = (uint32_t)lv_obj_get_user_data(btn); // 获取按钮的索引
|
||
lv_obj_t * label = lv_obj_get_child(btn, NULL);
|
||
|
||
printf("第%d按钮被按下!\n",i); // 打印信息
|
||
|
||
// if(i == 0) {
|
||
// Drawing_board_screen(disp_480x320);
|
||
// Drawing_board_screen(disp_300x240);
|
||
|
||
// }else {
|
||
// // lv_disp_set_default(disp_480x320);
|
||
// lv_font_open_Init(32);
|
||
// /*Create style with the new font*/
|
||
// static lv_style_t style;
|
||
// lv_style_init(&style);
|
||
// lv_style_set_text_font(&style, MHEIGB_Info[32].font);
|
||
// lv_style_set_text_align(&style, LV_TEXT_ALIGN_AUTO);
|
||
// lv_obj_t * Hello_lable = lv_obj_get_child(Lock_screen.screen,NULL);
|
||
|
||
// lv_obj_add_style(Hello_lable, &style, 0);
|
||
// lv_label_set_text_fmt(Hello_lable, "%d:画板",i);
|
||
|
||
// lv_disp_set_default(disp_300x240);
|
||
// lv_label_set_text_fmt(label, "%d:按下",i);
|
||
// }
|
||
|
||
if(i == 2) {
|
||
lv_disp_set_default(disp_480x320);
|
||
lv_example_scroll_3();
|
||
}
|
||
|
||
|
||
}
|
||
|
||
// 定义面板的事件回调函数
|
||
static void panel_event_cb(lv_event_t * e)
|
||
{
|
||
int i=0;
|
||
lv_obj_t * panel = lv_event_get_target(e);
|
||
lv_coord_t scroll_x = lv_obj_get_scroll_x(panel);
|
||
lv_coord_t panel_width = lv_obj_get_width(panel);
|
||
lv_coord_t btn_width = 150; // 按钮宽度
|
||
|
||
|
||
}
|
||
|
||
void lv_example_scroll_2(void)
|
||
{
|
||
lv_obj_t * panel = lv_obj_create(lv_scr_act());
|
||
lv_obj_set_size(panel, 300, 220);
|
||
lv_obj_set_scroll_snap_x(panel, LV_SCROLL_SNAP_CENTER);
|
||
lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW);
|
||
lv_obj_align(panel, LV_ALIGN_CENTER, 0, 0);
|
||
lv_obj_set_scroll_dir(panel, LV_DIR_HOR);
|
||
uint32_t i;
|
||
uint32_t btn_width = 150; // 按钮宽度
|
||
lv_font_open_Init(36);
|
||
static lv_style_t style;
|
||
lv_style_init(&style);
|
||
lv_style_set_text_font(&style, MHEIGB_Info[36].font);
|
||
for(i = 0; i < 9; i++) {
|
||
lv_obj_t * btn = lv_btn_create(panel);
|
||
lv_obj_set_size(btn, btn_width, lv_pct(108));
|
||
|
||
lv_obj_t * label = lv_label_create(btn);
|
||
lv_obj_add_style(label, &style, 0);
|
||
switch (i)
|
||
{
|
||
case 0:
|
||
lv_label_set_text(label, "画板测试");
|
||
break;
|
||
case 1:
|
||
lv_label_set_text(label, "手势测试");
|
||
break;
|
||
case 2:
|
||
lv_label_set_text(label, "按键测试");
|
||
break;
|
||
default:
|
||
lv_label_set_text_fmt(label, "Panel %"LV_PRIu32, i);
|
||
break;
|
||
}
|
||
// lv_group_add_obj(Key_Matrix_Group, btn);
|
||
lv_obj_center(label);
|
||
|
||
// 设置按钮的索引作为用户数据
|
||
lv_obj_set_user_data(btn, i);
|
||
|
||
// 为按钮添加事件回调,监听点击事件
|
||
lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_CLICKED, NULL);
|
||
}
|
||
|
||
// 滚动到第二个按钮
|
||
lv_obj_scroll_to_x(panel, btn_width * 1, LV_ANIM_OFF); // 第二个按钮的位置
|
||
lv_obj_update_snap(panel, LV_ANIM_ON);
|
||
lv_obj_add_flag(panel, LV_OBJ_FLAG_SCROLL_ONE);
|
||
|
||
// 添加事件回调,监听滚动事件
|
||
// lv_obj_add_event_cb(panel, panel_event_cb, LV_EVENT_SCROLL, NULL);
|
||
// 使得滚动面板实现循环
|
||
lv_obj_add_event_cb(panel, panel_event_cb, LV_EVENT_SCROLL, NULL);
|
||
lv_obj_add_event_cb(panel, panel_event_cb, LV_EVENT_SCROLL_END, NULL);
|
||
// lv_group_add_obj(Key_Matrix_Group, panel);
|
||
}
|
||
|
||
void lv_example_scroll_3(void)
|
||
{
|
||
lv_obj_t * panel = lv_obj_create(lv_scr_act());
|
||
lv_obj_set_size(panel, 300, 220);
|
||
lv_obj_set_scroll_snap_x(panel, LV_SCROLL_SNAP_CENTER);
|
||
lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW);
|
||
lv_obj_align(panel, LV_ALIGN_CENTER, 0, 0);
|
||
lv_obj_set_scroll_dir(panel, LV_DIR_HOR);
|
||
uint32_t i;
|
||
uint32_t btn_width = 150; // 按钮宽度
|
||
lv_font_open_Init(36);
|
||
static lv_style_t style;
|
||
lv_style_init(&style);
|
||
lv_style_set_text_font(&style, MHEIGB_Info[36].font);
|
||
for(i = 0; i < 9; i++) {
|
||
lv_obj_t * btn = lv_btn_create(panel);
|
||
lv_obj_set_size(btn, btn_width, 100);
|
||
|
||
lv_obj_t * label = lv_label_create(btn);
|
||
lv_obj_add_style(label, &style, 0);
|
||
switch (i)
|
||
{
|
||
// case 0:
|
||
// lv_label_set_text(label, "画板测试");
|
||
// break;
|
||
// case 1:
|
||
// lv_label_set_text(label, "手势测试");
|
||
// break;
|
||
// case 2:
|
||
// lv_label_set_text(label, "按键测试");
|
||
// break;
|
||
default:
|
||
lv_label_set_text_fmt(label, "Panel %"LV_PRIu32, i);
|
||
break;
|
||
}
|
||
lv_group_add_obj(Key_Matrix_Group, btn);
|
||
lv_obj_center(label);
|
||
|
||
// 设置按钮的索引作为用户数据
|
||
lv_obj_set_user_data(btn, i);
|
||
|
||
// 为按钮添加事件回调,监听点击事件
|
||
// lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_CLICKED, NULL);
|
||
}
|
||
|
||
// 滚动到第二个按钮
|
||
lv_obj_scroll_to_x(panel, btn_width * 1, LV_ANIM_OFF); // 第二个按钮的位置
|
||
lv_obj_update_snap(panel, LV_ANIM_ON);
|
||
lv_obj_add_flag(panel, LV_OBJ_FLAG_SCROLL_ONE);
|
||
|
||
// 添加事件回调,监听滚动事件
|
||
// lv_obj_add_event_cb(panel, panel_event_cb, LV_EVENT_SCROLL, NULL);
|
||
// 使得滚动面板实现循环
|
||
// lv_obj_add_event_cb(panel, panel_event_cb, LV_EVENT_SCROLL, NULL);
|
||
// lv_obj_add_event_cb(panel, panel_event_cb, LV_EVENT_SCROLL_END, NULL);
|
||
// lv_group_add_obj(Key_Matrix_Group, panel);
|
||
}
|
||
|
||
|
||
void Center_menu()
|
||
{
|
||
lv_example_scroll_2();
|
||
}
|
||
|
||
void Physical_Screen_480x320()
|
||
{
|
||
lv_disp_t * disp = disp_480x320;
|
||
// disp = lv_disp_get_next(disp);
|
||
lv_disp_set_default(disp);
|
||
|
||
lv_style_init(&Lock_screen.style);
|
||
lv_style_set_outline_color(&Lock_screen.style,lv_palette_main(LV_PALETTE_BLUE));
|
||
lv_style_set_border_opa(&Lock_screen.style,LV_OPA_0); //设置边框透明度
|
||
// lv_style_set_outline_opa(&Lock_screen.style,LV_OPA_0); //设置外轮廓透明度
|
||
Lock_screen.screen = lv_obj_create(lv_scr_act());
|
||
lv_obj_set_style_bg_color(Lock_screen.screen, lv_color_hex(0x696969), 0); // 设置背景颜色
|
||
lv_obj_set_size(Lock_screen.screen,480,320);
|
||
lv_obj_set_align(Lock_screen.screen,LV_ALIGN_CENTER);
|
||
lv_obj_set_style_pad_all(Lock_screen.screen, 0, 0);
|
||
lv_obj_set_scrollbar_mode(Lock_screen.screen, LV_SCROLLBAR_MODE_OFF);//关闭滚动条
|
||
lv_obj_set_style_radius(Lock_screen.screen,0,0);//设置容器圆角为直角
|
||
lv_obj_add_style(Lock_screen.screen, &Lock_screen.style, 0);
|
||
lv_font_open_Init(72);
|
||
/*Create style with the new font*/
|
||
static lv_style_t style;
|
||
lv_style_init(&style);
|
||
lv_style_set_text_font(&style, MHEIGB_Info[72].font);
|
||
lv_style_set_text_align(&style, LV_TEXT_ALIGN_AUTO);
|
||
/*Create a label with the new style*/
|
||
lv_obj_t * Hello_lable = lv_label_create(Lock_screen.screen);
|
||
|
||
lv_obj_add_style(Hello_lable, &style, 0);
|
||
lv_label_set_text(Hello_lable, "LinkEase-NAS");
|
||
lv_obj_align(Hello_lable, LV_ALIGN_CENTER, 0, 0);
|
||
|
||
// lv_group_add_obj(Key_Matrix_Group ,Lock_screen.screen);
|
||
lv_obj_add_event_cb(Lock_screen.screen, Lock_screen.event_cb, LV_EVENT_ALL, NULL);
|
||
}
|
||
|
||
void Physical_Screen_300x240()
|
||
{
|
||
lv_disp_t * disp = disp_300x240;
|
||
// disp = lv_disp_get_next(disp);
|
||
lv_disp_set_default(disp);
|
||
|
||
lv_example_scroll_2();
|
||
}
|
||
void lvgl_app_start(void *arg)
|
||
{
|
||
uint16_t i=0;
|
||
int num = (unsigned long long)arg;
|
||
// int res;
|
||
// /* 互斥锁上锁 */
|
||
// res = pthread_mutex_lock(&mutex_disp_Refresh);
|
||
// if (res)
|
||
// { /*获取失败*/
|
||
// printf("Thread %d lock failed\n",num);
|
||
|
||
// /* 互斥锁解锁 */
|
||
// pthread_mutex_unlock(&mutex_disp_Refresh);
|
||
|
||
// pthread_exit(NULL);
|
||
// }
|
||
|
||
// Physical_Screen_480x320();
|
||
Physical_Screen_300x240();
|
||
// /* 互斥锁解锁 */
|
||
// pthread_mutex_unlock(&mutex_disp_Refresh);
|
||
// while (1)
|
||
// {
|
||
// sleep(1);
|
||
// }
|
||
|
||
return;
|
||
// lv_example_btn_1();
|
||
// return;
|
||
lv_style_init(&Lock_screen.style);
|
||
lv_style_set_outline_color(&Lock_screen.style,lv_palette_main(LV_PALETTE_BLUE));
|
||
lv_style_set_border_opa(&Lock_screen.style,LV_OPA_0); //设置边框透明度
|
||
// lv_style_set_outline_opa(&Lock_screen.style,LV_OPA_0); //设置外轮廓透明度
|
||
Lock_screen.screen = lv_obj_create(lv_scr_act());
|
||
lv_obj_set_style_bg_color(Lock_screen.screen, lv_color_hex(0x696969), 0); // 设置背景颜色
|
||
lv_obj_set_size(Lock_screen.screen,480,320);
|
||
lv_obj_set_align(Lock_screen.screen,LV_ALIGN_CENTER);
|
||
lv_obj_set_style_pad_all(Lock_screen.screen, 0, 0);
|
||
lv_obj_set_scrollbar_mode(Lock_screen.screen, LV_SCROLLBAR_MODE_OFF);//关闭滚动条
|
||
lv_obj_set_style_radius(Lock_screen.screen,0,0);//设置容器圆角为直角
|
||
lv_obj_add_style(Lock_screen.screen, &Lock_screen.style, 0);
|
||
lv_font_open_Init(72);
|
||
/*Create style with the new font*/
|
||
static lv_style_t style;
|
||
lv_style_init(&style);
|
||
lv_style_set_text_font(&style, MHEIGB_Info[72].font);
|
||
lv_style_set_text_align(&style, LV_TEXT_ALIGN_AUTO);
|
||
/*Create a label with the new style*/
|
||
lv_obj_t * Hello_lable = lv_label_create(Lock_screen.screen);
|
||
|
||
lv_obj_add_style(Hello_lable, &style, 0);
|
||
lv_label_set_text(Hello_lable, "GG Printer");
|
||
lv_obj_align(Hello_lable, LV_ALIGN_CENTER, 0, 0);
|
||
|
||
lv_group_add_obj(Key_Matrix_Group ,Lock_screen.screen);
|
||
lv_obj_add_event_cb(Lock_screen.screen, Lock_screen.event_cb, LV_EVENT_ALL, NULL);
|
||
|
||
|
||
return;
|
||
static lv_style_t Enter_btn_style;
|
||
lv_obj_t * Enter_label;
|
||
// lv_obj_t * Enter_btn = lv_btn_create(lv_scr_act());
|
||
// lv_obj_set_size(Enter_btn,120,60);
|
||
// lv_obj_set_style_bg_color(Enter_btn, lv_color_hex(0xA9A9A9), 0); // 设置背景颜色
|
||
// //lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
|
||
// lv_obj_align(Enter_btn, LV_ALIGN_CENTER, 0, 30);
|
||
// lv_group_add_obj(Key_Matrix_Group ,Enter_btn);
|
||
|
||
lv_font_open_Init(32);
|
||
lv_style_init(&Enter_btn_style);
|
||
// lv_style_set_border_opa(&Enter_btn_style,LV_OPA_0); //设置边框透明度
|
||
// lv_style_set_outline_opa(&Enter_btn_style,LV_OPA_0); //设置外轮廓透明度
|
||
// lv_style_set_outline_color(&Enter_btn_style,lv_palette_main(LV_PALETTE_BLUE)); //设置外罗阔颜色
|
||
// lv_obj_add_style(Enter_btn, &Enter_btn_style, 0);
|
||
// lv_obj_clear_state(Enter_btn, LV_STATE_CHECKED); //清除先前的选择状态
|
||
//Enter_btn_style.body.border.color = LV_COLOR_RED; //设置边框颜色
|
||
lv_style_set_text_font(&Enter_btn_style, MHEIGB_Info[32].font);
|
||
Enter_label = lv_label_create(lv_scr_act());
|
||
lv_obj_add_style(Enter_label, &Enter_btn_style, 0);
|
||
lv_label_set_text(Enter_label, "Enter");
|
||
lv_obj_center(Enter_label);
|
||
lv_obj_add_flag(Enter_label, LV_OBJ_FLAG_CHECKABLE);
|
||
lv_group_add_obj(Key_Matrix_Group ,Enter_label);
|
||
|
||
|
||
|
||
//lv_obj_align(Hello_lable, LV_ALIGN_CENTER, 40, 40);
|
||
//lv_obj_center(Hello_lable);
|
||
//lv_example_btn_1();
|
||
//lv_example_freetype_1(lv_scr_act());
|
||
//lv_btnmatrix_draw_test();
|
||
// desktop_init();
|
||
//return;
|
||
|
||
// Main_Scr = lv_obj_create(lv_scr_act());
|
||
// lv_obj_set_size(Main_Scr,480,320);
|
||
// lv_obj_set_align(Main_Scr,LV_ALIGN_CENTER);
|
||
// lv_obj_set_style_pad_all(Main_Scr, 0, 0);
|
||
// lv_obj_set_scrollbar_mode(Main_Scr, LV_SCROLLBAR_MODE_OFF);//关闭滚动条
|
||
// lv_obj_set_style_radius(Main_Scr,0,0);//设置容器圆角为直角
|
||
// lv_obj_clear_flag(Main_Scr, LV_OBJ_FLAG_SCROLLABLE);//禁止滚动
|
||
// lv_obj_set_flex_flow(Main_Scr, LV_FLEX_FLOW_ROW); // 设置对象容器使用基于行的流失弹性布局flex,设置超出部分换行模式
|
||
// lv_obj_set_flex_align(Main_Scr, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_CENTER);
|
||
|
||
|
||
|
||
|
||
//lv_example_freetype_1(lv_scr_act());
|
||
// lv_example_imgbtn_1();
|
||
|
||
// Set_Scr = lv_obj_create(Main_Scr);
|
||
// lv_obj_set_size(Set_Scr,370,470);
|
||
// lv_obj_set_align(Set_Scr,LV_ALIGN_LEFT_MID);
|
||
// lv_obj_set_style_pad_all(Set_Scr, 0, 0);
|
||
// lv_obj_set_scrollbar_mode(Set_Scr, LV_SCROLLBAR_MODE_OFF);//关闭滚动条
|
||
// //lv_obj_set_scroll_dir(Columnlab_Scr,LV_DIR_HOR);//设置滚动方向
|
||
// lv_obj_clear_flag(Set_Scr, LV_OBJ_FLAG_SCROLLABLE);//禁止滚动
|
||
|
||
return;
|
||
|
||
// Columnlab_Scr = lv_obj_create(Main_Scr);
|
||
// lv_obj_set_size(Columnlab_Scr,100,470);
|
||
// lv_obj_set_align(Columnlab_Scr,LV_ALIGN_RIGHT_MID);
|
||
// lv_obj_set_style_pad_all(Columnlab_Scr, 0, 0);
|
||
// lv_obj_set_scrollbar_mode(Columnlab_Scr, LV_SCROLLBAR_MODE_OFF);//关闭滚动条
|
||
// //lv_obj_set_scroll_dir(Columnlab_Scr,LV_DIR_HOR);//设置滚动方向
|
||
// lv_obj_set_style_bg_color(Columnlab_Scr, lv_color_hex(0xF98E2D), 0); // 设置背景颜色
|
||
// lv_obj_clear_flag(Columnlab_Scr, LV_OBJ_FLAG_SCROLLABLE);//禁止滚动
|
||
// lv_obj_set_flex_flow(Columnlab_Scr, LV_FLEX_FLOW_COLUMN); // 设置对象容器使用基于行的流失弹性布局flex,设置超出部分换行模式
|
||
// lv_obj_set_flex_align(Columnlab_Scr, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_CENTER);
|
||
|
||
Columnlab_Scr = lv_obj_create(Main_Scr);
|
||
lv_obj_set_size(Columnlab_Scr,100,470);
|
||
lv_obj_set_align(Columnlab_Scr,LV_ALIGN_RIGHT_MID);
|
||
lv_obj_set_scrollbar_mode(Columnlab_Scr, LV_SCROLLBAR_MODE_OFF);
|
||
lv_obj_set_flex_flow(Columnlab_Scr, LV_FLEX_FLOW_COLUMN);
|
||
lv_obj_set_flex_align(Columnlab_Scr, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||
lv_obj_set_scroll_snap_y(Columnlab_Scr, LV_SCROLL_SNAP_CENTER);
|
||
lv_obj_set_style_bg_opa(Columnlab_Scr, LV_OPA_0, LV_PART_MAIN);
|
||
lv_obj_set_style_bg_color(Columnlab_Scr, lv_color_black(), LV_PART_MAIN);
|
||
lv_obj_set_style_border_width(Columnlab_Scr, 0, LV_PART_MAIN);
|
||
lv_obj_set_style_pad_column(Columnlab_Scr, 60, LV_PART_MAIN); //图标之间的间隙
|
||
lv_obj_center(Columnlab_Scr);
|
||
|
||
for(i=0;i<5;i++)
|
||
{
|
||
printf("imgbtn[%d]:%s\n",Button_Group[0][i].event_num,Button_Group[0][i].src_left);
|
||
Button_Group[0][i].btn = lv_imgbtn_create(Columnlab_Scr);
|
||
lv_obj_t * imgbtn = Button_Group[0][i].btn;
|
||
lv_imgbtn_set_src(imgbtn, LV_IMGBTN_STATE_RELEASED, Button_Group[0][i].src_left, NULL, NULL);
|
||
lv_obj_align(imgbtn, LV_ALIGN_CENTER, 0, 0);
|
||
lv_obj_set_size(imgbtn,64,64);
|
||
//lv_obj_add_event_cb(imgbtn, event_handler, LV_EVENT_CLICKED, NULL);
|
||
lv_obj_add_event_cb(imgbtn, button_event_cb, LV_EVENT_ALL, NULL);
|
||
}
|
||
|
||
|
||
|
||
lv_obj_t * label;
|
||
|
||
lv_obj_t * btn1 = lv_btn_create(Set_Scr);
|
||
lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
|
||
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -100);
|
||
lv_obj_set_size(btn1, 110, 110); // 设置控件大小
|
||
|
||
label = lv_label_create(btn1);
|
||
lv_label_set_text(label, "UP");
|
||
lv_obj_center(label);
|
||
|
||
|
||
lv_obj_t * label2;
|
||
|
||
lv_obj_t * btn2 = lv_btn_create(Set_Scr);
|
||
lv_obj_add_event_cb(btn2, event_handlerdown, LV_EVENT_ALL, NULL);
|
||
lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 100);
|
||
lv_obj_set_size(btn2, 110, 110); // 设置控件大小
|
||
|
||
label = lv_label_create(btn2);
|
||
lv_label_set_text(label, "Down");
|
||
lv_obj_center(label);
|
||
|
||
|
||
|
||
|
||
// uint32_t mid_btn_index = (lv_obj_get_child_cnt(Columnlab_Scr) - 1) / 2;
|
||
// for (uint32_t i = 0; i < mid_btn_index; i++)
|
||
// {
|
||
// lv_obj_move_to_index(lv_obj_get_child(Columnlab_Scr, -1), 0);
|
||
// }
|
||
/*当按钮数为偶数时,确保按钮居中*/
|
||
// lv_obj_scroll_to_view(lv_obj_get_child(Columnlab_Scr, mid_btn_index), LV_ANIM_OFF);
|
||
lv_obj_scroll_to_view(Button_Group[0][0].btn, LV_ANIM_OFF);
|
||
|
||
// lv_obj_t* cont = lv_obj_create(lv_scr_act()); // 创建一个对象容器 cont
|
||
// lv_obj_set_size(cont, 350, 420); // 设置对象容器大小
|
||
// lv_obj_align(cont, LV_ALIGN_TOP_MID, 0, 5); // 设置对象容器基于屏幕中间对齐
|
||
// lv_obj_set_style_pad_all(cont, 25, LV_PART_MAIN); // 设置对象容器内部 item 与容器边的上下左右间距
|
||
// //lv_obj_set_style_pad_row(cont, 10, LV_PART_MAIN); // 设置对象容器内部 item 之间的行间距
|
||
// //lv_obj_set_style_pad_column(cont, 10, LV_PART_MAIN); // 设置对象容器内部 item 之间的列间距
|
||
// lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE); // 取消滚动条
|
||
|
||
// lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW_WRAP); // 设置对象容器使用基于行的流失弹性布局flex,设置超出部分换行模式
|
||
|
||
// /**
|
||
// * 设置容器弹性模式
|
||
// * 1. 容器指针
|
||
// * 2. LV_FLEX_ALIGN_SPACE_EVENLY 均匀分部子元素之间的间距
|
||
// * 3. LV_FLEX_ALIGN_END 容器中每行所有的子元素底部对齐
|
||
// * 4. LV_FLEX_ALIGN_CENTER 容器中内容的子元素向容器中心对齐
|
||
// */
|
||
// lv_obj_set_flex_align(cont, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_CENTER);
|
||
|
||
|
||
// Menulable = lv_obj_create(Columnlab_Scr);
|
||
// lv_obj_set_width(Menulable, 100);
|
||
// lv_label_set_text(Menulable,"Set");
|
||
// lv_obj_align(Menulable,LV_ALIGN_TOP_MID);
|
||
|
||
|
||
// lv_obj_t * imgbtn1 = lv_imgbtn_create(Columnlab_Scr);
|
||
// lv_imgbtn_set_src(imgbtn1, LV_IMGBTN_STATE_RELEASED, "A:/root/nfs_tools/lvgl_imgs/Home2.bin", NULL, NULL);
|
||
// lv_obj_align(imgbtn1, LV_ALIGN_CENTER, 0, 0);
|
||
// lv_obj_set_size(imgbtn1,64,64);
|
||
// lv_obj_add_event_cb(imgbtn1, event_handler, LV_EVENT_CLICKED, NULL);
|
||
|
||
|
||
// lv_obj_t * textarea = lv_textarea_create(Columnlab_Scr);
|
||
|
||
|
||
// static lv_style_t text_area_style;
|
||
// lv_style_reset(&text_area_style); // 重置样式
|
||
// lv_style_init(&text_area_style); // 初始化样式
|
||
// lv_style_set_border_width(&text_area_style, 0); // 设置边框宽度
|
||
// //lv_style_set_radius(&text_area_style, 0); // 设置样式的圆角弧度
|
||
// lv_style_set_pad_all(&text_area_style, 8); // 设置样式底部padding填充宽度
|
||
// lv_style_set_text_font(&text_area_style, &lv_font_montserrat_20); //设置字体
|
||
// lv_obj_add_style(textarea, &text_area_style, 0); // 给对象添加样式
|
||
|
||
// lv_textarea_set_max_length(textarea, 6); // 设置最大输入长度
|
||
// lv_textarea_set_one_line(textarea, true); // 只显示一行
|
||
// lv_textarea_set_password_mode(textarea, false); // 关闭密码模式
|
||
// lv_obj_set_size(textarea, 110, 40); // 设置对象大小
|
||
// lv_obj_align(textarea, LV_ALIGN_TOP_MID, 0, 0); // 设置对齐
|
||
// lv_obj_set_style_text_align(textarea, LV_TEXT_ALIGN_CENTER, 0);
|
||
|
||
|
||
// lv_obj_t * obj_btnm = lv_btnmatrix_create(Columnlab_Scr); // 创建一个按钮矩阵对象
|
||
// lv_btnmatrix_set_one_checked(obj_btnm, true); // 启用“一次检查”功能,允许一次只检查一个按钮。
|
||
// lv_obj_set_size(obj_btnm, 110, 410); // 设置控件大小
|
||
// lv_obj_align(obj_btnm, LV_ALIGN_CENTER, 0, 10);
|
||
// lv_obj_clear_flag(obj_btnm, LV_OBJ_FLAG_CLICK_FOCUSABLE); // 按钮按下的是时候焦点才聚集到该控件,确保按钮按下后焦点聚集到文本框
|
||
// lv_btnmatrix_set_map(obj_btnm, btnm_map); // 给按钮矩阵添加键盘映射
|
||
// // lv_obj_clear_flag(obj_btnm, LV_OBJ_FLAG_SCROLLABLE);//禁止滚动
|
||
// int i = 0;
|
||
// for (i = 0; i < 4; i++)
|
||
// {
|
||
// lv_btnmatrix_set_btn_ctrl(obj_btnm, i, LV_BTNMATRIX_CTRL_NO_REPEAT); // 长按按钮时禁用重复
|
||
// }
|
||
// lv_obj_set_style_radius(obj_btnm, 0, 0); // 设置样式的圆角弧度
|
||
// lv_obj_set_style_border_width(obj_btnm, 0, 0); //设置边框宽度
|
||
// lv_obj_set_style_bg_color(obj_btnm, lv_color_hex(0xFFFFFF), 0); // 设置背景颜色
|
||
// lv_obj_set_style_bg_opa(obj_btnm, LV_OPA_0, 0); // 设置样式背景的不透明度
|
||
// lv_obj_set_style_text_font(obj_btnm, &lv_font_montserrat_20, 0); //设置字体
|
||
// lv_obj_add_event_cb(obj_btnm, btnmatrix_event_callback, LV_EVENT_ALL, (void *)textarea); // 按钮矩阵添加事件回调函数
|
||
// lv_textarea_set_text(textarea, "Home");
|
||
|
||
|
||
// lv_obj_t* back_image = lv_img_create(lv_scr_act());
|
||
// lv_img_set_src(back_image, "A:/root/nfs_tools/lvgl_imgs/Home.bin");
|
||
// lv_obj_center(back_image);
|
||
|
||
} |