内部文件管理系统移植成功 并进行了测试

This commit is contained in:
jarvis 2025-03-11 08:52:40 +08:00
parent caaa816163
commit 22c60ee94d
8 changed files with 97 additions and 6 deletions

View File

@ -1,3 +1,3 @@
idf_component_register(SRCS "FluxPower.c" idf_component_register(SRCS "FluxPower.c"
REQUIRES driver freertos esp_adc FluxUI lvgl FluxWifi REQUIRES driver freertos esp_adc FluxUI lvgl FluxWifi FluxSpifs
INCLUDE_DIRS ".") INCLUDE_DIRS ".")

View File

@ -2,6 +2,7 @@
#include "FluxPower.h" #include "FluxPower.h"
#include "FluxWifi.h" #include "FluxWifi.h"
#include "FluxSpifs.h"
static const char *TAG = "POWER_IO"; static const char *TAG = "POWER_IO";
@ -23,6 +24,12 @@ static float Bat_Voltage_Value = 0;
void powerTask(void) void powerTask(void)
{ {
/*初始化存储系统*/
spifs_init();
/*进行WIFI扫描*/
wifi_scan();
while (1) while (1)
{ {
ESP_ERROR_CHECK(adc_oneshot_read(adc1_handle, EXAMPLE_ADC1_CHAN8, &Bat_Adc_Value)); ESP_ERROR_CHECK(adc_oneshot_read(adc1_handle, EXAMPLE_ADC1_CHAN8, &Bat_Adc_Value));
@ -40,9 +47,6 @@ void powerTask(void)
/*设置Home页的显示电量*/ /*设置Home页的显示电量*/
lv_slider_set_value(ui_Home_SliderHeaderBat,Bat_Voltage_Value/4.2*100,LV_ANIM_ON); lv_slider_set_value(ui_Home_SliderHeaderBat,Bat_Voltage_Value/4.2*100,LV_ANIM_ON);
lv_label_set_text_fmt(ui_Home_LabelHeaderBatValue,"%.0f%%",Bat_Voltage_Value/4.2*100); lv_label_set_text_fmt(ui_Home_LabelHeaderBatValue,"%.0f%%",Bat_Voltage_Value/4.2*100);
/*进行WIFI扫描*/
wifi_scan();
} }
} }

View File

@ -0,0 +1,3 @@
idf_component_register(SRCS "FluxSpifs.c"
INCLUDE_DIRS "."
REQUIRES spiffs)

View File

@ -0,0 +1,67 @@
#include <stdio.h>
#include "FluxSpifs.h"
#include "esp_log.h"
static const char *TAG = "spifs_example";
void spifs_init(void)
{
ESP_LOGI(TAG, "Initializing SPIFFS");
esp_vfs_spiffs_conf_t conf = {
.base_path = "/spiffs",
.partition_label = NULL,
.max_files = 5,
.format_if_mount_failed = true
};
// Use settings defined above to initialize and mount SPIFFS filesystem.
// Note: esp_vfs_spiffs_register is an all-in-one convenience function.
esp_err_t ret = esp_vfs_spiffs_register(&conf);
if (ret != ESP_OK) {
if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount or format filesystem");
} else if (ret == ESP_ERR_NOT_FOUND) {
ESP_LOGE(TAG, "Failed to find SPIFFS partition");
} else {
ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
}
return;
}
#ifdef CONFIG_EXAMPLE_SPIFFS_CHECK_ON_START
ESP_LOGI(TAG, "Performing SPIFFS_check().");
ret = esp_spiffs_check(conf.partition_label);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "SPIFFS_check() failed (%s)", esp_err_to_name(ret));
return;
} else {
ESP_LOGI(TAG, "SPIFFS_check() successful");
}
#endif
size_t total = 0, used = 0;
ret = esp_spiffs_info(conf.partition_label, &total, &used);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s). Formatting...", esp_err_to_name(ret));
esp_spiffs_format(conf.partition_label);
return;
} else {
ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
}
// Check consistency of reported partition size info.
if (used > total) {
ESP_LOGW(TAG, "Number of used bytes cannot be larger than total. Performing SPIFFS_check().");
ret = esp_spiffs_check(conf.partition_label);
// Could be also used to mend broken files, to clean unreferenced pages, etc.
// More info at https://github.com/pellepl/spiffs/wiki/FAQ#powerlosses-contd-when-should-i-run-spiffs_check
if (ret != ESP_OK) {
ESP_LOGE(TAG, "SPIFFS_check() failed (%s)", esp_err_to_name(ret));
return;
} else {
ESP_LOGI(TAG, "SPIFFS_check() successful");
}
}
}

View File

@ -0,0 +1,14 @@
#include <stdio.h>
#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include "esp_err.h"
#include "esp_spiffs.h"
#define CONFIG_EXAMPLE_SPIFFS_CHECK_ON_START (1)
void spifs_init(void);

View File

@ -4,7 +4,7 @@ if(CONFIG_EXAMPLE_LCD_IMAGE_FROM_EMBEDDED_BINARY)
endif() endif()
idf_component_register(SRCS "i80_controller_example_main.c" "lvgl_demo_ui.c" ${embedded_images} idf_component_register(SRCS "i80_controller_example_main.c" "lvgl_demo_ui.c" ${embedded_images}
REQUIRES FluxUI FluxPower spiffs FluxSD FluxMod FluxButton FluxWifi REQUIRES FluxUI FluxPower spiffs FluxSD FluxMod FluxButton FluxWifi FluxSpifs
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
if(CONFIG_EXAMPLE_LCD_IMAGE_FROM_FILE_SYSTEM) if(CONFIG_EXAMPLE_LCD_IMAGE_FROM_FILE_SYSTEM)

View File

@ -41,6 +41,9 @@
/*添加WiFi管理头文件*/ /*添加WiFi管理头文件*/
#include "FluxWifi.h" #include "FluxWifi.h"
/*包含内部存储的头文件*/
#include "FluxSpifs.h"
static const char *TAG = "example"; static const char *TAG = "example";
#include "modbus_params.h" #include "modbus_params.h"

View File

@ -3,4 +3,4 @@
nvs, data, nvs, 0x9000, 0x6000, nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000, phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 2M, factory, app, factory, 0x10000, 2M,
storage, data, spiffs, , 0xF0000, storage, data, spiffs, , 0xA0000,

1 # Name, Type, SubType, Offset, Size, Flags
3 nvs, data, nvs, 0x9000, 0x6000,
4 phy_init, data, phy, 0xf000, 0x1000,
5 factory, app, factory, 0x10000, 2M,
6 storage, data, spiffs, , 0xF0000, storage, data, spiffs, , 0xA0000,