From 4f6bd98b966f79a0e5207040a971bf89cea6dd81 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, 19 Mar 2026 11:18:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E7=94=B5=E5=8E=8B=E7=94=B5?= =?UTF-8?q?=E6=B5=81=E6=95=B0=E6=8D=AE=E4=BC=A0=E8=BE=93=E7=9A=84=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E9=98=9F=E5=88=97=EF=BC=8C=E5=8F=96=E6=B6=88=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E8=AE=BF=E9=97=AE=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- software/Power_Pico/User/GUI/ui_helpers.c | 23 ++++++++++++++++--- software/Power_Pico/User/GUI/ui_helpers.h | 8 ++++++- .../User/Tasks/Inc/user_TasksInit.h | 14 ++++++++--- .../Power_Pico/User/Tasks/Src/user_LVGLTask.c | 10 +++++++- .../User/Tasks/Src/user_MessageTask.c | 15 ++++++++++++ .../User/Tasks/Src/user_TasksInit.c | 11 +++++++++ 6 files changed, 73 insertions(+), 8 deletions(-) diff --git a/software/Power_Pico/User/GUI/ui_helpers.c b/software/Power_Pico/User/GUI/ui_helpers.c index 850ef12..4b633e9 100644 --- a/software/Power_Pico/User/GUI/ui_helpers.c +++ b/software/Power_Pico/User/GUI/ui_helpers.c @@ -8,7 +8,12 @@ #include "./ui_helpers.h" -///////////////////// ui help funtions //////////////////// +///////////////////// ui variables //////////////////// + +float ui_current_voltage = 0.0f; // 当前电压,单位 V +float ui_current_current = 0.0f; // 当前电流,单位 uA + +///////////////////// ui help functions //////////////////// void ui_full_screen_refresh(lv_obj_t * screen) { // 标记整个屏幕为脏区域 @@ -60,7 +65,12 @@ uint16_t ui_get_display_rotation(void) { // 获取当前电压, 单位 V; 当前电流, 单位 uA void ui_get_vol_cur(float *voltage, float *current) { - Data_Monitor_Get_Values(voltage, current); + if (voltage != NULL) { + *voltage = ui_current_voltage; + } + if (current != NULL) { + *current = ui_current_current; + } } //////////////// set functions /////////////// @@ -85,8 +95,15 @@ void ui_set_display_rotation(uint16_t rotation) { Sys_Set_Rotation(rotation); } +// 设置 UI 层的电压电流变量, 供 UI 层显示使用, 单位分别为 V 和 uA +void ui_update_vol_cur_varables(float voltage, float current) { + ui_current_voltage = voltage; + ui_current_current = current; +} + void ui_clear_data_monitor(void) { - Data_Monitor_Clear(); + // 不能直接访问其他层的数据,to be write + // Data_Monitor_Clear(); } //////////////// sys save functions /////////////// diff --git a/software/Power_Pico/User/GUI/ui_helpers.h b/software/Power_Pico/User/GUI/ui_helpers.h index c317875..50a997e 100644 --- a/software/Power_Pico/User/GUI/ui_helpers.h +++ b/software/Power_Pico/User/GUI/ui_helpers.h @@ -11,7 +11,12 @@ extern "C" { #include "lvgl.h" #include "stdio.h" -///////////////////// help funtions //////////////////// +///////////////////// ui variables //////////////////// + +extern float ui_current_voltage; +extern float ui_current_current; + +///////////////////// help functions //////////////////// void ui_full_screen_refresh(lv_obj_t * screen); @@ -34,6 +39,7 @@ void ui_set_back_light_level(uint8_t level); void ui_set_key_sound_enable(bool enable); void ui_set_language_select(uint8_t lang); void ui_set_display_rotation(uint16_t rotation); +void ui_update_vol_cur_varables(float voltage, float current); void ui_clear_data_monitor(void); // sys save function diff --git a/software/Power_Pico/User/Tasks/Inc/user_TasksInit.h b/software/Power_Pico/User/Tasks/Inc/user_TasksInit.h index ff5a3e0..b544529 100644 --- a/software/Power_Pico/User/Tasks/Inc/user_TasksInit.h +++ b/software/Power_Pico/User/Tasks/Inc/user_TasksInit.h @@ -8,18 +8,26 @@ extern "C" { #include "FreeRTOS.h" #include "cmsis_os.h" -// 定义一个标志位,表示 ADC 数据已经准备好,可以发送了 +// 用于数据传输的结构体,包含电压和电流 +// 流向为 MessageSendTask -> LVGLtask +typedef struct { + float voltage; // 电压 (V) + float current; // 电流 (uA) +} PowerData_t; + +// 定义一个标志位,表示 ADC 数据已经准备好,在ADC DMA中断中被置位 +// 在 MessageSendTask 中等待这个标志位,表示可以发送 ADC 数据了 #define FLAG_ADC_HALF_READY 0x0001U // 0000 0001 #define FLAG_ADC_FULL_READY 0x0002U // 0000 0010 -extern osThreadId_t MessageSendTaskHandle; // 用于发送 ADC 数据的任务句柄 +extern osThreadId_t MessageSendTaskHandle; extern osMessageQueueId_t Key_MessageQueue; extern osMessageQueueId_t PD_cmd_MessageQueue; extern osMessageQueueId_t PD_handle_event_MsgQueue; +extern osMessageQueueId_t PowerDataQueue; void User_Tasks_Init(void); -void TaskTickHook(void); #ifdef __cplusplus } diff --git a/software/Power_Pico/User/Tasks/Src/user_LVGLTask.c b/software/Power_Pico/User/Tasks/Src/user_LVGLTask.c index 7798348..eb8b441 100644 --- a/software/Power_Pico/User/Tasks/Src/user_LVGLTask.c +++ b/software/Power_Pico/User/Tasks/Src/user_LVGLTask.c @@ -11,6 +11,7 @@ //gui #include "lvgl.h" #include "lv_lib_pm.h" +#include "ui.h" /* Private typedef -----------------------------------------------------------*/ @@ -41,11 +42,18 @@ void TaskTickHook(void) void LvHandlerTask(void *argument) { key_event_t key_event; + PowerData_t power_data; uint32_t _time = 1; // default delay time while(1) { - if(osMessageQueueGet(Key_MessageQueue, &key_event, NULL, 1)==osOK) { + // 按键事件处理 + if(osMessageQueueGet(Key_MessageQueue, &key_event, NULL, 0)==osOK) { lv_lib_pm_handle_key_event(&key_event); + } + // 数据更新处理 + if(osMessageQueueGet(PowerDataQueue, &power_data, NULL, 0)==osOK) { + // 刷新UI层的电压电流数据变量 + ui_update_vol_cur_varables(power_data.voltage, power_data.current); } _time = lv_timer_handler(); osDelay(_time); diff --git a/software/Power_Pico/User/Tasks/Src/user_MessageTask.c b/software/Power_Pico/User/Tasks/Src/user_MessageTask.c index 3019d40..ab8e207 100644 --- a/software/Power_Pico/User/Tasks/Src/user_MessageTask.c +++ b/software/Power_Pico/User/Tasks/Src/user_MessageTask.c @@ -71,5 +71,20 @@ void MessageSendTask(void *argument) { Process_ADC_Chunk(&adc_raw_buffer[ADC_TIMES][0], 1); } + + // 发送数据给UI层进行显示 + PowerData_t newData; + Data_Monitor_Get_Values(&newData.voltage, &newData.current); + + // 尝试发送,如果不等待直接返回错误,说明队列可能满了 + osStatus_t status = osMessageQueuePut(PowerDataQueue, &newData, 0, 0); + + if (status == osErrorResource) { + PowerData_t dummy; + // 1. 强行从队列头部取出一个旧数据(丢弃) + osMessageQueueGet(PowerDataQueue, &dummy, NULL, 0); + // 2. 再次存入新数据 + osMessageQueuePut(PowerDataQueue, &newData, 0, 0); + } } } diff --git a/software/Power_Pico/User/Tasks/Src/user_TasksInit.c b/software/Power_Pico/User/Tasks/Src/user_TasksInit.c index befc38c..278146d 100644 --- a/software/Power_Pico/User/Tasks/Src/user_TasksInit.c +++ b/software/Power_Pico/User/Tasks/Src/user_TasksInit.c @@ -83,13 +83,23 @@ const osThreadAttr_t LvHandlerTask_attributes = { /* Message queues ------------------------------------------------------------*/ + // Key task 中发送出的按键信息的消息队列 +// 流向为 KeyTask -> LVGLtask osMessageQueueId_t Key_MessageQueue; + // UI layer发送给PDUFPTask任务的命令消息队列 +// 流向为 LVGLtask -> PDUFPTask osMessageQueueId_t PD_cmd_MessageQueue; + // PDUFPTask任务发送给UI层的通知处理情况的消息队列 +// 流向为 PDUFPTask -> LVGLtask osMessageQueueId_t PD_handle_event_MsgQueue; +// 数据处理Task任务发送给UI层的电压电流数据的消息队列 +// 流向为 MessageSendTask -> LVGLtask +osMessageQueueId_t PowerDataQueue; + /* Private function prototypes -----------------------------------------------*/ void LvHandlerTask(void *argument); @@ -110,6 +120,7 @@ void User_Tasks_Init(void) Key_MessageQueue = osMessageQueueNew(4, sizeof(key_event_t), NULL); PD_cmd_MessageQueue = osMessageQueueNew(4, sizeof(PD_command_msg_t), NULL); PD_handle_event_MsgQueue = osMessageQueueNew(4, 1, NULL); // uint8_t message + PowerDataQueue = osMessageQueueNew(8, sizeof(PowerData_t), NULL); /* add threads, ... */ HardwareInitTaskHandle = osThreadNew(HardwareInitTask, NULL, &HardwareInitTask_attributes);