加入快充诱骗调压逻辑

This commit is contained in:
不吃油炸鸡
2025-12-06 16:28:47 +08:00
parent 31578725f9
commit 9af7f612cd
7 changed files with 429 additions and 156 deletions

View File

@@ -33,22 +33,29 @@ static lv_obj_t * ui_LabelValDec = NULL;
static lv_obj_t * ui_BtnValInc = NULL; static lv_obj_t * ui_BtnValInc = NULL;
static lv_obj_t * ui_LabelValInc = NULL; static lv_obj_t * ui_LabelValInc = NULL;
static lv_obj_t * ui_BtnCurSet = NULL; static lv_obj_t * ui_BtnCurSet = NULL;
static lv_obj_t * ui_LabelValSet1 = NULL; static lv_obj_t * ui_LabelCurSet = NULL;
static lv_obj_t * ui_BtnCurDec = NULL; static lv_obj_t * ui_BtnCurDec = NULL;
static lv_obj_t * ui_LabelValDec1 = NULL; static lv_obj_t * ui_LabelCurDec = NULL;
static lv_obj_t * ui_BtnCurInc = NULL; static lv_obj_t * ui_BtnCurInc = NULL;
static lv_obj_t * ui_LabelCurInc = NULL; static lv_obj_t * ui_LabelCurInc = NULL;
static lv_obj_t * ui_BtnSwitch = NULL; static lv_obj_t * ui_BtnSwitch = NULL;
static lv_obj_t * ui_LabelSwitch2fixed = NULL; static lv_obj_t * ui_LabelSwitch = NULL;
static lv_obj_t * ui_BtnClose = NULL; static lv_obj_t * ui_BtnClose = NULL;
static lv_obj_t * ui_LabelClose = NULL; static lv_obj_t * ui_LabelClose = NULL;
static lv_timer_t* ui_pps_timer = NULL; static lv_timer_t* ui_pps_timer = NULL;
static lv_obj_t * panels[8]; // 存储所有 panel 的指针 // variables
static int current_panel_index = 0; // 当前选中的 panel 索引
// event funtions static uint8_t pps_voltage_index = 0; // 6-settings: 0:5V, 1:9V, 2:12V, 3:15V, 4:18V, 5:20V
static uint8_t pps_panel_index = 1; // 1 or 2
static lv_obj_t * btns[14]; // 存储所有 btn 的指针
static int current_btn_index = 0; // 当前选中的 btn 索引
static float cur_voltage = 5.0;
static float cur_current = 1.0;
///////////////// timer functions ///////////////////
static void _flush_timer_cb(void) { static void _flush_timer_cb(void) {
// 刷新 PPS 电压电流显示 // 刷新 PPS 电压电流显示
@@ -63,17 +70,167 @@ static void _flush_timer_cb(void) {
lv_label_set_text(ui_LabelPPSCur, buf); lv_label_set_text(ui_LabelPPSCur, buf);
} }
///////////////// key function ///////////////////
static void _set_label_val_cur(void) {
char buf[8];
sprintf(buf, "%.2f V", cur_voltage);
lv_label_set_text(ui_LabelValSet, buf);
sprintf(buf, "%.2f A", cur_current);
lv_label_set_text(ui_LabelCurSet, buf);
}
static void _switch_pps_panel(void)
{
if(pps_panel_index == 1)
{
lv_lib_anim_user_animation(ui_PanelPPS, 0, 500, 120, -120, 0, 0, 0, 0, lv_anim_path_ease_in_out, lv_lib_anim_callback_set_x, NULL);
pps_panel_index = 2;
// 取消当前对象红色边框
lv_obj_set_style_border_width(btns[current_btn_index], 0, LV_PART_MAIN | LV_STATE_DEFAULT);
current_btn_index = 8;
// 设置当前对象红色边框
lv_obj_set_style_border_width(btns[current_btn_index], 3, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_label_set_text(ui_LabelSwitch, "press here to Fixed Set");
_set_label_val_cur();
}
else
{
lv_lib_anim_user_animation(ui_PanelPPS, 0, 500, -120, 120, 0, 0, 0, 0, lv_anim_path_ease_in_out, lv_lib_anim_callback_set_x, NULL);
pps_panel_index = 1;
// 取消当前对象红色边框
lv_obj_set_style_border_width(btns[current_btn_index], 0, LV_PART_MAIN | LV_STATE_DEFAULT);
current_btn_index = 0;
// 设置当前对象红色边框
lv_obj_set_style_border_width(btns[current_btn_index], 3, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_label_set_text(ui_LabelSwitch, "press here to Variable");
}
}
static void _switch_btn(bool inc)
{
// 取消当前对象红色边框
lv_obj_set_style_border_width(btns[current_btn_index], 0, LV_PART_MAIN | LV_STATE_DEFAULT);
// 加减
if(inc) {
current_btn_index++;
if (pps_panel_index == 1 && current_btn_index > 7) {
current_btn_index = 0;
}
else if (pps_panel_index == 2 && current_btn_index > 13) {
current_btn_index = 8;
}
} else {
if (pps_panel_index == 1) {
if (current_btn_index == 0) {
current_btn_index = 7;
} else {
current_btn_index--;
}
}
else if (pps_panel_index == 2) {
if (current_btn_index == 8) {
current_btn_index = 13;
} else {
current_btn_index--;
}
}
}
// 设置当前对象红色边框
lv_obj_set_style_border_width(btns[current_btn_index], 3, LV_PART_MAIN | LV_STATE_DEFAULT);
}
#include "key.h" #include "key.h"
void ui_pps_page_key_handler(void* key_event) void ui_pps_page_key_handler(void* key_event)
{ {
if(((key_event_t*)key_event)->id == KEY_ID_B && ((key_event_t*)key_event)->type == KEY_EVT_CLICK) if(((key_event_t*)key_event)->id == KEY_ID_B && ((key_event_t*)key_event)->type == KEY_EVT_CLICK)
{ {
lv_lib_pm_goto("Set Page", NULL); _switch_pps_panel();
}
else if(((key_event_t*)key_event)->id == KEY_ID_L || ((key_event_t*)key_event)->id == KEY_ID_R)
{
if (((key_event_t*)key_event)->id == KEY_ID_R) {
_switch_btn(1);
} else if (((key_event_t*)key_event)->id == KEY_ID_L) {
_switch_btn(0);
}
}
else if (((key_event_t*)key_event)->id == KEY_ID_Y)
{
switch (current_btn_index)
{
// 6和12 切换 pps panel
case 6:
_switch_pps_panel();
break;
case 12:
_switch_pps_panel();
break;
// 7和13 关闭 PPS
case 7:
ui_send_pps_stop_msg();
lv_lib_pm_goto("Set Page", NULL);
break;
case 13:
ui_send_pps_stop_msg();
lv_lib_pm_goto("Set Page", NULL);
break;
case 0:
cur_voltage = 5.0;
cur_current = 1.0;
ui_send_pps_set_msg(cur_voltage, cur_current);
break;
case 1:
cur_voltage = 9.0;
cur_current = 1.0;
ui_send_pps_set_msg(cur_voltage, cur_current);
break;
case 2:
cur_voltage = 12.0;
cur_current = 1.0;
ui_send_pps_set_msg(cur_voltage, cur_current);
break;
case 3:
cur_voltage = 15.0;
cur_current = 1.0;
ui_send_pps_set_msg(cur_voltage, cur_current);
break;
case 4:
cur_voltage = 18.0;
cur_current = 1.0;
ui_send_pps_set_msg(cur_voltage, cur_current);
break;
case 5:
cur_voltage = 20.0;
cur_current = 1.0;
ui_send_pps_set_msg(cur_voltage, cur_current);
break;
case 8:
cur_voltage -= 0.1;
if (cur_voltage < 5.0) cur_voltage = 5.0;
ui_send_pps_set_msg(cur_voltage, cur_current);
break;
case 9:
cur_voltage += 0.1;
if (cur_voltage > 20.0) cur_voltage = 20.0;
ui_send_pps_set_msg(cur_voltage, cur_current);
break;
case 10:
cur_current -= 0.1;
if (cur_current < 1.0) cur_current = 1.0;
ui_send_pps_set_msg(cur_voltage, cur_current);
break;
case 11:
cur_current += 0.1;
if (cur_current > 3.0) cur_current = 3.0;
ui_send_pps_set_msg(cur_voltage, cur_current);
break;
}
_set_label_val_cur();
} }
} }
// build funtions /////////////////////// ui_initialize //////////////////////
void ui_PPSPage_screen_init(void) void ui_PPSPage_screen_init(void)
{ {
@@ -298,6 +455,9 @@ void ui_PPSPage_screen_init(void)
lv_obj_set_align(ui_BtnValDec, LV_ALIGN_CENTER); lv_obj_set_align(ui_BtnValDec, LV_ALIGN_CENTER);
lv_obj_add_flag(ui_BtnValDec, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_add_flag(ui_BtnValDec, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags
lv_obj_remove_flag(ui_BtnValDec, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_remove_flag(ui_BtnValDec, LV_OBJ_FLAG_SCROLLABLE); /// Flags
lv_obj_set_style_border_color(ui_BtnValDec, lv_color_hex(0xF40F0F), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_opa(ui_BtnValDec, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_width(ui_BtnValDec, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_LabelValDec = lv_label_create(ui_BtnValDec); ui_LabelValDec = lv_label_create(ui_BtnValDec);
lv_obj_set_width(ui_LabelValDec, LV_SIZE_CONTENT); /// 1 lv_obj_set_width(ui_LabelValDec, LV_SIZE_CONTENT); /// 1
@@ -316,6 +476,9 @@ void ui_PPSPage_screen_init(void)
lv_obj_set_align(ui_BtnValInc, LV_ALIGN_CENTER); lv_obj_set_align(ui_BtnValInc, LV_ALIGN_CENTER);
lv_obj_add_flag(ui_BtnValInc, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_add_flag(ui_BtnValInc, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags
lv_obj_remove_flag(ui_BtnValInc, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_remove_flag(ui_BtnValInc, LV_OBJ_FLAG_SCROLLABLE); /// Flags
lv_obj_set_style_border_color(ui_BtnValInc, lv_color_hex(0xF40F0F), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_opa(ui_BtnValInc, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_width(ui_BtnValInc, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_LabelValInc = lv_label_create(ui_BtnValInc); ui_LabelValInc = lv_label_create(ui_BtnValInc);
lv_obj_set_width(ui_LabelValInc, LV_SIZE_CONTENT); /// 1 lv_obj_set_width(ui_LabelValInc, LV_SIZE_CONTENT); /// 1
@@ -333,12 +496,12 @@ void ui_PPSPage_screen_init(void)
lv_obj_add_flag(ui_BtnCurSet, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_add_flag(ui_BtnCurSet, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags
lv_obj_remove_flag(ui_BtnCurSet, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_remove_flag(ui_BtnCurSet, LV_OBJ_FLAG_SCROLLABLE); /// Flags
ui_LabelValSet1 = lv_label_create(ui_BtnCurSet); ui_LabelCurSet = lv_label_create(ui_BtnCurSet);
lv_obj_set_width(ui_LabelValSet1, LV_SIZE_CONTENT); /// 1 lv_obj_set_width(ui_LabelCurSet, LV_SIZE_CONTENT); /// 1
lv_obj_set_height(ui_LabelValSet1, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_LabelCurSet, LV_SIZE_CONTENT); /// 1
lv_obj_set_align(ui_LabelValSet1, LV_ALIGN_CENTER); lv_obj_set_align(ui_LabelCurSet, LV_ALIGN_CENTER);
lv_label_set_text(ui_LabelValSet1, "1.00 A"); lv_label_set_text(ui_LabelCurSet, "1.00 A");
lv_obj_set_style_text_font(ui_LabelValSet1, &lv_font_montserrat_18, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_font(ui_LabelCurSet, &lv_font_montserrat_18, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_BtnCurDec = lv_button_create(ui_PanelPPS); ui_BtnCurDec = lv_button_create(ui_PanelPPS);
lv_obj_set_width(ui_BtnCurDec, 30); lv_obj_set_width(ui_BtnCurDec, 30);
@@ -348,15 +511,18 @@ void ui_PPSPage_screen_init(void)
lv_obj_set_align(ui_BtnCurDec, LV_ALIGN_CENTER); lv_obj_set_align(ui_BtnCurDec, LV_ALIGN_CENTER);
lv_obj_add_flag(ui_BtnCurDec, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_add_flag(ui_BtnCurDec, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags
lv_obj_remove_flag(ui_BtnCurDec, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_remove_flag(ui_BtnCurDec, LV_OBJ_FLAG_SCROLLABLE); /// Flags
lv_obj_set_style_border_color(ui_BtnCurDec, lv_color_hex(0xF40F0F), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_opa(ui_BtnCurDec, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_width(ui_BtnCurDec, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_LabelValDec1 = lv_label_create(ui_BtnCurDec); ui_LabelCurDec = lv_label_create(ui_BtnCurDec);
lv_obj_set_width(ui_LabelValDec1, LV_SIZE_CONTENT); /// 1 lv_obj_set_width(ui_LabelCurDec, LV_SIZE_CONTENT); /// 1
lv_obj_set_height(ui_LabelValDec1, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_LabelCurDec, LV_SIZE_CONTENT); /// 1
lv_obj_set_x(ui_LabelValDec1, 0); lv_obj_set_x(ui_LabelCurDec, 0);
lv_obj_set_y(ui_LabelValDec1, -7); lv_obj_set_y(ui_LabelCurDec, -7);
lv_obj_set_align(ui_LabelValDec1, LV_ALIGN_CENTER); lv_obj_set_align(ui_LabelCurDec, LV_ALIGN_CENTER);
lv_label_set_text(ui_LabelValDec1, "_"); lv_label_set_text(ui_LabelCurDec, "_");
lv_obj_set_style_text_font(ui_LabelValDec1, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_font(ui_LabelCurDec, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_BtnCurInc = lv_button_create(ui_PanelPPS); ui_BtnCurInc = lv_button_create(ui_PanelPPS);
lv_obj_set_width(ui_BtnCurInc, 30); lv_obj_set_width(ui_BtnCurInc, 30);
@@ -366,6 +532,9 @@ void ui_PPSPage_screen_init(void)
lv_obj_set_align(ui_BtnCurInc, LV_ALIGN_CENTER); lv_obj_set_align(ui_BtnCurInc, LV_ALIGN_CENTER);
lv_obj_add_flag(ui_BtnCurInc, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_add_flag(ui_BtnCurInc, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags
lv_obj_remove_flag(ui_BtnCurInc, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_remove_flag(ui_BtnCurInc, LV_OBJ_FLAG_SCROLLABLE); /// Flags
lv_obj_set_style_border_color(ui_BtnCurInc, lv_color_hex(0xF40F0F), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_opa(ui_BtnCurInc, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_width(ui_BtnCurInc, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_LabelCurInc = lv_label_create(ui_BtnCurInc); ui_LabelCurInc = lv_label_create(ui_BtnCurInc);
lv_obj_set_width(ui_LabelCurInc, LV_SIZE_CONTENT); /// 1 lv_obj_set_width(ui_LabelCurInc, LV_SIZE_CONTENT); /// 1
@@ -389,12 +558,12 @@ void ui_PPSPage_screen_init(void)
lv_obj_set_style_border_width(ui_BtnSwitch, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_border_width(ui_BtnSwitch, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_LabelSwitch2fixed = lv_label_create(ui_BtnSwitch); ui_LabelSwitch = lv_label_create(ui_BtnSwitch);
lv_obj_set_width(ui_LabelSwitch2fixed, LV_SIZE_CONTENT); /// 1 lv_obj_set_width(ui_LabelSwitch, LV_SIZE_CONTENT); /// 1
lv_obj_set_height(ui_LabelSwitch2fixed, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_LabelSwitch, LV_SIZE_CONTENT); /// 1
lv_obj_set_align(ui_LabelSwitch2fixed, LV_ALIGN_CENTER); lv_obj_set_align(ui_LabelSwitch, LV_ALIGN_CENTER);
lv_label_set_text(ui_LabelSwitch2fixed, "press here to Variable"); lv_label_set_text(ui_LabelSwitch, "press here to Variable");
lv_obj_set_style_text_font(ui_LabelSwitch2fixed, &lv_font_montserrat_18, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_font(ui_LabelSwitch, &lv_font_montserrat_18, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_BtnClose = lv_button_create(ui_PPSPage); ui_BtnClose = lv_button_create(ui_PPSPage);
lv_obj_set_width(ui_BtnClose, 210); lv_obj_set_width(ui_BtnClose, 210);
@@ -420,16 +589,22 @@ void ui_PPSPage_screen_init(void)
ui_pps_timer = lv_timer_create(_flush_timer_cb, 500, NULL); ui_pps_timer = lv_timer_create(_flush_timer_cb, 500, NULL);
// store panels in array // store panels in array
panels[0] = ui_BtnSet1; btns[0] = ui_BtnSet1;
panels[1] = ui_BtnSet2; btns[1] = ui_BtnSet2;
panels[2] = ui_BtnSet3; btns[2] = ui_BtnSet3;
panels[3] = ui_BtnSet4; btns[3] = ui_BtnSet4;
panels[4] = ui_BtnSet5; btns[4] = ui_BtnSet5;
panels[5] = ui_BtnSet6; btns[5] = ui_BtnSet6;
panels[6] = ui_BtnSwitch; btns[6] = ui_BtnSwitch;
panels[7] = ui_BtnClose; btns[7] = ui_BtnClose;
btns[8] = ui_BtnValDec;
btns[9] = ui_BtnValInc;
btns[10] = ui_BtnCurDec;
btns[11] = ui_BtnCurInc;
btns[12] = ui_BtnSwitch;
btns[13] = ui_BtnClose;
// //
current_panel_index = 0; current_btn_index = 0;
} }
void ui_PPSPage_screen_destroy(void) void ui_PPSPage_screen_destroy(void)

View File

@@ -40,37 +40,30 @@ static bool waiting_for_signal = false; // 标志位,表示是否在等待信
static lv_obj_t * panels[6]; // 存储所有 panel 的指针 static lv_obj_t * panels[6]; // 存储所有 panel 的指针
static int current_panel_index = 0; // 当前选中的 panel 索引 static int current_panel_index = 0; // 当前选中的 panel 索引
static void show_msgbox(void); static void show_wait_msgbox(void);
static void hide_msgbox(void); static void hide_wait_msgbox(void);
static void show_fail_msgbox(void);
// event funtions // event funtions
// comunicate with PD UFP Task
#include "user_PDUFPTask.h"
/////////////////////// Timer ////////////////////// /////////////////////// Timer //////////////////////
static void _setting_timer_cb(lv_timer_t * timer) { static void _setting_timer_cb(lv_timer_t * timer) {
PD_handle_event_t pd_handle_event; int8_t Msg = 0;
// 非阻塞获取消息 Msg = MsgQueueGet_PPS_ready();
if(osMessageQueueGet(PD_handle_event_MsgQueue, &pd_handle_event, NULL, 0)==osOK) { if(Msg == 1) {
if(pd_handle_event == PD_EVT_PPS_READY) { // 隐藏等待框
// 隐藏等待框 hide_wait_msgbox();
hide_msgbox(); lv_lib_pm_goto("PPS Page", NULL);
lv_lib_pm_goto("PPS Page", NULL); } else if(Msg == -1) {
} else if(pd_handle_event == PD_EVT_PPS_FAILED) { // 隐藏等待框
// 隐藏等待框 hide_wait_msgbox();
hide_msgbox(); // 显示失败框
} show_fail_msgbox();
ui_send_pps_stop_msg();
} }
} }
///////////////// outer function /////////////////// ///////////////// key function ///////////////////
static void _send_pps_start_msg(void) {
PD_command_msg_t pd_ui_msg;
pd_ui_msg.event = PD_CMD_START;
osMessageQueuePut(PD_cmd_MessageQueue, &pd_ui_msg, 0, 1);
}
#include "key.h" #include "key.h"
void ui_set_page_key_handler(void *key_event) void ui_set_page_key_handler(void *key_event)
@@ -174,9 +167,9 @@ void ui_set_page_key_handler(void *key_event)
if (((key_event_t*)key_event)->id == KEY_ID_Y && ((key_event_t*)key_event)->type == KEY_EVT_CLICK) if (((key_event_t*)key_event)->id == KEY_ID_Y && ((key_event_t*)key_event)->type == KEY_EVT_CLICK)
{ {
// 发送pps开始信号到PD UFP Task // 发送pps开始信号到PD UFP Task
_send_pps_start_msg(); ui_send_pps_start_msg();
// 弹出 msgbox 等待PD完成并锁住按键操作 // 弹出 msgbox 等待PD完成并锁住按键操作
show_msgbox(); show_wait_msgbox();
// lv_lib_pm_goto("PPS Page", NULL); // lv_lib_pm_goto("PPS Page", NULL);
} }
break; break;
@@ -223,8 +216,8 @@ static void _setting_init(void) {
/////////////////////// ui_initialize ////////////////////// /////////////////////// ui_initialize //////////////////////
// 显示 msgbox // 显示 PD msgbox
static void show_msgbox(void) { static void show_wait_msgbox(void) {
// 获取当前视角y pos // 获取当前视角y pos
int32_t view_y = lv_obj_get_scroll_top(ui_SetPage); int32_t view_y = lv_obj_get_scroll_top(ui_SetPage);
@@ -251,8 +244,8 @@ static void show_msgbox(void) {
waiting_for_signal = true; waiting_for_signal = true;
} }
// 隐藏 msgbox // 隐藏 PD msgbox
static void hide_msgbox(void) { static void hide_wait_msgbox(void) {
if (msgbox) { if (msgbox) {
lv_obj_del(msgbox); lv_obj_del(msgbox);
msgbox = NULL; msgbox = NULL;
@@ -261,7 +254,39 @@ static void hide_msgbox(void) {
waiting_for_signal = false; waiting_for_signal = false;
} }
// build funtions // 定时器回调函数,用于关闭失败弹窗
static void _fail_msgbox_timer_cb(lv_timer_t * t) {
lv_obj_t * mbox = (lv_obj_t *)lv_timer_get_user_data(t);
if (mbox) {
lv_obj_del(mbox); // 删除 msgbox
}
lv_timer_del(t); // 删除定时器
}
// 显示PPS失败提示弹窗
static void show_fail_msgbox(void) {
// 获取当前视角y pos
int32_t view_y = lv_obj_get_scroll_top(ui_SetPage);
// 创建 msgbox
msgbox = lv_obj_create(ui_SetPage);
lv_obj_set_size(msgbox, 200, 100);
lv_obj_center(msgbox);
lv_obj_set_pos(msgbox, 0, view_y);
lv_obj_set_style_bg_color(msgbox, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_DEFAULT); // 红色背景
lv_obj_set_style_bg_opa(msgbox, 200, LV_PART_MAIN | LV_STATE_DEFAULT);
// 添加文本
lv_obj_t * label = lv_label_create(msgbox);
lv_label_set_text(label, "PD Setting Failed!");
lv_obj_center(label);
lv_obj_set_style_text_font(label, &lv_font_montserrat_18, LV_PART_MAIN | LV_STATE_DEFAULT);
// 设置定时器2 秒后关闭弹窗
lv_timer_t * timer = lv_timer_create(_fail_msgbox_timer_cb, 2000, msgbox); // 传递 msgbox 对象
lv_timer_set_repeat_count(timer, 1); // 只执行一次
}
/////////////////////// ui_initialize //////////////////////
void ui_SetPage_screen_init(void) void ui_SetPage_screen_init(void)
{ {

View File

@@ -1,10 +1,6 @@
// LVGL version: 9.2 // LVGL version: 9.2
// Project name: PowerPico // Project name: PowerPico
#include "BL24C02.h" // system settings
#include "rtc.h" // elapsed time
#include "data_queue.h" // bsp/data_queue.h for voltage/current queues
#include "./ui.h" #include "./ui.h"
#include "./screens/ui_StartPage.h" #include "./screens/ui_StartPage.h"
#include "./screens/ui_mainPage.h" #include "./screens/ui_mainPage.h"
@@ -12,53 +8,6 @@
#include "./screens/ui_SetPage.h" #include "./screens/ui_SetPage.h"
#include "./screens/ui_PPSPage.h" #include "./screens/ui_PPSPage.h"
//////////// interface for system hw settings ///////////
// get functions
void ui_GetElapsedTime_HMS(uint8_t *hours, uint8_t *minutes, uint8_t *seconds) {
GetElapsedTime_HMS(hours, minutes, seconds);
}
uint8_t ui_get_back_light_level(void) {
return Sys_Get_BacklightLevel();
}
bool ui_get_key_sound_enable(void) {
return Sys_Get_KeySoundEnable();
}
uint16_t ui_get_display_rotation(void) {
return Sys_Get_Rotation();
}
float ui_get_voltage(void) {
return queue_average(global_voltage_queue);
}
float ui_get_current(void) {
return queue_average(global_current_queue);
}
// set functions
void ui_set_back_light_level(uint8_t level) {
Sys_Set_BacklightLevel(level);
}
void ui_set_key_sound_enable(bool enable) {
Sys_Set_KeySoundEnable(enable);
}
void ui_set_display_rotation(uint16_t rotation) {
Sys_Set_Rotation(rotation);
}
// sys save function
void ui_system_settings_save(void) {
EEPROM_SysSetting_Save();
}
///////////////////// VARIABLES //////////////////// ///////////////////// VARIABLES ////////////////////
// pages // pages
@@ -99,15 +48,6 @@ Page_t pages[] = {
#error "LV_COLOR_DEPTH should be 16bit to match SquareLine Studio's settings" #error "LV_COLOR_DEPTH should be 16bit to match SquareLine Studio's settings"
#endif #endif
///////////////////// help funtions ////////////////////
void ui_full_screen_refresh(lv_obj_t * screen) {
// 标记整个屏幕为脏区域
lv_obj_invalidate(screen);
// 或者立即刷新整个屏幕
lv_refr_now(NULL);
}
/////////////////////// Timer ////////////////////// /////////////////////// Timer //////////////////////
/** /**
* Main timer for Refreshing the screens * Main timer for Refreshing the screens

View File

@@ -8,39 +8,14 @@
extern "C" { extern "C" {
#endif #endif
#include "lvgl.h"
#include "stdio.h" #include "stdio.h"
#include "lvgl.h"
#include "./common/lv_lib_pm.h" #include "./common/lv_lib_pm.h"
#include "./common/lv_lib_animation.h" #include "./common/lv_lib_animation.h"
#include "./ui_helpers.h"
void ui_init(void); void ui_init(void);
///////////////////// help funtions ////////////////////
void ui_full_screen_refresh(lv_obj_t * screen);
///////////// interface for system settings ////////////
// get functions
void ui_GetElapsedTime_HMS(uint8_t *hours, uint8_t *minutes, uint8_t *seconds);
uint8_t ui_get_back_light_level(void);
bool ui_get_key_sound_enable(void);
uint16_t ui_get_display_rotation(void);
float ui_get_voltage(void);
float ui_get_current(void);
// set functions
void ui_set_back_light_level(uint8_t level);
void ui_set_key_sound_enable(bool enable);
void ui_set_display_rotation(uint16_t rotation);
// sys save function
void ui_system_settings_save(void);
// FONTS // FONTS
LV_FONT_DECLARE(ui_font_HeiTi32); LV_FONT_DECLARE(ui_font_HeiTi32);
LV_FONT_DECLARE(ui_font_HeiTi48); LV_FONT_DECLARE(ui_font_HeiTi48);

View File

@@ -0,0 +1,100 @@
// LVGL version: 9.2
// Project name: PowerPico
#include "BL24C02.h" // system settings
#include "rtc.h" // elapsed time
#include "data_queue.h" // bsp/data_queue.h for voltage/current queues
#include "user_PDUFPTask.h" // comunicate with PD UFP Task
#include "./ui_helpers.h"
///////////////////// ui help funtions ////////////////////
void ui_full_screen_refresh(lv_obj_t * screen) {
// 标记整个屏幕为脏区域
lv_obj_invalidate(screen);
// 或者立即刷新整个屏幕
lv_refr_now(NULL);
}
//////////// interface for system hw settings ///////////
// get functions
void ui_GetElapsedTime_HMS(uint8_t *hours, uint8_t *minutes, uint8_t *seconds) {
GetElapsedTime_HMS(hours, minutes, seconds);
}
uint8_t ui_get_back_light_level(void) {
return Sys_Get_BacklightLevel();
}
bool ui_get_key_sound_enable(void) {
return Sys_Get_KeySoundEnable();
}
uint16_t ui_get_display_rotation(void) {
return Sys_Get_Rotation();
}
float ui_get_voltage(void) {
return queue_average(global_voltage_queue);
}
float ui_get_current(void) {
return queue_average(global_current_queue);
}
// set functions
void ui_set_back_light_level(uint8_t level) {
Sys_Set_BacklightLevel(level);
}
void ui_set_key_sound_enable(bool enable) {
Sys_Set_KeySoundEnable(enable);
}
void ui_set_display_rotation(uint16_t rotation) {
Sys_Set_Rotation(rotation);
}
// sys save function
void ui_system_settings_save(void) {
EEPROM_SysSetting_Save();
}
///////////// interface for com with PD UFP Task //////////////
void ui_send_pps_start_msg(void) {
PD_command_msg_t pd_ui_msg;
pd_ui_msg.event = PD_CMD_START;
osMessageQueuePut(PD_cmd_MessageQueue, &pd_ui_msg, 0, 1);
}
void ui_send_pps_stop_msg(void) {
PD_command_msg_t pd_ui_msg;
pd_ui_msg.event = PD_CMD_STOP;
osMessageQueuePut(PD_cmd_MessageQueue, &pd_ui_msg, 0, 1);
}
void ui_send_pps_set_msg(float voltage, float current) {
PD_command_msg_t pd_ui_msg;
pd_ui_msg.event = PD_CMD_SET_PPS;
pd_ui_msg.set_voltage = voltage;
pd_ui_msg.set_current = current;
osMessageQueuePut(PD_cmd_MessageQueue, &pd_ui_msg, 0, 1);
}
// 非阻塞获取消息队列, 查看是否ready
int8_t MsgQueueGet_PPS_ready(void) {
PD_handle_event_t pd_handle_event;
if(osMessageQueueGet(PD_handle_event_MsgQueue, &pd_handle_event, NULL, 0)==osOK) {
if(pd_handle_event == PD_EVT_PPS_READY) {
return 1;
} else if(pd_handle_event == PD_EVT_PPS_FAILED) {
return -1;
}
}
return 0;
}

View File

@@ -0,0 +1,55 @@
// LVGL VERSION: 9.2
#ifndef _UI_HELPERS_H
#define _UI_HELPERS_H
#ifdef __cplusplus
extern "C" {
#endif
#include "lvgl.h"
#include "stdio.h"
///////////////////// help funtions ////////////////////
void ui_full_screen_refresh(lv_obj_t * screen);
///////////// interface for system settings ////////////
// get functions
void ui_GetElapsedTime_HMS(uint8_t *hours, uint8_t *minutes, uint8_t *seconds);
uint8_t ui_get_back_light_level(void);
bool ui_get_key_sound_enable(void);
uint16_t ui_get_display_rotation(void);
float ui_get_voltage(void);
float ui_get_current(void);
// set functions
void ui_set_back_light_level(uint8_t level);
void ui_set_key_sound_enable(bool enable);
void ui_set_display_rotation(uint16_t rotation);
// sys save function
void ui_system_settings_save(void);
///////////////////////////////////////////////////////////////
///////////// interface for com with PD UFP Task //////////////
void ui_send_pps_start_msg(void);
void ui_send_pps_stop_msg(void);
void ui_send_pps_set_msg(float voltage, float current);
int8_t MsgQueueGet_PPS_ready(void);
///////////////////////////////////////////////////////////////
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif

View File

@@ -30,6 +30,8 @@ static void _timer_callback(void *argument)
osMessageQueuePut(PD_handle_event_MsgQueue, &ready, 0, 1); osMessageQueuePut(PD_handle_event_MsgQueue, &ready, 0, 1);
time_count = 0; time_count = 0;
osTimerStop(PD_UFP_Task_timer_id); osTimerStop(PD_UFP_Task_timer_id);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET); // FUSB CC pin disconnect
_pd_working_status = 0;
} }
} }
@@ -63,8 +65,9 @@ void PDUFPTask(void *argument)
_pd_working_status = 1; _pd_working_status = 1;
} else if(_pd_working_status && ui_msg.event == PD_CMD_STOP) { } else if(_pd_working_status && ui_msg.event == PD_CMD_STOP) {
// FUSB CC pin disconnect
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET);
_pd_working_status = 0;
} else if(_pd_working_status && ui_msg.event == PD_CMD_SET_PPS) { } else if(_pd_working_status && ui_msg.event == PD_CMD_SET_PPS) {
// 设置PPS电压电流 // 设置PPS电压电流