This commit is contained in:
不吃油炸鸡
2025-10-15 10:25:22 +08:00
parent 2e2c365223
commit 71350e51ce
4 changed files with 26 additions and 28 deletions

View File

@@ -4,9 +4,9 @@
#include "math.h" #include "math.h"
// 量程阈值 // 量程阈值
#define ADC_TRUST_MAX 4000 #define ADC_TRUST_MAX 1952
#define ADC_TRUST_MIN 10 #define ADC_TRUST_MIN 10
#define THRESH_HIGH 1900 #define THRESH_HIGH 1800
#define THRESH_LOW 18 #define THRESH_LOW 18
// 次数 // 次数
#define THRESH_TIMES 8 #define THRESH_TIMES 8
@@ -14,9 +14,9 @@
uint8_t gate_status = HIGH_CUR; // Default status 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 const 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 const 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_HIGH = 3.0f / 4096.0f / 50.0f / HIGH_CUR_RES * 1000000.0; // uA
void Gate_Port_Init(void) void Gate_Port_Init(void)
{ {
@@ -95,7 +95,8 @@ void Gate_Swich_and_UART_Send(ADC_Packet adc_packet)
// 可信范围内 // 可信范围内
float voltage; float voltage;
float current; 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.header[3] = Gate_get_status();
ADC_Packet adc_packet_trans = adc_packet; ADC_Packet adc_packet_trans = adc_packet;
HAL_UART_Transmit_DMA(&huart6, (uint8_t*)&adc_packet_trans, sizeof(adc_packet_trans)); 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); queue_push(global_current_queue, current);
// 判断是否需要切换档位 // 判断是否需要切换档位
// ADC码值超过量程 // ADC码值超过量程
uint16_t diff = abs((int)cur_adc - 2048);
if(diff > THRESH_HIGH) { if(diff > THRESH_HIGH) {
high_times++; high_times++;
low_times = 0; low_times = 0;
@@ -143,9 +143,9 @@ void Gate_Swich_and_UART_Send(ADC_Packet adc_packet)
} }
// 不可信范围内 // 不可信范围内
else { else {
if(cur_adc >= ADC_TRUST_MAX) // 过大,切换到更大档位 if(diff >= ADC_TRUST_MAX) // 过大,切换到更大档位
flow_route_selection(Gate_get_status()+1); 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); flow_route_selection(Gate_get_status()-1);
} }
} }

View File

