This commit is contained in:
YuXifeng 2025-04-14 19:27:42 +08:00
parent 72ef13eaeb
commit e99d3cdff8
4 changed files with 65 additions and 10 deletions

View File

@ -12,6 +12,7 @@
#include "lvgl.h"
#include "spiffs.h"
#include "flasher_tool.h"
#include "public.h"
static const char *TAG = "events_init";
@ -21,13 +22,16 @@ static const char *TAG = "events_init";
#endif
extern lv_indev_t *lvgl_button_indev;
const char* chip_list[6] = {
"esp32c2",
"esp32c3",
"esp32c6",
const char* chip_list[9] = {
"esp8266",
"esp32",
"esp32s2",
"esp32c3",
"esp32s3",
"esp32c2",
"null",
"esp32h2",
"esp32c6",
};
static char chip_path[48] = {0};
// static char download_file[64] = {0};
@ -49,6 +53,8 @@ static void file_btn_event_handler(lv_event_t *e) {
lv_obj_t *btn = lv_event_get_target(e); // 获取被点击的按钮
const char *btn_text = lv_list_get_btn_text(guider_ui.screen_imglist_list_1,btn); // 获取按钮上的文本
return;
// 使用 strncpy 复制,并确保字符串以 '\0' 结尾
strncpy(guider_ui.user_obj.burn_title, btn_text, sizeof(guider_ui.user_obj.burn_title) - 1);
guider_ui.user_obj.burn_title[sizeof(guider_ui.user_obj.burn_title) - 1] = '\0';
@ -71,6 +77,7 @@ static void btn_event_handler(lv_event_t *e)
lv_event_code_t code = lv_event_get_code(e);
// 通过 lv_event_get_param() 获取传递的按键值
uint32_t key = (uint32_t)lv_event_get_param(e);
if (code == LV_EVENT_VALUE_CHANGED) {
if (key == LV_KEY_ESC) {
ESP_LOGI(TAG,"LV_KEY_ESC");
lv_indev_set_group(lvgl_button_indev, guider_ui.user_obj.home_btn_group);
@ -78,6 +85,38 @@ static void btn_event_handler(lv_event_t *e)
ui_load_scr_animation(&guider_ui, &guider_ui.screen, guider_ui.screen_del, &guider_ui.screen_imglist_del, setup_scr_screen, LV_SCR_LOAD_ANIM_OVER_RIGHT, 200, 200, true, true);
}
} else if (code == LV_EVENT_CLICKED) {
ESP_LOGI(TAG,"LV_EVENT_CLICKED");
}
}
static void file_imglist_handler(lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_CLICKED) {
ESP_LOGI(TAG,"LV_EVENT_CLICKED");
lv_obj_t *dropdown = lv_event_get_target(e);
uint16_t selected_index = lv_dropdown_get_selected(dropdown);
sprintf(&chip_path[0],"/spiffs/%s",chip_list[selected_index]);
// printf("用户选择了: %s (索引: %d)\n", chip_list[selected_index], selected_index);
lv_obj_clean(guider_ui.screen_imglist_list_1);
lv_obj_t *file_btn[5];
spiffs_list_t directory[5];
uint8_t file_num = 0;
file_num = list_files_in_spiffs(chip_path,directory,5);
for(int i=0;i<file_num;i++)
{
ESP_LOGI(TAG,"[%d] Fond esp32s2 file:%s,size:%ld",i,directory[i].name,directory[i].size);
file_btn[i] = lv_list_add_btn(guider_ui.screen_imglist_list_1,NULL,directory[i].name);
lv_obj_add_event_cb(file_btn[i], file_btn_event_handler, LV_EVENT_CLICKED, NULL);
lv_group_add_obj(guider_ui.user_obj.imglist_group,file_btn[i]);
}
}
}
static void key_event_handler(lv_event_t *e)
@ -169,6 +208,17 @@ static void screen_btn_2_event_handler (lv_event_t *e)//镜像按钮
lv_group_set_default(guider_ui.user_obj.imglist_group);
lv_group_add_obj(guider_ui.user_obj.imglist_group,guider_ui.screen_imglist_ddlist_1);
lv_obj_add_event_cb(guider_ui.screen_imglist_ddlist_1, btn_event_handler, LV_EVENT_VALUE_CHANGED, NULL);
lv_obj_add_event_cb(guider_ui.screen_imglist_ddlist_1, file_imglist_handler, LV_EVENT_CLICKED, NULL);
for (int i=0;i < 9;i++) {
//chip_list
lv_dropdown_add_option(guider_ui.screen_imglist_ddlist_1,chip_list[i],i);
}
// lv_dropdown_add_option(guider_ui.screen_imglist_ddlist_1,"ESP32",1);
// lv_dropdown_add_option(guider_ui.screen_imglist_ddlist_1,"ESP32S2",2);
// lv_dropdown_add_option(guider_ui.screen_imglist_ddlist_1,"ESP32C3",3);
lv_dropdown_set_selected(guider_ui.screen_imglist_ddlist_1, System_Config.def_target_chip);
lv_event_send(guider_ui.screen_imglist_ddlist_1,LV_EVENT_CLICKED,NULL);
break;
}
default:

View File

@ -128,7 +128,7 @@ void setup_scr_screen_imglist(lv_ui *ui)
//Write codes screen_imglist_ddlist_1
ui->screen_imglist_ddlist_1 = lv_dropdown_create(ui->screen_imglist);
lv_dropdown_set_options(ui->screen_imglist_ddlist_1, "ESP32C2\nESP32C3\nESP32C6\nESP32\nESP32S2\nESP32S3");
// lv_dropdown_set_options(ui->screen_imglist_ddlist_1, "ESP8266");
lv_obj_set_pos(ui->screen_imglist_ddlist_1, 4, 18);
lv_obj_set_size(ui->screen_imglist_ddlist_1, 120, 24);

View File

@ -158,6 +158,9 @@ void app_main(void)
ESP_ERROR_CHECK(i2c_master_init());
System_Config.def_target_chip = ESP32S2_CHIP;
#if CONFIG_IDF_TARGET_ESP32C3
usb_serial2Uart(NULL);
#endif

View File

@ -72,6 +72,8 @@ extern esp_timer_handle_t SysTick_timer;
extern EventGroupHandle_t System_eventGroup;
extern Sys_config_t System_Config;
extern void usb_serial2Uart(void *pvParameters);
extern void Read_CMD_task(void *pvParameter);
extern void Flasher_tool_task(void *pvParameter);