LVGL 8.3.10版本,tabview_1_tab_1

	void events_init_zhu_mian_screen(lv_ui *ui)
	->static void zhu_mian_screen_imgbtn_1_event_handler(lv_event_t *e)
	->	void setup_scr_tong_hua_screen(lv_ui *ui)
	->	events_init_tong_hua_screen(ui);
	->void call_screen_enter_cb(void)
	->static void call_screen_update_timer_callback(lv_timer_t *timer)
	->static void on_tong_hua_screen_imgbtn_4_click(lv_event_t *e)
	void create_tong_hua_screen_cont_2(lv_obj_t *parent, int x, int y, int id)
	
// 事件处理函数
#include <lvgl/lvgl.h>
#include <lvgl.h>
#include <stdio.h>

#define TIMER_INTERVAL_MS 30 // 定时器间隔,单位毫秒

// 假设这是您的容器创建函数
void create_tong_hua_screen_cont_2(lv_obj_t *parent, int x, int y, int id);
void create_tong_hua_screen_cont_6(lv_obj_t *parent, int x, int y, int id);

// 定时器回调函数
lv_timer_t *call_screen_enter_timer;
static int container_counter = 0;
static int container_counter2 = 0;
static int container_counter3 = 0;
const char *button_str = "Hello, World!";

// 图像按钮 tong_hua_screen_imgbtn_4 的点击事件回调函数
static void on_tong_hua_screen_imgbtn_4_click(lv_event_t *e)
{
    // 获取触发事件的对象
    lv_obj_t *obj = lv_event_get_target(e);
    // 获取附加数据(这里是按钮的唯一标识符)
    // int id = (int)lv_event_get_user_data(e); // 将 user_data 转换为 int 类型

    // 获取用户数据(这里是一个字符串)
    char *str_ptr = (char *)lv_event_get_user_data(e);

    // 获取触发事件的容器
    lv_obj_t *container = lv_obj_get_parent(obj);

    // 检查按钮的状态
    bool checked = lv_obj_has_state(obj, LV_STATE_CHECKED);

    if (checked)
    {
        // 如果按钮被选中
        printf("Button clicked! User data: %s\n", str_ptr);
    }
    else
    {
        // 如果按钮未被选中
        printf("Button clicked! User data: %s\n", str_ptr);
    }
}

// 图像按钮 tong_hua_screen_imgbtn_8 的点击事件回调函数
static void on_tong_hua_screen_imgbtn_8_click(lv_event_t *e)
{
    // 获取触发事件的对象
    lv_obj_t *obj = lv_event_get_target(e);
    // 获取附加数据(这里是按钮的唯一标识符)
    // int id = (int)lv_event_get_user_data(e); // 将 user_data 转换为 int 类型

    // 获取用户数据(这里是一个字符串)
    char *str_ptr = (char *)lv_event_get_user_data(e);

    // 获取触发事件的容器
    lv_obj_t *container = lv_obj_get_parent(obj);

    // 检查按钮的状态
    bool checked = lv_obj_has_state(obj, LV_STATE_CHECKED);

    if (checked)
    {
        // 如果按钮被选中
        printf("Button clicked! User data: %s\n", str_ptr);
    }
    else
    {
        // 如果按钮未被选中
        printf("Button clicked! User data: %s\n", str_ptr);
    }
}

