From aa9d78998fd9d723ec8505f3c90fa4d0936280cd Mon Sep 17 00:00:00 2001 From: Siyuan Date: Fri, 10 Oct 2025 22:56:27 +0000 Subject: [PATCH] fix: dhcpc button doesnt work --- internal/native/eez/jetkvm.eez-project | 16 ++++++++++++---- internal/native/eez/src/ui/actions.c | 4 ++++ internal/native/eez/src/ui/actions.h | 1 + internal/native/eez/src/ui/screens.c | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/internal/native/eez/jetkvm.eez-project b/internal/native/eez/jetkvm.eez-project index 5d09cb25..d174f159 100644 --- a/internal/native/eez/jetkvm.eez-project +++ b/internal/native/eez/jetkvm.eez-project @@ -48,7 +48,7 @@ { "objID": "58af3ebb-96b3-494c-f4e3-9c23852e3e42", "fileName": "actions.c", - "template": "#include \"actions.h\"\n#include \"screens.h\"\n#include \n#include \n#include \"ui.h\"\n#include \"vars.h\"\n\nint handle_gesture_screen_switch(lv_event_t *e, lv_dir_t direction, int screenId) {\n lv_event_code_t event_code = lv_event_get_code(e);\n if (event_code != LV_EVENT_GESTURE) {\n return 0;\n }\n\n if (lv_indev_get_gesture_dir(lv_indev_get_act()) != direction) {\n return 0;\n }\n lv_indev_wait_release(lv_indev_get_act());\n loadScreen(screenId);\n return 1;\n}\n\nvoid handle_gesture_main_screen_switch(lv_event_t *e, lv_dir_t direction) {\n const char *main_screen = get_var_main_screen();\n if (strcmp(main_screen, \"home_screen\") == 0) { \n loadScreen(SCREEN_ID_HOME_SCREEN);\n } else if (strcmp(main_screen, \"no_network_screen\") == 0) {\n loadScreen(SCREEN_ID_NO_NETWORK_SCREEN);\n }\n}\n\nvoid action_switch_to_menu(lv_event_t *e) {\n loadScreen(SCREEN_ID_MENU_SCREEN);\n}\n\nvoid action_switch_to_advanced_menu(lv_event_t *e) {\n loadScreen(SCREEN_ID_MENU_ADVANCED_SCREEN);\n}\n\nvoid action_switch_to_status(lv_event_t *e) {\n loadScreen(SCREEN_ID_STATUS_SCREEN);\n}\n\nvoid action_switch_to_about(lv_event_t *e) {\n loadScreen(SCREEN_ID_ABOUT_SCREEN);\n}\n\nvoid action_switch_to_reset_config(lv_event_t *e) {\n loadScreen(SCREEN_ID_RESET_CONFIG_SCREEN);\n}\n\nvoid action_switch_to_reboot(lv_event_t *e) {\n loadScreen(SCREEN_ID_REBOOT_SCREEN);\n}\n\nvoid action_menu_screen_gesture(lv_event_t * e) {\n handle_gesture_main_screen_switch(e, LV_DIR_RIGHT);\n}\n\nvoid action_menu_advanced_screen_gesture(lv_event_t * e) {\n handle_gesture_screen_switch(e, LV_DIR_RIGHT, SCREEN_ID_MENU_SCREEN);\n}\n\nvoid action_reset_config_screen_gesture(lv_event_t * e) {\n handle_gesture_screen_switch(e, LV_DIR_RIGHT, SCREEN_ID_MENU_SCREEN);\n}\n\nvoid action_home_screen_gesture(lv_event_t * e) {\n handle_gesture_screen_switch(e, LV_DIR_LEFT, SCREEN_ID_MENU_SCREEN);\n}\n\nvoid action_about_screen_gesture(lv_event_t * e) {\n handle_gesture_screen_switch(e, LV_DIR_RIGHT, SCREEN_ID_MENU_SCREEN);\n}\n\n// user_data doesn't seem to be working, so we use a global variable here\nstatic uint32_t t_reset_config;\nstatic uint32_t t_reboot;\nstatic uint32_t t_dhcpc;\n\nstatic bool b_reboot = false;\nstatic bool b_reset_config = false;\nstatic bool b_dhcpc = false;\n\nstatic bool b_reboot_lock = false;\nstatic bool b_reset_config_lock = false;\nstatic bool b_dhcpc_lock = false;\n\nconst int RESET_CONFIG_HOLD_TIME = 10;\nconst int REBOOT_HOLD_TIME = 5;\nconst int DHCPC_HOLD_TIME = 5;\n\ntypedef struct {\n uint32_t *start_time;\n bool *completed;\n bool *lock;\n int hold_time_seconds;\n const char *rpc_method;\n lv_obj_t *button_obj;\n lv_obj_t *spinner_obj;\n lv_obj_t *label_obj;\n const char *default_text;\n} hold_action_config_t;\n\nstatic void handle_hold_action(lv_event_t *e, hold_action_config_t *config) {\n lv_event_code_t event_code = lv_event_get_code(e);\n \n if (event_code == LV_EVENT_PRESSED) {\n *(config->start_time) = lv_tick_get();\n }\n else if (event_code == LV_EVENT_PRESSING) {\n int remaining_time = config->hold_time_seconds * 1000 - lv_tick_elaps(*(config->start_time));\n if (remaining_time <= 0) {\n if (*(config->lock)) {\n return;\n }\n if (config->button_obj && config->spinner_obj) {\n lv_obj_add_flag(config->button_obj, LV_OBJ_FLAG_HIDDEN);\n lv_obj_clear_flag(config->spinner_obj, LV_OBJ_FLAG_HIDDEN);\n }\n ui_call_rpc_handler(config->rpc_method, NULL);\n *(config->lock) = true;\n *(config->completed) = true;\n } else {\n *(config->completed) = false;\n char buf[100];\n int remaining_time_seconds = remaining_time / 1000;\n if (remaining_time_seconds <= 1) {\n remaining_time_seconds = 1;\n }\n sprintf(buf, \"Press and hold for\\n%d seconds\", remaining_time_seconds);\n lv_label_set_text(config->label_obj, buf);\n }\n } else if (event_code == LV_EVENT_RELEASED) {\n if (*(config->lock)) {\n *(config->lock) = false;\n }\n\n if (!*(config->completed)) {\n lv_label_set_text(config->label_obj, config->default_text);\n }\n }\n}\n\nvoid action_reset_config(lv_event_t * e) {\n hold_action_config_t config = {\n .start_time = &t_reset_config,\n .completed = &b_reset_config,\n .lock = &b_reset_config_lock,\n .hold_time_seconds = RESET_CONFIG_HOLD_TIME,\n .rpc_method = \"resetConfig\",\n .button_obj = objects.reset_config_button,\n .spinner_obj = objects.reset_config_spinner,\n .label_obj = objects.reset_config_label,\n .default_text = \"Press and hold for\\n10 seconds\"\n };\n \n handle_hold_action(e, &config);\n}\n\nvoid action_dhcpc(lv_event_t * e) {\n hold_action_config_t config = {\n .start_time = &t_dhcpc,\n .completed = &b_dhcpc,\n .lock = &b_dhcpc_lock,\n .hold_time_seconds = DHCPC_HOLD_TIME,\n .rpc_method = \"toggleDHCPClient\",\n .button_obj = NULL, // No button/spinner for reboot\n .spinner_obj = NULL,\n .label_obj = objects.dhcpc_label,\n .default_text = \"Press and hold for\\n5 seconds\"\n };\n \n handle_hold_action(e, &config);\n}\n\nvoid action_reboot(lv_event_t * e) {\n hold_action_config_t config = {\n .start_time = &t_reboot,\n .completed = &b_reboot,\n .lock = &b_reboot_lock,\n .hold_time_seconds = REBOOT_HOLD_TIME,\n .rpc_method = \"reboot\",\n .button_obj = NULL, // No button/spinner for reboot\n .spinner_obj = NULL,\n .label_obj = objects.reboot_label,\n .default_text = \"Press and hold for\\n5 seconds\"\n };\n \n handle_hold_action(e, &config);\n}" + "template": "#include \"actions.h\"\n#include \"screens.h\"\n#include \n#include \n#include \"ui.h\"\n#include \"vars.h\"\n\nint handle_gesture_screen_switch(lv_event_t *e, lv_dir_t direction, int screenId) {\n lv_event_code_t event_code = lv_event_get_code(e);\n if (event_code != LV_EVENT_GESTURE) {\n return 0;\n }\n\n if (lv_indev_get_gesture_dir(lv_indev_get_act()) != direction) {\n return 0;\n }\n lv_indev_wait_release(lv_indev_get_act());\n loadScreen(screenId);\n return 1;\n}\n\nvoid handle_gesture_main_screen_switch(lv_event_t *e, lv_dir_t direction) {\n const char *main_screen = get_var_main_screen();\n if (strcmp(main_screen, \"home_screen\") == 0) { \n loadScreen(SCREEN_ID_HOME_SCREEN);\n } else if (strcmp(main_screen, \"no_network_screen\") == 0) {\n loadScreen(SCREEN_ID_NO_NETWORK_SCREEN);\n }\n}\n\nvoid action_switch_to_menu(lv_event_t *e) {\n loadScreen(SCREEN_ID_MENU_SCREEN);\n}\n\nvoid action_switch_to_advanced_menu(lv_event_t *e) {\n loadScreen(SCREEN_ID_MENU_ADVANCED_SCREEN);\n}\n\nvoid action_switch_to_status(lv_event_t *e) {\n loadScreen(SCREEN_ID_STATUS_SCREEN);\n}\n\nvoid action_switch_to_about(lv_event_t *e) {\n loadScreen(SCREEN_ID_ABOUT_SCREEN);\n}\n\nvoid action_switch_to_reset_config(lv_event_t *e) {\n loadScreen(SCREEN_ID_RESET_CONFIG_SCREEN);\n}\n\nvoid action_switch_to_dhcpc(lv_event_t *e) {\n loadScreen(SCREEN_ID_SWITCH_DHCP_CLIENT_SCREEN);\n}\n\nvoid action_switch_to_reboot(lv_event_t *e) {\n loadScreen(SCREEN_ID_REBOOT_SCREEN);\n}\n\nvoid action_menu_screen_gesture(lv_event_t * e) {\n handle_gesture_main_screen_switch(e, LV_DIR_RIGHT);\n}\n\nvoid action_menu_advanced_screen_gesture(lv_event_t * e) {\n handle_gesture_screen_switch(e, LV_DIR_RIGHT, SCREEN_ID_MENU_SCREEN);\n}\n\nvoid action_reset_config_screen_gesture(lv_event_t * e) {\n handle_gesture_screen_switch(e, LV_DIR_RIGHT, SCREEN_ID_MENU_SCREEN);\n}\n\nvoid action_home_screen_gesture(lv_event_t * e) {\n handle_gesture_screen_switch(e, LV_DIR_LEFT, SCREEN_ID_MENU_SCREEN);\n}\n\nvoid action_about_screen_gesture(lv_event_t * e) {\n handle_gesture_screen_switch(e, LV_DIR_RIGHT, SCREEN_ID_MENU_SCREEN);\n}\n\n// user_data doesn't seem to be working, so we use a global variable here\nstatic uint32_t t_reset_config;\nstatic uint32_t t_reboot;\nstatic uint32_t t_dhcpc;\n\nstatic bool b_reboot = false;\nstatic bool b_reset_config = false;\nstatic bool b_dhcpc = false;\n\nstatic bool b_reboot_lock = false;\nstatic bool b_reset_config_lock = false;\nstatic bool b_dhcpc_lock = false;\n\nconst int RESET_CONFIG_HOLD_TIME = 10;\nconst int REBOOT_HOLD_TIME = 5;\nconst int DHCPC_HOLD_TIME = 5;\n\ntypedef struct {\n uint32_t *start_time;\n bool *completed;\n bool *lock;\n int hold_time_seconds;\n const char *rpc_method;\n lv_obj_t *button_obj;\n lv_obj_t *spinner_obj;\n lv_obj_t *label_obj;\n const char *default_text;\n} hold_action_config_t;\n\nstatic void handle_hold_action(lv_event_t *e, hold_action_config_t *config) {\n lv_event_code_t event_code = lv_event_get_code(e);\n \n if (event_code == LV_EVENT_PRESSED) {\n *(config->start_time) = lv_tick_get();\n }\n else if (event_code == LV_EVENT_PRESSING) {\n int remaining_time = config->hold_time_seconds * 1000 - lv_tick_elaps(*(config->start_time));\n if (remaining_time <= 0) {\n if (*(config->lock)) {\n return;\n }\n if (config->button_obj && config->spinner_obj) {\n lv_obj_add_flag(config->button_obj, LV_OBJ_FLAG_HIDDEN);\n lv_obj_clear_flag(config->spinner_obj, LV_OBJ_FLAG_HIDDEN);\n }\n ui_call_rpc_handler(config->rpc_method, NULL);\n *(config->lock) = true;\n *(config->completed) = true;\n } else {\n *(config->completed) = false;\n char buf[100];\n int remaining_time_seconds = remaining_time / 1000;\n if (remaining_time_seconds <= 1) {\n remaining_time_seconds = 1;\n }\n sprintf(buf, \"Press and hold for\\n%d seconds\", remaining_time_seconds);\n lv_label_set_text(config->label_obj, buf);\n }\n } else if (event_code == LV_EVENT_RELEASED) {\n if (*(config->lock)) {\n *(config->lock) = false;\n }\n\n if (!*(config->completed)) {\n lv_label_set_text(config->label_obj, config->default_text);\n }\n }\n}\n\nvoid action_reset_config(lv_event_t * e) {\n hold_action_config_t config = {\n .start_time = &t_reset_config,\n .completed = &b_reset_config,\n .lock = &b_reset_config_lock,\n .hold_time_seconds = RESET_CONFIG_HOLD_TIME,\n .rpc_method = \"resetConfig\",\n .button_obj = objects.reset_config_button,\n .spinner_obj = objects.reset_config_spinner,\n .label_obj = objects.reset_config_label,\n .default_text = \"Press and hold for\\n10 seconds\"\n };\n \n handle_hold_action(e, &config);\n}\n\nvoid action_dhcpc(lv_event_t * e) {\n hold_action_config_t config = {\n .start_time = &t_dhcpc,\n .completed = &b_dhcpc,\n .lock = &b_dhcpc_lock,\n .hold_time_seconds = DHCPC_HOLD_TIME,\n .rpc_method = \"toggleDHCPClient\",\n .button_obj = NULL, // No button/spinner for reboot\n .spinner_obj = NULL,\n .label_obj = objects.dhcpc_label,\n .default_text = \"Press and hold for\\n5 seconds\"\n };\n \n handle_hold_action(e, &config);\n}\n\nvoid action_reboot(lv_event_t * e) {\n hold_action_config_t config = {\n .start_time = &t_reboot,\n .completed = &b_reboot,\n .lock = &b_reboot_lock,\n .hold_time_seconds = REBOOT_HOLD_TIME,\n .rpc_method = \"reboot\",\n .button_obj = NULL, // No button/spinner for reboot\n .spinner_obj = NULL,\n .label_obj = objects.reboot_label,\n .default_text = \"Press and hold for\\n5 seconds\"\n };\n \n handle_hold_action(e, &config);\n}" }, { "objID": "1dbd1b7e-7270-47f0-ee02-e80bdae287cf", @@ -281,6 +281,14 @@ "localVariables": [], "userProperties": [], "name": "DHCPC" + }, + { + "objID": "1fbdb292-2b01-4dfe-a4ab-da889959259e", + "components": [], + "connectionLines": [], + "localVariables": [], + "userProperties": [], + "name": "SwitchToDHCPC" } ], "userPages": [ @@ -3367,7 +3375,7 @@ "objID": "6a730d9a-c11d-4800-9833-f4d7b5a8a40d", "eventName": "PRESSED", "handlerType": "action", - "action": "SwitchToReboot", + "action": "SwitchToDHCPC", "userData": 0 } ], @@ -8379,7 +8387,7 @@ "type": "LVGLLabelWidget", "left": 0, "top": 0, - "width": 116, + "width": 115, "height": 20, "customInputs": [], "customOutputs": [], @@ -8408,7 +8416,7 @@ "objID": "0ac01432-b282-41c4-b119-316fe81ad79b" }, "groupIndex": 0, - "text": "Reset Config", + "text": "DHCP Client", "textType": "literal", "longMode": "WRAP", "recolor": false diff --git a/internal/native/eez/src/ui/actions.c b/internal/native/eez/src/ui/actions.c index 135d8938..fd13c142 100644 --- a/internal/native/eez/src/ui/actions.c +++ b/internal/native/eez/src/ui/actions.c @@ -48,6 +48,10 @@ void action_switch_to_reset_config(lv_event_t *e) { loadScreen(SCREEN_ID_RESET_CONFIG_SCREEN); } +void action_switch_to_dhcpc(lv_event_t *e) { + loadScreen(SCREEN_ID_SWITCH_DHCP_CLIENT_SCREEN); +} + void action_switch_to_reboot(lv_event_t *e) { loadScreen(SCREEN_ID_REBOOT_SCREEN); } diff --git a/internal/native/eez/src/ui/actions.h b/internal/native/eez/src/ui/actions.h index 4ec4a807..a4179b3c 100644 --- a/internal/native/eez/src/ui/actions.h +++ b/internal/native/eez/src/ui/actions.h @@ -25,6 +25,7 @@ extern void action_reset_config(lv_event_t * e); extern void action_reboot(lv_event_t * e); extern void action_switch_to_reboot(lv_event_t * e); extern void action_dhcpc(lv_event_t * e); +extern void action_switch_to_dhcpc(lv_event_t * e); #ifdef __cplusplus diff --git a/internal/native/eez/src/ui/screens.c b/internal/native/eez/src/ui/screens.c index 566006f1..d2824a57 100644 --- a/internal/native/eez/src/ui/screens.c +++ b/internal/native/eez/src/ui/screens.c @@ -893,7 +893,7 @@ void create_screen_menu_advanced_screen() { objects.menu_btn_dhcp_client = obj; lv_obj_set_pos(obj, 0, 0); lv_obj_set_size(obj, LV_PCT(100), 50); - lv_obj_add_event_cb(obj, action_switch_to_reboot, LV_EVENT_PRESSED, (void *)0); + lv_obj_add_event_cb(obj, action_switch_to_dhcpc, LV_EVENT_PRESSED, (void *)0); lv_obj_clear_flag(obj, LV_OBJ_FLAG_SNAPPABLE); add_style_menu_button(obj); { @@ -2278,7 +2278,7 @@ void create_screen_switch_dhcp_client_screen() { lv_obj_set_pos(obj, LV_PCT(0), LV_PCT(0)); lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT); add_style_header_link(obj); - lv_label_set_text(obj, "Reset Config"); + lv_label_set_text(obj, "DHCP Client"); } } }