From dd9032157abb01090d29f94da8dc579ff73995ef Mon Sep 17 00:00:00 2001 From: Siyuan Date: Fri, 26 Sep 2025 14:51:10 +0000 Subject: [PATCH] change no network screen height --- internal/native/eez/jetkvm.eez-project | 12 ++++++++---- internal/native/eez/src/ui/screens.c | 7 +++++-- usb.go | 4 ++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/internal/native/eez/jetkvm.eez-project b/internal/native/eez/jetkvm.eez-project index f11cb1b5..1c2cd179 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 bool b_reboot = false;\nstatic bool b_reset_config = false;\nconst int RESET_CONFIG_HOLD_TIME = 10;\nconst int REBOOT_HOLD_TIME = 5;\n\ntypedef struct {\n uint32_t *start_time;\n bool *completed;\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->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->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 %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->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 .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 10 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 .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 5 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_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;\n\nstatic bool b_reboot = false;\nstatic bool b_reset_config = false;\n\nstatic bool b_reboot_lock = false;\nstatic bool b_reset_config_lock = false;\n\nconst int RESET_CONFIG_HOLD_TIME = 10;\nconst int REBOOT_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_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", @@ -681,9 +681,9 @@ "objID": "06bed1cd-f7c9-4044-a7bf-769d252a3eba", "type": "LVGLContainerWidget", "left": 0, - "top": 0, + "top": 20, "width": 100, - "height": 60, + "height": 75, "customInputs": [], "customOutputs": [], "style": { @@ -845,6 +845,9 @@ "flex_main_place": "CENTER", "flex_cross_place": "CENTER", "flex_track_place": "CENTER" + }, + "CHECKED": { + "margin_top": 200 } } } @@ -857,7 +860,7 @@ "hiddenFlagType": "literal", "clickableFlag": false, "clickableFlagType": "literal", - "flagScrollbarMode": "", + "flagScrollbarMode": "off", "flagScrollDirection": "", "scrollSnapX": "", "scrollSnapY": "", @@ -1270,6 +1273,7 @@ "heightUnit": "px", "children": [], "widgetFlags": "CLICK_FOCUSABLE|GESTURE_BUBBLE|PRESS_LOCK|SCROLLABLE|SCROLL_CHAIN_HOR|SCROLL_CHAIN_VER|SCROLL_ELASTIC|SCROLL_MOMENTUM|SCROLL_WITH_ARROW|SNAPPABLE", + "hiddenFlag": true, "hiddenFlagType": "literal", "clickableFlagType": "literal", "checkedStateType": "literal", diff --git a/internal/native/eez/src/ui/screens.c b/internal/native/eez/src/ui/screens.c index 14cf6029..80cce866 100644 --- a/internal/native/eez/src/ui/screens.c +++ b/internal/native/eez/src/ui/screens.c @@ -115,6 +115,7 @@ void create_screen_no_network_screen() { lv_obj_set_style_border_width(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_radius(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICKABLE); + lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_OFF); add_style_flex_start(obj); { lv_obj_t *parent_obj = obj; @@ -151,8 +152,8 @@ void create_screen_no_network_screen() { // NoNetworkContentContainer lv_obj_t *obj = lv_obj_create(parent_obj); objects.no_network_content_container = obj; - lv_obj_set_pos(obj, 0, 0); - lv_obj_set_size(obj, LV_PCT(100), LV_PCT(60)); + lv_obj_set_pos(obj, 0, 20); + lv_obj_set_size(obj, LV_PCT(100), LV_PCT(75)); lv_obj_set_style_pad_left(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_pad_top(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_pad_right(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -166,6 +167,7 @@ void create_screen_no_network_screen() { lv_obj_set_style_flex_main_place(obj, LV_FLEX_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_flex_cross_place(obj, LV_FLEX_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_flex_track_place(obj, LV_FLEX_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_margin_top(obj, 200, LV_PART_MAIN | LV_STATE_CHECKED); { lv_obj_t *parent_obj = obj; { @@ -327,6 +329,7 @@ void create_screen_home_screen() { lv_obj_set_pos(obj, LV_PCT(0), LV_PCT(0)); lv_obj_set_size(obj, LV_PCT(98), 17); lv_label_set_long_mode(obj, LV_LABEL_LONG_DOT); + lv_obj_add_flag(obj, LV_OBJ_FLAG_HIDDEN); add_style_label_font16(obj); lv_obj_set_style_text_align(obj, LV_TEXT_ALIGN_LEFT, LV_PART_MAIN | LV_STATE_DEFAULT); lv_label_set_text(obj, "fe80::ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); diff --git a/usb.go b/usb.go index f476773b..af57692f 100644 --- a/usb.go +++ b/usb.go @@ -103,11 +103,15 @@ func checkUSBState() { newState := gadget.GetUsbState() + usbLogger.Trace().Str("old", usbState).Str("new", newState).Msg("Checking USB state") + if newState == usbState { return } + usbState = newState usbLogger.Info().Str("from", usbState).Str("to", newState).Msg("USB state changed") + requestDisplayUpdate(true, "usb_state_changed") triggerUSBStateUpdate() }