Skip to content

Commit 028cb7d

Browse files
committed
feat: add reset config and reboot buttons to UI
1 parent e930363 commit 028cb7d

File tree

17 files changed

+1104
-88
lines changed

17 files changed

+1104
-88
lines changed

internal/native/cgo/ctrl.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
jetkvm_video_state_t state;
2020
jetkvm_video_state_handler_t *video_state_handler = NULL;
21-
21+
jetkvm_rpc_handler_t *rpc_handler = NULL;
2222
jetkvm_video_handler_t *video_handler = NULL;
2323

2424

@@ -34,6 +34,16 @@ void jetkvm_set_indev_handler(jetkvm_indev_handler_t *handler) {
3434
lvgl_set_indev_handler(handler);
3535
}
3636

37+
void jetkvm_set_rpc_handler(jetkvm_rpc_handler_t *handler) {
38+
rpc_handler = handler;
39+
}
40+
41+
void jetkvm_call_rpc_handler(const char *method, const char *params) {
42+
if (rpc_handler != NULL) {
43+
(*rpc_handler)(method, params);
44+
}
45+
}
46+
3747
const char *jetkvm_ui_event_code_to_name(int code) {
3848
lv_event_code_t cCode = (lv_event_code_t)code;
3949
return lv_event_code_get_name(code);

internal/native/cgo/ctrl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ typedef struct
1616

1717
typedef void (jetkvm_video_state_handler_t)(jetkvm_video_state_t *state);
1818
typedef void (jetkvm_log_handler_t)(int level, const char *filename, const char *funcname, int line, const char *message);
19+
typedef void (jetkvm_rpc_handler_t)(const char *method, const char *params);
1920
typedef void (jetkvm_video_handler_t)(const uint8_t *frame, ssize_t len);
2021
typedef void (jetkvm_indev_handler_t)(int code);
2122

2223
void jetkvm_set_log_handler(jetkvm_log_handler_t *handler);
2324
void jetkvm_set_video_handler(jetkvm_video_handler_t *handler);
2425
void jetkvm_set_indev_handler(jetkvm_indev_handler_t *handler);
26+
void jetkvm_set_rpc_handler(jetkvm_rpc_handler_t *handler);
27+
void jetkvm_call_rpc_handler(const char *method, const char *params);
2528
void jetkvm_set_video_state_handler(jetkvm_video_state_handler_t *handler);
2629

2730
void jetkvm_ui_set_var(const char *name, const char *value);

internal/native/cgo/screen.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// #include "st7789/lcd.h"
1010
#include "ui/ui.h"
1111
#include "ui_index.h"
12+
#include "ctrl.h"
1213

1314
#define DISP_BUF_SIZE (300 * 240 * 2)
1415
static lv_color_t buf[DISP_BUF_SIZE];
@@ -76,10 +77,9 @@ void lvgl_init(u_int16_t rotation) {
7677

7778
ui_init();
7879

80+
ui_set_rpc_handler((jetkvm_rpc_handler_t *)jetkvm_call_rpc_handler);
81+
7982
log_info("ui initalized");
80-
// lv_label_set_text(ui_Boot_Screen_Version, "");
81-
// lv_label_set_text(ui_Home_Content_Ip, "...");
82-
// lv_label_set_text(ui_Home_Header_Cloud_Status_Label, "0 active");
8383
}
8484

8585
void lvgl_tick(void) {

internal/native/cgo/video.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void *run_video_stream(void *arg)
323323
{
324324
if (detected_signal == false)
325325
{
326-
usleep(100000);
326+
usleep(10000); // Reduced to 10ms for better responsiveness to streaming_flag changes
327327
continue;
328328
}
329329

internal/native/cgo_linux.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ extern void jetkvm_go_indev_handler(int code);
3737
static inline void jetkvm_cgo_setup_indev_handler() {
3838
jetkvm_set_indev_handler(&jetkvm_go_indev_handler);
3939
}
40+
41+
extern void jetkvm_go_rpc_handler(cchar_t *method, cchar_t *params);
42+
static inline void jetkvm_cgo_setup_rpc_handler() {
43+
jetkvm_set_rpc_handler(&jetkvm_go_rpc_handler);
44+
}
4045
*/
4146
import "C"
4247

@@ -75,6 +80,11 @@ func jetkvm_go_indev_handler(code C.int) {
7580
indevEventChan <- int(code)
7681
}
7782

83+
//export jetkvm_go_rpc_handler
84+
func jetkvm_go_rpc_handler(method *C.cchar_t, params *C.cchar_t) {
85+
rpcEventChan <- C.GoString(method)
86+
}
87+
7888
var eventCodeToNameMap = map[int]string{}
7989

8090
func uiEventCodeToName(code int) string {
@@ -94,6 +104,7 @@ func setUpNativeHandlers() {
94104
C.jetkvm_cgo_setup_video_state_handler()
95105
C.jetkvm_cgo_setup_video_handler()
96106
C.jetkvm_cgo_setup_indev_handler()
107+
C.jetkvm_cgo_setup_rpc_handler()
97108
}
98109

99110
func uiInit(rotation uint16) {

internal/native/chan.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var (
1111
videoStateChan chan VideoState = make(chan VideoState)
1212
logChan chan nativeLogMessage = make(chan nativeLogMessage)
1313
indevEventChan chan int = make(chan int)
14+
rpcEventChan chan string = make(chan string)
1415
)
1516

1617
func (n *Native) handleVideoFrameChan() {
@@ -70,3 +71,10 @@ func (n *Native) handleIndevEventChan() {
7071
n.onIndevEvent(name)
7172
}
7273
}
74+
75+
func (n *Native) handleRpcEventChan() {
76+
for {
77+
event := <-rpcEventChan
78+
n.onRpcEvent(event)
79+
}
80+
}

internal/native/eez/jetkvm.eez-project

Lines changed: 733 additions & 25 deletions
Large diffs are not rendered by default.

internal/native/eez/jetkvm.eez-project-ui-state

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"navigation": {
33
"selectedUserPageObject": "[jetkvm.eez-project]:/userPages/8",
4-
"selectedActionObject": "[jetkvm.eez-project]:/actions/5",
4+
"selectedActionObject": "[jetkvm.eez-project]:/actions/12",
55
"selectedGlobalVariableObject": "[jetkvm.eez-project]:/variables/globalVariables/1",
66
"selectedStyleObject": "[jetkvm.eez-project]:/lvglStyles/styles/8",
77
"selectedThemeObject": "[jetkvm.eez-project]:/themes/0",
@@ -30,7 +30,7 @@
3030
{
3131
"type": "border",
3232
"selected": 2,
33-
"size": 296.5,
33+
"size": 271.5,
3434
"location": "right",
3535
"children": [
3636
{
@@ -130,7 +130,6 @@
130130
"type": "tabset",
131131
"id": "#2e3d9a08-c69c-42b5-b434-525109f2a5a7",
132132
"weight": 1,
133-
"selected": 1,
134133
"enableClose": false,
135134
"children": [
136135
{
@@ -196,25 +195,25 @@
196195
{
197196
"type": "tabset",
198197
"id": "EDITORS",
199-
"weight": 56.255429602160085,
200-
"selected": 2,
198+
"weight": 52.479136828866125,
199+
"selected": 5,
201200
"enableDeleteWhenEmpty": false,
202201
"enableClose": false,
203202
"children": [
204203
{
205204
"type": "tab",
206-
"id": "#4610a27a-ce31-4747-b3c0-488eafeb606b",
207-
"name": "StatusScreen",
205+
"id": "#2b774476-9ef3-4363-83f8-8b478f163b02",
206+
"name": "MenuAdvancedScreen",
208207
"component": "editor",
209208
"config": {
210-
"objectPath": "[jetkvm.eez-project]:/userPages/7",
209+
"objectPath": "[jetkvm.eez-project]:/userPages/4",
211210
"permanent": false
212211
},
213212
"icon": "svg:page"
214213
},
215214
{
216215
"type": "tab",
217-
"id": "#ef9d764d-e942-47f4-beec-136cbd40ffd7",
216+
"id": "#7bbd8382-ea41-467d-8ad3-4312a2d47266",
218217
"name": "ResetConfigScreen",
219218
"component": "editor",
220219
"config": {
@@ -223,21 +222,10 @@
223222
},
224223
"icon": "svg:page"
225224
},
226-
{
227-
"type": "tab",
228-
"id": "#aec56ae8-5b75-4a2f-ad81-f0d7d683c77a",
229-
"name": "FontBook24",
230-
"component": "editor",
231-
"config": {
232-
"objectPath": "[jetkvm.eez-project]:/fonts/4",
233-
"permanent": false
234-
},
235-
"icon": "material:font_download"
236-
},
237225
{
238226
"type": "tab",
239227
"id": "#c8dece00-e490-46b8-8a14-5dcfa8bbce36",
240-
"name": "NoNetworkScreen",
228+
"name": "StatusScreen",
241229
"component": "editor",
242230
"config": {
243231
"objectPath": "[jetkvm.eez-project]:/userPages/7",
@@ -259,7 +247,7 @@
259247
{
260248
"type": "tab",
261249
"id": "#f5a057a5-977c-46be-8702-5447d603a34f",
262-
"name": "MenuScreen",
250+
"name": "HomeScreen",
263251
"component": "editor",
264252
"config": {
265253
"objectPath": "[jetkvm.eez-project]:/userPages/2",
@@ -285,7 +273,7 @@
285273
{
286274
"type": "row",
287275
"id": "#ee319cf9-6145-49e4-b40e-1d999be897c8",
288-
"weight": 18.007499872650474,
276+
"weight": 21.78379264594443,
289277
"children": [
290278
{
291279
"type": "tabset",
@@ -1237,24 +1225,20 @@
12371225
"0": {
12381226
"0": {
12391227
"0": {
1240-
"0": {
1241-
"$selected": true
1242-
}
1228+
"0": {}
12431229
},
12441230
"1": {
12451231
"0": {
1246-
"0": {},
1247-
"1": {},
1248-
"2": {}
1232+
"3": {}
12491233
}
12501234
}
12511235
}
12521236
}
12531237
},
12541238
"transform": {
12551239
"translate": {
1256-
"x": -176,
1257-
"y": -127
1240+
"x": -181,
1241+
"y": -256.3828125
12581242
},
12591243
"scale": 1
12601244
},
@@ -1372,16 +1356,19 @@
13721356
"selection": {
13731357
"0": {
13741358
"0": {
1375-
"0": {},
1359+
"0": {
1360+
"0": {}
1361+
},
13761362
"1": {
13771363
"0": {
1378-
"0": {},
1379-
"1": {
1364+
"0": {
13801365
"0": {
1381-
"0": {
1382-
"$selected": true
1383-
}
1366+
"$selected": true
13841367
}
1368+
},
1369+
"1": {},
1370+
"2": {
1371+
"0": {}
13851372
}
13861373
}
13871374
}
@@ -1418,10 +1405,8 @@
14181405
"lvglPart": "MAIN",
14191406
"lvglState": "DEFAULT",
14201407
"lvglExpandedPropertiesGroup": [
1421-
"TEXT",
1422-
"ARC",
14231408
"POSITION AND SIZE",
1424-
"PADDING"
1409+
"LAYOUT"
14251410
],
14261411
"showInactiveFlowsInDebugger": true,
14271412
"globalFlowZoom": true,

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

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

46
int handle_gesture_screen_switch(lv_event_t *e, lv_dir_t direction, int screenId) {
57
lv_event_code_t event_code = lv_event_get_code(e);
@@ -31,6 +33,14 @@ void action_switch_to_about(lv_event_t *e) {
3133
loadScreen(SCREEN_ID_ABOUT_SCREEN);
3234
}
3335

36+
void action_switch_to_reset_config(lv_event_t *e) {
37+
loadScreen(SCREEN_ID_RESET_CONFIG_SCREEN);
38+
}
39+
40+
void action_switch_to_reboot(lv_event_t *e) {
41+
loadScreen(SCREEN_ID_REBOOT_SCREEN);
42+
}
43+
3444
void action_menu_screen_gesture(lv_event_t * e) {
3545
handle_gesture_screen_switch(e, LV_DIR_RIGHT, SCREEN_ID_HOME_SCREEN);
3646
}
@@ -51,27 +61,56 @@ void action_about_screen_gesture(lv_event_t * e) {
5161
handle_gesture_screen_switch(e, LV_DIR_RIGHT, SCREEN_ID_MENU_SCREEN);
5262
}
5363

54-
static const int RESET_LONG_PRESS_DURATION = 1000 * 20; // 20 seconds
64+
// user_data doesn't seem to be working, so we use a global variable here
65+
static uint32_t t_reset_config;
66+
static uint32_t t_reboot;
67+
const int RESET_CONFIG_HOLD_TIME = 10;
68+
const int REBOOT_HOLD_TIME = 5;
5569

5670
void action_reset_config(lv_event_t * e) {
5771
lv_event_code_t event_code = lv_event_get_code(e);
5872
lv_obj_t *obj = lv_event_get_target(e);
5973

6074
if (event_code == LV_EVENT_PRESSED) {
61-
// Button pressed - start timing
62-
uint32_t reset_press_start_time = lv_tick_get();
63-
lv_obj_set_user_data(obj, (uint32_t) reset_press_start_time);
75+
t_reset_config = lv_tick_get();
6476
}
6577
else if (event_code == LV_EVENT_PRESSING) {
66-
uint32_t reset_press_start_time = (uint32_t) lv_obj_get_user_data(obj);
67-
if (reset_press_start_time == 0) {
68-
return;
78+
int remaining_time = RESET_CONFIG_HOLD_TIME * 1000 - lv_tick_elaps(t_reset_config);
79+
if (remaining_time <= 0) {
80+
lv_obj_add_flag(objects.reset_config_button, LV_OBJ_FLAG_HIDDEN);
81+
lv_obj_clear_flag(objects.reset_config_spinner, LV_OBJ_FLAG_HIDDEN);
82+
ui_call_rpc_handler("resetConfig", NULL);
83+
} else {
84+
char buf[100];
85+
int remaining_time_seconds = remaining_time / 1000;
86+
if (remaining_time_seconds <= 1) {
87+
remaining_time_seconds = 1;
88+
}
89+
sprintf(buf, "Press and hold for %d seconds", remaining_time_seconds);
90+
lv_label_set_text(objects.reset_config_label, buf);
6991
}
92+
}
93+
}
7094

71-
uint32_t current_time = lv_tick_get();
72-
if (current_time - reset_press_start_time >= RESET_LONG_PRESS_DURATION) {
73-
lv_obj_add_flag(objects.reset_config_button, LV_OBJ_FLAG_HIDDEN);
74-
lv_obj_clear_flag(objects.reset_config_spinner, LV_OBJ_FLAG_HIDDEN);
95+
void action_reboot(lv_event_t * e) {
96+
lv_event_code_t event_code = lv_event_get_code(e);
97+
lv_obj_t *obj = lv_event_get_target(e);
98+
99+
if (event_code == LV_EVENT_PRESSED) {
100+
t_reboot = lv_tick_get();
101+
}
102+
else if (event_code == LV_EVENT_PRESSING) {
103+
int remaining_time = REBOOT_HOLD_TIME * 1000 - lv_tick_elaps(t_reboot);
104+
if (remaining_time <= 0) {
105+
ui_call_rpc_handler("reboot", NULL);
106+
} else {
107+
char buf[100];
108+
int remaining_time_seconds = remaining_time / 1000;
109+
if (remaining_time_seconds <= 1) {
110+
remaining_time_seconds = 1;
111+
}
112+
sprintf(buf, "Press and hold for %d seconds", remaining_time_seconds);
113+
lv_label_set_text(objects.reboot_label, buf);
75114
}
76115
}
77116
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern int handle_gesture_screen_switch(lv_event_t *e, lv_dir_t direction, int s
1111

1212
extern void action_switch_to_menu(lv_event_t * e);
1313
extern void action_switch_to_advanced_menu(lv_event_t * e);
14+
extern void action_switch_to_reset_config(lv_event_t * e);
1415
extern void action_switch_to_about(lv_event_t * e);
1516
extern void action_menu_screen_gesture(lv_event_t * e);
1617
extern void action_home_screen_gesture(lv_event_t * e);
@@ -21,6 +22,8 @@ extern void action_switch_to_status(lv_event_t * e);
2122
extern void action_common_click_event(lv_event_t * e);
2223
extern void action_handle_common_press_event(lv_event_t * e);
2324
extern void action_reset_config(lv_event_t * e);
25+
extern void action_reboot(lv_event_t * e);
26+
extern void action_switch_to_reboot(lv_event_t * e);
2427

2528

2629
#ifdef __cplusplus

0 commit comments

Comments
 (0)