esp32-off-Line-tools/main/GUI/generated/events_init.c

155 lines
6.1 KiB
C

/*
* Copyright 2025 NXP
* NXP Proprietary. This software is owned or controlled by NXP and may only be used strictly in
* accordance with the applicable license terms. By expressly accepting such terms or by downloading, installing,
* activating and/or otherwise using the software, you are agreeing that you have read, and that you agree to
* comply with and are bound by, such license terms. If you do not agree to be bound by the applicable license
* terms, then you may not retain, install, activate or otherwise use the software.
*/
#include "events_init.h"
#include <stdio.h>
#include "lvgl.h"
#include "spiffs.h"
static const char *TAG = "events_init";
#if LV_USE_GUIDER_SIMULATOR && LV_USE_FREEMASTER
#include "freemaster_client.h"
#endif
extern lv_indev_t *lvgl_button_indev;
const char* chip_list[6] = {
"esp32c2",
"esp32c3",
"esp32c6",
"esp32",
"esp32s2",
"esp32s3",
};
static char chip_path[48] = {0};
static char download_file[64] = {0};
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); // 获取按钮上的文本
memset(&download_file[0],0x00,64);
sprintf(&download_file[0],"%s/%s",chip_path,btn_text);
printf("被点击的文件: %s\n", download_file);
ui_load_scr_animation(&guider_ui, &guider_ui.sscreen_burn, guider_ui.sscreen_burn_del, &guider_ui.screen_imglist_del, setup_scr_sscreen_burn, LV_SCR_LOAD_ANIM_OVER_LEFT, 200, 200, false, true);
}
static void key_event_handler(lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *obj = lv_event_get_target(e);
if (code == LV_EVENT_VALUE_CHANGED)
{
// 通过 lv_event_get_param() 获取传递的按键值
uint32_t key = (uint32_t)lv_event_get_param(e);
if (key == LV_KEY_ESC) {
printf("LV_EVENT_VALUE_CHANGED 事件: key=%ld\n", key);
lv_group_remove_all_objs(guider_ui.imglist_group);
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, false, true);
lv_indev_set_group(lvgl_button_indev, guider_ui.home_btn_group);
lv_group_set_default(guider_ui.home_btn_group);
lv_group_add_obj(guider_ui.home_btn_group,guider_ui.screen_btn_1);
lv_group_add_obj(guider_ui.home_btn_group,guider_ui.screen_btn_2);
lv_group_add_obj(guider_ui.home_btn_group,guider_ui.screen_btn_3);
}else{
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.imglist_group,file_btn[i]);
}
}
}
}
static void screen_btn_1_event_handler (lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
switch (code) {
case LV_EVENT_CLICKED:
{
lv_group_remove_all_objs(guider_ui.home_btn_group);
ui_load_scr_animation(&guider_ui, &guider_ui.screen_imglist, guider_ui.screen_imglist_del, &guider_ui.screen_del, setup_scr_screen_imglist, LV_SCR_LOAD_ANIM_OVER_LEFT, 200, 200, false, false);
lv_indev_set_group(lvgl_button_indev, guider_ui.imglist_group);
lv_group_set_default(guider_ui.imglist_group);
lv_group_add_obj(guider_ui.imglist_group,guider_ui.screen_imglist_btn_1);
lv_group_add_obj(guider_ui.imglist_group,guider_ui.screen_imglist_ddlist_1);
lv_obj_add_event_cb(guider_ui.screen_imglist_ddlist_1, key_event_handler, LV_EVENT_VALUE_CHANGED, NULL);
uint16_t selected_index = lv_dropdown_get_selected(guider_ui.screen_imglist_ddlist_1);
sprintf(&chip_path[0],"/spiffs/%s",chip_list[selected_index]);
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_group_add_obj(guider_ui.imglist_group,file_btn[i]);
}
// lv_obj_t * btn1;
// btn1 = lv_list_add_btn(guider_ui.screen_imglist_list_1,NULL,"OfflineBurn.bin");
// lv_group_add_obj(guider_ui.imglist_group,btn1);
// lv_obj_t * btn2;
// btn2 = lv_list_add_btn(guider_ui.screen_imglist_list_1,NULL,"target_esp32s3.bin");
// lv_group_add_obj(guider_ui.imglist_group,btn2);
break;
}
default:
break;
}
}
static void screen_btn_3_event_handler (lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
switch (code) {
case LV_EVENT_CLICKED:
{
ui_load_scr_animation(&guider_ui, &guider_ui.sscreen_burn, guider_ui.sscreen_burn_del, &guider_ui.screen_del, setup_scr_sscreen_burn, LV_SCR_LOAD_ANIM_OVER_RIGHT, 200, 200, false, false);
break;
}
default:
break;
}
}
void events_init_screen (lv_ui *ui)
{
lv_obj_add_event_cb(ui->screen_btn_1, screen_btn_1_event_handler, LV_EVENT_ALL, ui);
lv_obj_add_event_cb(ui->screen_btn_3, screen_btn_3_event_handler, LV_EVENT_ALL, ui);
}
void events_init(lv_ui *ui)
{
}