Skip to content

Commit e9bcdc5

Browse files
committed
minor ui fixes
1 parent 028cb7d commit e9bcdc5

File tree

8 files changed

+80
-7
lines changed

8 files changed

+80
-7
lines changed

display.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ func updateDisplay() {
5353
nativeInstance.UpdateLabelIfChanged("cloud_status_label", fmt.Sprintf("%d active", actionSessions))
5454

5555
if networkState.IsUp() {
56+
nativeInstance.UISetVar("main_screen", "home_screen")
5657
nativeInstance.SwitchToScreenIf("home_screen", []string{"no_network_screen", "boot_screen"})
5758
} else {
59+
nativeInstance.UISetVar("main_screen", "no_network_screen")
5860
nativeInstance.SwitchToScreenIf("no_network_screen", []string{"home_screen", "boot_screen"})
5961
}
6062

internal/native/display.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ func (n *Native) UIObjShow(objName string) (bool, error) {
3737
return uiObjShow(objName)
3838
}
3939

40+
// UISetVar sets the variable
41+
func (n *Native) UISetVar(name string, value string) {
42+
uiSetVar(name, value)
43+
}
44+
45+
// UIGetVar gets the variable
46+
func (n *Native) UIGetVar(name string) string {
47+
return uiGetVar(name)
48+
}
49+
4050
// UIObjSetState clears the state then adds the new state
4151
func (n *Native) UIObjSetState(objName string, state string) (bool, error) {
4252
return uiObjSetState(objName, state)

internal/native/eez/jetkvm.eez-project

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
{
4949
"objID": "58af3ebb-96b3-494c-f4e3-9c23852e3e42",
5050
"fileName": "actions.c",
51-
"template": "#include \"actions.h\"\n#include \"screens.h\"\n#include \"ui.h\"\n#include <stdio.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 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_screen_switch(e, LV_DIR_RIGHT, SCREEN_ID_HOME_SCREEN);\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;\nconst int RESET_CONFIG_HOLD_TIME = 10;\nconst int REBOOT_HOLD_TIME = 5;\n\nvoid action_reset_config(lv_event_t * e) {\n lv_event_code_t event_code = lv_event_get_code(e);\n lv_obj_t *obj = lv_event_get_target(e);\n \n if (event_code == LV_EVENT_PRESSED) {\n t_reset_config = lv_tick_get();\n }\n else if (event_code == LV_EVENT_PRESSING) {\n int remaining_time = RESET_CONFIG_HOLD_TIME * 1000 - lv_tick_elaps(t_reset_config);\n if (remaining_time <= 0) { \n lv_obj_add_flag(objects.reset_config_button, LV_OBJ_FLAG_HIDDEN);\n lv_obj_clear_flag(objects.reset_config_spinner, LV_OBJ_FLAG_HIDDEN); \n ui_call_rpc_handler(\"resetConfig\", NULL);\n } else {\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(objects.reset_config_label, buf);\n }\n }\n}\n\nvoid action_reboot(lv_event_t * e) {\n lv_event_code_t event_code = lv_event_get_code(e);\n lv_obj_t *obj = lv_event_get_target(e);\n \n if (event_code == LV_EVENT_PRESSED) {\n t_reboot = lv_tick_get();\n }\n else if (event_code == LV_EVENT_PRESSING) {\n int remaining_time = REBOOT_HOLD_TIME * 1000 - lv_tick_elaps(t_reboot);\n if (remaining_time <= 0) {\n ui_call_rpc_handler(\"reboot\", NULL);\n } else {\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(objects.reboot_label, buf);\n }\n }\n}"
51+
"template": "#include \"actions.h\"\n#include \"screens.h\"\n#include <stdio.h>\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\nvoid action_reset_config(lv_event_t * e) {\n lv_event_code_t event_code = lv_event_get_code(e);\n lv_obj_t *obj = lv_event_get_target(e);\n \n if (event_code == LV_EVENT_PRESSED) {\n t_reset_config = lv_tick_get();\n }\n else if (event_code == LV_EVENT_PRESSING) {\n int remaining_time = RESET_CONFIG_HOLD_TIME * 1000 - lv_tick_elaps(t_reset_config);\n if (remaining_time <= 0) { \n lv_obj_add_flag(objects.reset_config_button, LV_OBJ_FLAG_HIDDEN);\n lv_obj_clear_flag(objects.reset_config_spinner, LV_OBJ_FLAG_HIDDEN); \n ui_call_rpc_handler(\"resetConfig\", NULL);\n b_reset_config = true;\n } else {\n b_reset_config = 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(objects.reset_config_label, buf);\n }\n } else if (event_code == LV_EVENT_RELEASED) {\n if (!b_reset_config) {\n lv_label_set_text(objects.reset_config_label, \"Press and hold for 10 seconds\");\n }\n }\n}\n\nvoid action_reboot(lv_event_t * e) {\n lv_event_code_t event_code = lv_event_get_code(e);\n lv_obj_t *obj = lv_event_get_target(e);\n \n if (event_code == LV_EVENT_PRESSED) {\n t_reboot = lv_tick_get();\n }\n else if (event_code == LV_EVENT_PRESSING) {\n int remaining_time = REBOOT_HOLD_TIME * 1000 - lv_tick_elaps(t_reboot);\n if (remaining_time <= 0) {\n ui_call_rpc_handler(\"reboot\", NULL);\n b_reboot = false;\n } else {\n b_reboot = 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(objects.reboot_label, buf);\n }\n } else if (event_code == LV_EVENT_RELEASED) {\n if (!b_reboot) {\n lv_label_set_text(objects.reboot_label, \"Press and hold for 5 seconds\");\n }\n }\n}"
5252
},
5353
{
5454
"objID": "1dbd1b7e-7270-47f0-ee02-e80bdae287cf",
@@ -58,7 +58,7 @@
5858
{
5959
"objID": "316b04e4-a7de-4afc-c413-31f5f36d3843",
6060
"fileName": "vars.c",
61-
"template": "#include <string.h>\n//${eez-studio LVGL_INCLUDE}\n#include \"vars.h\"\n\nchar app_version[100] = { 0 };\nchar system_version[100] = { 0 };\nchar lvgl_version[32] = { 0 };\n\nconst char *get_var_app_version() {\n return app_version;\n}\n\nconst char *get_var_system_version() {\n return system_version;\n}\n\nconst char *get_var_lvgl_version() {\n if (lvgl_version[0] == '\\0') {\n char buf[32];\n sprintf(buf, \"%d.%d.%d\", LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH);\n \n \n strncpy(lvgl_version, buf, sizeof(lvgl_version) / sizeof(char));\n app_version[sizeof(lvgl_version) / sizeof(char) - 1] = 0;\n }\n return lvgl_version;\n}\n\nvoid set_var_app_version(const char *value) {\n strncpy(app_version, value, sizeof(app_version) / sizeof(char));\n app_version[sizeof(app_version) / sizeof(char) - 1] = 0;\n}\n\nvoid set_var_system_version(const char *value) {\n strncpy(system_version, value, sizeof(system_version) / sizeof(char));\n system_version[sizeof(system_version) / sizeof(char) - 1] = 0;\n}\n\nvoid set_var_lvgl_version(const char *value) {}"
61+
"template": "#include <string.h>\n//${eez-studio LVGL_INCLUDE}\n#include \"vars.h\"\n\nchar app_version[100] = { 0 };\nchar system_version[100] = { 0 };\nchar lvgl_version[32] = { 0 };\nchar main_screen[32] = \"home_screen\";\n\nconst char *get_var_app_version() {\n return app_version;\n}\n\nconst char *get_var_system_version() {\n return system_version;\n}\n\nconst char *get_var_lvgl_version() {\n if (lvgl_version[0] == '\\0') {\n char buf[32];\n sprintf(buf, \"%d.%d.%d\", LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH);\n \n \n strncpy(lvgl_version, buf, sizeof(lvgl_version) / sizeof(char));\n app_version[sizeof(lvgl_version) / sizeof(char) - 1] = 0;\n }\n return lvgl_version;\n}\n\nvoid set_var_app_version(const char *value) {\n strncpy(app_version, value, sizeof(app_version) / sizeof(char));\n app_version[sizeof(app_version) / sizeof(char) - 1] = 0;\n}\n\nvoid set_var_system_version(const char *value) {\n strncpy(system_version, value, sizeof(system_version) / sizeof(char));\n system_version[sizeof(system_version) / sizeof(char) - 1] = 0;\n}\n\nvoid set_var_lvgl_version(const char *value) {}\n\nvoid set_var_main_screen(const char *value) {\n strncpy(main_screen, value, sizeof(main_screen) / sizeof(char));\n main_screen[sizeof(main_screen) / sizeof(char) - 1] = 0;\n}\n\nconst char *get_var_main_screen() {\n return main_screen;\n}"
6262
},
6363
{
6464
"objID": "cbe7cde1-8920-476a-b2a2-1761ae7451b0",
@@ -140,6 +140,14 @@
140140
"defaultValue": "\"\"",
141141
"persistent": false,
142142
"native": false
143+
},
144+
{
145+
"objID": "8a98241b-8720-417c-9ffe-6237387dd2fd",
146+
"name": "mainScreen",
147+
"type": "string",
148+
"defaultValue": "false",
149+
"persistent": false,
150+
"native": false
143151
}
144152
],
145153
"structures": [],
@@ -6968,6 +6976,13 @@
69686976
"handlerType": "action",
69696977
"action": "ResetConfig",
69706978
"userData": 0
6979+
},
6980+
{
6981+
"objID": "1db00129-3a48-4fe9-8de4-8fb694a779ee",
6982+
"eventName": "RELEASED",
6983+
"handlerType": "action",
6984+
"action": "ResetConfig",
6985+
"userData": 0
69716986
}
69726987
],
69736988
"leftUnit": "px",
@@ -7608,11 +7623,18 @@
76087623
"userData": 0
76097624
},
76107625
{
7611-
"objID": "35cd8033-6cd0-4359-c995-e627dac3815c",
7626+
"objID": "3c264f23-8262-4045-f48a-724205f112ca",
76127627
"eventName": "PRESSING",
76137628
"handlerType": "action",
76147629
"action": "Reboot",
76157630
"userData": 0
7631+
},
7632+
{
7633+
"objID": "35cd8033-6cd0-4359-c995-e627dac3815c",
7634+
"eventName": "RELEASED",
7635+
"handlerType": "action",
7636+
"action": "Reboot",
7637+
"userData": 0
76167638
}
76177639
],
76187640
"leftUnit": "px",

