From 22c60ee94da0bbe8c24dfcbe9e17f6aa6cee4dd1 Mon Sep 17 00:00:00 2001 From: jarvis Date: Tue, 11 Mar 2025 08:52:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E9=83=A8=E6=96=87=E4=BB=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=B3=BB=E7=BB=9F=E7=A7=BB=E6=A4=8D=E6=88=90=E5=8A=9F?= =?UTF-8?q?=20=E5=B9=B6=E8=BF=9B=E8=A1=8C=E4=BA=86=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/FluxPower/CMakeLists.txt | 2 +- components/FluxPower/FluxPower.c | 10 +++-- components/FluxSpifs/CMakeLists.txt | 3 ++ components/FluxSpifs/FluxSpifs.c | 67 +++++++++++++++++++++++++++++ components/FluxSpifs/FluxSpifs.h | 14 ++++++ main/CMakeLists.txt | 2 +- main/i80_controller_example_main.c | 3 ++ partitions_lvgl_example.csv | 2 +- 8 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 components/FluxSpifs/CMakeLists.txt create mode 100644 components/FluxSpifs/FluxSpifs.c create mode 100644 components/FluxSpifs/FluxSpifs.h diff --git a/components/FluxPower/CMakeLists.txt b/components/FluxPower/CMakeLists.txt index 9f7dce6..25678fe 100644 --- a/components/FluxPower/CMakeLists.txt +++ b/components/FluxPower/CMakeLists.txt @@ -1,3 +1,3 @@ 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 ".") diff --git a/components/FluxPower/FluxPower.c b/components/FluxPower/FluxPower.c index 1d2fae9..7d20b35 100644 --- a/components/FluxPower/FluxPower.c +++ b/components/FluxPower/FluxPower.c @@ -2,6 +2,7 @@ #include "FluxPower.h" #include "FluxWifi.h" +#include "FluxSpifs.h" static const char *TAG = "POWER_IO"; @@ -23,6 +24,12 @@ static float Bat_Voltage_Value = 0; void powerTask(void) { + /*初始化存储系统*/ + spifs_init(); + + /*进行WIFI扫描*/ + wifi_scan(); + while (1) { ESP_ERROR_CHECK(adc_oneshot_read(adc1_handle, EXAMPLE_ADC1_CHAN8, &Bat_Adc_Value)); @@ -40,9 +47,6 @@ void powerTask(void) /*设置Home页的显示电量*/ 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); - - /*进行WIFI扫描*/ - wifi_scan(); } } diff --git a/components/FluxSpifs/CMakeLists.txt b/components/FluxSpifs/CMakeLists.txt new file mode 100644 index 0000000..b204ece --- /dev/null +++ b/components/FluxSpifs/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "FluxSpifs.c" + INCLUDE_DIRS "." + REQUIRES spiffs) diff --git a/components/FluxSpifs/FluxSpifs.c b/components/FluxSpifs/FluxSpifs.c new file mode 100644 index 0000000..479769a --- /dev/null +++ b/components/FluxSpifs/FluxSpifs.c @@ -0,0 +1,67 @@ +#include +#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"); + } + } + +} diff --git a/components/FluxSpifs/FluxSpifs.h b/components/FluxSpifs/FluxSpifs.h new file mode 100644 index 0000000..4c421b5 --- /dev/null +++ b/components/FluxSpifs/FluxSpifs.h @@ -0,0 +1,14 @@ + +#include +#include +#include +#include +#include "esp_err.h" +#include "esp_spiffs.h" + +#define CONFIG_EXAMPLE_SPIFFS_CHECK_ON_START (1) + +void spifs_init(void); + + + diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 19a404e..d735d1a 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -4,7 +4,7 @@ if(CONFIG_EXAMPLE_LCD_IMAGE_FROM_EMBEDDED_BINARY) endif() 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 ".") if(CONFIG_EXAMPLE_LCD_IMAGE_FROM_FILE_SYSTEM) diff --git a/main/i80_controller_example_main.c b/main/i80_controller_example_main.c index c68c0db..3fe5887 100644 --- a/main/i80_controller_example_main.c +++ b/main/i80_controller_example_main.c @@ -41,6 +41,9 @@ /*添加WiFi管理头文件*/ #include "FluxWifi.h" +/*包含内部存储的头文件*/ +#include "FluxSpifs.h" + static const char *TAG = "example"; #include "modbus_params.h" diff --git a/partitions_lvgl_example.csv b/partitions_lvgl_example.csv index c11b9e8..4a88051 100644 --- a/partitions_lvgl_example.csv +++ b/partitions_lvgl_example.csv @@ -3,4 +3,4 @@ nvs, data, nvs, 0x9000, 0x6000, phy_init, data, phy, 0xf000, 0x1000, factory, app, factory, 0x10000, 2M, -storage, data, spiffs, , 0xF0000, +storage, data, spiffs, , 0xA0000,