Skip to content

Commit bba113f

Browse files
committed
chore: use UIObjSetState instead of Add+Remove
1 parent 068619f commit bba113f

File tree

9 files changed

+38
-26
lines changed

9 files changed

+38
-26
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
@@ -25,7 +25,7 @@ GO_ARGS := GOOS=linux GOARCH=arm GOARM=7 ARCHFLAGS="-arch arm"
2525
ifneq ($(wildcard $(BUILDKIT_PATH)),)
2626
GO_ARGS := $(GO_ARGS) \
2727
CGO_CFLAGS="-I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/include -I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/include" \
28-
CGO_LDFLAGS="-L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/lib -L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/lib -lrockit -lrockchip_mpp -lrga -lpthread -lm" \
28+
CGO_LDFLAGS="-L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/lib -L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/lib -lrockit -lrockchip_mpp -lrga -lpthread -lm -lgpiod" \
2929
CC="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-gcc" \
3030
LD="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-ld" \
3131
CGO_ENABLED=1
@@ -40,7 +40,10 @@ TEST_DIRS := $(shell find . -name "*_test.go" -type f -exec dirname {} \; | sort
4040

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

4548
build_dev: build_native
4649
@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
@@ -42,17 +42,21 @@ func updateDisplay() {
4242

4343
if usbState == "configured" {
4444
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")
4647
} else {
4748
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")
4951
}
5052
if lastVideoState.Ready {
5153
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")
5356
} else {
5457
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")
5660
}
5761
nativeInstance.UpdateLabelIfChanged("cloud_status_label", fmt.Sprintf("%d active", actionSessions))
5862

@@ -124,7 +128,7 @@ var (
124128
waitDisplayUpdate = sync.Mutex{}
125129
)
126130

127-
func requestDisplayUpdate(shouldWakeDisplay bool) {
131+
func requestDisplayUpdate(shouldWakeDisplay bool, reason string) {
128132
displayUpdateLock.Lock()
129133
defer displayUpdateLock.Unlock()
130134

@@ -134,20 +138,20 @@ func requestDisplayUpdate(shouldWakeDisplay bool) {
134138
}
135139
go func() {
136140
if shouldWakeDisplay {
137-
wakeDisplay(false)
141+
wakeDisplay(false, reason)
138142
}
139143
displayLogger.Debug().Msg("display updating")
140144
//TODO: only run once regardless how many pending updates
141145
updateDisplay()
142146
}()
143147
}
144148

145-
func waitCtrlAndRequestDisplayUpdate(shouldWakeDisplay bool) {
149+
func waitCtrlAndRequestDisplayUpdate(shouldWakeDisplay bool, reason string) {
146150
waitDisplayUpdate.Lock()
147151
defer waitDisplayUpdate.Unlock()
148152

149153
// nativeInstance.WaitCtrlClientConnected()
150-
requestDisplayUpdate(shouldWakeDisplay)
154+
requestDisplayUpdate(shouldWakeDisplay, reason)
151155
}
152156

153157
func updateStaticContents() {
@@ -182,7 +186,7 @@ func updateStaticContents() {
182186

183187
// setDisplayBrightness sets /sys/class/backlight/backlight/brightness to alter
184188
// the backlight brightness of the JetKVM hardware's display.
185-
func setDisplayBrightness(brightness int) error {
189+
func setDisplayBrightness(brightness int, reason string) error {
186190
// NOTE: The actual maximum value for this is 255, but out-of-the-box, the value is set to 64.
187191
// The maximum set here is set to 100 to reduce the risk of drawing too much power (and besides, 255 is very bright!).
188192
if brightness > 100 || brightness < 0 {
@@ -201,14 +205,14 @@ func setDisplayBrightness(brightness int) error {
201205
return err
202206
}
203207

204-
displayLogger.Info().Int("brightness", brightness).Msg("set brightness")
208+
displayLogger.Info().Int("brightness", brightness).Str("reason", reason).Msg("set brightness")
205209
return nil
206210
}
207211

208212
// tick_displayDim() is called when when dim ticker expires, it simply reduces the brightness
209213
// of the display by half of the max brightness.
210214
func tick_displayDim() {
211-
err := setDisplayBrightness(config.DisplayMaxBrightness / 2)
215+
err := setDisplayBrightness(config.DisplayMaxBrightness/2, "tick_display_dim")
212216
if err != nil {
213217
displayLogger.Warn().Err(err).Msg("failed to dim display")
214218
}
@@ -221,7 +225,7 @@ func tick_displayDim() {
221225
// tick_displayOff() is called when the off ticker expires, it turns off the display
222226
// by setting the brightness to zero.
223227
func tick_displayOff() {
224-
err := setDisplayBrightness(0)
228+
err := setDisplayBrightness(0, "tick_display_off")
225229
if err != nil {
226230
displayLogger.Warn().Err(err).Msg("failed to turn off display")
227231
}
@@ -234,7 +238,7 @@ func tick_displayOff() {
234238
// wakeDisplay sets the display brightness back to config.DisplayMaxBrightness and stores the time the display
235239
// last woke, ready for displayTimeoutTick to put the display back in the dim/off states.
236240
// 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) {
238242
if backlightState == 0 && !force {
239243
return
240244
}
@@ -244,7 +248,11 @@ func wakeDisplay(force bool) {
244248
return
245249
}
246250

247-
err := setDisplayBrightness(config.DisplayMaxBrightness)
251+
if reason == "" {
252+
reason = "wake_display"
253+
}
254+
255+
err := setDisplayBrightness(config.DisplayMaxBrightness, reason)
248256
if err != nil {
249257
displayLogger.Warn().Err(err).Msg("failed to wake display")
250258
}
@@ -266,7 +274,7 @@ func startBacklightTickers() {
266274
// Don't start the tickers if the display is switched off.
267275
// Set the display to off if that's the case.
268276
if config.DisplayMaxBrightness == 0 {
269-
_ = setDisplayBrightness(0)
277+
_ = setDisplayBrightness(0, "display_disabled")
270278
return
271279
}
272280

@@ -316,7 +324,6 @@ func initDisplay() {
316324
displayInited = true
317325
displayLogger.Info().Msg("display inited")
318326
startBacklightTickers()
319-
wakeDisplay(true)
320-
requestDisplayUpdate(true)
327+
requestDisplayUpdate(true, "init_display")
321328
}()
322329
}

jsonrpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func rpcSetBacklightSettings(params BacklightSettings) error {
348348
// are reset to the new settings, and will bring the display up to maxBrightness.
349349
// Calling with force set to true, to ignore the current state of the display, and force
350350
// it to reset the tickers.
351-
wakeDisplay(true)
351+
wakeDisplay(true, "backlight_settings_changed")
352352
return nil
353353
}
354354

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() {
2020
// do not block the main thread
21-
go waitCtrlAndRequestDisplayUpdate(true)
21+
go waitCtrlAndRequestDisplayUpdate(true, "network_state_changed")
2222

2323
// always restart mDNS when the network state changes
2424
if mDNS != nil {

usb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ func checkUSBState() {
8181
usbState = newState
8282

8383
usbLogger.Info().Str("from", usbState).Str("to", newState).Msg("USB state changed")
84-
requestDisplayUpdate(true)
84+
requestDisplayUpdate(true, "usb_state_changed")
8585
triggerUSBStateUpdate()
8686
}

webrtc.go

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

208208
func onActiveSessionsChanged() {
209-
requestDisplayUpdate(true)
209+
requestDisplayUpdate(true, "active_sessions_changed")
210210
}
211211

212212
func onFirstSessionConnected() {

0 commit comments

Comments
 (0)