Skip to content

Commit 3fa3af2

Browse files
committed
refactor functions
1 parent fb166e9 commit 3fa3af2

File tree

13 files changed

+183
-520
lines changed

13 files changed

+183
-520
lines changed

display.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,24 @@ func updateDisplay() {
3535
nativeInstance.UpdateLabelIfChanged("home_info_ipv4_addr", networkState.IPv4String())
3636
nativeInstance.UpdateLabelAndChangeVisibility("home_info_ipv6_addr", networkState.IPv6String())
3737

38-
nativeInstance.ObjHide("menu_btn_network")
39-
nativeInstance.ObjHide("menu_btn_access")
38+
nativeInstance.UIObjHide("menu_btn_network")
39+
nativeInstance.UIObjHide("menu_btn_access")
4040

4141
nativeInstance.UpdateLabelIfChanged("home_info_mac_addr", networkState.MACString())
4242

4343
if usbState == "configured" {
4444
nativeInstance.UpdateLabelIfChanged("usb_status_label", "Connected")
45-
_, _ = nativeInstance.ObjSetState("usb_status", "LV_STATE_DEFAULT")
45+
_, _ = nativeInstance.UIObjSetState("usb_status", "LV_STATE_DEFAULT")
4646
} else {
4747
nativeInstance.UpdateLabelIfChanged("usb_status_label", "Disconnected")
48-
_, _ = nativeInstance.ObjSetState("usb_status", "LV_STATE_DISABLED")
48+
_, _ = nativeInstance.UIObjSetState("usb_status", "LV_STATE_DISABLED")
4949
}
5050
if lastVideoState.Ready {
5151
nativeInstance.UpdateLabelIfChanged("hdmi_status_label", "Connected")
52-
_, _ = nativeInstance.ObjSetState("hdmi_status", "LV_STATE_DEFAULT")
52+
_, _ = nativeInstance.UIObjSetState("hdmi_status", "LV_STATE_DEFAULT")
5353
} else {
5454
nativeInstance.UpdateLabelIfChanged("hdmi_status_label", "Disconnected")
55-
_, _ = nativeInstance.ObjSetState("hdmi_status", "LV_STATE_DISABLED")
55+
_, _ = nativeInstance.UIObjSetState("hdmi_status", "LV_STATE_DISABLED")
5656
}
5757
nativeInstance.UpdateLabelIfChanged("cloud_status_label", fmt.Sprintf("%d active", actionSessions))
5858

@@ -63,20 +63,20 @@ func updateDisplay() {
6363
}
6464

6565
if cloudConnectionState == CloudConnectionStateNotConfigured {
66-
_, _ = nativeInstance.ObjHide("cloud_status_icon")
66+
_, _ = nativeInstance.UIObjHide("cloud_status_icon")
6767
} else {
68-
_, _ = nativeInstance.ObjShow("cloud_status_icon")
68+
_, _ = nativeInstance.UIObjShow("cloud_status_icon")
6969
}
7070

7171
switch cloudConnectionState {
7272
case CloudConnectionStateDisconnected:
73-
_, _ = nativeInstance.ImgSetSrc("cloud_status_icon", "cloud_disconnected")
73+
_, _ = nativeInstance.UIObjSetImageSrc("cloud_status_icon", "cloud_disconnected")
7474
stopCloudBlink()
7575
case CloudConnectionStateConnecting:
76-
_, _ = nativeInstance.ImgSetSrc("cloud_status_icon", "cloud")
76+
_, _ = nativeInstance.UIObjSetImageSrc("cloud_status_icon", "cloud")
7777
startCloudBlink()
7878
case CloudConnectionStateConnected:
79-
_, _ = nativeInstance.ImgSetSrc("cloud_status_icon", "cloud")
79+
_, _ = nativeInstance.UIObjSetImageSrc("cloud_status_icon", "cloud")
8080
stopCloudBlink()
8181
}
8282
}
@@ -100,9 +100,9 @@ func startCloudBlink() {
100100
if cloudConnectionState != CloudConnectionStateConnecting {
101101
continue
102102
}
103-
_, _ = nativeInstance.ObjFadeOut("cloud_status_icon", 1000)
103+
_, _ = nativeInstance.UIObjFadeOut("cloud_status_icon", 1000)
104104
time.Sleep(1000 * time.Millisecond)
105-
_, _ = nativeInstance.ObjFadeIn("cloud_status_icon", 1000)
105+
_, _ = nativeInstance.UIObjFadeIn("cloud_status_icon", 1000)
106106
time.Sleep(1000 * time.Millisecond)
107107
}
108108
}()
@@ -347,7 +347,7 @@ func initDisplay() {
347347
go func() {
348348
displayLogger.Info().Msg("setting initial display contents")
349349
time.Sleep(500 * time.Millisecond)
350-
_, _ = nativeInstance.DispSetRotation(config.DisplayRotation)
350+
_, _ = nativeInstance.DisplaySetRotation(config.DisplayRotation)
351351
updateStaticContents()
352352
displayInited = true
353353
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)