97fe13da26
2. 修复了LVGL渲染类当中的一些小bug 3. 增加了一些CPU资源占用的日志打印函数,运行在主线程当中 4. 完善了底层通信类的封装,基于websocket,尚未测试
126 lines
3.5 KiB
C++
126 lines
3.5 KiB
C++
//
|
|
// Created by misaki on 2025/9/2.
|
|
//
|
|
#include "OTAClass.h"
|
|
#include "esp_log.h"
|
|
|
|
#include <iostream>
|
|
#include <thread>
|
|
#include <chrono>
|
|
#include <memory>
|
|
#include <sstream>
|
|
#include <pthread.h>
|
|
#include <esp_pthread.h>
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/task.h>
|
|
|
|
using namespace std::chrono;
|
|
|
|
const auto sleep_time = seconds{
|
|
5
|
|
};
|
|
|
|
esp_pthread_cfg_t create_config(const char *name, int core_id, int stack, int prio)
|
|
{
|
|
|
|
auto cfg = esp_pthread_get_default_config();
|
|
cfg.thread_name = name;
|
|
cfg.pin_to_core = core_id;
|
|
cfg.stack_size = stack;
|
|
cfg.prio = prio;
|
|
return cfg;
|
|
}
|
|
|
|
#include "ThreadManager.h"
|
|
#include "WifiConnectors.h"
|
|
#include <string>
|
|
|
|
#include "LVGLRender.h"
|
|
#include "SDFileManager.h"
|
|
#include "AudioOutput.h"
|
|
|
|
void OTAClass::Init() {
|
|
ESP_LOGI("OTA", "Init");
|
|
|
|
ESP_LOGI("OTAClass::Init", "当前固件版本 1.0.1");
|
|
|
|
// 列出当前目录内容
|
|
std::string listing = SDFileManager::getInstance()->lsCommand(".", false, true);
|
|
ESP_LOGI("SD", "%s", listing.c_str());
|
|
|
|
// 切换到music目录
|
|
SDFileManager::getInstance()->cdCommand("music");
|
|
std::string pwdPath = SDFileManager::getInstance()->pwdCommand();
|
|
ESP_LOGI("SD", "%s", pwdPath.c_str());
|
|
|
|
// 列出当前目录内容
|
|
listing = SDFileManager::getInstance()->lsCommand(".", false, true);
|
|
ESP_LOGI("SD", "%s", listing.c_str());
|
|
|
|
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连接线程参数
|
|
ThreadConfig wifi_config;
|
|
wifi_config.name = "WifiConnector"; // 线程名称
|
|
wifi_config.core_id = 1; // 绑定到核心1(避免与主线程冲突)
|
|
wifi_config.stack_size = 4096; // 设置稍大的栈空间(Wifi连接可能需要)
|
|
wifi_config.priority = 6; // 设置较高优先级(确保连接及时)
|
|
// 使用单例方式创建线程,调用connectWifi成员函数
|
|
std::thread wifi_thread = ThreadManager::createSingletonThread<WifiConnectors>(
|
|
wifi_config,
|
|
&WifiConnectors::connectWifi,
|
|
"Misaki-2.4G", // SSID
|
|
"88888888", // 密码
|
|
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
|
|
// );
|
|
|
|
|
|
while (true) { // 主线程线程循环
|
|
ThreadManager::print_sys_memory(); // 打印系统内存使用情况
|
|
ThreadManager::stats_task(); // 打印任务统计信息
|
|
|
|
std::this_thread::sleep_for(sleep_time); // 休眠5秒
|
|
}
|
|
}
|
|
|
|
#include "ota_ws.h"
|
|
// 启动OTA更新线程,前提是已经连接WiFi
|
|
void OTAClass::Update() {
|
|
// 测试OTA服务器192.168.1.11
|
|
while (true) {
|
|
if (WifiConnectors::getInstance()->isWifiConnect()) { // 如果Wifi已连接
|
|
ota_ws_start("192.168.1.11", 8080);
|
|
// 启动完就退出,删除自身
|
|
break;
|
|
}else {
|
|
std::this_thread::sleep_for(sleep_time);
|
|
}
|
|
}
|
|
vTaskDelete(nullptr);
|
|
}
|
|
|