From 71350e51ceb2cc8c2ea704a44a46e8ef604635ea 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: Wed, 15 Oct 2025 10:25:22 +0800 Subject: [PATCH] update --- Power_Pico/BSP/GATE/gate.c | 18 +++++++------- Power_Pico/User/GUI/PageManager.c | 4 +--- Power_Pico/User/GUI/screens/ui_mainPage.c | 24 ++++++++----------- .../User/Tasks/Src/user_HardwareInitTask.c | 8 +++++-- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/Power_Pico/BSP/GATE/gate.c b/Power_Pico/BSP/GATE/gate.c index f38a6a2..b52c17d 100644 --- a/Power_Pico/BSP/GATE/gate.c +++ b/Power_Pico/BSP/GATE/gate.c @@ -4,9 +4,9 @@ #include "math.h" // 量程阈值 -#define ADC_TRUST_MAX 4000 +#define ADC_TRUST_MAX 1952 #define ADC_TRUST_MIN 10 -#define THRESH_HIGH 1900 +#define THRESH_HIGH 1800 #define THRESH_LOW 18 // 次数 #define THRESH_TIMES 8 @@ -14,9 +14,9 @@ uint8_t gate_status = HIGH_CUR; // Default status // 预先计算标度因子 -static double SCALE_LOW = 3.0f / 4096.0f / 50.0f / LOW_CUR_RES * 1000000.0; // uA -static double SCALE_MID = 3.0f / 4096.0f / 50.0f / MID_CUR_RES * 1000000.0; // uA -static double SCALE_HIGH = 3.0f / 4096.0f / 50.0f / HIGH_CUR_RES * 1000000.0; // uA +static const double SCALE_LOW = 3.0f / 4096.0f / 50.0f / LOW_CUR_RES * 1000000.0; // uA +static const double SCALE_MID = 3.0f / 4096.0f / 50.0f / MID_CUR_RES * 1000000.0; // uA +static const double SCALE_HIGH = 3.0f / 4096.0f / 50.0f / HIGH_CUR_RES * 1000000.0; // uA void Gate_Port_Init(void) { @@ -95,7 +95,8 @@ void Gate_Swich_and_UART_Send(ADC_Packet adc_packet) // 可信范围内 float voltage; float current; - if(cur_adc < ADC_TRUST_MAX && cur_adc > ADC_TRUST_MIN) { + uint16_t diff = abs((int)cur_adc - 2048); + if(diff < ADC_TRUST_MAX && diff > ADC_TRUST_MIN) { adc_packet.header[3] = Gate_get_status(); ADC_Packet adc_packet_trans = adc_packet; HAL_UART_Transmit_DMA(&huart6, (uint8_t*)&adc_packet_trans, sizeof(adc_packet_trans)); @@ -119,7 +120,6 @@ void Gate_Swich_and_UART_Send(ADC_Packet adc_packet) queue_push(global_current_queue, current); // 判断是否需要切换档位 // ADC码值超过量程 - uint16_t diff = abs((int)cur_adc - 2048); if(diff > THRESH_HIGH) { high_times++; low_times = 0; @@ -143,9 +143,9 @@ void Gate_Swich_and_UART_Send(ADC_Packet adc_packet) } // 不可信范围内 else { - if(cur_adc >= ADC_TRUST_MAX) // 过大,切换到更大档位 + if(diff >= ADC_TRUST_MAX) // 过大,切换到更大档位 flow_route_selection(Gate_get_status()+1); - else if(cur_adc <= ADC_TRUST_MIN) // 过小,切换到更小档位 + else if(diff <= ADC_TRUST_MIN) // 过小,切换到更小档位 flow_route_selection(Gate_get_status()-1); } } diff --git a/Power_Pico/User/GUI/PageManager.c b/Power_Pico/User/GUI/PageManager.c index ed7a0ed..3c12e25 100644 --- a/Power_Pico/User/GUI/PageManager.c +++ b/Power_Pico/User/GUI/PageManager.c @@ -102,7 +102,7 @@ Page_t* PageManager_get_current_page(void) { if (PageManager.count == 0) return NULL; return PageManager.pages[PageManager.current_index]; } -uint8_t key_handle_flag = 0; + /** * 处理按键事件,调用当前页面的按键事件处理函数 * @param key_id 按键ID @@ -111,9 +111,7 @@ void PageManager_handle_key_event(uint8_t key_id) { Page_t* current_page = PageManager_get_current_page(); if (current_page && current_page->key_event_handler) { current_page->key_event_handler(key_id); // 调用当前页面的按键事件处理函数 - key_handle_flag = 1; } else { - key_handle_flag = 0; LV_LOG_WARN("No key event handler for current page\n"); } } diff --git a/Power_Pico/User/GUI/screens/ui_mainPage.c b/Power_Pico/User/GUI/screens/ui_mainPage.c index 86f14d5..4c67240 100644 --- a/Power_Pico/User/GUI/screens/ui_mainPage.c +++ b/Power_Pico/User/GUI/screens/ui_mainPage.c @@ -40,13 +40,12 @@ static void set_val_cur_label(float voltage, float current) sprintf(buf, "%.2f", voltage); lv_label_set_text(ui_LabelValt, buf); // current - if(current >= 1000000.0) { + if (current >= 1000000.0) { current = current / 1000000.0; - sprintf(buf, "%.2f", current); + sprintf(buf, "%.2f", current); // 保留 2 位小数 lv_label_set_text(ui_LabelCur, buf); lv_label_set_text(ui_LabelUnitCur, "A"); - } - else if(current >= 1000.0) { + } else if(current >= 1000.0) { current = current / 1000.0; if(current >= 100.0) { sprintf(buf, "%.1f", current); @@ -56,8 +55,7 @@ static void set_val_cur_label(float voltage, float current) } lv_label_set_text(ui_LabelCur, buf); lv_label_set_text(ui_LabelUnitCur, "mA"); - } - else { + } else { if(current >= 100.0) { sprintf(buf, "%.1f", current); } @@ -74,8 +72,7 @@ static void set_val_cur_label(float voltage, float current) sprintf(buf, "%.2f", power); lv_label_set_text(ui_LabelEnerge, buf); lv_label_set_text(ui_LabelUnitEnerge, "W"); - } - else if(power >= 1000.0) { + } else if(power >= 1000.0) { power = power / 1000.0; if(power >= 100.0) { sprintf(buf, "%.1f", power); @@ -85,8 +82,7 @@ static void set_val_cur_label(float voltage, float current) } lv_label_set_text(ui_LabelEnerge, buf); lv_label_set_text(ui_LabelUnitEnerge, "mW"); - } - else { + } else { if(power >= 100.0) { sprintf(buf, "%.1f", power); } @@ -185,7 +181,7 @@ void ui_main_screen_init(void) lv_obj_set_x(ui_LabelValt, -30); lv_obj_set_y(ui_LabelValt, 14); lv_obj_set_align(ui_LabelValt, LV_ALIGN_TOP_MID); - lv_label_set_text(ui_LabelValt, "17.23"); + lv_label_set_text(ui_LabelValt, "0.00"); lv_obj_set_style_text_font(ui_LabelValt, &ui_font_HeiTi48, LV_PART_MAIN | LV_STATE_DEFAULT); ui_LabelUnitCur = lv_label_create(ui_HomeScreen); @@ -194,7 +190,7 @@ void ui_main_screen_init(void) lv_obj_set_x(ui_LabelUnitCur, 70); lv_obj_set_y(ui_LabelUnitCur, 80); lv_obj_set_align(ui_LabelUnitCur, LV_ALIGN_TOP_MID); - lv_label_set_text(ui_LabelUnitCur, "mA"); + lv_label_set_text(ui_LabelUnitCur, "uA"); lv_obj_set_style_text_font(ui_LabelUnitCur, &ui_font_HeiTi32, LV_PART_MAIN | LV_STATE_DEFAULT); ui_LabelCur = lv_label_create(ui_HomeScreen); @@ -203,7 +199,7 @@ void ui_main_screen_init(void) lv_obj_set_x(ui_LabelCur, -30); lv_obj_set_y(ui_LabelCur, 74); lv_obj_set_align(ui_LabelCur, LV_ALIGN_TOP_MID); - lv_label_set_text(ui_LabelCur, "283.2"); + lv_label_set_text(ui_LabelCur, "0.00"); lv_obj_set_style_text_font(ui_LabelCur, &ui_font_HeiTi48, LV_PART_MAIN | LV_STATE_DEFAULT); ui_LabelUnitEnerge = lv_label_create(ui_HomeScreen); @@ -221,7 +217,7 @@ void ui_main_screen_init(void) lv_obj_set_x(ui_LabelEnerge, -30); lv_obj_set_y(ui_LabelEnerge, 133); lv_obj_set_align(ui_LabelEnerge, LV_ALIGN_TOP_MID); - lv_label_set_text(ui_LabelEnerge, "543.2"); + lv_label_set_text(ui_LabelEnerge, "0.00"); lv_obj_set_style_text_font(ui_LabelEnerge, &ui_font_HeiTi48, LV_PART_MAIN | LV_STATE_DEFAULT); ui_LabelTime = lv_label_create(ui_HomeScreen); diff --git a/Power_Pico/User/Tasks/Src/user_HardwareInitTask.c b/Power_Pico/User/Tasks/Src/user_HardwareInitTask.c index 31f674c..ef7a3d9 100644 --- a/Power_Pico/User/Tasks/Src/user_HardwareInitTask.c +++ b/Power_Pico/User/Tasks/Src/user_HardwareInitTask.c @@ -54,6 +54,10 @@ void HardwareInitTask(void *argument) // queue for voltage and current global_voltage_queue = queue_create(8); global_current_queue = queue_create(8); + for(int i = 0; i < 8; i++) { + queue_push(global_voltage_queue, 0.0); + queue_push(global_current_queue, 0.0); + } // adc packet init adc_packet.header[0] = 0x55; @@ -78,8 +82,8 @@ void HardwareInitTask(void *argument) // key Key_Port_Init(); - // FUSB CC pin connect - HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_SET); + // FUSB CC pin dis connect + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET); // lcd // done in lvgl disp init