@@ -51,17 +51,21 @@ func updateDisplay() {
51
51
52
52
if usbState == "configured" {
53
53
nativeInstance .UpdateLabelIfChanged ("usb_status_label" , "Connected" )
54
- _ , _ = nativeInstance .UIObjSetState ("usb_status" , "LV_STATE_DEFAULT" )
54
+ _ , _ = nativeInstance .UIObjAddState ("usb_status" , "LV_STATE_DEFAULT" )
55
+ _ , _ = nativeInstance .UIObjRemoveState ("usb_status" , "LV_STATE_DISABLED" )
55
56
} else {
56
57
nativeInstance .UpdateLabelIfChanged ("usb_status_label" , "Disconnected" )
57
- _ , _ = nativeInstance .UIObjSetState ("usb_status" , "LV_STATE_DISABLED" )
58
+ _ , _ = nativeInstance .UIObjAddState ("usb_status" , "LV_STATE_DISABLED" )
59
+ _ , _ = nativeInstance .UIObjRemoveState ("usb_status" , "LV_STATE_DEFAULT" )
58
60
}
59
61
if lastVideoState .Ready {
60
62
nativeInstance .UpdateLabelIfChanged ("hdmi_status_label" , "Connected" )
61
- _ , _ = nativeInstance .UIObjSetState ("hdmi_status" , "LV_STATE_DEFAULT" )
63
+ _ , _ = nativeInstance .UIObjAddState ("hdmi_status" , "LV_STATE_DEFAULT" )
64
+ _ , _ = nativeInstance .UIObjRemoveState ("hdmi_status" , "LV_STATE_DISABLED" )
62
65
} else {
63
66
nativeInstance .UpdateLabelIfChanged ("hdmi_status_label" , "Disconnected" )
64
- _ , _ = nativeInstance .UIObjSetState ("hdmi_status" , "LV_STATE_DISABLED" )
67
+ _ , _ = nativeInstance .UIObjAddState ("hdmi_status" , "LV_STATE_DISABLED" )
68
+ _ , _ = nativeInstance .UIObjRemoveState ("hdmi_status" , "LV_STATE_DEFAULT" )
65
69
}
66
70
nativeInstance .UpdateLabelIfChanged ("cloud_status_label" , fmt .Sprintf ("%d active" , actionSessions ))
67
71
@@ -166,7 +170,7 @@ var (
166
170
waitDisplayUpdate = sync.Mutex {}
167
171
)
168
172
169
- func requestDisplayUpdate (shouldWakeDisplay bool ) {
173
+ func requestDisplayUpdate (shouldWakeDisplay bool , reason string ) {
170
174
displayUpdateLock .Lock ()
171
175
defer displayUpdateLock .Unlock ()
172
176
@@ -176,20 +180,20 @@ func requestDisplayUpdate(shouldWakeDisplay bool) {
176
180
}
177
181
go func () {
178
182
if shouldWakeDisplay {
179
- wakeDisplay (false )
183
+ wakeDisplay (false , reason )
180
184
}
181
185
displayLogger .Debug ().Msg ("display updating" )
182
186
//TODO: only run once regardless how many pending updates
183
187
updateDisplay ()
184
188
}()
185
189
}
186
190
187
- func waitCtrlAndRequestDisplayUpdate (shouldWakeDisplay bool ) {
191
+ func waitCtrlAndRequestDisplayUpdate (shouldWakeDisplay bool , reason string ) {
188
192
waitDisplayUpdate .Lock ()
189
193
defer waitDisplayUpdate .Unlock ()
190
194
191
195
// nativeInstance.WaitCtrlClientConnected()
192
- requestDisplayUpdate (shouldWakeDisplay )
196
+ requestDisplayUpdate (shouldWakeDisplay , reason )
193
197
}
194
198
195
199
func updateStaticContents () {
@@ -224,7 +228,7 @@ func updateStaticContents() {
224
228
225
229
// setDisplayBrightness sets /sys/class/backlight/backlight/brightness to alter
226
230
// the backlight brightness of the JetKVM hardware's display.
227
- func setDisplayBrightness (brightness int ) error {
231
+ func setDisplayBrightness (brightness int , reason string ) error {
228
232
// NOTE: The actual maximum value for this is 255, but out-of-the-box, the value is set to 64.
229
233
// The maximum set here is set to 100 to reduce the risk of drawing too much power (and besides, 255 is very bright!).
230
234
if brightness > 100 || brightness < 0 {
@@ -243,14 +247,14 @@ func setDisplayBrightness(brightness int) error {
243
247
return err
244
248
}
245
249
246
- displayLogger .Info ().Int ("brightness" , brightness ).Msg ("set brightness" )
250
+ displayLogger .Info ().Int ("brightness" , brightness ).Str ( "reason" , reason ). Msg ("set brightness" )
247
251
return nil
248
252
}
249
253
250
254
// tick_displayDim() is called when when dim ticker expires, it simply reduces the brightness
251
255
// of the display by half of the max brightness.
252
256
func tick_displayDim () {
253
- err := setDisplayBrightness (config .DisplayMaxBrightness / 2 )
257
+ err := setDisplayBrightness (config .DisplayMaxBrightness / 2 , "tick_display_dim" )
254
258
if err != nil {
255
259
displayLogger .Warn ().Err (err ).Msg ("failed to dim display" )
256
260
}
@@ -263,7 +267,7 @@ func tick_displayDim() {
263
267
// tick_displayOff() is called when the off ticker expires, it turns off the display
264
268
// by setting the brightness to zero.
265
269
func tick_displayOff () {
266
- err := setDisplayBrightness (0 )
270
+ err := setDisplayBrightness (0 , "tick_display_off" )
267
271
if err != nil {
268
272
displayLogger .Warn ().Err (err ).Msg ("failed to turn off display" )
269
273
}
@@ -276,7 +280,7 @@ func tick_displayOff() {
276
280
// wakeDisplay sets the display brightness back to config.DisplayMaxBrightness and stores the time the display
277
281
// last woke, ready for displayTimeoutTick to put the display back in the dim/off states.
278
282
// Set force to true to skip the backlight state check, this should be done if altering the tickers.
279
- func wakeDisplay (force bool ) {
283
+ func wakeDisplay (force bool , reason string ) {
280
284
if backlightState == 0 && ! force {
281
285
return
282
286
}
@@ -286,7 +290,11 @@ func wakeDisplay(force bool) {
286
290
return
287
291
}
288
292
289
- err := setDisplayBrightness (config .DisplayMaxBrightness )
293
+ if reason == "" {
294
+ reason = "wake_display"
295
+ }
296
+
297
+ err := setDisplayBrightness (config .DisplayMaxBrightness , reason )
290
298
if err != nil {
291
299
displayLogger .Warn ().Err (err ).Msg ("failed to wake display" )
292
300
}
@@ -308,7 +316,7 @@ func startBacklightTickers() {
308
316
// Don't start the tickers if the display is switched off.
309
317
// Set the display to off if that's the case.
310
318
if config .DisplayMaxBrightness == 0 {
311
- _ = setDisplayBrightness (0 )
319
+ _ = setDisplayBrightness (0 , "display_disabled" )
312
320
return
313
321
}
314
322
@@ -358,7 +366,6 @@ func initDisplay() {
358
366
displayInited = true
359
367
displayLogger .Info ().Msg ("display inited" )
360
368
startBacklightTickers ()
361
- wakeDisplay (true )
362
- requestDisplayUpdate (true )
369
+ requestDisplayUpdate (true , "init_display" )
363
370
}()
364
371
}
0 commit comments