1. 花了几天时间基于lvgl8.3封装了lvgl_cpp,写了一些基本需要的控件,支持链式调用
还存在一点点bug,不难fix 2. 增加了中文字库,支持中文显示 3. 修复和优化了一些地方
This commit is contained in:
@@ -92,6 +92,39 @@ std::string SDFileManager::readFileSync(const char* path) {
|
||||
return content;
|
||||
}
|
||||
|
||||
std::string SDFileManager::readFileSync(const std::string& path) {
|
||||
std::lock_guard<std::mutex> lock(file_operation_mutex);
|
||||
|
||||
if (!is_initialized) {
|
||||
ESP_LOGE("SDFileManager", "SD card not initialized");
|
||||
return "";
|
||||
}
|
||||
|
||||
FILE* file = fopen(path.c_str(), "r");
|
||||
if (file == nullptr) {
|
||||
ESP_LOGE("SDFileManager", "Failed to open file: %s", path.c_str());
|
||||
return "";
|
||||
}
|
||||
|
||||
// 获取文件大小
|
||||
fseek(file, 0, SEEK_END);
|
||||
long size = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
// 读取文件内容
|
||||
std::string content;
|
||||
content.resize(size);
|
||||
size_t bytes_read = fread(&content[0], 1, size, file);
|
||||
fclose(file);
|
||||
|
||||
if (bytes_read != static_cast<size_t>(size)) {
|
||||
ESP_LOGE("SDFileManager", "Failed to read entire file: %s", path.c_str());
|
||||
return "";
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
std::vector<std::string> SDFileManager::listFilesSync(const char* directory, const char* extension) {
|
||||
std::lock_guard<std::mutex> lock(file_operation_mutex);
|
||||
|
||||
|
||||
@@ -44,6 +44,13 @@ public:
|
||||
*/
|
||||
std::string readFileSync(const char* path);
|
||||
|
||||
/**
|
||||
* 同步读取文件(std::string)
|
||||
* @param path 文件路径
|
||||
* @return 文件内容
|
||||
*/
|
||||
std::string readFileSync(const std::string& path);
|
||||
|
||||
/**
|
||||
* 同步列出目录下的文件
|
||||
* @param directory 目录路径
|
||||
|
||||
Reference in New Issue
Block a user