Skip to content

Commit 616b625

Browse files
committed
chore: use UIObjSetState instead of Add+Remove
1 parent 82c2d6d commit 616b625

File tree

9 files changed

+38
-28
lines changed

9 files changed

+38
-28
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"tailwindCSS.classFunctions": [
33
"cva",
44
"cx"
5-
]
5+
],
6+
"cmake.sourceDirectory": "/Users/aveline/Projects/JetKVM/ymjk/internal/native/cgo"
67
}

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ GO_ARGS := GOOS=linux GOARCH=arm GOARM=7 ARCHFLAGS="-arch arm"
2626
ifneq ($(wildcard $(BUILDKIT_PATH)),)
2727
GO_ARGS := $(GO_ARGS) \
2828
CGO_CFLAGS="-I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/include -I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/include" \
29-
CGO_LDFLAGS="-L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/lib -L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/lib -lrockit -lrockchip_mpp -lrga -lpthread -lm" \
29+
CGO_LDFLAGS="-L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/lib -L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/lib -lrockit -lrockchip_mpp -lrga -lpthread -lm -lgpiod" \
3030
CC="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-gcc" \
3131
LD="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-ld" \
3232
CGO_ENABLED=1
@@ -41,7 +41,10 @@ TEST_DIRS := $(shell find . -name "*_test.go" -type f -exec dirname {} \; | sort
4141

4242
build_native:
4343
@echo "Building native..."
44-
cd internal/native/cgo && ./ui_index.gen.sh && ./build.sh
44+
cd internal/native/cgo && ./ui_index.gen.sh && \
45+
CC="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-gcc" \
46+
LD="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-ld" \
47+
./build.sh
4548

4649
build_dev: build_native
4750
@echo "Building..."

cloud.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ func setCloudConnectionState(state CloudConnectionState) {
170170

171171
go waitCtrlAndRequestDisplayUpdate(
172172
previousState != state,
173+
"set_cloud_connection_state",
173174
)
174175
}
175176

display.go

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,21 @@ func updateDisplay() {
5151

5252
if usbState == "configured" {
5353
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")
5556
} else {
5657
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")
5860
}
5961
if lastVideoState.Ready {
6062
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")
6265
} else {
6366
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")
6569
}
6670
nativeInstance.UpdateLabelIfChanged("cloud_status_label", fmt.Sprintf("%d active", actionSessions))
6771

@@ -166,7 +170,7 @@ var (
166170
waitDisplayUpdate = sync.Mutex{}
167171
)
168172

169-
func requestDisplayUpdate(shouldWakeDisplay bool) {
173+
func requestDisplayUpdate(shouldWakeDisplay bool, reason string) {
170174
displayUpdateLock.Lock()
171175
defer displayUpdateLock.Unlock()
172176

@@ -176,20 +180,20 @@ func requestDisplayUpdate(shouldWakeDisplay bool) {
176180
}
177181
go func() {
178182
if shouldWakeDisplay {
179-
wakeDisplay(false)
183+
wakeDisplay(false, reason)
180184
}
181185
displayLogger.Debug().Msg("display updating")
182186
//TODO: only run once regardless how many pending updates
183187
updateDisplay()
184188
}()
185189
}
186190

187-
func waitCtrlAndRequestDisplayUpdate(shouldWakeDisplay bool) {
191+
func waitCtrlAndRequestDisplayUpdate(shouldWakeDisplay bool, reason string) {
188192
waitDisplayUpdate.Lock()
189193
defer waitDisplayUpdate.Unlock()
190194

191195
// nativeInstance.WaitCtrlClientConnected()
192-
requestDisplayUpdate(shouldWakeDisplay)
196+
requestDisplayUpdate(shouldWakeDisplay, reason)
193197
}
194198

195199
func updateStaticContents() {
@@ -224,7 +228,7 @@ func updateStaticContents() {
224228

225229
// setDisplayBrightness sets /sys/class/backlight/backlight/brightness to alter
226230
// the backlight brightness of the JetKVM hardware's display.
227-
func setDisplayBrightness(brightness int) error {
231+
func setDisplayBrightness(brightness int, reason string) error {
228232
// NOTE: The actual maximum value for this is 255, but out-of-the-box, the value is set to 64.
229233
// The maximum set here is set to 100 to reduce the risk of drawing too much power (and besides, 255 is very bright!).
230234
if brightness > 100 || brightness < 0 {
@@ -243,14 +247,14 @@ func setDisplayBrightness(brightness int) error {
243247
return err
244248
}
245249

246-
displayLogger.Info().Int("brightness", brightness).Msg("set brightness")
250+
displayLogger.Info().Int("brightness", brightness).Str("reason", reason).Msg("set brightness")
247251
return nil
248252
}
249253

250254
// tick_displayDim() is called when when dim ticker expires, it simply reduces the brightness
251255
// of the display by half of the max brightness.
252256
func tick_displayDim() {
253-
err := setDisplayBrightness(config.DisplayMaxBrightness / 2)
257+
err := setDisplayBrightness(config.DisplayMaxBrightness/2, "tick_display_dim")
254258
if err != nil {
255259
displayLogger.Warn().Err(err).Msg("failed to dim display")
256260
}
@@ -263,7 +267,7 @@ func tick_displayDim() {
263267
// tick_displayOff() is called when the off ticker expires, it turns off the display
264268
// by setting the brightness to zero.
265269
func tick_displayOff() {
266-
err := setDisplayBrightness(0)
270+
err := setDisplayBrightness(0, "tick_display_off")
267271
if err != nil {
268272
displayLogger.Warn().Err(err).Msg("failed to turn off display")
269273
}
@@ -276,7 +280,7 @@ func tick_displayOff() {
276280
// wakeDisplay sets the display brightness back to config.DisplayMaxBrightness and stores the time the display
277281
// last woke, ready for displayTimeoutTick to put the display back in the dim/off states.
278282
// 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) {
280284
if backlightState == 0 && !force {
281285
return
282286
}
@@ -286,7 +290,11 @@ func wakeDisplay(force bool) {
286290
return
287291
}
288292

289-
err := setDisplayBrightness(config.DisplayMaxBrightness)
293+
if reason == "" {
294+
reason = "wake_display"
295+
}
296+
297+
err := setDisplayBrightness(config.DisplayMaxBrightness, reason)
290298
if err != nil {
291299
displayLogger.Warn().Err(err).Msg("failed to wake display")
292300
}
@@ -308,7 +316,7 @@ func startBacklightTickers() {
308316
// Don't start the tickers if the display is switched off.
309317
// Set the display to off if that's the case.
310318
if config.DisplayMaxBrightness == 0 {
311-
_ = setDisplayBrightness(0)
319+
_ = setDisplayBrightness(0, "display_disabled")
312320
return
313321
}
314322

@@ -358,7 +366,6 @@ func initDisplay() {
358366
displayInited = true
359367
displayLogger.Info().Msg("display inited")
360368
startBacklightTickers()
361-
wakeDisplay(true)
362-
requestDisplayUpdate(true)
369+
requestDisplayUpdate(true, "init_display")
363370
}()
364371
}

jsonrpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func rpcSetBacklightSettings(params BacklightSettings) error {
363363
// are reset to the new settings, and will bring the display up to maxBrightness.
364364
// Calling with force set to true, to ignore the current state of the display, and force
365365
// it to reset the tickers.
366-
wakeDisplay(true)
366+
wakeDisplay(true, "backlight_settings_changed")
367367
return nil
368368
}
369369

native.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ func initNative(systemVersion *semver.Version, appVersion *semver.Version) {
1919
OnVideoStateChange: func(state native.VideoState) {
2020
lastVideoState = state
2121
triggerVideoStateUpdate()
22-
requestDisplayUpdate(true)
22+
requestDisplayUpdate(true, "video_state_changed")
2323
},
2424
OnIndevEvent: func(event string) {
2525
nativeLogger.Trace().Str("event", event).Msg("indev event received")
26-
wakeDisplay(false)
26+
wakeDisplay(false, "indev_event")
2727
},
2828
OnVideoFrameReceived: func(frame []byte, duration time.Duration) {
2929
if currentSession != nil {

network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var (
1818

1919
func networkStateChanged(isOnline bool) {
2020
// do not block the main thread
21-
go waitCtrlAndRequestDisplayUpdate(true)
21+
go waitCtrlAndRequestDisplayUpdate(true, "network_state_changed")
2222

2323
if timeSync != nil {
2424
if networkState != nil {

usb.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ func checkUSBState() {
9999
return
100100
}
101101
usbLogger.Info().Str("from", usbState).Str("to", newState).Msg("USB state changed")
102-
usbState = newState
103-
104-
requestDisplayUpdate(true)
102+
requestDisplayUpdate(true, "usb_state_changed")
105103
triggerUSBStateUpdate()
106104
}

webrtc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func newSession(config SessionConfig) (*Session, error) {
367367
var actionSessions = 0
368368

369369
func onActiveSessionsChanged() {
370-
requestDisplayUpdate(true)
370+
requestDisplayUpdate(true, "active_sessions_changed")
371371
}
372372

373373
func onFirstSessionConnected() {

0 commit comments

Comments
 (0)