From 848f1173a9bd2e773397a13935221e25c745659a 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: Sun, 2 Nov 2025 17:02:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A1=AC=E4=BB=B6=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Power_Pico/BSP/EEPROM/BL24C02.c | 67 ++++++++++++++++++- Power_Pico/BSP/EEPROM/BL24C02.h | 23 ++++--- .../Middlewares/LVGL/porting/lv_port_disp.c | 3 +- Power_Pico/User/GUI/screens/ui_SetPage.c | 56 ++++++++++++---- Power_Pico/User/GUI/screens/ui_mainPage.c | 18 +++-- Power_Pico/User/GUI/ui.c | 2 +- Power_Pico/User/Tasks/Src/user_KeyTask.c | 3 +- 7 files changed, 140 insertions(+), 32 deletions(-) diff --git a/Power_Pico/BSP/EEPROM/BL24C02.c b/Power_Pico/BSP/EEPROM/BL24C02.c index 131fecb..f3dd9a7 100644 --- a/Power_Pico/BSP/EEPROM/BL24C02.c +++ b/Power_Pico/BSP/EEPROM/BL24C02.c @@ -1,7 +1,16 @@ #include "BL24C02.h" #include "i2c.h" +// hardware settings +#include "lcd_init.h" -SysSettings_T sys_settings = { +typedef struct { + uint8_t backlight_level; // 0-100 + uint8_t key_sound_enable; // 0:disable, 1:enable + uint8_t language_select; // 0:English, 1:Chinese + uint16_t rotation; // 0, 90, 180, 270 +} SysSettings_T; + +static SysSettings_T sys_settings = { .backlight_level = 50, .key_sound_enable = 1, .language_select = 0, @@ -123,3 +132,59 @@ bool EEPROM_UpdateCommand_Check(void) return false; } } + +// Set functions + +void Sys_Set_BacklightLevel(uint8_t level) +{ + if(level <= 100 && level >= 10) { + sys_settings.backlight_level = level; + LCD_Set_Light(level); + } +} + +void Sys_Set_KeySoundEnable(bool enable) +{ + if(enable) { + sys_settings.key_sound_enable = 1; + } else { + sys_settings.key_sound_enable = 0; + } +} + +void Sys_Set_LanguageSelect(uint8_t lang) +{ + if(lang <= 1) { + sys_settings.language_select = lang; + } +} + +void Sys_Set_Rotation(uint16_t rotation) +{ + if(rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270) { + sys_settings.rotation = rotation; + LCD_SetRotation(rotation); + } +} + +// Get functions + +uint8_t Sys_Get_BacklightLevel(void) +{ + return sys_settings.backlight_level; +} + +uint8_t Sys_Get_KeySoundEnable(void) +{ + return sys_settings.key_sound_enable; +} + +uint8_t Sys_Get_LanguageSelect(void) +{ + return sys_settings.language_select; +} + +uint16_t Sys_Get_Rotation(void) +{ + return sys_settings.rotation; +} diff --git a/Power_Pico/BSP/EEPROM/BL24C02.h b/Power_Pico/BSP/EEPROM/BL24C02.h index c20df71..f30323f 100644 --- a/Power_Pico/BSP/EEPROM/BL24C02.h +++ b/Power_Pico/BSP/EEPROM/BL24C02.h @@ -7,19 +7,24 @@ #define BL24C02_ADDRESS 0x50 -typedef struct { - uint8_t backlight_level; // 0-100 - uint8_t key_sound_enable; // 0:disable, 1:enable - uint8_t language_select; // 0:English, 1:Chinese - uint16_t rotation; // 0, 90, 180, 270 -} SysSettings_T; - -extern SysSettings_T sys_settings; - uint8_t EEPROM_Init_Check(void); void EEPROM_SysSetting_Save(void); void EEPROM_SysSetting_Get(void); void EEPROM_UpdateCommand_Write(bool is_update); bool EEPROM_UpdateCommand_Check(void); +// set functions + +void Sys_Set_BacklightLevel(uint8_t level); +void Sys_Set_KeySoundEnable(bool enable); +void Sys_Set_LanguageSelect(uint8_t lang); +void Sys_Set_Rotation(uint16_t rotation); + +// get functions + +uint8_t Sys_Get_BacklightLevel(void); +uint8_t Sys_Get_KeySoundEnable(void); +uint8_t Sys_Get_LanguageSelect(void); +uint16_t Sys_Get_Rotation(void); + #endif diff --git a/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c b/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c index 2086765..a92cf4b 100644 --- a/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c +++ b/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c @@ -109,7 +109,8 @@ static void disp_init(void) /*You code here*/ LCD_Init(); LCD_Fill(0,0, LCD_W, LCD_H, BLACK); - LCD_Set_Light(50); + #include "BL24C02.h" + LCD_Set_Light(Sys_Get_BacklightLevel()); } volatile bool disp_flush_enabled = true; diff --git a/Power_Pico/User/GUI/screens/ui_SetPage.c b/Power_Pico/User/GUI/screens/ui_SetPage.c index 0fc7088..660aa9e 100644 --- a/Power_Pico/User/GUI/screens/ui_SetPage.c +++ b/Power_Pico/User/GUI/screens/ui_SetPage.c @@ -57,19 +57,23 @@ void ui_set_page_key_handler(uint8_t key_id) slider_value += 10; if(slider_value > 100) slider_value = 100; lv_slider_set_value(ui_SliderBL, slider_value, LV_ANIM_ON); + Sys_Set_BacklightLevel(slider_value); } else if (key_id == KEYN_NUM) { int16_t slider_value = lv_slider_get_value(ui_SliderBL); slider_value -= 10; - if(slider_value < 0) slider_value = 10; + if(slider_value < 10) slider_value = 10; lv_slider_set_value(ui_SliderBL, slider_value, LV_ANIM_ON); + Sys_Set_BacklightLevel(slider_value); } break; // key sound case 1: if (key_id == KEYY_NUM) { lv_obj_add_state(ui_SwitchKS, LV_STATE_CHECKED); + Sys_Set_KeySoundEnable(1); } else if(key_id == KEYN_NUM) { lv_obj_clear_state(ui_SwitchKS, LV_STATE_CHECKED); + Sys_Set_KeySoundEnable(0); } break; @@ -80,26 +84,23 @@ void ui_set_page_key_handler(uint8_t key_id) // chose rotation case 3: + uint16_t rotation = Sys_Get_Rotation(); if (key_id == KEYY_NUM) { - sys_settings.rotation = (sys_settings.rotation + 360 + 90) % 360; - lv_display_rotation_t rotation = sys_settings.rotation / 90; - lv_display_set_rotation(lv_display_get_default(), rotation); - ui_full_screen_refresh(ui_SetPage); + rotation = (rotation + 360 + 90) % 360; } else if(key_id == KEYN_NUM) { - sys_settings.rotation = (sys_settings.rotation + 360 - 90) % 360; - lv_display_rotation_t rotation = sys_settings.rotation / 90; - lv_display_set_rotation(lv_display_get_default(), rotation); - ui_full_screen_refresh(ui_SetPage); + rotation = (rotation + 360 - 90) % 360; } - if (sys_settings.rotation == 0) { + if (rotation == 0) { lv_label_set_text(ui_LabelRotNum, "< 0 >"); - } else if (sys_settings.rotation == 90) { + } else if (rotation == 90) { lv_label_set_text(ui_LabelRotNum, "< 90 >"); - } else if (sys_settings.rotation == 180) { + } else if (rotation == 180) { lv_label_set_text(ui_LabelRotNum, "< 180 >"); - } else if (sys_settings.rotation == 270) { + } else if (rotation == 270) { lv_label_set_text(ui_LabelRotNum, "< 270 >"); } + Sys_Set_Rotation(rotation); + ui_full_screen_refresh(ui_SetPage); break; // about @@ -108,6 +109,32 @@ void ui_set_page_key_handler(uint8_t key_id) break; } + // save settings to eeprom + EEPROM_SysSetting_Save(); + } +} + +static void _setting_init(void) { + + // backlight + lv_slider_set_value(ui_SliderBL, Sys_Get_BacklightLevel(), LV_ANIM_OFF); + + // key sound + if(Sys_Get_KeySoundEnable()) + lv_obj_add_state(ui_SwitchKS, LV_STATE_CHECKED); + else + lv_obj_clear_state(ui_SwitchKS, LV_STATE_CHECKED); + + // lcd rotation + uint16_t rotation = Sys_Get_Rotation(); + if (rotation == 0) { + lv_label_set_text(ui_LabelRotNum, "< 0 >"); + } else if (rotation == 90) { + lv_label_set_text(ui_LabelRotNum, "< 90 >"); + } else if (rotation == 180) { + lv_label_set_text(ui_LabelRotNum, "< 180 >"); + } else if (rotation == 270) { + lv_label_set_text(ui_LabelRotNum, "< 270 >"); } } @@ -235,6 +262,9 @@ void ui_SetPage_screen_init(void) 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); + // init setting values + _setting_init(); + // store panels in array panels[0] = ui_PanelBL; panels[1] = ui_PanelKS; diff --git a/Power_Pico/User/GUI/screens/ui_mainPage.c b/Power_Pico/User/GUI/screens/ui_mainPage.c index 9bc8d60..334cc94 100644 --- a/Power_Pico/User/GUI/screens/ui_mainPage.c +++ b/Power_Pico/User/GUI/screens/ui_mainPage.c @@ -36,15 +36,21 @@ void ui_main_page_key_handler(uint8_t key_id) } else if (key_id == KEYL_NUM) { // rotation - 90 degrees // rotation – LV_DISPLAY_ROTATION_0/90/180/270 - sys_settings.rotation = (sys_settings.rotation + 360 - 90) % 360; - lv_display_rotation_t rotation = sys_settings.rotation / 90; - lv_display_set_rotation(lv_display_get_default(), rotation); + uint16_t rotation = Sys_Get_Rotation(); + rotation = (rotation + 360 - 90) % 360; + // set rotation value + Sys_Set_Rotation(rotation); + // save settings to eeprom + EEPROM_SysSetting_Save(); ui_full_screen_refresh(ui_HomeScreen); } else if (key_id == KEYR_NUM) { // rotation + 90 degrees - sys_settings.rotation = (sys_settings.rotation + 360 + 90) % 360; - lv_display_rotation_t rotation = sys_settings.rotation / 90; - lv_display_set_rotation(lv_display_get_default(), rotation); + uint16_t rotation = Sys_Get_Rotation(); + rotation = (rotation + 360 + 90) % 360; + // set rotation value + Sys_Set_Rotation(rotation); + // save settings to eeprom + EEPROM_SysSetting_Save(); ui_full_screen_refresh(ui_HomeScreen); } } diff --git a/Power_Pico/User/GUI/ui.c b/Power_Pico/User/GUI/ui.c index c00f0b9..612a521 100644 --- a/Power_Pico/User/GUI/ui.c +++ b/Power_Pico/User/GUI/ui.c @@ -72,7 +72,7 @@ void ui_init(void) PageManager_register(&pages[i]); } PageManager_load_init_screen(); - lv_display_set_rotation(dispp, sys_settings.rotation / 90); + lv_display_set_rotation(dispp, Sys_Get_Rotation() / 90); //timer // lv_timer_t * ui_MainTimer = lv_timer_create(main_timer, 1000, NULL); diff --git a/Power_Pico/User/Tasks/Src/user_KeyTask.c b/Power_Pico/User/Tasks/Src/user_KeyTask.c index 696fdb9..486a276 100644 --- a/Power_Pico/User/Tasks/Src/user_KeyTask.c +++ b/Power_Pico/User/Tasks/Src/user_KeyTask.c @@ -4,6 +4,7 @@ #include "main.h" #include "key.h" #include "beep.h" +#include "BL24C02.h" // settings /* Private typedef -----------------------------------------------------------*/ @@ -29,7 +30,7 @@ void KeyTask(void *argument) { osMessageQueuePut(Key_MessageQueue, &keystr, 0, 1); // beep - if(1) + if(Sys_Get_KeySoundEnable()) { beep_open(); osDelay(50);