Skip to content

Commit 4f1ddc8

Browse files
committed
refactor functions
1 parent 0361b24 commit 4f1ddc8

File tree

13 files changed

+181
-518
lines changed

13 files changed

+181
-518
lines changed

display.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,24 @@ func updateDisplay() {
4444
nativeInstance.UpdateLabelIfChanged("home_info_ipv4_addr", networkState.IPv4String())
4545
nativeInstance.UpdateLabelAndChangeVisibility("home_info_ipv6_addr", networkState.IPv6String())
4646

47-
nativeInstance.ObjHide("menu_btn_network")
48-
nativeInstance.ObjHide("menu_btn_access")
47+
nativeInstance.UIObjHide("menu_btn_network")
48+
nativeInstance.UIObjHide("menu_btn_access")
4949

5050
nativeInstance.UpdateLabelIfChanged("home_info_mac_addr", networkState.MACString())
5151

5252
if usbState == "configured" {
5353
nativeInstance.UpdateLabelIfChanged("usb_status_label", "Connected")
54-
_, _ = nativeInstance.ObjSetState("usb_status", "LV_STATE_DEFAULT")
54+
_, _ = nativeInstance.UIObjSetState("usb_status", "LV_STATE_DEFAULT")
5555
} else {
5656
nativeInstance.UpdateLabelIfChanged("usb_status_label", "Disconnected")
57-
_, _ = nativeInstance.ObjSetState("usb_status", "LV_STATE_DISABLED")
57+
_, _ = nativeInstance.UIObjSetState("usb_status", "LV_STATE_DISABLED")
5858
}
5959
if lastVideoState.Ready {
6060
nativeInstance.UpdateLabelIfChanged("hdmi_status_label", "Connected")
61-
_, _ = nativeInstance.ObjSetState("hdmi_status", "LV_STATE_DEFAULT")
61+
_, _ = nativeInstance.UIObjSetState("hdmi_status", "LV_STATE_DEFAULT")
6262
} else {
6363
nativeInstance.UpdateLabelIfChanged("hdmi_status_label", "Disconnected")
64-
_, _ = nativeInstance.ObjSetState("hdmi_status", "LV_STATE_DISABLED")
64+
_, _ = nativeInstance.UIObjSetState("hdmi_status", "LV_STATE_DISABLED")
6565
}
6666
nativeInstance.UpdateLabelIfChanged("cloud_status_label", fmt.Sprintf("%d active", actionSessions))
6767

@@ -72,20 +72,20 @@ func updateDisplay() {
7272
}
7373

7474
if cloudConnectionState == CloudConnectionStateNotConfigured {
75-
_, _ = nativeInstance.ObjHide("cloud_status_icon")
75+
_, _ = nativeInstance.UIObjHide("cloud_status_icon")
7676
} else {
77-
_, _ = nativeInstance.ObjShow("cloud_status_icon")
77+
_, _ = nativeInstance.UIObjShow("cloud_status_icon")
7878
}
7979

8080
switch cloudConnectionState {
8181
case CloudConnectionStateDisconnected:
82-
_, _ = nativeInstance.ImgSetSrc("cloud_status_icon", "cloud_disconnected")
82+
_, _ = nativeInstance.UIObjSetImageSrc("cloud_status_icon", "cloud_disconnected")
8383
stopCloudBlink()
8484
case CloudConnectionStateConnecting:
85-
_, _ = nativeInstance.ImgSetSrc("cloud_status_icon", "cloud")
85+
_, _ = nativeInstance.UIObjSetImageSrc("cloud_status_icon", "cloud")
8686
startCloudBlink()
8787
case CloudConnectionStateConnected:
88-
_, _ = nativeInstance.ImgSetSrc("cloud_status_icon", "cloud")
88+
_, _ = nativeInstance.UIObjSetImageSrc("cloud_status_icon", "cloud")
8989
stopCloudBlink()
9090
}
9191
}
@@ -389,7 +389,7 @@ func initDisplay() {
389389
go func() {
390390
displayLogger.Info().Msg("setting initial display contents")
391391
time.Sleep(500 * time.Millisecond)
392-
_, _ = nativeInstance.DispSetRotation(config.DisplayRotation)
392+
_, _ = nativeInstance.DisplaySetRotation(config.DisplayRotation)
393393
updateStaticContents()
394394
displayInited = true
395395
displayLogger.Info().Msg("display inited")

internal/native/cgo/ctrl.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "edid.h"
1313
#include "ctrl.h"
1414
#include <lvgl.h>
15-
#include "ui/vars.h"
15+
#include "ui_index.h"
1616
#include "log.h"
1717
#include "log_handler.h"
1818

@@ -154,8 +154,24 @@ lv_obj_flag_t str_to_lv_obj_flag(const char *flag)
154154
}
155155
}
156156

157-
void jetkvm_set_app_version(const char *version) {
158-
set_var_app_version(version);
157+
void jetkvm_ui_set_var(const char *name, const char *value) {
158+
for (int i = 0; i < ui_vars_size; i++) {
159+
if (strcmp(ui_vars[i].name, name) == 0) {
160+
ui_vars[i].setter(value);
161+
return;
162+
}
163+
}
164+
log_error("variable %s not found", name);
165+
}
166+
167+
const char *jetkvm_ui_get_var(const char *name) {
168+
for (int i = 0; i < ui_vars_size; i++) {
169+
if (strcmp(ui_vars[i].name, name) == 0) {
170+
return ui_vars[i].getter();
171+
}
172+
}
173+
log_error("variable %s not found", name);
174+
return NULL;
159175
}
160176

161177
void jetkvm_ui_init() {

internal/native/cgo/ctrl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ typedef void (jetkvm_video_handler_t)(const uint8_t *frame, ssize_t len);
2222
void jetkvm_set_log_handler(jetkvm_log_handler_t *handler);
2323
void jetkvm_set_video_handler(jetkvm_video_handler_t *handler);
2424

25-
void jetkvm_set_app_version(const char *version);
25+
void jetkvm_ui_set_var(const char *name, const char *value);
26+
const char *jetkvm_ui_get_var(const char *name);
2627

2728
void jetkvm_ui_init();
2829
void jetkvm_ui_tick();

internal/native/cgo/ui_index.gen.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ done)
1919
};
2020
2121
const int ui_images_size = sizeof(ui_images) / sizeof(ui_images[0]);
22+
23+
ui_var_map ui_vars[] = {
24+
$(grep 'extern const char \*get_var_' ui/vars.h | sed 's/extern const char \*get_var_//g' | sed 's/();//g' | sed 's/\r//' | while read -r line; do
25+
echo " {\"$line\", &get_var_$line, &set_var_$line},"
26+
done)
27+
};
28+
29+
const int ui_vars_size = sizeof(ui_vars) / sizeof(ui_vars[0]);
2230
EOF
2331
2432
echo "ui_index.c has been generated successfully."

internal/native/cgo/ui_index.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "ui/ui.h"
55
#include "ui/screens.h"
66
#include "ui/images.h"
7+
#include "ui/vars.h"
78

89
typedef struct {
910
const char *name;
@@ -21,5 +22,13 @@ typedef struct {
2122
extern ui_img_map ui_images[];
2223
extern const int ui_images_size;
2324

25+
typedef struct {
26+
const char *name;
27+
const char *(*getter)();
28+
void (*setter)(const char *value);
29+
} ui_var_map;
30+
31+
extern ui_var_map ui_vars[];
32+
extern const int ui_vars_size;
2433

2534
#endif // UI_INDEX_H

0 commit comments

Comments
 (0)