9
9
"time"
10
10
)
11
11
12
- var currentScreen = "ui_Boot_Screen "
12
+ var currentScreen = "boot_screen "
13
13
var backlightState = 0 // 0 - NORMAL, 1 - DIMMED, 2 - OFF
14
14
15
15
var (
@@ -22,120 +22,55 @@ const (
22
22
backlightControlClass string = "/sys/class/backlight/backlight/brightness"
23
23
)
24
24
25
- func switchToScreen (screen string ) {
26
- _ , err := CallCtrlAction ("lv_scr_load" , map [string ]interface {}{"obj" : screen })
27
- if err != nil {
28
- displayLogger .Warn ().Err (err ).Str ("screen" , screen ).Msg ("failed to switch to screen" )
29
- return
30
- }
31
- currentScreen = screen
32
- }
33
-
34
- var displayedTexts = make (map [string ]string )
35
-
36
- func lvObjSetState (objName string , state string ) (* CtrlResponse , error ) {
37
- return CallCtrlAction ("lv_obj_set_state" , map [string ]interface {}{"obj" : objName , "state" : state })
38
- }
39
-
40
- func lvObjAddFlag (objName string , flag string ) (* CtrlResponse , error ) {
41
- return CallCtrlAction ("lv_obj_add_flag" , map [string ]interface {}{"obj" : objName , "flag" : flag })
42
- }
43
-
44
- func lvObjClearFlag (objName string , flag string ) (* CtrlResponse , error ) {
45
- return CallCtrlAction ("lv_obj_clear_flag" , map [string ]interface {}{"obj" : objName , "flag" : flag })
46
- }
47
-
48
- func lvObjHide (objName string ) (* CtrlResponse , error ) {
49
- return lvObjAddFlag (objName , "LV_OBJ_FLAG_HIDDEN" )
50
- }
51
-
52
- func lvObjShow (objName string ) (* CtrlResponse , error ) {
53
- return lvObjClearFlag (objName , "LV_OBJ_FLAG_HIDDEN" )
54
- }
55
-
56
- func lvObjSetOpacity (objName string , opacity int ) (* CtrlResponse , error ) { // nolint:unused
57
- return CallCtrlAction ("lv_obj_set_style_opa_layered" , map [string ]interface {}{"obj" : objName , "opa" : opacity })
58
- }
59
-
60
- func lvObjFadeIn (objName string , duration uint32 ) (* CtrlResponse , error ) {
61
- return CallCtrlAction ("lv_obj_fade_in" , map [string ]interface {}{"obj" : objName , "time" : duration })
62
- }
63
-
64
- func lvObjFadeOut (objName string , duration uint32 ) (* CtrlResponse , error ) {
65
- return CallCtrlAction ("lv_obj_fade_out" , map [string ]interface {}{"obj" : objName , "time" : duration })
66
- }
67
-
68
- func lvLabelSetText (objName string , text string ) (* CtrlResponse , error ) {
69
- return CallCtrlAction ("lv_label_set_text" , map [string ]interface {}{"obj" : objName , "text" : text })
70
- }
71
-
72
- func lvImgSetSrc (objName string , src string ) (* CtrlResponse , error ) {
73
- return CallCtrlAction ("lv_img_set_src" , map [string ]interface {}{"obj" : objName , "src" : src })
74
- }
75
-
76
- func lvDispSetRotation (rotation string ) (* CtrlResponse , error ) {
77
- return CallCtrlAction ("lv_disp_set_rotation" , map [string ]interface {}{"rotation" : rotation })
78
- }
79
-
80
- func updateLabelIfChanged (objName string , newText string ) {
81
- if newText != "" && newText != displayedTexts [objName ] {
82
- _ , _ = lvLabelSetText (objName , newText )
83
- displayedTexts [objName ] = newText
84
- }
85
- }
86
-
87
- func switchToScreenIfDifferent (screenName string ) {
88
- if currentScreen != screenName {
89
- displayLogger .Info ().Str ("from" , currentScreen ).Str ("to" , screenName ).Msg ("switching screen" )
90
- switchToScreen (screenName )
91
- }
92
- }
93
-
94
25
var (
95
26
cloudBlinkLock sync.Mutex = sync.Mutex {}
96
27
cloudBlinkStopped bool
97
28
cloudBlinkTicker * time.Ticker
98
29
)
99
30
100
31
func updateDisplay () {
101
- updateLabelIfChanged ("ui_Home_Content_Ip" , networkState .IPv4String ())
32
+ nativeInstance .UpdateLabelIfChanged ("home_info_ipv4_addr" , networkState .IPv4String ())
33
+ nativeInstance .UpdateLabelIfChanged ("home_info_ipv6_addr" , networkState .IPv6String ())
34
+
35
+ nativeInstance .UpdateLabelIfChanged ("home_info_mac_addr" , networkState .MACString ())
36
+
102
37
if usbState == "configured" {
103
- updateLabelIfChanged ("ui_Home_Footer_Usb_Status_Label" , "Connected" )
104
- _ , _ = lvObjSetState ("ui_Home_Footer_Usb_Status_Label" , "LV_STATE_DEFAULT" )
38
+ nativeInstance . UpdateLabelIfChanged ("ui_Home_Footer_Usb_Status_Label" , "Connected" )
39
+ _ , _ = nativeInstance . ObjSetState ("ui_Home_Footer_Usb_Status_Label" , "LV_STATE_DEFAULT" )
105
40
} else {
106
- updateLabelIfChanged ("ui_Home_Footer_Usb_Status_Label" , "Disconnected" )
107
- _ , _ = lvObjSetState ("ui_Home_Footer_Usb_Status_Label" , "LV_STATE_USER_2" )
41
+ nativeInstance . UpdateLabelIfChanged ("ui_Home_Footer_Usb_Status_Label" , "Disconnected" )
42
+ _ , _ = nativeInstance . ObjSetState ("ui_Home_Footer_Usb_Status_Label" , "LV_STATE_USER_2" )
108
43
}
109
44
if lastVideoState .Ready {
110
- updateLabelIfChanged ("ui_Home_Footer_Hdmi_Status_Label" , "Connected" )
111
- _ , _ = lvObjSetState ("ui_Home_Footer_Hdmi_Status_Label" , "LV_STATE_DEFAULT" )
45
+ nativeInstance . UpdateLabelIfChanged ("ui_Home_Footer_Hdmi_Status_Label" , "Connected" )
46
+ _ , _ = nativeInstance . ObjSetState ("ui_Home_Footer_Hdmi_Status_Label" , "LV_STATE_DEFAULT" )
112
47
} else {
113
- updateLabelIfChanged ("ui_Home_Footer_Hdmi_Status_Label" , "Disconnected" )
114
- _ , _ = lvObjSetState ("ui_Home_Footer_Hdmi_Status_Label" , "LV_STATE_USER_2" )
48
+ nativeInstance . UpdateLabelIfChanged ("ui_Home_Footer_Hdmi_Status_Label" , "Disconnected" )
49
+ _ , _ = nativeInstance . ObjSetState ("ui_Home_Footer_Hdmi_Status_Label" , "LV_STATE_USER_2" )
115
50
}
116
- updateLabelIfChanged ("ui_Home_Header_Cloud_Status_Label" , fmt .Sprintf ("%d active" , actionSessions ))
51
+ nativeInstance . UpdateLabelIfChanged ("ui_Home_Header_Cloud_Status_Label" , fmt .Sprintf ("%d active" , actionSessions ))
117
52
118
53
if networkState .IsUp () {
119
- switchToScreenIfDifferent ( "ui_Home_Screen" )
54
+ nativeInstance . SwitchToScreenIf ( "home_screen" , [] string { "no_network_screen" , "boot_screen" } )
120
55
} else {
121
- switchToScreenIfDifferent ( "ui_No_Network_Screen" )
56
+ nativeInstance . SwitchToScreenIf ( "no_network_screen" , [] string { "home_screen" , "boot_screen" } )
122
57
}
123
58
124
59
if cloudConnectionState == CloudConnectionStateNotConfigured {
125
- _ , _ = lvObjHide ("ui_Home_Header_Cloud_Status_Icon" )
60
+ _ , _ = nativeInstance . ObjHide ("ui_Home_Header_Cloud_Status_Icon" )
126
61
} else {
127
- _ , _ = lvObjShow ("ui_Home_Header_Cloud_Status_Icon" )
62
+ _ , _ = nativeInstance . ObjShow ("ui_Home_Header_Cloud_Status_Icon" )
128
63
}
129
64
130
65
switch cloudConnectionState {
131
66
case CloudConnectionStateDisconnected :
132
- _ , _ = lvImgSetSrc ("ui_Home_Header_Cloud_Status_Icon" , "cloud_disconnected.png" )
67
+ _ , _ = nativeInstance . ImgSetSrc ("ui_Home_Header_Cloud_Status_Icon" , "cloud_disconnected.png" )
133
68
stopCloudBlink ()
134
69
case CloudConnectionStateConnecting :
135
- _ , _ = lvImgSetSrc ("ui_Home_Header_Cloud_Status_Icon" , "cloud.png" )
70
+ _ , _ = nativeInstance . ImgSetSrc ("ui_Home_Header_Cloud_Status_Icon" , "cloud.png" )
136
71
startCloudBlink ()
137
72
case CloudConnectionStateConnected :
138
- _ , _ = lvImgSetSrc ("ui_Home_Header_Cloud_Status_Icon" , "cloud.png" )
73
+ _ , _ = nativeInstance . ImgSetSrc ("ui_Home_Header_Cloud_Status_Icon" , "cloud.png" )
139
74
stopCloudBlink ()
140
75
}
141
76
}
@@ -159,9 +94,9 @@ func startCloudBlink() {
159
94
if cloudConnectionState != CloudConnectionStateConnecting {
160
95
continue
161
96
}
162
- _ , _ = lvObjFadeOut ("ui_Home_Header_Cloud_Status_Icon" , 1000 )
97
+ _ , _ = nativeInstance . ObjFadeOut ("ui_Home_Header_Cloud_Status_Icon" , 1000 )
163
98
time .Sleep (1000 * time .Millisecond )
164
- _ , _ = lvObjFadeIn ("ui_Home_Header_Cloud_Status_Icon" , 1000 )
99
+ _ , _ = nativeInstance . ObjFadeIn ("ui_Home_Header_Cloud_Status_Icon" , 1000 )
165
100
time .Sleep (1000 * time .Millisecond )
166
101
}
167
102
}()
@@ -205,20 +140,20 @@ func waitCtrlAndRequestDisplayUpdate(shouldWakeDisplay bool) {
205
140
waitDisplayUpdate .Lock ()
206
141
defer waitDisplayUpdate .Unlock ()
207
142
208
- waitCtrlClientConnected ()
143
+ // nativeInstance.WaitCtrlClientConnected ()
209
144
requestDisplayUpdate (shouldWakeDisplay )
210
145
}
211
146
212
147
func updateStaticContents () {
213
148
//contents that never change
214
- updateLabelIfChanged ("ui_Home_Content_Mac" , networkState .MACString ())
149
+ nativeInstance . UpdateLabelIfChanged ("ui_Home_Content_Mac" , networkState .MACString ())
215
150
systemVersion , appVersion , err := GetLocalVersion ()
216
151
if err == nil {
217
- updateLabelIfChanged ("ui_About_Content_Operating_System_Version_ContentLabel" , systemVersion .String ())
218
- updateLabelIfChanged ("ui_About_Content_App_Version_Content_Label" , appVersion .String ())
152
+ nativeInstance . UpdateLabelIfChanged ("ui_About_Content_Operating_System_Version_ContentLabel" , systemVersion .String ())
153
+ nativeInstance . UpdateLabelIfChanged ("ui_About_Content_App_Version_Content_Label" , appVersion .String ())
219
154
}
220
155
221
- updateLabelIfChanged ("ui_Status_Content_Device_Id_Content_Label" , GetDeviceID ())
156
+ nativeInstance . UpdateLabelIfChanged ("ui_Status_Content_Device_Id_Content_Label" , GetDeviceID ())
222
157
}
223
158
224
159
// setDisplayBrightness sets /sys/class/backlight/backlight/brightness to alter
@@ -379,10 +314,9 @@ func startBacklightTickers() {
379
314
380
315
func initDisplay () {
381
316
go func () {
382
- waitCtrlClientConnected ()
383
317
displayLogger .Info ().Msg ("setting initial display contents" )
384
318
time .Sleep (500 * time .Millisecond )
385
- _ , _ = lvDispSetRotation (config .DisplayRotation )
319
+ _ , _ = nativeInstance . DispSetRotation (config .DisplayRotation )
386
320
updateStaticContents ()
387
321
displayInited = true
388
322
displayLogger .Info ().Msg ("display inited" )
0 commit comments