From a8b434d86b0d18ea1bc098831eafd3ccb917906b Mon Sep 17 00:00:00 2001 From: vonweller <154695311+vonweller@users.noreply.github.com> Date: Sat, 31 May 2025 10:22:45 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D128*32=E5=B1=8F=E5=B9=95?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=96=87=E5=AD=97=E4=B8=8D=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ai_voice_display_oled/display.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/examples/ai_voice_display_oled/display.cpp b/examples/ai_voice_display_oled/display.cpp index 7702e7f..4e135e2 100644 --- a/examples/ai_voice_display_oled/display.cpp +++ b/examples/ai_voice_display_oled/display.cpp @@ -32,13 +32,11 @@ Display::Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t pane .mirror_x = mirror_x, .mirror_y = mirror_y, }, - .color_format = LV_COLOR_FORMAT_UNKNOWN, .flags = { .buff_dma = 1, .buff_spiram = 0, .sw_rotate = 0, - .swap_bytes = 0, .full_refresh = 0, .direct_mode = 0, }, @@ -65,14 +63,14 @@ void Display::Start() { lv_obj_set_style_border_width(container_, 0, 0); lv_obj_set_style_pad_row(container_, 0, 0); - /* Status bar */ + /* Status bar - 减小高度以适应32像素屏幕 */ status_bar_ = lv_obj_create(container_); - lv_obj_set_size(status_bar_, LV_HOR_RES, 16); + lv_obj_set_size(status_bar_, LV_HOR_RES, 12); // 从16改为12像素 lv_obj_set_style_border_width(status_bar_, 0, 0); lv_obj_set_style_pad_all(status_bar_, 0, 0); lv_obj_set_style_radius(status_bar_, 0, 0); - /* Content */ + /* Content - 现在有20像素高度可用 */ content_ = lv_obj_create(container_); lv_obj_set_scrollbar_mode(content_, LV_SCROLLBAR_MODE_OFF); lv_obj_set_style_radius(content_, 0, 0); @@ -82,17 +80,17 @@ void Display::Start() { lv_obj_set_flex_flow(content_, LV_FLEX_FLOW_ROW); lv_obj_set_style_flex_main_place(content_, LV_FLEX_ALIGN_CENTER, 0); - // 创建左侧固定宽度的容器 + // 创建左侧固定宽度的容器 - 减小宽度 content_left_ = lv_obj_create(content_); - lv_obj_set_size(content_left_, 32, LV_SIZE_CONTENT); // 固定宽度32像素 + lv_obj_set_size(content_left_, 20, LV_SIZE_CONTENT); // 从32改为20像素 lv_obj_set_style_pad_all(content_left_, 0, 0); lv_obj_set_style_border_width(content_left_, 0, 0); emotion_label_ = lv_label_create(content_left_); - lv_obj_set_style_text_font(emotion_label_, &font_awesome_30_1, 0); + lv_obj_set_style_text_font(emotion_label_, &font_awesome_14_1, 0); // 使用较小字体 lv_label_set_text(emotion_label_, FONT_AWESOME_AI_CHIP); lv_obj_center(emotion_label_); - lv_obj_set_style_pad_top(emotion_label_, 8, 0); + lv_obj_set_style_pad_top(emotion_label_, 2, 0); // 减小上边距 content_right_ = lv_obj_create(content_); lv_obj_set_size(content_right_, LV_SIZE_CONTENT, LV_SIZE_CONTENT); @@ -105,8 +103,8 @@ void Display::Start() { lv_label_set_text(chat_message_label_, ""); lv_label_set_long_mode(chat_message_label_, LV_LABEL_LONG_SCROLL_CIRCULAR); lv_obj_set_style_text_align(chat_message_label_, LV_TEXT_ALIGN_LEFT, 0); - lv_obj_set_width(chat_message_label_, width_ - 32); - lv_obj_set_style_pad_top(chat_message_label_, 14, 0); + lv_obj_set_width(chat_message_label_, width_ - 20); // 调整宽度从32改为20 + lv_obj_set_style_pad_top(chat_message_label_, 2, 0); // 减小上边距从14改为2 // 延迟一定的时间后开始滚动字幕 static lv_anim_t a; From 21b2a279c63c1da840d76993d2913c36e8ad8c02 Mon Sep 17 00:00:00 2001 From: vonweller <154695311+vonweller@users.noreply.github.com> Date: Sat, 31 May 2025 10:27:03 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E9=80=82=E9=85=8DOLED=E5=90=84=E7=A7=8D?= =?UTF-8?q?=E5=B1=8F=E5=B9=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 适配OLED 128*32 适配OLED 128*64 适配OLED 128*128 --- examples/ai_voice_display_oled/display.cpp | 50 ++++++++++++++++++---- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/examples/ai_voice_display_oled/display.cpp b/examples/ai_voice_display_oled/display.cpp index 4e135e2..0152eea 100644 --- a/examples/ai_voice_display_oled/display.cpp +++ b/examples/ai_voice_display_oled/display.cpp @@ -55,6 +55,38 @@ void Display::Start() { lv_obj_set_style_text_font(screen, &font_puhui_14_1, 0); lv_obj_set_style_text_color(screen, lv_color_black(), 0); + // 自适应布局计算 + // 基于屏幕尺寸计算合适的布局参数 + int status_bar_height; + int content_left_width; + int emotion_top_padding; + int chat_message_top_padding; + const lv_font_t* emotion_font; + + // 根据屏幕高度自适应调整布局 + if (height_ <= 32) { + // 小屏幕 (128x32 等) + status_bar_height = height_ * 0.375; // 约37.5% (32*0.375=12) + content_left_width = width_ * 0.15625; // 约15.6% (128*0.15625=20) + emotion_top_padding = 2; + chat_message_top_padding = 2; + emotion_font = &font_awesome_14_1; + } else if (height_ <= 64) { + // 中等屏幕 (128x64 等) + status_bar_height = height_ * 0.25; // 25% (64*0.25=16) + content_left_width = width_ * 0.25; // 25% (128*0.25=32) + emotion_top_padding = height_ * 0.125; // 12.5% (64*0.125=8) + chat_message_top_padding = height_ * 0.21875; // 约21.9% (64*0.21875≈14) + emotion_font = &font_awesome_30_1; + } else { + // 大屏幕 (128x128 等) + status_bar_height = height_ * 0.125; // 12.5% + content_left_width = width_ * 0.25; // 25% + emotion_top_padding = height_ * 0.0625; // 6.25% + chat_message_top_padding = height_ * 0.109375; // 约10.9% + emotion_font = &font_awesome_30_1; + } + /* Container */ container_ = lv_obj_create(screen); lv_obj_set_size(container_, LV_HOR_RES, LV_VER_RES); @@ -63,14 +95,14 @@ void Display::Start() { lv_obj_set_style_border_width(container_, 0, 0); lv_obj_set_style_pad_row(container_, 0, 0); - /* Status bar - 减小高度以适应32像素屏幕 */ + /* Status bar - 自适应高度 */ status_bar_ = lv_obj_create(container_); - lv_obj_set_size(status_bar_, LV_HOR_RES, 12); // 从16改为12像素 + lv_obj_set_size(status_bar_, LV_HOR_RES, status_bar_height); lv_obj_set_style_border_width(status_bar_, 0, 0); lv_obj_set_style_pad_all(status_bar_, 0, 0); lv_obj_set_style_radius(status_bar_, 0, 0); - /* Content - 现在有20像素高度可用 */ + /* Content - 剩余空间自动分配 */ content_ = lv_obj_create(container_); lv_obj_set_scrollbar_mode(content_, LV_SCROLLBAR_MODE_OFF); lv_obj_set_style_radius(content_, 0, 0); @@ -80,17 +112,17 @@ void Display::Start() { lv_obj_set_flex_flow(content_, LV_FLEX_FLOW_ROW); lv_obj_set_style_flex_main_place(content_, LV_FLEX_ALIGN_CENTER, 0); - // 创建左侧固定宽度的容器 - 减小宽度 + // 创建左侧固定宽度的容器 - 自适应宽度 content_left_ = lv_obj_create(content_); - lv_obj_set_size(content_left_, 20, LV_SIZE_CONTENT); // 从32改为20像素 + lv_obj_set_size(content_left_, content_left_width, LV_SIZE_CONTENT); lv_obj_set_style_pad_all(content_left_, 0, 0); lv_obj_set_style_border_width(content_left_, 0, 0); emotion_label_ = lv_label_create(content_left_); - lv_obj_set_style_text_font(emotion_label_, &font_awesome_14_1, 0); // 使用较小字体 + lv_obj_set_style_text_font(emotion_label_, emotion_font); // 自适应字体 lv_label_set_text(emotion_label_, FONT_AWESOME_AI_CHIP); lv_obj_center(emotion_label_); - lv_obj_set_style_pad_top(emotion_label_, 2, 0); // 减小上边距 + lv_obj_set_style_pad_top(emotion_label_, emotion_top_padding, 0); // 自适应上边距 content_right_ = lv_obj_create(content_); lv_obj_set_size(content_right_, LV_SIZE_CONTENT, LV_SIZE_CONTENT); @@ -103,8 +135,8 @@ void Display::Start() { lv_label_set_text(chat_message_label_, ""); lv_label_set_long_mode(chat_message_label_, LV_LABEL_LONG_SCROLL_CIRCULAR); lv_obj_set_style_text_align(chat_message_label_, LV_TEXT_ALIGN_LEFT, 0); - lv_obj_set_width(chat_message_label_, width_ - 20); // 调整宽度从32改为20 - lv_obj_set_style_pad_top(chat_message_label_, 2, 0); // 减小上边距从14改为2 + lv_obj_set_width(chat_message_label_, width_ - content_left_width); // 自适应宽度 + lv_obj_set_style_pad_top(chat_message_label_, chat_message_top_padding, 0); // 自适应上边距 // 延迟一定的时间后开始滚动字幕 static lv_anim_t a; From 36ac43d0b10e335ea468fe43ba4ec0167b1f47d9 Mon Sep 17 00:00:00 2001 From: vonweller <154695311+vonweller@users.noreply.github.com> Date: Sat, 31 May 2025 10:31:20 +0800 Subject: [PATCH 3/6] Update display.cpp --- examples/ai_voice_display_oled/display.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ai_voice_display_oled/display.cpp b/examples/ai_voice_display_oled/display.cpp index 0152eea..10b185d 100644 --- a/examples/ai_voice_display_oled/display.cpp +++ b/examples/ai_voice_display_oled/display.cpp @@ -119,7 +119,7 @@ void Display::Start() { lv_obj_set_style_border_width(content_left_, 0, 0); emotion_label_ = lv_label_create(content_left_); - lv_obj_set_style_text_font(emotion_label_, emotion_font); // 自适应字体 + lv_obj_set_style_text_font(emotion_label_, emotion_font, 0); // 自适应字体,添加缺失的第三个参数 lv_label_set_text(emotion_label_, FONT_AWESOME_AI_CHIP); lv_obj_center(emotion_label_); lv_obj_set_style_pad_top(emotion_label_, emotion_top_padding, 0); // 自适应上边距 From 1eac9e5ccd9658a6103843b0be04b0b0596d6ee2 Mon Sep 17 00:00:00 2001 From: vonweller <154695311+vonweller@users.noreply.github.com> Date: Sat, 31 May 2025 11:08:13 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=EF=BC=8C=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E5=8F=98=E9=87=8F=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ai_voice_display_oled/display.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/ai_voice_display_oled/display.cpp b/examples/ai_voice_display_oled/display.cpp index 10b185d..8978e19 100644 --- a/examples/ai_voice_display_oled/display.cpp +++ b/examples/ai_voice_display_oled/display.cpp @@ -32,6 +32,7 @@ Display::Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t pane .mirror_x = mirror_x, .mirror_y = mirror_y, }, + .color_format=LV_COLOR_FORMAT_UNKNOWN, .flags = { .buff_dma = 1, @@ -57,11 +58,11 @@ void Display::Start() { // 自适应布局计算 // 基于屏幕尺寸计算合适的布局参数 - int status_bar_height; - int content_left_width; - int emotion_top_padding; - int chat_message_top_padding; - const lv_font_t* emotion_font; + int status_bar_height=1; + int content_left_width=1; + int emotion_top_padding=1; + int chat_message_top_padding=1; + const lv_font_t* emotion_font=&font_awesome_14_1; // 根据屏幕高度自适应调整布局 if (height_ <= 32) { From e2531f25917064a23db5cfc4c8d9462c38ddd291 Mon Sep 17 00:00:00 2001 From: vonweller <154695311+vonweller@users.noreply.github.com> Date: Sat, 31 May 2025 11:12:35 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=8F=90=E9=AB=98=E9=98=85=E8=AF=BB?= =?UTF-8?q?=E6=80=A7=EF=BC=8C=E7=BB=9F=E4=B8=80=E4=BB=A3=E7=A0=81=E8=A7=84?= =?UTF-8?q?=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ai_voice_display_oled/display.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/ai_voice_display_oled/display.cpp b/examples/ai_voice_display_oled/display.cpp index 8978e19..f0b427a 100644 --- a/examples/ai_voice_display_oled/display.cpp +++ b/examples/ai_voice_display_oled/display.cpp @@ -32,7 +32,7 @@ Display::Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t pane .mirror_x = mirror_x, .mirror_y = mirror_y, }, - .color_format=LV_COLOR_FORMAT_UNKNOWN, + .color_format = LV_COLOR_FORMAT_UNKNOWN, .flags = { .buff_dma = 1, @@ -58,11 +58,11 @@ void Display::Start() { // 自适应布局计算 // 基于屏幕尺寸计算合适的布局参数 - int status_bar_height=1; - int content_left_width=1; - int emotion_top_padding=1; - int chat_message_top_padding=1; - const lv_font_t* emotion_font=&font_awesome_14_1; + int status_bar_height = 1; + int content_left_width = 1; + int emotion_top_padding = 1; + int chat_message_top_padding = 1; + const lv_font_t* emotion_font = &font_awesome_14_1; // 根据屏幕高度自适应调整布局 if (height_ <= 32) { From 419c02fff0de71dc09ed987fdb24ed4122359532 Mon Sep 17 00:00:00 2001 From: vonweller <154695311+vonweller@users.noreply.github.com> Date: Sat, 31 May 2025 11:20:38 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0swap=5Fbytes=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ai_voice_display_oled/display.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/ai_voice_display_oled/display.cpp b/examples/ai_voice_display_oled/display.cpp index f0b427a..0ffcedd 100644 --- a/examples/ai_voice_display_oled/display.cpp +++ b/examples/ai_voice_display_oled/display.cpp @@ -38,6 +38,7 @@ Display::Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t pane .buff_dma = 1, .buff_spiram = 0, .sw_rotate = 0, + .swap_bytes = 0, .full_refresh = 0, .direct_mode = 0, },