From 9527dd21ceed093a0d1f927d4f2caf36240e67c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=90=83=E6=B2=B9=E7=82=B8=E9=B8=A1?= <1425962791@qq.com> Date: Thu, 9 Oct 2025 19:54:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0set=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Power_Pico/Middlewares/LVGL/lv_conf.h | 2 +- .../Middlewares/LVGL/porting/lv_port_disp.c | 9 +- Power_Pico/User/GUI/screens/ui_SetPage.c | 135 ++++++++++++++++++ Power_Pico/User/GUI/screens/ui_SetPage.h | 26 ++++ Power_Pico/User/GUI/screens/ui_mainPage.c | 4 +- Power_Pico/User/GUI/ui.c | 19 ++- 6 files changed, 186 insertions(+), 9 deletions(-) create mode 100644 Power_Pico/User/GUI/screens/ui_SetPage.c create mode 100644 Power_Pico/User/GUI/screens/ui_SetPage.h diff --git a/Power_Pico/Middlewares/LVGL/lv_conf.h b/Power_Pico/Middlewares/LVGL/lv_conf.h index e2cd78c..6e2c3bd 100644 --- a/Power_Pico/Middlewares/LVGL/lv_conf.h +++ b/Power_Pico/Middlewares/LVGL/lv_conf.h @@ -485,7 +485,7 @@ #define LV_FONT_MONTSERRAT_10 0 #define LV_FONT_MONTSERRAT_12 0 #define LV_FONT_MONTSERRAT_14 1 -#define LV_FONT_MONTSERRAT_16 0 +#define LV_FONT_MONTSERRAT_16 1 #define LV_FONT_MONTSERRAT_18 1 #define LV_FONT_MONTSERRAT_20 0 #define LV_FONT_MONTSERRAT_22 0 diff --git a/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c b/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c index cca729a..2fd34ff 100644 --- a/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c +++ b/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c @@ -79,10 +79,10 @@ void lv_port_disp_init(void) * Two buffers for partial rendering * In flush_cb DMA or similar hardware should be used to update the display in the background.*/ LV_ATTRIBUTE_MEM_ALIGN - static uint8_t buf_2_1[MY_DISP_HOR_RES * MY_DISP_VER_RES / 10 * BYTE_PER_PIXEL]; + static uint8_t buf_2_1[MY_DISP_HOR_RES * MY_DISP_VER_RES / 8 * BYTE_PER_PIXEL]; LV_ATTRIBUTE_MEM_ALIGN - static uint8_t buf_2_2[MY_DISP_HOR_RES * MY_DISP_VER_RES / 10 * BYTE_PER_PIXEL]; + static uint8_t buf_2_2[MY_DISP_HOR_RES * MY_DISP_VER_RES / 8 * BYTE_PER_PIXEL]; lv_display_set_buffers(disp, buf_2_1, buf_2_2, sizeof(buf_2_1), LV_DISPLAY_RENDER_MODE_PARTIAL); #elif BUFFER_METHOD == 3 @@ -134,6 +134,11 @@ void disp_disable_update(void) *'lv_display_flush_ready()' has to be called when it's finished.*/ static void disp_flush(lv_display_t * disp_drv, const lv_area_t * area, uint8_t * px_map) { + lv_display_rotation_t rotation = lv_display_get_rotation(disp_drv); + lv_area_t rotated_area; + if(rotation != LV_DISPLAY_ROTATION_0) { + LCD_SetRotation(rotation * 90); + } if(disp_flush_enabled) { LCD_Color_Render(area->x1,area->y1,area->x2,area->y2, (uint16_t *)px_map); } diff --git a/Power_Pico/User/GUI/screens/ui_SetPage.c b/Power_Pico/User/GUI/screens/ui_SetPage.c new file mode 100644 index 0000000..2c7a4f3 --- /dev/null +++ b/Power_Pico/User/GUI/screens/ui_SetPage.c @@ -0,0 +1,135 @@ +// This file was generated by SquareLine Studio +// SquareLine Studio version: SquareLine Studio 1.5.3 +// LVGL version: 9.2.2 +// Project name: PowerPico + +#include "../ui.h" + +lv_obj_t * ui_SetPage = NULL; +static lv_obj_t * ui_PanelBL = NULL; +static lv_obj_t * ui_SliderBL = NULL; +static lv_obj_t * ui_LabelBL = NULL; +static lv_obj_t * ui_PanelKS = NULL; +static lv_obj_t * ui_SwitchKS = NULL; +static lv_obj_t * ui_LabelKS = NULL; +static lv_obj_t * ui_PanelLang = NULL; +static lv_obj_t * ui_SwitchLang = NULL; +static lv_obj_t * ui_LabelLang = NULL; +static lv_obj_t * ui_PanelAbout = NULL; +static lv_obj_t * ui_LabelAbout = NULL; + +// event funtions + +#include "key.h" +void ui_set_page_key_handler(uint8_t key_id) +{ + if(key_id == KEYB_NUM) { + PageManager_next(); + } +} + +// build funtions + +void ui_SetPage_screen_init(void) +{ + ui_SetPage = lv_obj_create(NULL); + + ui_PanelBL = lv_obj_create(ui_SetPage); + lv_obj_set_width(ui_PanelBL, 234); + lv_obj_set_height(ui_PanelBL, 65); + lv_obj_set_x(ui_PanelBL, 0); + lv_obj_set_y(ui_PanelBL, 5); + lv_obj_set_align(ui_PanelBL, LV_ALIGN_TOP_MID); + lv_obj_add_flag(ui_PanelBL, LV_OBJ_FLAG_CHECKABLE); /// Flags + lv_obj_remove_flag(ui_PanelBL, LV_OBJ_FLAG_SCROLLABLE); /// Flags + lv_obj_set_style_bg_color(ui_PanelBL, lv_color_hex(0x606060), LV_PART_MAIN | LV_STATE_CHECKED); + lv_obj_set_style_bg_opa(ui_PanelBL, 255, LV_PART_MAIN | LV_STATE_CHECKED); + + ui_SliderBL = lv_slider_create(ui_PanelBL); + lv_slider_set_value(ui_SliderBL, 50, LV_ANIM_OFF); + if(lv_slider_get_mode(ui_SliderBL) == LV_SLIDER_MODE_RANGE) lv_slider_set_left_value(ui_SliderBL, 0, LV_ANIM_OFF); + lv_obj_set_width(ui_SliderBL, 200); + lv_obj_set_height(ui_SliderBL, 10); + lv_obj_set_align(ui_SliderBL, LV_ALIGN_BOTTOM_MID); + + //Compensating for LVGL9.1 draw crash with bar/slider max value when top-padding is nonzero and right-padding is 0 + if(lv_obj_get_style_pad_top(ui_SliderBL, LV_PART_MAIN) > 0) lv_obj_set_style_pad_right(ui_SliderBL, + lv_obj_get_style_pad_right(ui_SliderBL, LV_PART_MAIN) + 1, LV_PART_MAIN); + ui_LabelBL = lv_label_create(ui_PanelBL); + lv_obj_set_width(ui_LabelBL, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_LabelBL, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_LabelBL, 0); + lv_obj_set_y(ui_LabelBL, -5); + lv_label_set_text(ui_LabelBL, "Screen Brightness :"); + lv_obj_set_style_text_font(ui_LabelBL, &lv_font_montserrat_16, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_PanelKS = lv_obj_create(ui_SetPage); + lv_obj_set_width(ui_PanelKS, 234); + lv_obj_set_height(ui_PanelKS, 45); + lv_obj_set_x(ui_PanelKS, 0); + lv_obj_set_y(ui_PanelKS, 75); + lv_obj_set_align(ui_PanelKS, LV_ALIGN_TOP_MID); + lv_obj_add_flag(ui_PanelKS, LV_OBJ_FLAG_CHECKABLE); /// Flags + lv_obj_remove_flag(ui_PanelKS, LV_OBJ_FLAG_SCROLLABLE); /// Flags + lv_obj_set_style_bg_color(ui_PanelKS, lv_color_hex(0x606060), LV_PART_MAIN | LV_STATE_CHECKED); + lv_obj_set_style_bg_opa(ui_PanelKS, 255, LV_PART_MAIN | LV_STATE_CHECKED); + + ui_SwitchKS = lv_switch_create(ui_PanelKS); + lv_obj_set_width(ui_SwitchKS, 50); + lv_obj_set_height(ui_SwitchKS, 25); + lv_obj_set_align(ui_SwitchKS, LV_ALIGN_RIGHT_MID); + lv_obj_add_state(ui_SwitchKS, LV_STATE_CHECKED); /// States + + ui_LabelKS = lv_label_create(ui_PanelKS); + lv_obj_set_width(ui_LabelKS, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_LabelKS, LV_SIZE_CONTENT); /// 1 + lv_obj_set_align(ui_LabelKS, LV_ALIGN_LEFT_MID); + lv_label_set_text(ui_LabelKS, "Enable key sound"); + lv_obj_set_style_text_font(ui_LabelKS, &lv_font_montserrat_16, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_PanelLang = lv_obj_create(ui_SetPage); + lv_obj_set_width(ui_PanelLang, 234); + lv_obj_set_height(ui_PanelLang, 45); + lv_obj_set_x(ui_PanelLang, 0); + lv_obj_set_y(ui_PanelLang, 125); + lv_obj_set_align(ui_PanelLang, LV_ALIGN_TOP_MID); + lv_obj_add_flag(ui_PanelLang, LV_OBJ_FLAG_CHECKABLE); /// Flags + lv_obj_remove_flag(ui_PanelLang, LV_OBJ_FLAG_SCROLLABLE); /// Flags + lv_obj_set_style_bg_color(ui_PanelLang, lv_color_hex(0x606060), LV_PART_MAIN | LV_STATE_CHECKED); + lv_obj_set_style_bg_opa(ui_PanelLang, 255, LV_PART_MAIN | LV_STATE_CHECKED); + + ui_SwitchLang = lv_switch_create(ui_PanelLang); + lv_obj_set_width(ui_SwitchLang, 50); + lv_obj_set_height(ui_SwitchLang, 25); + lv_obj_set_align(ui_SwitchLang, LV_ALIGN_RIGHT_MID); + + ui_LabelLang = lv_label_create(ui_PanelLang); + lv_obj_set_width(ui_LabelLang, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_LabelLang, LV_SIZE_CONTENT); /// 1 + lv_obj_set_align(ui_LabelLang, LV_ALIGN_LEFT_MID); + lv_label_set_text(ui_LabelLang, "Enable Chinese"); + lv_obj_set_style_text_font(ui_LabelLang, &lv_font_montserrat_16, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_PanelAbout = lv_obj_create(ui_SetPage); + lv_obj_set_width(ui_PanelAbout, 234); + lv_obj_set_height(ui_PanelAbout, 100); + lv_obj_set_x(ui_PanelAbout, 0); + lv_obj_set_y(ui_PanelAbout, 175); + lv_obj_set_align(ui_PanelAbout, LV_ALIGN_TOP_MID); + lv_obj_add_flag(ui_PanelAbout, LV_OBJ_FLAG_CHECKABLE); /// Flags + lv_obj_remove_flag(ui_PanelAbout, LV_OBJ_FLAG_SCROLLABLE); /// Flags + lv_obj_set_style_bg_color(ui_PanelAbout, lv_color_hex(0x606060), LV_PART_MAIN | LV_STATE_CHECKED); + lv_obj_set_style_bg_opa(ui_PanelAbout, 255, LV_PART_MAIN | LV_STATE_CHECKED); + + ui_LabelAbout = lv_label_create(ui_PanelAbout); + lv_obj_set_width(ui_LabelAbout, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_LabelAbout, LV_SIZE_CONTENT); /// 1 + lv_label_set_text(ui_LabelAbout, "About\nPower-Pico\nA uA current meter\nV 1.0.0"); + lv_obj_set_style_text_font(ui_LabelAbout, &lv_font_montserrat_16, LV_PART_MAIN | LV_STATE_DEFAULT); + +} + +void ui_SetPage_screen_destroy(void) +{ + +} diff --git a/Power_Pico/User/GUI/screens/ui_SetPage.h b/Power_Pico/User/GUI/screens/ui_SetPage.h new file mode 100644 index 0000000..beb4a85 --- /dev/null +++ b/Power_Pico/User/GUI/screens/ui_SetPage.h @@ -0,0 +1,26 @@ +// This file was generated by SquareLine Studio +// SquareLine Studio version: SquareLine Studio 1.5.3 +// LVGL version: 9.2.2 +// Project name: PowerPico + +#ifndef UI_SETPAGE_H +#define UI_SETPAGE_H + +#ifdef __cplusplus +extern "C" { +#endif + +// SCREEN: ui_SetPage +extern void ui_SetPage_screen_init(void); +extern void ui_SetPage_screen_destroy(void); +extern lv_obj_t * ui_SetPage; +void ui_set_page_key_handler(uint8_t key_id); + +// CUSTOM VARIABLES + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif + diff --git a/Power_Pico/User/GUI/screens/ui_mainPage.c b/Power_Pico/User/GUI/screens/ui_mainPage.c index e8e1954..86f14d5 100644 --- a/Power_Pico/User/GUI/screens/ui_mainPage.c +++ b/Power_Pico/User/GUI/screens/ui_mainPage.c @@ -36,8 +36,10 @@ static void full_screen_refresh(void) { static void set_val_cur_label(float voltage, float current) { char buf[16]; + // voltage sprintf(buf, "%.2f", voltage); lv_label_set_text(ui_LabelValt, buf); + // current if(current >= 1000000.0) { current = current / 1000000.0; sprintf(buf, "%.2f", current); @@ -106,7 +108,7 @@ static void set_val_cur_label(float voltage, float current) static void _flush_timer_cb() { timecount++; - if(timecount >= 4) { // 2s + if(timecount >= 2) { // 1s timecount = 0; full_screen_refresh(); } diff --git a/Power_Pico/User/GUI/ui.c b/Power_Pico/User/GUI/ui.c index 7d678a5..2dbe5ac 100644 --- a/Power_Pico/User/GUI/ui.c +++ b/Power_Pico/User/GUI/ui.c @@ -4,6 +4,7 @@ #include "./ui.h" #include "./screens/ui_mainPage.h" #include "./screens/ui_chartPage.h" +#include "./screens/ui_SetPage.h" ///////////////////// VARIABLES //////////////////// @@ -16,12 +17,19 @@ Page_t pages[] = { .key_event_handler = ui_main_page_key_handler, .name = "Main Page" }, + // { + // .init = ui_main_screen_init, + // .deinit = ui_main_screen_destroy, + // .page_obj = &ui_HomeScreen, + // .key_event_handler = ui_main_page_key_handler, + // .name = "Chart Page" + // }, { - .init = ui_ChartPage_screen_init, - .deinit = ui_ChartPage_screen_destroy, - .page_obj = &ui_ChartPage, - .key_event_handler = ui_chart_page_key_handler, - .name = "Chart Page" + .init = ui_SetPage_screen_init, + .deinit = ui_SetPage_screen_destroy, + .page_obj = &ui_SetPage, + .key_event_handler = ui_set_page_key_handler, + .name = "Set Page" }, // 可以在这里添加更多页面 }; @@ -53,6 +61,7 @@ void ui_init(void) PageManager_register(&pages[i]); } PageManager_load_init_screen(); + lv_display_set_rotation(dispp, LV_DISP_ROTATION_180); //timer // lv_timer_t * ui_MainTimer = lv_timer_create(main_timer, 1000, NULL);