1. 完成了对音频播放类的完整C++封装,测试通过
2. 修复了LVGL渲染类当中的一些小bug 3. 增加了一些CPU资源占用的日志打印函数,运行在主线程当中 4. 完善了底层通信类的封装,基于websocket,尚未测试
This commit is contained in:
@@ -20,35 +20,6 @@ const auto sleep_time = seconds{
|
||||
5
|
||||
};
|
||||
|
||||
// 下面的这个函数可以放在任何线程中,自动打印出对应线程的信息
|
||||
void print_thread_info(const char *extra = nullptr)
|
||||
{
|
||||
std::stringstream ss;
|
||||
if (extra) {
|
||||
ss << extra;
|
||||
}
|
||||
ss << "Core id: " << xPortGetCoreID()
|
||||
<< ", prio: " << uxTaskPriorityGet(nullptr)
|
||||
<< ", minimum free stack: " << uxTaskGetStackHighWaterMark(nullptr) << " bytes.";
|
||||
ESP_LOGI(pcTaskGetName(nullptr), "%s", ss.str().c_str());
|
||||
}
|
||||
|
||||
void thread_func_inherited()
|
||||
{
|
||||
while (true) {
|
||||
print_thread_info("我是 普普通通的inherited 线程");
|
||||
std::this_thread::sleep_for(sleep_time);
|
||||
}
|
||||
}
|
||||
|
||||
void thread_func_any_core()
|
||||
{
|
||||
while (true) {
|
||||
print_thread_info("我是一个会跑在任意一个核的任务~");
|
||||
std::this_thread::sleep_for(sleep_time);
|
||||
}
|
||||
}
|
||||
|
||||
esp_pthread_cfg_t create_config(const char *name, int core_id, int stack, int prio)
|
||||
{
|
||||
|
||||
@@ -66,6 +37,8 @@ esp_pthread_cfg_t create_config(const char *name, int core_id, int stack, int pr
|
||||
|
||||
#include "LVGLRender.h"
|
||||
#include "SDFileManager.h"
|
||||
#include "AudioOutput.h"
|
||||
|
||||
void OTAClass::Init() {
|
||||
ESP_LOGI("OTA", "Init");
|
||||
|
||||
@@ -75,22 +48,28 @@ void OTAClass::Init() {
|
||||
std::string listing = SDFileManager::getInstance()->lsCommand(".", false, true);
|
||||
ESP_LOGI("SD", "%s", listing.c_str());
|
||||
|
||||
LVGLRender::getInstance()->RenderGif("sequence01.gif");
|
||||
// 切换到music目录
|
||||
SDFileManager::getInstance()->cdCommand("music");
|
||||
std::string pwdPath = SDFileManager::getInstance()->pwdCommand();
|
||||
ESP_LOGI("SD", "%s", pwdPath.c_str());
|
||||
|
||||
// 1. 创建普通函数一个可以运行在任意核上的线程
|
||||
ThreadConfig config1;
|
||||
config1.name = "NormalThread";
|
||||
// config1.core_id = 0; // 不指定运行在哪个核,使其自动选择
|
||||
config1.stack_size = 3072;
|
||||
config1.priority = 5; // 优先级
|
||||
std::thread normal_thread = ThreadManager::createThread(config1, thread_func_any_core);
|
||||
// 列出当前目录内容
|
||||
listing = SDFileManager::getInstance()->lsCommand(".", false, true);
|
||||
ESP_LOGI("SD", "%s", listing.c_str());
|
||||
|
||||
ThreadConfig config2;
|
||||
config2.name = "Thread2";
|
||||
config2.core_id = 1; // 指定运行在核1
|
||||
config2.stack_size = 3072;
|
||||
config2.priority = 5;
|
||||
std::thread thread2 = ThreadManager::createThread(config2, thread_func_inherited);
|
||||
LVGLRender::getInstance()->RenderGif("sequence01m.gif");
|
||||
|
||||
// 设置音量
|
||||
AudioOutput::getInstance()->setVolume(5);
|
||||
|
||||
// 同步播放
|
||||
AudioOutput::getInstance()->playSync("/sdcard/music", "Old_Memory.mp3");
|
||||
|
||||
// 等待5秒
|
||||
// vTaskDelay(pdMS_TO_TICKS(10000));
|
||||
|
||||
// 暂停
|
||||
// AudioOutput::getInstance()->pause();
|
||||
|
||||
|
||||
// 配置Wifi连接线程参数
|
||||
@@ -108,25 +87,23 @@ void OTAClass::Init() {
|
||||
5 // 最大重试次数
|
||||
);
|
||||
|
||||
ThreadConfig ota_config;
|
||||
ota_config.name = "OTA";
|
||||
ota_config.stack_size = 4096;
|
||||
ota_config.priority = 6;
|
||||
ota_config.core_id = 0;
|
||||
std::thread ota_thread = ThreadManager::createMemberThread<OTAClass>(
|
||||
ota_config,
|
||||
this,
|
||||
&OTAClass::Update
|
||||
);
|
||||
// ThreadConfig ota_config;
|
||||
// ota_config.name = "OTA";
|
||||
// ota_config.stack_size = 4096;
|
||||
// ota_config.priority = 6;
|
||||
// ota_config.core_id = 0;
|
||||
// std::thread ota_thread = ThreadManager::createMemberThread<OTAClass>(
|
||||
// ota_config,
|
||||
// this,
|
||||
// &OTAClass::Update
|
||||
// );
|
||||
|
||||
|
||||
while (true) {
|
||||
std::stringstream ss;
|
||||
ss << "core id: " << xPortGetCoreID()
|
||||
<< ", prio: " << uxTaskPriorityGet(nullptr)
|
||||
<< ", minimum free stack: " << uxTaskGetStackHighWaterMark(nullptr) << " bytes.";
|
||||
ESP_LOGI(pcTaskGetName(nullptr), "%s", ss.str().c_str());
|
||||
std::this_thread::sleep_for(sleep_time);
|
||||
while (true) { // 主线程线程循环
|
||||
ThreadManager::print_sys_memory(); // 打印系统内存使用情况
|
||||
ThreadManager::stats_task(); // 打印任务统计信息
|
||||
|
||||
std::this_thread::sleep_for(sleep_time); // 休眠5秒
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user