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);