internal/native/eez/src/ui/actions.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "actions.h"
22
#include "screens.h"
3-
#include "ui.h"
43
#include <stdio.h>
4+
#include "ui.h"
5+
#include "vars.h"
56

67
int handle_gesture_screen_switch(lv_event_t *e, lv_dir_t direction, int screenId) {
78
lv_event_code_t event_code = lv_event_get_code(e);
@@ -17,6 +18,15 @@ int handle_gesture_screen_switch(lv_event_t *e, lv_dir_t direction, int screenId
1718
return 1;
1819
}
1920

21+
void handle_gesture_main_screen_switch(lv_event_t *e, lv_dir_t direction) {
22+
const char *main_screen = get_var_main_screen();
23+
if (strcmp(main_screen, "home_screen") == 0) {
24+
loadScreen(SCREEN_ID_HOME_SCREEN);
25+
} else if (strcmp(main_screen, "no_network_screen") == 0) {
26+
loadScreen(SCREEN_ID_NO_NETWORK_SCREEN);
27+
}
28+
}
29+
2030
void action_switch_to_menu(lv_event_t *e) {
2131
loadScreen(SCREEN_ID_MENU_SCREEN);
2232
}
@@ -42,7 +52,7 @@ void action_switch_to_reboot(lv_event_t *e) {
4252
}
4353

4454
void action_menu_screen_gesture(lv_event_t * e) {
45-
handle_gesture_screen_switch(e, LV_DIR_RIGHT, SCREEN_ID_HOME_SCREEN);
55+
handle_gesture_main_screen_switch(e, LV_DIR_RIGHT);
4656
}
4757

4858
void action_menu_advanced_screen_gesture(lv_event_t * e) {
@@ -64,6 +74,8 @@ void action_about_screen_gesture(lv_event_t * e) {
6474
// user_data doesn't seem to be working, so we use a global variable here
6575
static uint32_t t_reset_config;
6676
static uint32_t t_reboot;
77+
static bool b_reboot = false;
78+
static bool b_reset_config = false;
6779
const int RESET_CONFIG_HOLD_TIME = 10;
6880
const int REBOOT_HOLD_TIME = 5;
6981

@@ -80,7 +92,9 @@ void action_reset_config(lv_event_t * e) {
8092
lv_obj_add_flag(objects.reset_config_button, LV_OBJ_FLAG_HIDDEN);
8193
lv_obj_clear_flag(objects.reset_config_spinner, LV_OBJ_FLAG_HIDDEN);
8294
ui_call_rpc_handler("resetConfig", NULL);
95+
b_reset_config = true;
8396
} else {
97+
b_reset_config = false;
8498
char buf[100];
8599
int remaining_time_seconds = remaining_time / 1000;
86100
if (remaining_time_seconds <= 1) {
@@ -89,6 +103,10 @@ void action_reset_config(lv_event_t * e) {
89103
sprintf(buf, "Press and hold for %d seconds", remaining_time_seconds);
90104
lv_label_set_text(objects.reset_config_label, buf);
91105
}
106+
} else if (event_code == LV_EVENT_RELEASED) {
107+
if (!b_reset_config) {
108+
lv_label_set_text(objects.reset_config_label, "Press and hold for 10 seconds");
109+
}
92110
}
93111
}
94112

@@ -103,7 +121,9 @@ void action_reboot(lv_event_t * e) {
103121
int remaining_time = REBOOT_HOLD_TIME * 1000 - lv_tick_elaps(t_reboot);
104122
if (remaining_time <= 0) {
105123
ui_call_rpc_handler("reboot", NULL);
124+
b_reboot = false;
106125
} else {
126+
b_reboot = false;
107127
char buf[100];
108128
int remaining_time_seconds = remaining_time / 1000;
109129
if (remaining_time_seconds <= 1) {
@@ -112,5 +132,9 @@ void action_reboot(lv_event_t * e) {
112132
sprintf(buf, "Press and hold for %d seconds", remaining_time_seconds);
113133
lv_label_set_text(objects.reboot_label, buf);
114134
}
135+
} else if (event_code == LV_EVENT_RELEASED) {
136+
if (!b_reboot) {
137+
lv_label_set_text(objects.reboot_label, "Press and hold for 5 seconds");
138+
}
115139
}
116140
}

internal/native/eez/src/ui/screens.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,7 @@ void create_screen_reset_config_screen() {
19051905
lv_obj_set_size(obj, LV_PCT(100), 50);
19061906
lv_obj_add_event_cb(obj, action_reset_config, LV_EVENT_PRESSED, (void *)0);
19071907
lv_obj_add_event_cb(obj, action_reset_config, LV_EVENT_PRESSING, (void *)0);
1908+
lv_obj_add_event_cb(obj, action_reset_config, LV_EVENT_RELEASED, (void *)0);
19081909
lv_obj_set_style_bg_color(obj, lv_color_hex(0xffdc2626), LV_PART_MAIN | LV_STATE_DEFAULT);
19091910
lv_obj_set_style_text_align(obj, LV_TEXT_ALIGN_LEFT, LV_PART_MAIN | LV_STATE_DEFAULT);
19101911
lv_obj_set_style_pad_right(obj, 13, LV_PART_MAIN | LV_STATE_DEFAULT);
@@ -2088,6 +2089,7 @@ void create_screen_reboot_screen() {
20882089
lv_obj_set_size(obj, LV_PCT(100), 50);
20892090
lv_obj_add_event_cb(obj, action_reboot, LV_EVENT_PRESSED, (void *)0);
20902091
lv_obj_add_event_cb(obj, action_reboot, LV_EVENT_PRESSING, (void *)0);
2092+
lv_obj_add_event_cb(obj, action_reboot, LV_EVENT_RELEASED, (void *)0);
20912093
lv_obj_set_style_bg_color(obj, lv_color_hex(0xffdc2626), LV_PART_MAIN | LV_STATE_DEFAULT);
20922094
lv_obj_set_style_text_align(obj, LV_TEXT_ALIGN_LEFT, LV_PART_MAIN | LV_STATE_DEFAULT);
20932095
lv_obj_set_style_pad_right(obj, 13, LV_PART_MAIN | LV_STATE_DEFAULT);

0 commit comments

Comments
 (0)