mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
update ui manager
This commit is contained in:
@@ -100,3 +100,16 @@ Page_t* PageManager_get_current_page(void) {
|
|||||||
if (PageManager.count == 0) return NULL;
|
if (PageManager.count == 0) return NULL;
|
||||||
return PageManager.pages[PageManager.current_index];
|
return PageManager.pages[PageManager.current_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理按键事件,调用当前页面的按键事件处理函数
|
||||||
|
* @param key_id 按键ID
|
||||||
|
*/
|
||||||
|
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); // 调用当前页面的按键事件处理函数
|
||||||
|
} else {
|
||||||
|
printf("No key event handler for current page\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ typedef struct {
|
|||||||
void (*init)(void);
|
void (*init)(void);
|
||||||
void (*deinit)(void);
|
void (*deinit)(void);
|
||||||
lv_obj_t** page_obj; // 指向页面对象指针的指针
|
lv_obj_t** page_obj; // 指向页面对象指针的指针
|
||||||
|
void (*key_event_handler)(uint8_t key_id); // 按键事件处理函数
|
||||||
const char* name; // 可选:用于调试
|
const char* name; // 可选:用于调试
|
||||||
} Page_t;
|
} Page_t;
|
||||||
|
|
||||||
@@ -27,10 +28,11 @@ extern PageManager_t PageManager;
|
|||||||
// API 函数声明
|
// API 函数声明
|
||||||
void PageManager_init(void);
|
void PageManager_init(void);
|
||||||
void PageManager_register(Page_t* page);
|
void PageManager_register(Page_t* page);
|
||||||
|
void PageManager_load_init_screen(void);
|
||||||
void PageManager_next(void);
|
void PageManager_next(void);
|
||||||
void PageManager_prev(void);
|
void PageManager_prev(void);
|
||||||
void PageManager_goto(uint8_t index);
|
void PageManager_goto(uint8_t index);
|
||||||
Page_t* PageManager_get_current_page(void);
|
Page_t* PageManager_get_current_page(void);
|
||||||
void PageManager_load_init_screen(void);
|
void PageManager_handle_key_event(uint8_t key_id);
|
||||||
|
|
||||||
#endif // PAGE_MANAGER_H
|
#endif // PAGE_MANAGER_H
|
||||||
|
|||||||
@@ -223,3 +223,8 @@ void ui_main_screen_destroy(void)
|
|||||||
_flush_timer = NULL;
|
_flush_timer = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ui_main_page_key_handler(uint8_t key_id)
|
||||||
|
{
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ extern "C" {
|
|||||||
// SCREEN: ui_Screen1
|
// SCREEN: ui_Screen1
|
||||||
void ui_main_screen_init(void);
|
void ui_main_screen_init(void);
|
||||||
void ui_main_screen_destroy(void);
|
void ui_main_screen_destroy(void);
|
||||||
|
void ui_main_page_key_handler(uint8_t key_id);
|
||||||
|
|
||||||
extern lv_obj_t * ui_HomeScreen;
|
extern lv_obj_t * ui_HomeScreen;
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ Page_t pages[] = {
|
|||||||
.init = ui_main_screen_init,
|
.init = ui_main_screen_init,
|
||||||
.deinit = ui_main_screen_destroy,
|
.deinit = ui_main_screen_destroy,
|
||||||
.page_obj = &ui_HomeScreen,
|
.page_obj = &ui_HomeScreen,
|
||||||
|
.key_event_handler = ui_main_page_key_handler,
|
||||||
.name = "Main Page"
|
.name = "Main Page"
|
||||||
},
|
},
|
||||||
// 可以在这里添加更多页面
|
// 可以在这里添加更多页面
|
||||||
@@ -28,6 +29,7 @@ Page_t pages[] = {
|
|||||||
*/
|
*/
|
||||||
static void main_timer(lv_timer_t * timer)
|
static void main_timer(lv_timer_t * timer)
|
||||||
{
|
{
|
||||||
|
// do nothing
|
||||||
// LV_LOG_WARN("Main timer");
|
// LV_LOG_WARN("Main timer");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
#ifndef __USER_SENDTASK_H__
|
|
||||||
#define __USER_SENDTASK_H__
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void UartSendTask(void *argument);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -29,20 +29,10 @@ void DataTask(void *argument)
|
|||||||
if(osMessageQueueGet(Key_MessageQueue, &keystr, NULL, 0)==osOK)
|
if(osMessageQueueGet(Key_MessageQueue, &keystr, NULL, 0)==osOK)
|
||||||
{
|
{
|
||||||
// UART6_TX_Send((uint8_t *)"key pressed\r\n", 13);
|
// UART6_TX_Send((uint8_t *)"key pressed\r\n", 13);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
// over current and valtage, beep
|
||||||
// __disable_irq();
|
|
||||||
// if(adc_buf_index == 0)
|
osDelay(100);
|
||||||
// memcpy((uint16_t*)adc_packet.data, (uint16_t*)ADC_BUF[1], sizeof(adc_packet.data));
|
|
||||||
// else
|
|
||||||
// memcpy((uint16_t*)adc_packet.data, (uint16_t*)ADC_BUF[0], sizeof(adc_packet.data));
|
|
||||||
// __enable_irq();
|
|
||||||
// adc_packet.header[0] = 0x55;
|
|
||||||
// adc_packet.header[1] = 0xAA;
|
|
||||||
// adc_packet.header[2] = ADC_TIMES;
|
|
||||||
// adc_packet.header[3] = ADC_CHANELS;
|
|
||||||
// adc_packet.header[4] = 0x10;
|
|
||||||
// HAL_UART_Transmit_DMA(&huart6, (uint8_t *)&adc_packet, sizeof(adc_packet));
|
|
||||||
osDelay(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,127 +0,0 @@
|
|||||||
/* Private includes -----------------------------------------------------------*/
|
|
||||||
//includes
|
|
||||||
#include "user_TasksInit.h"
|
|
||||||
#include "main.h"
|
|
||||||
#include "adc.h"
|
|
||||||
#include "gate.h"
|
|
||||||
#include "usart.h"
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
|
|
||||||
// 定义档位阈值
|
|
||||||
#define LOW_TO_MID_THRESHOLD 55000 // 550uA
|
|
||||||
#define MID_TO_LOW_THRESHOLD 45000 // 450uA (滞回)
|
|
||||||
#define MID_TO_HIGH_THRESHOLD 5000000 // 50mA
|
|
||||||
#define HIGH_TO_MID_THRESHOLD 4500 // 45mA (滞回)
|
|
||||||
|
|
||||||
// 定义连续超过阈值的次数
|
|
||||||
#define SWITCH_COUNT_THRESHOLD 2
|
|
||||||
|
|
||||||
// 切换计数器
|
|
||||||
uint8_t low_to_mid_count = 0;
|
|
||||||
uint8_t mid_to_low_count = 0;
|
|
||||||
uint8_t mid_to_high_count = 0;
|
|
||||||
uint8_t high_to_mid_count = 0;
|
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
|
|
||||||
// 检查当前电流并根据阈值切换流路
|
|
||||||
void check_and_switch_flow_route(uint8_t unit, uint32_t cur) {
|
|
||||||
if (unit == LOW_CUR) {
|
|
||||||
if (cur > LOW_TO_MID_THRESHOLD) {
|
|
||||||
low_to_mid_count++;
|
|
||||||
if (low_to_mid_count >= SWITCH_COUNT_THRESHOLD) {
|
|
||||||
flow_route_selection(MID_CUR); // 切换到中档位
|
|
||||||
low_to_mid_count = 0; // 重置计数器
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
low_to_mid_count = 0; // 清零计数器
|
|
||||||
}
|
|
||||||
} else if (unit == MID_CUR) {
|
|
||||||
if (cur > MID_TO_HIGH_THRESHOLD) {
|
|
||||||
mid_to_high_count++;
|
|
||||||
if (mid_to_high_count >= SWITCH_COUNT_THRESHOLD) {
|
|
||||||
flow_route_selection(HIGH_CUR); // 切换到高档位
|
|
||||||
mid_to_high_count = 0; // 重置计数器
|
|
||||||
}
|
|
||||||
} else if (cur < MID_TO_LOW_THRESHOLD) {
|
|
||||||
mid_to_low_count++;
|
|
||||||
if (mid_to_low_count >= SWITCH_COUNT_THRESHOLD) {
|
|
||||||
flow_route_selection(LOW_CUR); // 切换到低档位
|
|
||||||
mid_to_low_count = 0; // 重置计数器
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mid_to_high_count = 0; // 清零计数器
|
|
||||||
mid_to_low_count = 0; // 清零计数器
|
|
||||||
}
|
|
||||||
} else if (unit == HIGH_CUR) {
|
|
||||||
if (cur < HIGH_TO_MID_THRESHOLD) {
|
|
||||||
high_to_mid_count++;
|
|
||||||
if (high_to_mid_count >= SWITCH_COUNT_THRESHOLD) {
|
|
||||||
flow_route_selection(MID_CUR); // 切换到中档位
|
|
||||||
high_to_mid_count = 0; // 重置计数器
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
high_to_mid_count = 0; // 清零计数器
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief task for send messages or data
|
|
||||||
* @param argument: Not used
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void UartSendTask(void *argument)
|
|
||||||
{
|
|
||||||
uint8_t keystr = 0;
|
|
||||||
uint16_t cur_bias = 4096 / 2;
|
|
||||||
while(1)
|
|
||||||
{
|
|
||||||
if(osMessageQueueGet(Key_MessageQueue, &keystr, NULL, 0)==osOK)
|
|
||||||
{
|
|
||||||
// UART6_TX_Send((uint8_t *)"key pressed\r\n", 13);
|
|
||||||
}
|
|
||||||
// send protocol frame
|
|
||||||
for(int i = 0 ; i < ADC_TIMES ; i++)
|
|
||||||
{
|
|
||||||
// direct & unit
|
|
||||||
uint8_t dir_unit = 0x00; // 0x00 means: positive, (A) unit
|
|
||||||
uint8_t unit = Gate_get_status(); // 0 - low current(500uA), 1 - mid current(50mA), 2 - high current(5A)
|
|
||||||
dir_unit = (unit & 0x0F); // unit
|
|
||||||
// current
|
|
||||||
uint32_t cur;
|
|
||||||
uint64_t cur_adc; // 64位避免溢出
|
|
||||||
// voltage = VADC/4096 * 3.0Vref * 11( this means: 1MR + 100kR)
|
|
||||||
uint16_t volt = adc_buf[i][3] * 3 * 11 * 100 / 4096; // 100times
|
|
||||||
// cur direction and value
|
|
||||||
if(adc_buf[i][2-unit] > cur_bias) {
|
|
||||||
dir_unit |= 0x10; // negative
|
|
||||||
cur_adc = adc_buf[i][2-unit] - cur_bias;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cur_adc = cur_bias - adc_buf[i][2-unit];
|
|
||||||
}
|
|
||||||
// cur = (IADC/4096 * 3.0Vref - 1.5Vref) / 50(ina199) / R
|
|
||||||
if(unit == HIGH_CUR) {
|
|
||||||
cur = cur_adc * 3 * 100 * 1000 / HIGH_CUR_RES / 50 / 4096; // 100times. (mA)
|
|
||||||
}
|
|
||||||
else if(unit == MID_CUR) {
|
|
||||||
cur = cur_adc * 3 * 100 * 1000000 / MID_CUR_RES / 50 / 4096; // 100times. (uA)
|
|
||||||
}
|
|
||||||
else if(unit == LOW_CUR) {
|
|
||||||
cur = cur_adc * 3 * 100 * 1000000 / LOW_CUR_RES / 50 / 4096; // 100times. (uA)
|
|
||||||
}
|
|
||||||
|
|
||||||
check_and_switch_flow_route(unit, cur); // 检查并切换流路
|
|
||||||
|
|
||||||
// protocol frame
|
|
||||||
uint8_t protocol_frame[11] = {0x55, 0xAA, dir_unit, (cur>>24 & 0xff), (cur>>16 & 0xff), (cur>>8 & 0xff), (cur & 0xff), (volt>>8 & 0xff), (volt & 0xff), 0xAA, 0x55};
|
|
||||||
UART6_TX_Send(protocol_frame, sizeof(protocol_frame));
|
|
||||||
}
|
|
||||||
osDelay(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user