1. 完成了对音频播放类的完整C++封装,测试通过

2. 修复了LVGL渲染类当中的一些小bug
3. 增加了一些CPU资源占用的日志打印函数,运行在主线程当中
4. 完善了底层通信类的封装,基于websocket,尚未测试
This commit is contained in:
Misaki
2025-09-12 02:11:50 +08:00
parent 4985fee7c2
commit 97fe13da26
16 changed files with 1297 additions and 85 deletions
@@ -54,7 +54,7 @@ LVGLRender::LVGLRender() {
std::thread tick_thread = ThreadManager::createMemberThread(trickConfig, this, &LVGLRender::LVGL_Update);
tick_thread.detach(); // 线程分离 生命周期跟随主线程结束,线程结束后自动销毁
tick_thread.detach(); // 线程分离 生命周期跟随主线程结束,线程结束后自动销毁(核心渲染线程)
ESP_LOGI("LVGL_Render", "LVGL_Render构造函数...创建LVGL心跳成功...");
}
@@ -104,36 +104,50 @@ bool LVGLRender::getGifWH(const uint8_t* raw, uint32_t& w, uint32_t& h)
void LVGLRender::renderGifInternal(const std::vector<uint8_t>& data,
uint32_t w, uint32_t h)
{
// 构造 lv_img_dsc_t —— 数据指针直接指向 vector 内部
static lv_img_dsc_t gif_desc;
// 删除旧对象
if (current_gif_obj != nullptr) {
lv_obj_del(current_gif_obj);
current_gif_obj = nullptr;
}
// 保存数据,防止被释放
current_gif_data = data;
// 构造新的描述符(不要 static)
lv_img_dsc_t gif_desc = {};
gif_desc.header.cf = LV_IMG_CF_RAW_CHROMA_KEYED;
gif_desc.header.always_zero = 0;
gif_desc.header.reserved = 0;
gif_desc.header.w = (lv_coord_t)w;
gif_desc.header.h = (lv_coord_t)h;
gif_desc.data_size = data.size();
gif_desc.data = data.data(); // 指向 vector 内部
gif_desc.data_size = current_gif_data.size();
gif_desc.data = current_gif_data.data();
// 创建 lv_gif 对象
lv_obj_t* gif = lv_gif_create(lv_scr_act());
lv_gif_set_src(gif, &gif_desc);
lv_obj_center(gif);
// 创建新的 GIF 对象
current_gif_obj = lv_gif_create(lv_scr_act());
lv_gif_set_src(current_gif_obj, &gif_desc);
lv_obj_center(current_gif_obj);
ESP_LOGI("LVGLRender", "GIF 已渲染到屏幕");
ESP_LOGI("LVGLRender", "GIF 已渲染并循环播放");
}
void LVGLRender::RenderGif(const std::string &filename) {
std::string fullPath = makeFullPath(filename);
if (filename == last_gif_filename) {
ESP_LOGW("LVGLRender", "重复加载同一 GIF,忽略");
return;
}
last_gif_filename = filename;
// 读文件
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_black(), 0); // 背景黑色
lv_obj_set_style_bg_opa(lv_scr_act(), LV_OPA_COVER, 0); // 透明度
std::string fullPath = makeFullPath(filename);
std::vector<uint8_t> gifBin = readWholeFile(fullPath);
if (gifBin.empty()) return;
// 校验并解析宽高
uint32_t w = 0, h = 0;
if (!getGifWH(gifBin.data(), w, h)) return;
// LVGL 渲染函数
renderGifInternal(gifBin, w, h);
}
@@ -12,6 +12,8 @@
#include <mutex>
#include <string>
#include <vector>
#include <core/lv_obj.h>
class LVGLRender {
public:
@@ -54,6 +56,10 @@ private:
static LVGLRender* LVGLRenderInstance; /// 单例实例
static std::mutex instance_mutex; /// 单例锁
static uint16_t fps; /// 帧率
lv_obj_t* current_gif_obj = nullptr; /// 当前GIF对象
std::vector<uint8_t> current_gif_data; /// 当前GIF数据
std::string last_gif_filename; /// 最后一次渲染的GIF文件名
};