load image from file and storage
from storage doesn't work yet, because of memory issues
This commit is contained in:
@@ -3,6 +3,7 @@ idf_component_register(SRCS
|
||||
"main.cpp"
|
||||
PRIV_REQUIRES
|
||||
fatfs
|
||||
storage
|
||||
esp_wifi
|
||||
wpa_supplicant
|
||||
INCLUDE_DIRS ".")
|
||||
|
16173
firmware/main/image.h
16173
firmware/main/image.h
File diff suppressed because one or more lines are too long
@@ -1,12 +1,12 @@
|
||||
#include <lgfx.h>
|
||||
#include <lvgl.h>
|
||||
|
||||
#include "esp_vfs.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "ff.h"
|
||||
#include "image.h"
|
||||
#include "storage.h"
|
||||
|
||||
#define screenWidth (480)
|
||||
#define screenHeight (320)
|
||||
@@ -16,9 +16,9 @@ uint8_t lvBuffer1[lvBufferSize];
|
||||
uint8_t lvBuffer2[lvBufferSize];
|
||||
|
||||
static const char *TAG = "main";
|
||||
const char *base_path = "/storage";
|
||||
|
||||
LGFX tft;
|
||||
static FATFS fs;
|
||||
|
||||
void setup_tft(void)
|
||||
{
|
||||
@@ -52,71 +52,25 @@ void my_touch_read(lv_indev_t *indev_driver, lv_indev_data_t *data)
|
||||
}
|
||||
}
|
||||
|
||||
void lv_handler()
|
||||
void fatfs_lvgl_init(void)
|
||||
{
|
||||
static uint64_t previousUpdate = 0;
|
||||
static uint64_t interval = 0;
|
||||
// 1. Das Dateisystem "mounten" (einmalig für FatFS)
|
||||
f_mount(&fs, "S:", 1); // "S:" ist der Laufwerksbuchstabe
|
||||
|
||||
uint64_t eus = esp_timer_get_time();
|
||||
if (eus - previousUpdate > interval)
|
||||
{
|
||||
previousUpdate = eus;
|
||||
interval = lv_timer_handler(); // Update the UI
|
||||
lv_tick_inc(interval);
|
||||
vTaskDelay(pdMS_TO_TICKS(interval - 1));
|
||||
}
|
||||
}
|
||||
// 2. Eine Treiber-Variable deklarieren
|
||||
static lv_fs_drv_t drv;
|
||||
lv_fs_drv_init(&drv); // Treiberstruktur initialisieren
|
||||
|
||||
void setup_fatfs()
|
||||
{
|
||||
const esp_vfs_fat_mount_config_t mount_config = {
|
||||
.format_if_mount_failed = false,
|
||||
.max_files = 4,
|
||||
.allocation_unit_size = CONFIG_WL_SECTOR_SIZE,
|
||||
.disk_status_check_enable = false,
|
||||
.use_one_fat = false,
|
||||
};
|
||||
// 3. Unsere Bridge-Funktionen zuweisen
|
||||
drv.letter = 'S'; // WICHTIG: Muss mit dem Buchstaben in f_mount übereinstimmen
|
||||
drv.open_cb = fs_open;
|
||||
drv.close_cb = fs_close;
|
||||
drv.read_cb = fs_read;
|
||||
drv.seek_cb = fs_seek;
|
||||
drv.tell_cb = fs_tell;
|
||||
|
||||
ESP_LOGI(TAG, "Mounting FAT filesystem in read/write mode");
|
||||
static wl_handle_t wl_handle = WL_INVALID_HANDLE;
|
||||
esp_err_t err = esp_vfs_fat_spiflash_mount_rw_wl(base_path, "storage", &mount_config, &wl_handle);
|
||||
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err));
|
||||
return;
|
||||
}
|
||||
|
||||
FILE *f;
|
||||
ESP_LOGI(TAG, "Reading file");
|
||||
|
||||
const char *host_filename1 = "/storage/response.png";
|
||||
|
||||
struct stat info;
|
||||
struct tm timeinfo;
|
||||
char buffer[32];
|
||||
|
||||
if (stat(host_filename1, &info) < 0)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to read file stats");
|
||||
return;
|
||||
}
|
||||
localtime_r(&info.st_mtime, &timeinfo);
|
||||
strftime(buffer, sizeof(buffer), "%Y-%m-%d", &timeinfo);
|
||||
|
||||
ESP_LOGI(TAG, "The file '%s' was modified at date: %s", host_filename1, buffer);
|
||||
|
||||
f = fopen(host_filename1, "rb");
|
||||
if (f == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to open file for reading");
|
||||
return;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
ESP_LOGI(TAG, "Unmounting FAT filesystem");
|
||||
ESP_ERROR_CHECK(esp_vfs_fat_spiflash_unmount_rw_wl(base_path, wl_handle));
|
||||
ESP_LOGI(TAG, "Done");
|
||||
// 4. Den Treiber bei LVGL registrieren
|
||||
lv_fs_drv_register(&drv);
|
||||
}
|
||||
|
||||
void esp_lv_log_print(lv_log_level_t level, const char *buf)
|
||||
@@ -145,14 +99,15 @@ void esp_lv_log_print(lv_log_level_t level, const char *buf)
|
||||
|
||||
void setup()
|
||||
{
|
||||
setup_fatfs();
|
||||
|
||||
setup_tft();
|
||||
|
||||
lv_init();
|
||||
|
||||
lv_log_register_print_cb(esp_lv_log_print);
|
||||
|
||||
fs_mount();
|
||||
fatfs_lvgl_init();
|
||||
|
||||
static auto *display = lv_display_create(screenWidth, screenHeight);
|
||||
lv_display_set_color_format(display, LV_COLOR_FORMAT_RGB565);
|
||||
lv_display_set_flush_cb(display, flush);
|
||||
@@ -163,15 +118,23 @@ void setup()
|
||||
lv_indev_set_read_cb(lvInput, my_touch_read);
|
||||
|
||||
ESP_LOGI(TAG, "create image");
|
||||
#ifndef LOCAL
|
||||
static auto *image = lv_image_create(lv_scr_act());
|
||||
lv_image_set_src(image, &image_data);
|
||||
lv_obj_align(image, LV_ALIGN_TOP_LEFT, 0, 0);
|
||||
#else
|
||||
lv_obj_t *img = lv_image_create(lv_screen_active());
|
||||
lv_image_set_src(img, "S:/response.png"); // Pfad beginnt mit "S:"
|
||||
lv_obj_center(img);
|
||||
#endif
|
||||
ESP_LOGI(TAG, "image created");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
lv_handler();
|
||||
lv_tick_inc(10);
|
||||
lv_timer_handler();
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
|
||||
void lvgl_task(void *pvParameter)
|
||||
@@ -181,9 +144,10 @@ void lvgl_task(void *pvParameter)
|
||||
{
|
||||
loop();
|
||||
}
|
||||
fs_unmount();
|
||||
}
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
xTaskCreatePinnedToCore(lvgl_task, "lvgl_task", 4096, NULL, 5, NULL, 1);
|
||||
xTaskCreatePinnedToCore(lvgl_task, "lvgl_task", 8192, NULL, 5, NULL, 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user