@@ -42,17 +42,21 @@ func updateDisplay() {
42
42
43
43
if usbState == "configured" {
44
44
nativeInstance .UpdateLabelIfChanged ("usb_status_label" , "Connected" )
45
- _ , _ = nativeInstance .UIObjSetState ("usb_status" , "LV_STATE_DEFAULT" )
45
+ _ , _ = nativeInstance .UIObjAddState ("usb_status" , "LV_STATE_DEFAULT" )
46
+ _ , _ = nativeInstance .UIObjRemoveState ("usb_status" , "LV_STATE_DISABLED" )
46
47
} else {
47
48
nativeInstance .UpdateLabelIfChanged ("usb_status_label" , "Disconnected" )
48
- _ , _ = nativeInstance .UIObjSetState ("usb_status" , "LV_STATE_DISABLED" )
49
+ _ , _ = nativeInstance .UIObjAddState ("usb_status" , "LV_STATE_DISABLED" )
50
+ _ , _ = nativeInstance .UIObjRemoveState ("usb_status" , "LV_STATE_DEFAULT" )
49
51
}
50
52
if lastVideoState .Ready {
51
53
nativeInstance .UpdateLabelIfChanged ("hdmi_status_label" , "Connected" )
52
- _ , _ = nativeInstance .UIObjSetState ("hdmi_status" , "LV_STATE_DEFAULT" )
54
+ _ , _ = nativeInstance .UIObjAddState ("hdmi_status" , "LV_STATE_DEFAULT" )
55
+ _ , _ = nativeInstance .UIObjRemoveState ("hdmi_status" , "LV_STATE_DISABLED" )
53
56
} else {
54
57
nativeInstance .UpdateLabelIfChanged ("hdmi_status_label" , "Disconnected" )
55
- _ , _ = nativeInstance .UIObjSetState ("hdmi_status" , "LV_STATE_DISABLED" )
58
+ _ , _ = nativeInstance .UIObjAddState ("hdmi_status" , "LV_STATE_DISABLED" )
59
+ _ , _ = nativeInstance .UIObjRemoveState ("hdmi_status" , "LV_STATE_DEFAULT" )
56
60
}
57
61
nativeInstance .UpdateLabelIfChanged ("cloud_status_label" , fmt .Sprintf ("%d active" , actionSessions ))
58
62
@@ -124,7 +128,7 @@ var (
124
128
waitDisplayUpdate = sync.Mutex {}
125
129
)
126
130
127
- func requestDisplayUpdate (shouldWakeDisplay bool ) {
131
+ func requestDisplayUpdate (shouldWakeDisplay bool , reason string ) {
128
132
displayUpdateLock .Lock ()
129
133
defer displayUpdateLock .Unlock ()
130
134
@@ -134,20 +138,20 @@ func requestDisplayUpdate(shouldWakeDisplay bool) {
134
138
}
135
139
go func () {
136
140
if shouldWakeDisplay {
137
- wakeDisplay (false )
141
+ wakeDisplay (false , reason )
138
142
}
139
143
displayLogger .Debug ().Msg ("display updating" )
140
144
//TODO: only run once regardless how many pending updates
141
145
updateDisplay ()
142
146
}()
143
147
}
144
148
145
- func waitCtrlAndRequestDisplayUpdate (shouldWakeDisplay bool ) {
149
+ func waitCtrlAndRequestDisplayUpdate (shouldWakeDisplay bool , reason string ) {
146
150
waitDisplayUpdate .Lock ()
147
151
defer waitDisplayUpdate .Unlock ()
148
152
149
153
// nativeInstance.WaitCtrlClientConnected()
150
- requestDisplayUpdate (shouldWakeDisplay )
154
+ requestDisplayUpdate (shouldWakeDisplay , reason )
151
155
}
152
156
153
157
func updateStaticContents () {
@@ -182,7 +186,7 @@ func updateStaticContents() {
182
186
183
187
// setDisplayBrightness sets /sys/class/backlight/backlight/brightness to alter
184
188
// the backlight brightness of the JetKVM hardware's display.
185
- func setDisplayBrightness (brightness int ) error {
189
+ func setDisplayBrightness (brightness int , reason string ) error {
186
190
// NOTE: The actual maximum value for this is 255, but out-of-the-box, the value is set to 64.
187
191
// The maximum set here is set to 100 to reduce the risk of drawing too much power (and besides, 255 is very bright!).
188
192
if brightness > 100 || brightness < 0 {
@@ -201,14 +205,14 @@ func setDisplayBrightness(brightness int) error {
201
205
return err
202
206
}
203
207
204
- displayLogger .Info ().Int ("brightness" , brightness ).Msg ("set brightness" )
208
+ displayLogger .Info ().Int ("brightness" , brightness ).Str ( "reason" , reason ). Msg ("set brightness" )
205
209
return nil
206
210
}
207
211
208
212
// tick_displayDim() is called when when dim ticker expires, it simply reduces the brightness
209
213
// of the display by half of the max brightness.
210
214
func tick_displayDim () {
211
- err := setDisplayBrightness (config .DisplayMaxBrightness / 2 )
215
+ err := setDisplayBrightness (config .DisplayMaxBrightness / 2 , "tick_display_dim" )
212
216
if err != nil {
213
217
displayLogger .Warn ().Err (err ).Msg ("failed to dim display" )
214
218
}
@@ -221,7 +225,7 @@ func tick_displayDim() {
221
225
// tick_displayOff() is called when the off ticker expires, it turns off the display
222
226
// by setting the brightness to zero.
223
227
func tick_displayOff () {
224
- err := setDisplayBrightness (0 )
228
+ err := setDisplayBrightness (0 , "tick_display_off" )
225
229
if err != nil {
226
230
displayLogger .Warn ().Err (err ).Msg ("failed to turn off display" )
227
231
}
@@ -234,7 +238,7 @@ func tick_displayOff() {
234
238
// wakeDisplay sets the display brightness back to config.DisplayMaxBrightness and stores the time the display
235
239
// last woke, ready for displayTimeoutTick to put the display back in the dim/off states.
236
240
// Set force to true to skip the backlight state check, this should be done if altering the tickers.
237
- func wakeDisplay (force bool ) {
241
+ func wakeDisplay (force bool , reason string ) {
238
242
if backlightState == 0 && ! force {
239
243
return
240
244
}
@@ -244,7 +248,11 @@ func wakeDisplay(force bool) {
244
248
return
245
249
}
246
250
247
- err := setDisplayBrightness (config .DisplayMaxBrightness )
251
+ if reason == "" {
252
+ reason = "wake_display"
253
+ }
254
+
255
+ err := setDisplayBrightness (config .DisplayMaxBrightness , reason )
248
256
if err != nil {
249
257
displayLogger .Warn ().Err (err ).Msg ("failed to wake display" )
250
258
}
@@ -266,7 +274,7 @@ func startBacklightTickers() {
266
274
// Don't start the tickers if the display is switched off.
267
275
// Set the display to off if that's the case.
268
276
if config .DisplayMaxBrightness == 0 {
269
- _ = setDisplayBrightness (0 )
277
+ _ = setDisplayBrightness (0 , "display_disabled" )
270
278
return
271
279
}
272
280
@@ -316,7 +324,6 @@ func initDisplay() {
316
324
displayInited = true
317
325
displayLogger .Info ().Msg ("display inited" )
318
326
startBacklightTickers ()
319
- wakeDisplay (true )
320
- requestDisplayUpdate (true )
327
+ requestDisplayUpdate (true , "init_display" )
321
328
}()
322
329
}
0 commit comments