void create_tong_hua_screen_cont_2(lv_obj_t *parent, int x, int y, int id)
{
    // 创建一个容器对象并设置其位置和大小
    lv_obj_t *tong_hua_screen_cont_2 = lv_obj_create(parent);
    lv_obj_set_pos(tong_hua_screen_cont_2, x, y);                             // 设置容器的位置
    lv_obj_set_size(tong_hua_screen_cont_2, 80, 120);                         // 设置容器的尺寸
    lv_obj_set_scrollbar_mode(tong_hua_screen_cont_2, LV_SCROLLBAR_MODE_OFF); // 关闭滚动条

    // 设置容器的边框宽度、不透明度、颜色、边角半径等样式
    lv_obj_set_style_border_width(tong_hua_screen_cont_2, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_opa(tong_hua_screen_cont_2, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_color(tong_hua_screen_cont_2, lv_color_hex(0x2195f6), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_side(tong_hua_screen_cont_2, LV_BORDER_SIDE_NONE, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_radius(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_top(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_bottom(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_left(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_right(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    // 创建一个可检查的图像按钮
    lv_obj_t *tong_hua_screen_imgbtn_4 = lv_imgbtn_create(tong_hua_screen_cont_2);
    lv_obj_add_flag(tong_hua_screen_imgbtn_4, LV_OBJ_FLAG_CHECKABLE);                                    // 图像按钮可以被选中
    lv_imgbtn_set_src(tong_hua_screen_imgbtn_4, LV_IMGBTN_STATE_RELEASED, NULL, &_AQ_alpha_75x75, NULL); // 设置图像按钮的源图片
    lv_obj_set_pos(tong_hua_screen_imgbtn_4, 2, 8);                                                      // 设置图像按钮的位置
    lv_obj_set_size(tong_hua_screen_imgbtn_4, 75, 75);                                                   // 设置图像按钮的尺寸

    // 设置图像按钮的文字标签
    lv_obj_t *tong_hua_screen_imgbtn_4_label = lv_label_create(tong_hua_screen_imgbtn_4);
    lv_label_set_text(tong_hua_screen_imgbtn_4_label, "");                      // 文字为空
    lv_label_set_long_mode(tong_hua_screen_imgbtn_4_label, LV_LABEL_LONG_WRAP); // 文字换行模式
    lv_obj_align(tong_hua_screen_imgbtn_4_label, LV_ALIGN_CENTER, 0, 0);        // 文字居中对齐
    lv_obj_set_style_pad_all(tong_hua_screen_imgbtn_4, 0, LV_STATE_DEFAULT);    // 设置内部填充为0

    // 设置图像按钮的样式
    lv_obj_set_style_text_color(tong_hua_screen_imgbtn_4, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(tong_hua_screen_imgbtn_4, &lv_font_SourceHanSerifSC_Regular_12, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_opa(tong_hua_screen_imgbtn_4, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_align(tong_hua_screen_imgbtn_4, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(tong_hua_screen_imgbtn_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    // 设置图像按钮在不同状态下的样式
    lv_obj_set_style_img_opa(tong_hua_screen_imgbtn_4, 255, LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_text_color(tong_hua_screen_imgbtn_4, lv_color_hex(0xFF33FF), LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_text_font(tong_hua_screen_imgbtn_4, &lv_font_SourceHanSerifSC_Regular_12, LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_text_opa(tong_hua_screen_imgbtn_4, 255, LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_shadow_width(tong_hua_screen_imgbtn_4, 0, LV_PART_MAIN | LV_STATE_PRESSED);

    // 设置图像按钮在选中状态下的样式
    lv_obj_set_style_img_opa(tong_hua_screen_imgbtn_4, 255, LV_PART_MAIN | LV_STATE_CHECKED);
    lv_obj_set_style_text_color(tong_hua_screen_imgbtn_4, lv_color_hex(0xFF33FF), LV_PART_MAIN | LV_STATE_CHECKED);
    lv_obj_set_style_text_font(tong_hua_screen_imgbtn_4, &lv_font_SourceHanSerifSC_Regular_12, LV_PART_MAIN | LV_STATE_CHECKED);
    lv_obj_set_style_text_opa(tong_hua_screen_imgbtn_4, 255, LV_PART_MAIN | LV_STATE_CHECKED);
    lv_obj_set_style_shadow_width(tong_hua_screen_imgbtn_4, 0, LV_PART_MAIN | LV_STATE_CHECKED);

    // 创建一个文本标签
    lv_obj_t *tong_hua_screen_label_4 = lv_label_create(tong_hua_screen_cont_2);
    lv_label_set_text(tong_hua_screen_label_4, "yong1");                 // 设置文本内容
    lv_label_set_long_mode(tong_hua_screen_label_4, LV_LABEL_LONG_WRAP); // 文字换行模式
    lv_obj_set_pos(tong_hua_screen_label_4, 5, 91);                      // 设置文本标签的位置
    lv_obj_set_size(tong_hua_screen_label_4, 69, 32);                    // 设置文本标签的尺寸

    // 设置文本标签的样式
    lv_obj_set_style_border_width(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_radius(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_color(tong_hua_screen_label_4, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(tong_hua_screen_label_4, &lv_font_SourceHanSerifSC_Regular_24, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_opa(tong_hua_screen_label_4, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_letter_space(tong_hua_screen_label_4, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_line_space(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_align(tong_hua_screen_label_4, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_top(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_right(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_bottom(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_left(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    // 创建一个LED指示灯
    lv_obj_t *tong_hua_screen_led_1 = lv_led_create(tong_hua_screen_cont_2);
    lv_led_set_brightness(tong_hua_screen_led_1, 255);               // 设置亮度
    lv_led_set_color(tong_hua_screen_led_1, lv_color_hex(0xff5700)); // 设置颜色
    lv_obj_set_pos(tong_hua_screen_led_1, 19, 15);                   // 设置位置
    lv_obj_set_size(tong_hua_screen_led_1, 12, 12);                  // 设置尺寸

    // 为图像按钮添加点击事件回调
    // lv_obj_add_event_cb(tong_hua_screen_imgbtn_4, on_tong_hua_screen_imgbtn_4_click, LV_EVENT_CLICKED, (void*)id);
    lv_obj_add_event_cb(tong_hua_screen_imgbtn_4, on_tong_hua_screen_imgbtn_4_click, LV_EVENT_CLICKED, (void *)button_str);
}

void create_tong_hua_screen_cont_6(lv_obj_t *parent, int x, int y, int id)
{
    // 创建一个容器对象并设置其位置和大小
    lv_obj_t *tong_hua_screen_cont_6 = lv_obj_create(parent);
    lv_obj_set_pos(tong_hua_screen_cont_6, x, y);                             // 设置容器的位置
    lv_obj_set_size(tong_hua_screen_cont_6, 80, 120);                         // 设置容器的尺寸
    lv_obj_set_scrollbar_mode(tong_hua_screen_cont_6, LV_SCROLLBAR_MODE_OFF); // 关闭滚动条

    // 设置容器的边框宽度、不透明度、颜色、边角半径等样式
    lv_obj_set_style_border_width(tong_hua_screen_cont_6, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_opa(tong_hua_screen_cont_6, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_color(tong_hua_screen_cont_6, lv_color_hex(0x2195f6), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_side(tong_hua_screen_cont_6, LV_BORDER_SIDE_NONE, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_radius(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_top(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_bottom(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_left(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_right(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    // 创建一个可检查的图像按钮
    lv_obj_t *tong_hua_screen_imgbtn_8 = lv_imgbtn_create(tong_hua_screen_cont_6);
    lv_obj_add_flag(tong_hua_screen_imgbtn_8, LV_OBJ_FLAG_CHECKABLE);                                    // 图像按钮可以被选中
    lv_imgbtn_set_src(tong_hua_screen_imgbtn_8, LV_IMGBTN_STATE_RELEASED, NULL, &_A6_alpha_80x90, NULL); // 设置图像按钮的源图片
    lv_obj_set_pos(tong_hua_screen_imgbtn_8, 5, 0);                                                      // 设置图像按钮的位置
    lv_obj_set_size(tong_hua_screen_imgbtn_8, 80, 90);                                                   // 设置图像按钮的尺寸

    // 创建一个文本标签
    lv_obj_t *tong_hua_screen_label_8 = lv_label_create(tong_hua_screen_cont_6);
    lv_label_set_text(tong_hua_screen_label_8, "sss");                   // 设置文本内容
    lv_label_set_long_mode(tong_hua_screen_label_8, LV_LABEL_LONG_WRAP); // 文字换行模式
    lv_obj_set_pos(tong_hua_screen_label_8, 5, 91);                      // 设置文本标签的位置
    lv_obj_set_size(tong_hua_screen_label_8, 69, 32);                    // 设置文本标签的尺寸

    // 设置文本标签的样式
    lv_obj_set_style_border_width(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_radius(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_color(tong_hua_screen_label_8, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(tong_hua_screen_label_8, &lv_font_SourceHanSerifSC_Regular_24, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_opa(tong_hua_screen_label_8, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_letter_space(tong_hua_screen_label_8, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_line_space(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_align(tong_hua_screen_label_8, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_top(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_right(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_bottom(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_left(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    // 设置图像按钮的样式
    lv_obj_set_style_text_color(tong_hua_screen_imgbtn_8, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(tong_hua_screen_imgbtn_8, &lv_font_SourceHanSerifSC_Regular_12, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_opa(tong_hua_screen_imgbtn_8, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_align(tong_hua_screen_imgbtn_8, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(tong_hua_screen_imgbtn_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    // 设置图像按钮在不同状态下的样式
    lv_obj_set_style_img_opa(tong_hua_screen_imgbtn_8, 255, LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_text_color(tong_hua_screen_imgbtn_8, lv_color_hex(0xFF33FF), LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_text_font(tong_hua_screen_imgbtn_8, &lv_font_SourceHanSerifSC_Regular_12, LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_text_opa(tong_hua_screen_imgbtn_8, 255, LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_shadow_width(tong_hua_screen_imgbtn_8, 0, LV_PART_MAIN | LV_STATE_PRESSED);

    // 创建一个LED指示灯
    lv_obj_t *tong_hua_screen_led_2 = lv_led_create(tong_hua_screen_cont_6);
    lv_led_set_brightness(tong_hua_screen_led_2, 255);               // 设置亮度
    lv_led_set_color(tong_hua_screen_led_2, lv_color_hex(0xff5700)); // 设置颜色
    lv_obj_set_pos(tong_hua_screen_led_2, 19, 15);                   // 设置位置
    lv_obj_set_size(tong_hua_screen_led_2, 12, 12);                  // 设置尺寸

    // 为图像按钮添加点击事件回调
    // lv_obj_add_event_cb(tong_hua_screen_imgbtn_8, on_tong_hua_screen_imgbtn_8_click, LV_EVENT_CLICKED, (void*)id);
    lv_obj_add_event_cb(tong_hua_screen_imgbtn_8, on_tong_hua_screen_imgbtn_8_click, LV_EVENT_CLICKED, (void *)button_str);
}

static void call_screen_update_timer_callback(lv_timer_t *timer)
{
    int i = 0;
    int n = 0;
    int row = 0; // 行号
    int col = 0; // 列号
    int x = 0;   // 根据列数调整水平位置
    int y = 0;   // 根据行数调整垂直位置
    int cont2_num = 0;
    int cont6_num = 0;
    static int last_index;

    printf("call_screen_update_cb\n");

    // 加锁
#if defined(_WIN32) || defined(_WIN64)
    DWORD result = WaitForSingleObject(tab_content_mutex, INFINITE);
    if (result != WAIT_OBJECT_0)
    {
        // Handle error
        printf("Failed to wait on the event.\n");
        return;
    }
#elif defined(__FreeRTOS__)
    if (xSemaphoreTake(tab_content_mutex, portMAX_DELAY) != pdTRUE)
    {
        // Handle timeout or failure
        printf("Failed to take the mutex.\n");
        return;
    }
#endif
    int index = lv_tabview_get_tab_act(guider_ui.tong_hua_screen_tabview_1);
    if (last_index != index)
    {
        last_index = index;
        cont2_num = 0;
        cont6_num = 0;
        // container_counter = 0;
    }
    switch (index)
    {
    case 0: // Tab 1: 显示所有内容
        // 计算 USER_DEV 和 STAFF_DEV 的数量
        for (int i = 0; i < NUM_SLAVE_DEV; i++)
        {
            if (host_dev.slave_dev_params_t[i].ext.is_registered)
            {
                if (host_dev.slave_dev_params_t[i].ext.type == USER_DEV)
                {
                    cont2_num++;
                }
                else if (host_dev.slave_dev_params_t[i].ext.type == STAFF_DEV)
                {
                    cont6_num++;
                }
            }
        }

        // 创建容器
        if (container_counter < cont2_num)
        {
            int n = container_counter; // 当前容器的编号
            int row = n / 10;          // 行号
            int col = n % 10;          // 列号

            int x = 10 + col * (80 + 10);  // 根据列数调整水平位置,并加上 10 像素的空隙
            int y = 10 + row * (120 + 10); // 根据行数调整垂直位置,并加上 10 像素的空隙
            create_tong_hua_screen_cont_2(guider_ui.tong_hua_screen_tabview_1_tab_1, x, y, container_counter + 1);
            container_counter++;
        }
        else if (container_counter < cont2_num + cont6_num)
        {
            int n = container_counter; // 当前容器的编号
            int row = n / 10;          // 行号
            int col = n % 10;          // 列号

            int x = 10 + col * (80 + 10);  // 根据列数调整水平位置,并加上 10 像素的空隙
            int y = 10 + row * (120 + 10); // 根据行数调整垂直位置,并加上 10 像素的空隙
            create_tong_hua_screen_cont_6(guider_ui.tong_hua_screen_tabview_1_tab_1, x, y, container_counter + 1);
            container_counter++;
        }

        // 如果所有容器都已经创建完毕,则停止定时器
        if (container_counter >= cont2_num + cont6_num)
        {
            container_counter = 0;

            if (call_screen_enter_timer != NULL)
            {
                lv_timer_del(call_screen_enter_timer);
                call_screen_enter_timer = NULL; // 删除定时器
            }
        }
        break;
    case 1: // Tab 2: 显示 USER_DEV 类型的内容
    {
        // 计算 USER_DEV 的数量
        // cont2_num = 0;
        for (int i = 0; i < NUM_SLAVE_DEV; i++)
        {
            if (host_dev.slave_dev_params_t[i].ext.type == USER_DEV && host_dev.slave_dev_params_t[i].ext.is_registered)
            {
                cont2_num++;
            }
        }

        // 创建容器
        if (container_counter2 < cont2_num)
        {
            int n = container_counter2; // 当前容器的编号
            int row = n / 10;           // 行号
            int col = n % 10;           // 列号

            int x = 10 + col * (80 + 10);  // 根据列数调整水平位置,并加上 10 像素的空隙
            int y = 10 + row * (120 + 10); // 根据行数调整垂直位置,并加上 10 像素的空隙
            create_tong_hua_screen_cont_2(guider_ui.tong_hua_screen_tabview_1_tab_2, x, y, container_counter2 + 1);
            container_counter2++;
        }
        else
        {
            container_counter2 = 0;

            // 如果所有容器都已经创建完毕,则停止定时器
            if (call_screen_enter_timer != NULL)
            {
                lv_timer_del(call_screen_enter_timer);
                call_screen_enter_timer = NULL; // 删除定时器
            }
        }

        break;
    }
    case 2: // Tab 3: 显示 STAFF_DEV 类型的内容
    {
        // 计算 STAFF_DEV 的数量
        // cont6_num = 0;
        for (int i = 0; i < NUM_SLAVE_DEV; i++)
        {
            if (host_dev.slave_dev_params_t[i].ext.type == STAFF_DEV && host_dev.slave_dev_params_t[i].ext.is_registered)
            {
                cont6_num++;
            }
        }

        // 创建容器
        if (container_counter3 < cont6_num)
        {
            int n = container_counter3; // 当前容器的编号
            int row = n / 10;           // 行号
            int col = n % 10;           // 列号

            int x = 10 + col * (80 + 10);  // 根据列数调整水平位置,并加上 10 像素的空隙
            int y = 10 + row * (120 + 10); // 根据行数调整垂直位置,并加上 10 像素的空隙
            create_tong_hua_screen_cont_6(guider_ui.tong_hua_screen_tabview_1_tab_3, x, y, container_counter3 + 1);
            container_counter3++;
        }
        else
        {
            container_counter3 = 0;

            // 如果所有容器都已经创建完毕,则停止定时器
            if (call_screen_enter_timer != NULL)
            {
                lv_timer_del(call_screen_enter_timer);
                call_screen_enter_timer = NULL; // 删除定时器
            }
        }

        break;
    }
    }
    // 解锁
#if defined(_WIN32) || defined(_WIN64)
    SetEvent(tab_content_mutex);
#elif defined(__FreeRTOS__)
    xSemaphoreGive(tab_content_mutex);
#endif
}

void call_screen_enter_cb(void)
{
    // 屏幕进入时的操作
    printf("Screen entered\n");

    // 创建定时器
    if (!call_screen_enter_timer)
    {
        // 注册设备并设置类型
        for (int i = 0; i < NUM_SLAVE_DEV; i++)
        {
            host_dev.slave_dev_params_t[i].ext.is_registered = true;
            host_dev.slave_dev_params_t[i].ext.type = (i % 2 == 0) ? USER_DEV : STAFF_DEV;
        }

        call_screen_enter_timer = lv_timer_create(call_screen_update_timer_callback, TIMER_INTERVAL_MS, NULL);
        lv_timer_set_repeat_count(call_screen_enter_timer, -1); // 设置定时器无限重复
    }
}


extern void call_screen_enter_cb(void);
extern void call_screenexit_cb(void);

static void tong_hua_screen_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.zhu_mian_screen, guider_ui.zhu_mian_screen_del, &guider_ui.tong_hua_screen_del, setup_scr_zhu_mian_screen, LV_SCR_LOAD_ANIM_NONE, 200, 200, false, true);
		break;
	}
	case LV_EVENT_SCREEN_LOAD_START:
	{
		call_screen_enter_cb();
        //int index = lv_tabview_get_tab_act(guider_ui.tong_hua_screen_tabview_1);
        //call_screen_update_cb(index);
		break;
	}

	case LV_EVENT_SCREEN_UNLOAD_START:
	{

		break;
	}

	default:
		break;
	}
}
static void tong_hua_screen_tabview_1_event_handler(lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);

	switch (code)
	{
	case LV_EVENT_VALUE_CHANGED:
	{
		//int index = lv_tabview_get_tab_act(guider_ui.tong_hua_screen_tabview_1);
		//call_screen_update_cb(index);
        call_screen_enter_cb();
		break;
	}
	default:
		break;
	}
}

void events_init_tong_hua_screen(lv_ui *ui)
{
	lv_obj_add_event_cb(ui->tong_hua_screen, tong_hua_screen_event_handler, LV_EVENT_ALL, ui);
	lv_obj_add_event_cb(ui->tong_hua_screen_imgbtn_1, tong_hua_screen_imgbtn_1_event_handler, LV_EVENT_ALL, ui);
	lv_obj_add_event_cb(ui->tong_hua_screen_tabview_1, tong_hua_screen_tabview_1_event_handler, LV_EVENT_ALL, ui);
	lv_obj_add_event_cb(ui->tong_hua_screen_imgbtn_4, tong_hua_screen_imgbtn_4_event_handler, LV_EVENT_ALL, ui);
	lv_obj_add_event_cb(ui->tong_hua_screen_imgbtn_8, tong_hua_screen_imgbtn_8_event_handler, LV_EVENT_ALL, ui);
}

void events_init_tong_hua_screen(lv_ui *ui)
{
	lv_obj_add_event_cb(ui->tong_hua_screen, tong_hua_screen_event_handler, LV_EVENT_ALL, ui);
	lv_obj_add_event_cb(ui->tong_hua_screen_imgbtn_1, tong_hua_screen_imgbtn_1_event_handler, LV_EVENT_ALL, ui);
	lv_obj_add_event_cb(ui->tong_hua_screen_tabview_1, tong_hua_screen_tabview_1_event_handler, LV_EVENT_ALL, ui);
	lv_obj_add_event_cb(ui->tong_hua_screen_imgbtn_4, tong_hua_screen_imgbtn_4_event_handler, LV_EVENT_ALL, ui);
	lv_obj_add_event_cb(ui->tong_hua_screen_imgbtn_8, tong_hua_screen_imgbtn_8_event_handler, LV_EVENT_ALL, ui);
}



#include <lvgl.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h> // For memset

// 定义一个结构体来存储 tab 的内容
typedef struct
{
    int x;
    int y;
    lv_obj_t *container; // 容器
    lv_obj_t *label;     // 文本标签
    lv_obj_t *led;       // LED 控件
    lv_obj_t *imgbtn;    // 图像按钮
} TabContent;

TabContent tab_content_1;
TabContent tab_content_2;

// 信号锁的定义
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h> // Windows API
HANDLE tab_content_mutex = NULL;
#elif defined(__FreeRTOS__)
SemaphoreHandle_t tab_content_mutex = NULL;
#else
#error "Unsupported platform"
#endif

// 初始化信号锁
void init_tab_content_mutex(void)
{
#if defined(_WIN32) || defined(_WIN64)
    SECURITY_ATTRIBUTES sa;
    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
    sa.bInheritHandle = FALSE;
    sa.lpSecurityDescriptor = NULL;

    tab_content_mutex = CreateEvent(&sa, TRUE, TRUE, NULL);
    if (tab_content_mutex == NULL)
    {
        // Handle error
        printf("Failed to create event.\n");
    }
#elif defined(__FreeRTOS__)
    tab_content_mutex = xSemaphoreCreateMutex();
    if (tab_content_mutex == NULL)
    {
        // Handle error
        printf("Failed to create mutex.\n");
    }
#endif
}

// 释放信号锁
void destroy_tab_content_mutex(void)
{
#if defined(_WIN32) || defined(_WIN64)
    CloseHandle(tab_content_mutex);
#elif defined(__FreeRTOS__)
    vSemaphoreDelete(tab_content_mutex);
#endif
}

void set_tab_content(TabContent *content, int x, int y, const char *label_text, bool tab_cont_checked, bool led_checked, bool imgbtn_src)
{
    // 设置容器的位置
    set_widget_pos(content->container, x, y);

    // 设置容器的可见
    if (tab_cont_checked)
    {
        lv_obj_clear_flag(content->container, LV_OBJ_FLAG_HIDDEN);
    }
    else
    {
        lv_obj_add_flag(content->container, LV_OBJ_FLAG_HIDDEN);
    }

    // 更新标签的文字
    lv_label_set_text(content->label, label_text);

    // 设置 LED 可见
    lv_obj_clear_flag(content->led, LV_OBJ_FLAG_HIDDEN);
    if (led_checked)
    {
        lv_led_on(content->led);
    }
    else
    {
        lv_led_off(content->led);
    }

    // 设置图像按钮的可见性和图像
    if (imgbtn_src)
    {
        lv_obj_clear_flag(content->imgbtn, LV_OBJ_FLAG_HIDDEN);
    }
    else
    {
        lv_obj_add_flag(content->imgbtn, LV_OBJ_FLAG_HIDDEN);
    }
}
// 事件处理函数
#include <lvgl/lvgl.h>

// 图像按钮 tong_hua_screen_imgbtn_4 的点击事件回调函数
static void on_tong_hua_screen_imgbtn_4_click(lv_event_t *e)
{
    // 获取触发事件的对象
    lv_obj_t *obj = lv_event_get_target(e);
    // 获取附加数据(这里是按钮的唯一标识符)
    int *id_ptr = (int *)lv_event_get_param(e); // 将 user_data 转换为 int* 类型
    int id = *id_ptr;                           // 解引用获取实际的 int 值
    // 获取触发事件的容器
    lv_obj_t *container = lv_obj_get_parent(obj);

    // 检查按钮的状态
    bool checked = lv_obj_has_state(obj, LV_STATE_CHECKED);

    if (checked)
    {
        // 如果按钮被选中
        printf("Button %d .", id);
    }
    else
    {
        // 如果按钮未被选中
        printf("Button %d .", id);
    }
}

// 图像按钮 tong_hua_screen_imgbtn_8 的点击事件回调函数
static void on_tong_hua_screen_imgbtn_8_click(lv_event_t *e)
{
    // 获取触发事件的对象
    lv_obj_t *obj = lv_event_get_target(e);
    // 获取附加数据(这里是按钮的唯一标识符)
    int *id_ptr = (int *)lv_event_get_param(e); // 将 user_data 转换为 int* 类型
    int id = *id_ptr;                           // 解引用获取实际的 int 值
    // 获取触发事件的容器
    lv_obj_t *container = lv_obj_get_parent(obj);

    // 检查按钮的状态
    bool checked = lv_obj_has_state(obj, LV_STATE_CHECKED);

    if (checked)
    {
        // 如果按钮被选中
        printf("Button %d .", id);
    }
    else
    {
        // 如果按钮未被选中
        printf("Button %d .", id);
    }
}

void create_tong_hua_screen_cont_2(lv_obj_t *parent, int x, int y, int id)
{
    // 创建一个容器对象并设置其位置和大小
    lv_obj_t *tong_hua_screen_cont_2 = lv_obj_create(parent);
    lv_obj_set_pos(tong_hua_screen_cont_2, x, y);                             // 设置容器的位置
    lv_obj_set_size(tong_hua_screen_cont_2, 80, 120);                         // 设置容器的尺寸
    lv_obj_set_scrollbar_mode(tong_hua_screen_cont_2, LV_SCROLLBAR_MODE_OFF); // 关闭滚动条

    // 设置容器的边框宽度、不透明度、颜色、边角半径等样式
    lv_obj_set_style_border_width(tong_hua_screen_cont_2, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_opa(tong_hua_screen_cont_2, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_color(tong_hua_screen_cont_2, lv_color_hex(0x2195f6), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_side(tong_hua_screen_cont_2, LV_BORDER_SIDE_NONE, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_radius(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_top(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_bottom(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_left(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_right(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(tong_hua_screen_cont_2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    // 创建一个可检查的图像按钮
    lv_obj_t *tong_hua_screen_imgbtn_4 = lv_imgbtn_create(tong_hua_screen_cont_2);
    lv_obj_add_flag(tong_hua_screen_imgbtn_4, LV_OBJ_FLAG_CHECKABLE);                                    // 图像按钮可以被选中
    lv_imgbtn_set_src(tong_hua_screen_imgbtn_4, LV_IMGBTN_STATE_RELEASED, NULL, &_AQ_alpha_75x75, NULL); // 设置图像按钮的源图片
    lv_obj_set_pos(tong_hua_screen_imgbtn_4, 2, 8);                                                      // 设置图像按钮的位置
    lv_obj_set_size(tong_hua_screen_imgbtn_4, 75, 75);                                                   // 设置图像按钮的尺寸

    // 设置图像按钮的文字标签
    lv_obj_t *tong_hua_screen_imgbtn_4_label = lv_label_create(tong_hua_screen_imgbtn_4);
    lv_label_set_text(tong_hua_screen_imgbtn_4_label, "");                      // 文字为空
    lv_label_set_long_mode(tong_hua_screen_imgbtn_4_label, LV_LABEL_LONG_WRAP); // 文字换行模式
    lv_obj_align(tong_hua_screen_imgbtn_4_label, LV_ALIGN_CENTER, 0, 0);        // 文字居中对齐
    lv_obj_set_style_pad_all(tong_hua_screen_imgbtn_4, 0, LV_STATE_DEFAULT);    // 设置内部填充为0

    // 设置图像按钮的样式
    lv_obj_set_style_text_color(tong_hua_screen_imgbtn_4, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(tong_hua_screen_imgbtn_4, &lv_font_SourceHanSerifSC_Regular_12, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_opa(tong_hua_screen_imgbtn_4, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_align(tong_hua_screen_imgbtn_4, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(tong_hua_screen_imgbtn_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    // 设置图像按钮在不同状态下的样式
    lv_obj_set_style_img_opa(tong_hua_screen_imgbtn_4, 255, LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_text_color(tong_hua_screen_imgbtn_4, lv_color_hex(0xFF33FF), LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_text_font(tong_hua_screen_imgbtn_4, &lv_font_SourceHanSerifSC_Regular_12, LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_text_opa(tong_hua_screen_imgbtn_4, 255, LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_shadow_width(tong_hua_screen_imgbtn_4, 0, LV_PART_MAIN | LV_STATE_PRESSED);

    // 设置图像按钮在选中状态下的样式
    lv_obj_set_style_img_opa(tong_hua_screen_imgbtn_4, 255, LV_PART_MAIN | LV_STATE_CHECKED);
    lv_obj_set_style_text_color(tong_hua_screen_imgbtn_4, lv_color_hex(0xFF33FF), LV_PART_MAIN | LV_STATE_CHECKED);
    lv_obj_set_style_text_font(tong_hua_screen_imgbtn_4, &lv_font_SourceHanSerifSC_Regular_12, LV_PART_MAIN | LV_STATE_CHECKED);
    lv_obj_set_style_text_opa(tong_hua_screen_imgbtn_4, 255, LV_PART_MAIN | LV_STATE_CHECKED);
    lv_obj_set_style_shadow_width(tong_hua_screen_imgbtn_4, 0, LV_PART_MAIN | LV_STATE_CHECKED);

    // 创建一个文本标签
    lv_obj_t *tong_hua_screen_label_4 = lv_label_create(tong_hua_screen_cont_2);
    lv_label_set_text(tong_hua_screen_label_4, "yong1");                 // 设置文本内容
    lv_label_set_long_mode(tong_hua_screen_label_4, LV_LABEL_LONG_WRAP); // 文字换行模式
    lv_obj_set_pos(tong_hua_screen_label_4, 5, 91);                      // 设置文本标签的位置
    lv_obj_set_size(tong_hua_screen_label_4, 69, 32);                    // 设置文本标签的尺寸

    // 设置文本标签的样式
    lv_obj_set_style_border_width(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_radius(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_color(tong_hua_screen_label_4, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(tong_hua_screen_label_4, &lv_font_SourceHanSerifSC_Regular_24, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_opa(tong_hua_screen_label_4, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_letter_space(tong_hua_screen_label_4, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_line_space(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_align(tong_hua_screen_label_4, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_top(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_right(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_bottom(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_left(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(tong_hua_screen_label_4, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    // 创建一个LED指示灯
    lv_obj_t *tong_hua_screen_led_1 = lv_led_create(tong_hua_screen_cont_2);
    lv_led_set_brightness(tong_hua_screen_led_1, 255);               // 设置亮度
    lv_led_set_color(tong_hua_screen_led_1, lv_color_hex(0xff5700)); // 设置颜色
    lv_obj_set_pos(tong_hua_screen_led_1, 19, 15);                   // 设置位置
    lv_obj_set_size(tong_hua_screen_led_1, 12, 12);                  // 设置尺寸

    // 为图像按钮添加点击事件回调
    lv_obj_add_event_cb(tong_hua_screen_imgbtn_4, on_tong_hua_screen_imgbtn_4_click, LV_EVENT_CLICKED, &id);
}

void create_tong_hua_screen_cont_6(lv_obj_t *parent, int x, int y, int id)
{
    // 创建一个容器对象并设置其位置和大小
    lv_obj_t *tong_hua_screen_cont_6 = lv_obj_create(parent);
    lv_obj_set_pos(tong_hua_screen_cont_6, x, y);                             // 设置容器的位置
    lv_obj_set_size(tong_hua_screen_cont_6, 80, 120);                         // 设置容器的尺寸
    lv_obj_set_scrollbar_mode(tong_hua_screen_cont_6, LV_SCROLLBAR_MODE_OFF); // 关闭滚动条

    // 设置容器的边框宽度、不透明度、颜色、边角半径等样式
    lv_obj_set_style_border_width(tong_hua_screen_cont_6, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_opa(tong_hua_screen_cont_6, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_color(tong_hua_screen_cont_6, lv_color_hex(0x2195f6), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_side(tong_hua_screen_cont_6, LV_BORDER_SIDE_NONE, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_radius(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_top(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_bottom(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_left(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_right(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(tong_hua_screen_cont_6, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    // 创建一个可检查的图像按钮
    lv_obj_t *tong_hua_screen_imgbtn_8 = lv_imgbtn_create(tong_hua_screen_cont_6);
    lv_obj_add_flag(tong_hua_screen_imgbtn_8, LV_OBJ_FLAG_CHECKABLE);                                    // 图像按钮可以被选中
    lv_imgbtn_set_src(tong_hua_screen_imgbtn_8, LV_IMGBTN_STATE_RELEASED, NULL, &_A6_alpha_80x90, NULL); // 设置图像按钮的源图片
    lv_obj_set_pos(tong_hua_screen_imgbtn_8, 5, 0);                                                      // 设置图像按钮的位置
    lv_obj_set_size(tong_hua_screen_imgbtn_8, 80, 90);                                                   // 设置图像按钮的尺寸

    // 创建一个文本标签
    lv_obj_t *tong_hua_screen_label_8 = lv_label_create(tong_hua_screen_cont_6);
    lv_label_set_text(tong_hua_screen_label_8, "sss");                   // 设置文本内容
    lv_label_set_long_mode(tong_hua_screen_label_8, LV_LABEL_LONG_WRAP); // 文字换行模式
    lv_obj_set_pos(tong_hua_screen_label_8, 5, 91);                      // 设置文本标签的位置
    lv_obj_set_size(tong_hua_screen_label_8, 69, 32);                    // 设置文本标签的尺寸

    // 设置文本标签的样式
    lv_obj_set_style_border_width(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_radius(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_color(tong_hua_screen_label_8, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(tong_hua_screen_label_8, &lv_font_SourceHanSerifSC_Regular_24, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_opa(tong_hua_screen_label_8, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_letter_space(tong_hua_screen_label_8, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_line_space(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_align(tong_hua_screen_label_8, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_top(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_right(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_bottom(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_left(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(tong_hua_screen_label_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    // 设置图像按钮的样式
    lv_obj_set_style_text_color(tong_hua_screen_imgbtn_8, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(tong_hua_screen_imgbtn_8, &lv_font_SourceHanSerifSC_Regular_12, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_opa(tong_hua_screen_imgbtn_8, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_align(tong_hua_screen_imgbtn_8, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(tong_hua_screen_imgbtn_8, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    // 设置图像按钮在不同状态下的样式
    lv_obj_set_style_img_opa(tong_hua_screen_imgbtn_8, 255, LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_text_color(tong_hua_screen_imgbtn_8, lv_color_hex(0xFF33FF), LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_text_font(tong_hua_screen_imgbtn_8, &lv_font_SourceHanSerifSC_Regular_12, LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_text_opa(tong_hua_screen_imgbtn_8, 255, LV_PART_MAIN | LV_STATE_PRESSED);
    lv_obj_set_style_shadow_width(tong_hua_screen_imgbtn_8, 0, LV_PART_MAIN | LV_STATE_PRESSED);

    // 创建一个LED指示灯
    lv_obj_t *tong_hua_screen_led_2 = lv_led_create(tong_hua_screen_cont_6);
    lv_led_set_brightness(tong_hua_screen_led_2, 255);               // 设置亮度
    lv_led_set_color(tong_hua_screen_led_2, lv_color_hex(0xff5700)); // 设置颜色
    lv_obj_set_pos(tong_hua_screen_led_2, 19, 15);                   // 设置位置
    lv_obj_set_size(tong_hua_screen_led_2, 12, 12);                  // 设置尺寸

    // 为图像按钮添加点击事件回调
    lv_obj_add_event_cb(tong_hua_screen_imgbtn_8, on_tong_hua_screen_imgbtn_8_click, LV_EVENT_CLICKED, &id);
}


void call_screen_enter_cb(void)
{
    // 屏幕进入时的操作
    int i = 0;
    int n = 0;
    int row = 0; // 行号
    int col = 0; // 列号
    int x = 0;   // 根据列数调整水平位置
    int y = 0;   // 根据行数调整垂直位置
    int cont2_num = 0;
    int cont6_num = 0;


    printf("Screen entered\n");
    for (i = 0; i < NUM_SLAVE_DEV; i++)
    {
        host_dev.slave_dev_params_t[i].ext.is_registered = true;
        if (i % 2 == 0)
        {
            host_dev.slave_dev_params_t[i].ext.type = USER_DEV;
        }
        else
        {
            host_dev.slave_dev_params_t[i].ext.type = STAFF_DEV;
        }
    }

    // 更新 Tab 1、Tab 2 和 Tab 3 的内容
    for (i = 0; i < NUM_SLAVE_DEV; i++)
    {
        if (host_dev.slave_dev_params_t[i].ext.is_registered)
        {
            if (host_dev.slave_dev_params_t[i].ext.type == USER_DEV)
            {
                cont2_num++;
            }
            else if (host_dev.slave_dev_params_t[i].ext.type == STAFF_DEV)
            {
                cont6_num++;
            }
        }
    }

    // 循环创建 cont2_num 个 tong_hua_screen_cont_2 容器
    for (n = 0; n < cont2_num; n++)
    {
        row = n / 10;             // 行号
        col = n % 10;             // 列号
        x = 10 + col * (80 + 10); // 根据列数调整水平位置,并加上 10 像素的空隙
        y = 0 + row * (120 + 10); // 根据行数调整垂直位置,并加上 10 像素的空隙
        create_tong_hua_screen_cont_2(guider_ui.tong_hua_screen_tabview_1_tab_1, x, y, n + 1);
    }

    // 循环创建 9 个 tong_hua_screen_cont_6 容器
    for (; n < (cont2_num + cont6_num); n++)
    {
        row = n / 10;             // 行号
        col = n % 10;             // 列号
        x = 10 + col * (80 + 10); // 根据列数调整水平位置,并加上 10 像素的空隙
        y = 0 + row * (120 + 10); // 根据行数调整垂直位置,并加上 10 像素的空隙
        create_tong_hua_screen_cont_6(guider_ui.tong_hua_screen_tabview_1_tab_1, x, y, n + cont2_num + 1);
    }
}

// 事件处理函数
void call_screen_update_cb(unsigned char index)
{
    int i = 0;
    int n = 0;
    int row = 0; // 行号
    int col = 0; // 列号
    int x = 0;   // 根据列数调整水平位置
    int y = 0;   // 根据行数调整垂直位置
    int cont2_num = 0;
    int cont6_num = 0;

    printf("call_screen_update_cb\n");

    // 加锁
#if defined(_WIN32) || defined(_WIN64)
    DWORD result = WaitForSingleObject(tab_content_mutex, INFINITE);
    if (result != WAIT_OBJECT_0)
    {
        // Handle error
        printf("Failed to wait on the event.\n");
        return;
    }
#elif defined(__FreeRTOS__)
    if (xSemaphoreTake(tab_content_mutex, portMAX_DELAY) != pdTRUE)
    {
        // Handle timeout or failure
        printf("Failed to take the mutex.\n");
        return;
    }
#endif

    switch (index)
    {
    case 0: // Tab 1: 显示所有内容
        call_screen_enter_cb();
        break;
    case 1: // Tab 2: 显示 USER_DEV 类型的内容
 
        // 更新 Tab 1、Tab 2 和 Tab 3 的内容
        for (i = 0; i < NUM_SLAVE_DEV; i++)
        {
            if (host_dev.slave_dev_params_t[i].ext.type == USER_DEV)
            {
                if (host_dev.slave_dev_params_t[i].ext.is_registered)
                {
                    // 检查是否需要更新
                    if (host_dev.slave_dev_params_t[i].ext.is_registered != host_dev.slave_dev_params_t[i].ext.last_is_registered)
                    {
                        // 更新 last_is_registered
                        host_dev.slave_dev_params_t[i].ext.last_is_registered = host_dev.slave_dev_params_t[i].ext.is_registered;

                        cont2_num++;
                    }
                }
            }
        }

        // 循环创建 cont2_num 个 tong_hua_screen_cont_2 容器
        for (n = 0; n < cont2_num; n++)
        {
            row = n / 10;             // 行号
            col = n % 10;             // 列号
            x = 10 + col * (80 + 10); // 根据列数调整水平位置,并加上 10 像素的空隙
            y = 0 + row * (120 + 10); // 根据行数调整垂直位置,并加上 10 像素的空隙
            create_tong_hua_screen_cont_2(guider_ui.tong_hua_screen_tabview_1_tab_2, x, y, n + 1);
        }

        break;
    case 2: // Tab 3: 显示 STAFF_DEV 类型的内容

        // 更新 Tab 1、Tab 2 和 Tab 3 的内容
        for (i = 0; i < NUM_SLAVE_DEV; i++)
        {

            if (host_dev.slave_dev_params_t[i].ext.type == STAFF_DEV)
            {
                if (host_dev.slave_dev_params_t[i].ext.is_registered)
                {
                    // 检查是否需要更新
                    if (host_dev.slave_dev_params_t[i].ext.is_registered != host_dev.slave_dev_params_t[i].ext.last_is_registered)
                    {
                        // 更新 last_is_registered
                        host_dev.slave_dev_params_t[i].ext.last_is_registered = host_dev.slave_dev_params_t[i].ext.is_registered;

                        cont6_num++;
                    }
                }
            }
        }
        // 循环创建 9 个 tong_hua_screen_cont_6 容器
        for (n = 0; n < (cont6_num); n++)
        {
            row = n / 10;             // 行号
            col = n % 10;             // 列号
            x = 10 + col * (80 + 10); // 根据列数调整水平位置,并加上 10 像素的空隙
            y = 0 + row * (120 + 10); // 根据行数调整垂直位置,并加上 10 像素的空隙
            create_tong_hua_screen_cont_6(guider_ui.tong_hua_screen_tabview_1_tab_3, x, y, n + 1);
        }
        break;
    }

    // 解锁
#if defined(_WIN32) || defined(_WIN64)
    SetEvent(tab_content_mutex);
#elif defined(__FreeRTOS__)
    xSemaphoreGive(tab_content_mutex);
#endif
}

#include <lvgl.h>
#include <stdio.h>

#define TIMER_INTERVAL_MS 60 // 定时器间隔,单位毫秒

// 假设这是您的容器创建函数
void create_tong_hua_screen_cont_2(lv_obj_t *parent, int x, int y, int id);
void create_tong_hua_screen_cont_6(lv_obj_t *parent, int x, int y, int id);

// 定时器回调函数
static int container_counter = 0;
static void timer_callback(lv_timer_t *timer)
{
    int cont2_num = 0;
    int cont6_num = 0;
    
    // 计算 USER_DEV 和 STAFF_DEV 的数量
    for (int i = 0; i < NUM_SLAVE_DEV; i++)
    {
        if (host_dev.slave_dev_params_t[i].ext.is_registered)
        {
            if (host_dev.slave_dev_params_t[i].ext.type == USER_DEV)
            {
                cont2_num++;
            }
            else if (host_dev.slave_dev_params_t[i].ext.type == STAFF_DEV)
            {
                cont6_num++;
            }
        }
    }

    // 创建容器
    if (container_counter < cont2_num)
    {
        int n = container_counter; // 当前容器的编号
        int row = n / 10;          // 行号
        int col = n % 10;          // 列号
        
        int x = 10 + col * (80 + 10); // 根据列数调整水平位置,并加上 10 像素的空隙
        int y = 10 + row * (120 + 10); // 根据行数调整垂直位置,并加上 10 像素的空隙
        create_tong_hua_screen_cont_2(guider_ui.tong_hua_screen_tabview_1_tab_1, x, y, container_counter + 1);
        container_counter++;
    }
    else if (container_counter < cont2_num + cont6_num)
    {
        int n = container_counter; // 当前容器的编号
        int row = n / 10;          // 行号
        int col = n % 10;          // 列号
        
        int x = 10 + col * (80 + 10); // 根据列数调整水平位置,并加上 10 像素的空隙
        int y = 10 + row * (120 + 10); // 根据行数调整垂直位置,并加上 10 像素的空隙
        create_tong_hua_screen_cont_6(guider_ui.tong_hua_screen_tabview_1_tab_1, x, y, container_counter + 1 - cont2_num);
        container_counter++;
    }

    // 如果所有容器都已经创建完毕,则停止定时器
    if (container_counter >= cont2_num + cont6_num)
    {
        container_counter = 0;
        lv_timer_del(timer); // 删除定时器
    }
}

void call_screen_enter_cb(void)
{
    // 屏幕进入时的操作
    printf("Screen entered\n");
    
    // 注册设备并设置类型
    for (int i = 0; i < NUM_SLAVE_DEV; i++)
    {
        host_dev.slave_dev_params_t[i].ext.is_registered = true;
        host_dev.slave_dev_params_t[i].ext.type = (i % 2 == 0) ? USER_DEV : STAFF_DEV;
    }

    // 创建定时器
    lv_timer_t *timer = lv_timer_create(timer_callback, TIMER_INTERVAL_MS, NULL);
    lv_timer_set_repeat_count(timer, -1); // 设置定时器无限重复
}


// 事件处理函数
void call_screen_update_cb(unsigned char index)
{
    int i = 0;
    int n = 0;
    int row = 0; // 行号
    int col = 0; // 列号
    int x = 0;   // 根据列数调整水平位置
    int y = 0;   // 根据行数调整垂直位置
    int cont2_num = 0;
    int cont6_num = 0;

    printf("call_screen_update_cb\n");

    // 加锁
#if defined(_WIN32) || defined(_WIN64)
    DWORD result = WaitForSingleObject(tab_content_mutex, INFINITE);
    if (result != WAIT_OBJECT_0)
    {
        // Handle error
        printf("Failed to wait on the event.\n");
        return;
    }
#elif defined(__FreeRTOS__)
    if (xSemaphoreTake(tab_content_mutex, portMAX_DELAY) != pdTRUE)
    {
        // Handle timeout or failure
        printf("Failed to take the mutex.\n");
        return;
    }
#endif

    switch (index)
    {
    case 0: // Tab 1: 显示所有内容
        call_screen_enter_cb();
        break;
    case 1: // Tab 2: 显示 USER_DEV 类型的内容
 
        // 更新 Tab 1、Tab 2 和 Tab 3 的内容
        for (i = 0; i < NUM_SLAVE_DEV; i++)
        {
            if (host_dev.slave_dev_params_t[i].ext.type == USER_DEV)
            {
                if (host_dev.slave_dev_params_t[i].ext.is_registered)
                {
                    // 检查是否需要更新
                    if (host_dev.slave_dev_params_t[i].ext.is_registered != host_dev.slave_dev_params_t[i].ext.last_is_registered)
                    {
                        // 更新 last_is_registered
                        host_dev.slave_dev_params_t[i].ext.last_is_registered = host_dev.slave_dev_params_t[i].ext.is_registered;
                        cont2_num++;
                    }
                }
            }
        }

        // 循环创建 cont2_num 个 tong_hua_screen_cont_2 容器
        for (n = 0; n < cont2_num; n++)
        {
            row = n / 10;             // 行号
            col = n % 10;             // 列号
            x = 10 + col * (80 + 10); // 根据列数调整水平位置,并加上 10 像素的空隙
            y = 0 + row * (120 + 10); // 根据行数调整垂直位置,并加上 10 像素的空隙
            create_tong_hua_screen_cont_2(guider_ui.tong_hua_screen_tabview_1_tab_2, x, y, n + 1);
        }

        break;
    case 2: // Tab 3: 显示 STAFF_DEV 类型的内容

        // 更新 Tab 1、Tab 2 和 Tab 3 的内容
        for (i = 0; i < NUM_SLAVE_DEV; i++)
        {

            if (host_dev.slave_dev_params_t[i].ext.type == STAFF_DEV)
            {
                if (host_dev.slave_dev_params_t[i].ext.is_registered)
                {
                    // 检查是否需要更新
                    if (host_dev.slave_dev_params_t[i].ext.is_registered != host_dev.slave_dev_params_t[i].ext.last_is_registered)
                    {
                        // 更新 last_is_registered
                        host_dev.slave_dev_params_t[i].ext.last_is_registered = host_dev.slave_dev_params_t[i].ext.is_registered;
                        cont6_num++;
                    }
                }
            }
        }
        // 循环创建 9 个 tong_hua_screen_cont_6 容器
        for (n = 0; n < (cont6_num); n++)
        {
            row = n / 10;             // 行号
            col = n % 10;             // 列号
            x = 10 + col * (80 + 10); // 根据列数调整水平位置,并加上 10 像素的空隙
            y = 0 + row * (120 + 10); // 根据行数调整垂直位置,并加上 10 像素的空隙
            create_tong_hua_screen_cont_6(guider_ui.tong_hua_screen_tabview_1_tab_3, x, y, n + 1);
        }
        break;
    }

    // 解锁
#if defined(_WIN32) || defined(_WIN64)
    SetEvent(tab_content_mutex);
#elif defined(__FreeRTOS__)
    xSemaphoreGive(tab_content_mutex);
#endif
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值