这是一次长久的提交:

1. 应用界面增加了返回主页的按钮
2. 修复了gif渲染内存泄漏的严重bug
3. 将PetDao当中的cJSON API替换为cpp_json,完美通过测试
4. 整合已经实现的各种上层建筑,实现了一个宠物对话基本业务应用,用于样品测试展示用
5. 重构了音频播放类,使其更modern,更加便于移植和拓展
This commit is contained in:
Misaki
2025-10-16 11:36:45 +08:00
parent 801138631e
commit ba5e47bc77
38 changed files with 2487 additions and 2008 deletions
+85
View File
@@ -306,4 +306,89 @@ extern "C" void app_main() {
}
}
}
```
```c++
// 有关lvgl_cpp的部分控件使用
/* LVGL 已经初始化,屏幕驱动已注册 */
auto scr = lvgl_cpp::Screen{}; // RAII,离开作用域自动 del
lv_scr_load(scr.raw()); // 让 LVGL 把它当活动屏幕
lvgl_cpp::Image img(scr);
img.bin("pic_no_alp_swap.bin", 720, 720)
.center();
/* 1. 创建按钮 */
/* 1. 黑色文字样式 */
static lvgl_cpp::Style txt_style;
txt_style.text_color(lv_color_black());
/* 2. 按钮 */
lvgl_cpp::Button btn{scr};
btn.size(150, 60).pos(40, 40);
/* 3. 先创建 Label 对象并保存,再链式调 */
lvgl_cpp::Label lbl{btn}; // 一定要存实例
lbl.text("Click Me")
.add_style(&txt_style.s, LV_PART_MAIN); // 样式作用到文字本身
/* 3. 注册点击事件 */
btn.on(LV_EVENT_CLICKED, [](lv_event_t*){
lvgl_cpp::Toast::show("Saved successfully !");
/* 2. 警告,3 s,顶部 */
lvgl_cpp::Toast::show("SD card missing", lvgl_cpp::Toast::Type::WARN, 3000, LV_ALIGN_TOP_MID, 20);
/* 3. 错误,1.5 s,底部右侧 */
lvgl_cpp::Toast::show("Network error", lvgl_cpp::Toast::Type::ERROR, 1500, LV_ALIGN_BOTTOM_RIGHT, -30);
ESP_LOGI("BTN", "pressed");
});
/* 1. 消息框 */
const char* btns[] = {"Yes", "No", ""};
auto mbox = lvgl_cpp::MsgBox::create("Hint", "Delete file ?", btns);
/* 3. 进度条(双向 + 动画) */
lvgl_cpp::Bar bar(scr);
bar.range(0, 100)
.start_value(20) // 左端
.value(80, LV_ANIM_ON) // 右端带动画
.anim_time(500)
.size(200, 15)
.align(LV_ALIGN_CENTER, nullptr, 0, 40);
/* 4. 折线:画一个 △ */
std::vector<lv_point_t> triangle = {{0,0}, {40,0}, {20,40}, {0,0}};
lvgl_cpp::Line line(scr);
line.points(triangle)
.y_invert(false)
.align(LV_ALIGN_CENTER, nullptr, 0, 100);
lvgl_cpp::Battery bat(scr);
bat.size(60, 30) // 手机经典尺寸
.percent(true) // 显示 50%
.onRead([]() -> uint8_t { // 替换成你的 ADC/INA219 回调
static uint8_t v = 100;
if (v) --v;
return v;
})
.align(LV_ALIGN_TOP_RIGHT, -10, 10); // 九宫格对齐
/* 3. 日期时间 */
lvgl_cpp::DateTime dt(scr);
dt.format("%m/%d %a %H:%M")
.onRead([](char* buf, size_t len){
/* 这里用 SNTP / RTC 填充,示例直接给假时间 */
snprintf(buf, len, "06/25 Tue 14:30");
})
.align(LV_ALIGN_BOTTOM_MID, nullptr, 0, -10);
lvgl_cpp::ColorPicker cp(scr);
cp.size(120, 120)
.align(LV_ALIGN_BOTTOM_MID, nullptr, 0, -20)
.on(LV_EVENT_VALUE_CHANGED, [&](lv_event_t*){
lv_color_t c = cp.color();
ESP_LOGI("CP", "rgb=%d,%d,%d", c.ch.red, c.ch.green_h, c.ch.blue);
});
```