#include "ui_bt.h" #include "img_bg.h" #include "kt_ui.h" #include "kt.h" #include "key_event_deal.h" #include "user_cfg.h" #include "lvgl.h" #include "drv_st7789.h" extern void bt_get_play_time(tPlayTime *pt); static lv_obj_t *bar_progress; static lv_obj_t *label_curr_time; static lv_obj_t *label_total_time; /* 刷新播放时间显示 */ static void ui_bt_refresh_play_time(void) { tPlayTime pt; bt_get_play_time(&pt); char buf[16]; /* 当前时间 M:SS */ lv_snprintf(buf, sizeof(buf), "%" LV_PRIu32 ":%02" LV_PRIu32, pt.curr_min, pt.curr_sec); lv_label_set_text(label_curr_time, buf); /* 总时间 M:SS */ lv_snprintf(buf, sizeof(buf), "%" LV_PRIu32 ":%02" LV_PRIu32, pt.total_min, pt.total_sec); lv_label_set_text(label_total_time, buf); /* 进度条 0~100 */ u32 total_sec = pt.total_min * 60 + pt.total_sec; u32 curr_sec = pt.curr_min * 60 + pt.curr_sec; int val = (total_sec > 0) ? (int)(curr_sec * 100 / total_sec) : 0; if (val > 100) val = 100; lv_bar_set_value(bar_progress, val, LV_ANIM_OFF); } void ui_bt_update_play_time(void) { ui_bt_refresh_play_time(); } lv_obj_t *ui_bt_create(void) { lv_obj_t *scr = lv_obj_create(NULL); lv_obj_set_style_bg_img_src(scr, &img_bg, 0); lv_obj_set_style_pad_all(scr, 0, 0); lv_obj_clear_flag(scr, LV_OBJ_FLAG_SCROLLABLE); #define TITLE_H 36 #define BAR_W (LCD_W - 48) #define BAR_X 24 #define BAR_H 14 /* 加粗进度条 */ #define BAR_Y (LCD_H - 70) /* 靠下 */ #define TIME_Y (BAR_Y + BAR_H + 8) /* 顶部标题 */ lv_obj_t *title = lv_label_create(scr); lv_label_set_text(title, "BT"); lv_obj_set_style_text_font(title, &lv_font_montserrat_20, 0); lv_obj_set_style_text_color(title, lv_color_hex(0xFFFFFF), 0); lv_obj_set_pos(title, 0, 8); lv_obj_set_width(title, LCD_W); lv_obj_set_style_text_align(title, LV_TEXT_ALIGN_CENTER, 0); /* 蓝牙名:屏幕正中 */ lv_obj_t *label_bt_name = lv_label_create(scr); { const char *name = bt_get_local_name(); lv_label_set_text(label_bt_name, (name && name[0]) ? name : "---"); } lv_obj_set_style_text_color(label_bt_name, lv_color_hex(0xFFFFFF), 0); lv_obj_set_style_text_font(label_bt_name, &lv_font_montserrat_16, 0); lv_obj_set_width(label_bt_name, LCD_W); lv_obj_set_style_text_align(label_bt_name, LV_TEXT_ALIGN_CENTER, 0); lv_obj_center(label_bt_name); /* 进度条:靠下、加粗,背景色调亮便于与背景图区分 */ bar_progress = lv_bar_create(scr); lv_obj_set_size(bar_progress, BAR_W, BAR_H); lv_obj_set_pos(bar_progress, BAR_X, BAR_Y); lv_bar_set_range(bar_progress, 0, 100); lv_bar_set_value(bar_progress, 0, LV_ANIM_OFF); lv_obj_set_style_bg_color(bar_progress, lv_color_hex(0xAAAAAA), LV_PART_MAIN); /* 浅灰,与背景图对比明显 */ lv_obj_set_style_bg_opa(bar_progress, LV_OPA_70, LV_PART_MAIN); lv_obj_set_style_bg_color(bar_progress, lv_color_hex(0x2196F3), LV_PART_INDICATOR); lv_obj_set_style_radius(bar_progress, 7, 0); lv_obj_set_style_radius(bar_progress, 7, LV_PART_INDICATOR); /* 当前时间 / 总时间 标签 */ label_curr_time = lv_label_create(scr); lv_label_set_text(label_curr_time, "0:00"); lv_obj_set_style_text_color(label_curr_time, lv_color_hex(0xFFFFFF), 0); lv_obj_set_style_text_font(label_curr_time, &lv_font_montserrat_16, 0); lv_obj_set_pos(label_curr_time, BAR_X, TIME_Y); label_total_time = lv_label_create(scr); lv_label_set_text(label_total_time, "0:00"); lv_obj_set_style_text_color(label_total_time, lv_color_hex(0xFFFFFF), 0); lv_obj_set_style_text_font(label_total_time, &lv_font_montserrat_16, 0); lv_obj_set_pos(label_total_time, BAR_X + BAR_W - 48, TIME_Y); ui_bt_refresh_play_time(); return scr; } void ui_bt_on_key(int key_event, int key_value) { (void)key_value; switch (key_event) { case KEY_MUSIC_PREV: case KEY_USER_PREV: kt_ui_show_page(KT_PAGE_HOME); break; case KEY_USER_PLAY_TIME_UPDATE: ui_bt_refresh_play_time(); break; default: break; } }