@@ -102,7 +102,7 @@ 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];
} }
uint8_t key_handle_flag = 0;
/** /**
* 处理按键事件,调用当前页面的按键事件处理函数 * 处理按键事件,调用当前页面的按键事件处理函数
* @param key_id 按键ID * @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(); Page_t* current_page = PageManager_get_current_page();
if (current_page && current_page->key_event_handler) { if (current_page && current_page->key_event_handler) {
current_page->key_event_handler(key_id); // 调用当前页面的按键事件处理函数 current_page->key_event_handler(key_id); // 调用当前页面的按键事件处理函数
key_handle_flag = 1;
} else { } else {
key_handle_flag = 0;
LV_LOG_WARN("No key event handler for current page\n"); LV_LOG_WARN("No key event handler for current page\n");
} }
} }

View File

@@ -40,13 +40,12 @@ static void set_val_cur_label(float voltage, float current)
sprintf(buf, "%.2f", voltage); sprintf(buf, "%.2f", voltage);
lv_label_set_text(ui_LabelValt, buf); lv_label_set_text(ui_LabelValt, buf);
// current // current
if(current >= 1000000.0) { if (current >= 1000000.0) {
current = 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_LabelCur, buf);
lv_label_set_text(ui_LabelUnitCur, "A"); lv_label_set_text(ui_LabelUnitCur, "A");
} } else if(current >= 1000.0) {
else if(current >= 1000.0) {
current = current / 1000.0; current = current / 1000.0;
if(current >= 100.0) { if(current >= 100.0) {
sprintf(buf, "%.1f", current); 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_LabelCur, buf);
lv_label_set_text(ui_LabelUnitCur, "mA"); lv_label_set_text(ui_LabelUnitCur, "mA");
} } else {
else {
if(current >= 100.0) { if(current >= 100.0) {
sprintf(buf, "%.1f", current); sprintf(buf, "%.1f", current);
} }
@@ -74,8 +72,7 @@ static void set_val_cur_label(float voltage, float current)
sprintf(buf, "%.2f", power); sprintf(buf, "%.2f", power);
lv_label_set_text(ui_LabelEnerge, buf); lv_label_set_text(ui_LabelEnerge, buf);
lv_label_set_text(ui_LabelUnitEnerge, "W"); lv_label_set_text(ui_LabelUnitEnerge, "W");
} } else if(power >= 1000.0) {
else if(power >= 1000.0) {
power = power / 1000.0; power = power / 1000.0;
if(power >= 100.0) { if(power >= 100.0) {
sprintf(buf, "%.1f", power); 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_LabelEnerge, buf);
lv_label_set_text(ui_LabelUnitEnerge, "mW"); lv_label_set_text(ui_LabelUnitEnerge, "mW");
} } else {
else {
if(power >= 100.0) { if(power >= 100.0) {
sprintf(buf, "%.1f", power); sprintf(buf, "%.1f", power);
} }
@@ -185,7 +181,7 @@ void ui_main_screen_init(void)
lv_obj_set_x(ui_LabelValt, -30); lv_obj_set_x(ui_LabelValt, -30);
lv_obj_set_y(ui_LabelValt, 14); lv_obj_set_y(ui_LabelValt, 14);
lv_obj_set_align(ui_LabelValt, LV_ALIGN_TOP_MID); 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); lv_obj_set_style_text_font(ui_LabelValt, &ui_font_HeiTi48, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_LabelUnitCur = lv_label_create(ui_HomeScreen); 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_x(ui_LabelUnitCur, 70);
lv_obj_set_y(ui_LabelUnitCur, 80); lv_obj_set_y(ui_LabelUnitCur, 80);
lv_obj_set_align(ui_LabelUnitCur, LV_ALIGN_TOP_MID); 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); lv_obj_set_style_text_font(ui_LabelUnitCur, &ui_font_HeiTi32, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_LabelCur = lv_label_create(ui_HomeScreen); 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_x(ui_LabelCur, -30);
lv_obj_set_y(ui_LabelCur, 74); lv_obj_set_y(ui_LabelCur, 74);
lv_obj_set_align(ui_LabelCur, LV_ALIGN_TOP_MID); 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); lv_obj_set_style_text_font(ui_LabelCur, &ui_font_HeiTi48, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_LabelUnitEnerge = lv_label_create(ui_HomeScreen); 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_x(ui_LabelEnerge, -30);
lv_obj_set_y(ui_LabelEnerge, 133); lv_obj_set_y(ui_LabelEnerge, 133);
lv_obj_set_align(ui_LabelEnerge, LV_ALIGN_TOP_MID); 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); lv_obj_set_style_text_font(ui_LabelEnerge, &ui_font_HeiTi48, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_LabelTime = lv_label_create(ui_HomeScreen); ui_LabelTime = lv_label_create(ui_HomeScreen);

View File

@@ -54,6 +54,10 @@ void HardwareInitTask(void *argument)
// queue for voltage and current // queue for voltage and current
global_voltage_queue = queue_create(8); global_voltage_queue = queue_create(8);
global_current_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 init
adc_packet.header[0] = 0x55; adc_packet.header[0] = 0x55;
@@ -78,8 +82,8 @@ void HardwareInitTask(void *argument)
// key // key
Key_Port_Init(); Key_Port_Init();
// FUSB CC pin connect // FUSB CC pin dis connect
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET);
// lcd // lcd
// done in lvgl disp init // done in lvgl disp init