90 lines
2.8 KiB
C
90 lines
2.8 KiB
C
#include "esp_check.h"
|
|
#include "esp_log.h"
|
|
#include "esp_lvgl_port.h"
|
|
#include "lcd/lcd.h"
|
|
#include "sd/sd.h"
|
|
#include "lvgl.h"
|
|
|
|
static const char *TAG = "app";
|
|
static lv_obj_t *log_textarea = NULL;
|
|
|
|
static void ui_log_append(const char *text)
|
|
{
|
|
if(log_textarea == NULL || text == NULL) return;
|
|
|
|
lvgl_port_lock(0);
|
|
lv_textarea_add_text(log_textarea, text);
|
|
lv_textarea_add_text(log_textarea, "\n");
|
|
lv_textarea_set_cursor_pos(log_textarea, LV_TEXTAREA_CURSOR_LAST);
|
|
lvgl_port_unlock();
|
|
}
|
|
|
|
static void create_log_ui(void)
|
|
{
|
|
lv_obj_t *screen = lv_screen_active();
|
|
lv_obj_set_style_bg_color(screen, lv_color_hex(0x101418), 0);
|
|
|
|
lv_obj_t *title = lv_label_create(screen);
|
|
lv_label_set_text(title, "SD Image Viewer");
|
|
lv_obj_set_style_text_color(title, lv_color_white(), 0);
|
|
lv_obj_align(title, LV_ALIGN_TOP_MID, 0, 14);
|
|
|
|
log_textarea = lv_textarea_create(screen);
|
|
lv_obj_set_size(log_textarea, lv_pct(92), lv_pct(84));
|
|
lv_obj_align(log_textarea, LV_ALIGN_BOTTOM_MID, 0, -14);
|
|
lv_textarea_set_one_line(log_textarea, false);
|
|
lv_textarea_set_cursor_click_pos(log_textarea, false);
|
|
lv_textarea_set_text(log_textarea, "");
|
|
lv_obj_set_style_bg_color(log_textarea, lv_color_hex(0x182028), 0);
|
|
lv_obj_set_style_text_color(log_textarea, lv_color_hex(0xdde7ef), 0);
|
|
lv_obj_set_style_border_color(log_textarea, lv_color_hex(0x4b6478), 0);
|
|
lv_obj_set_style_radius(log_textarea, 4, 0);
|
|
lv_obj_set_style_pad_all(log_textarea, 12, 0);
|
|
|
|
lv_textarea_add_text(log_textarea, "Boot UI ready\n");
|
|
lv_textarea_set_cursor_pos(log_textarea, LV_TEXTAREA_CURSOR_LAST);
|
|
}
|
|
|
|
void app_main(void)
|
|
{
|
|
ESP_LOGI(TAG, "Start display application");
|
|
ESP_ERROR_CHECK(lcd_init());
|
|
|
|
ESP_LOGI(TAG, "Creating log UI");
|
|
lvgl_port_lock(0);
|
|
create_log_ui();
|
|
lvgl_port_unlock();
|
|
|
|
ESP_LOGI(TAG, "Initializing SD card");
|
|
ui_log_append("Initializing SD card...");
|
|
sd_init();
|
|
print_sd_card_info();
|
|
ui_log_append("SD initialization done");
|
|
ESP_LOGI(TAG, "SD card initialization complete");
|
|
|
|
size_t file_count = sd_get_file_count();
|
|
ESP_LOGI(TAG, "Found %d files in root directory", file_count);
|
|
const char* filename = NULL;
|
|
|
|
while(file_count-- > 0 && (filename = sd_get_next_file()) != NULL){
|
|
ESP_LOGI(TAG, "Found file: %s", filename);
|
|
char line[96];
|
|
snprintf(line, sizeof(line), "Found file: %s", filename);
|
|
ui_log_append(line);
|
|
}
|
|
|
|
/*
|
|
FILE* file = sd_open_write("test.txt");
|
|
if(file != NULL){
|
|
fprintf(file, "Hello, SD card!\n");
|
|
sd_close_file(file);
|
|
ui_log_append("Wrote test.txt");
|
|
} else {
|
|
ui_log_append("Failed to open test.txt for writing");
|
|
}
|
|
*/
|
|
|
|
sd_destroy();
|
|
ui_log_append("SD card unmounted");
|
|
}
|