mirror of https://github.com/jetkvm/kvm.git
chore: use UIObjSetState instead of Add+Remove
This commit is contained in:
parent
068619fee6
commit
bba113f58b
|
@ -2,5 +2,6 @@
|
|||
"tailwindCSS.classFunctions": [
|
||||
"cva",
|
||||
"cx"
|
||||
]
|
||||
],
|
||||
"cmake.sourceDirectory": "/Users/aveline/Projects/JetKVM/ymjk/internal/native/cgo"
|
||||
}
|
7
Makefile
7
Makefile
|
@ -25,7 +25,7 @@ GO_ARGS := GOOS=linux GOARCH=arm GOARM=7 ARCHFLAGS="-arch arm"
|
|||
ifneq ($(wildcard $(BUILDKIT_PATH)),)
|
||||
GO_ARGS := $(GO_ARGS) \
|
||||
CGO_CFLAGS="-I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/include -I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/include" \
|
||||
CGO_LDFLAGS="-L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/lib -L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/lib -lrockit -lrockchip_mpp -lrga -lpthread -lm" \
|
||||
CGO_LDFLAGS="-L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/lib -L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/lib -lrockit -lrockchip_mpp -lrga -lpthread -lm -lgpiod" \
|
||||
CC="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-gcc" \
|
||||
LD="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-ld" \
|
||||
CGO_ENABLED=1
|
||||
|
@ -40,7 +40,10 @@ TEST_DIRS := $(shell find . -name "*_test.go" -type f -exec dirname {} \; | sort
|
|||
|
||||
build_native:
|
||||
@echo "Building native..."
|
||||
cd internal/native/cgo && ./ui_index.gen.sh && ./build.sh
|
||||
cd internal/native/cgo && ./ui_index.gen.sh && \
|
||||
CC="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-gcc" \
|
||||
LD="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-ld" \
|
||||
./build.sh
|
||||
|
||||
build_dev: build_native
|
||||
@echo "Building..."
|
||||
|
|
1
cloud.go
1
cloud.go
|
@ -170,6 +170,7 @@ func setCloudConnectionState(state CloudConnectionState) {
|
|||
|
||||
go waitCtrlAndRequestDisplayUpdate(
|
||||
previousState != state,
|
||||
"set_cloud_connection_state",
|
||||
)
|
||||
}
|
||||
|
||||
|
|
41
display.go
41
display.go
|
@ -42,17 +42,21 @@ func updateDisplay() {
|
|||
|
||||
if usbState == "configured" {
|
||||
nativeInstance.UpdateLabelIfChanged("usb_status_label", "Connected")
|
||||
_, _ = nativeInstance.UIObjSetState("usb_status", "LV_STATE_DEFAULT")
|
||||
_, _ = nativeInstance.UIObjAddState("usb_status", "LV_STATE_DEFAULT")
|
||||
_, _ = nativeInstance.UIObjRemoveState("usb_status", "LV_STATE_DISABLED")
|
||||
} else {
|
||||
nativeInstance.UpdateLabelIfChanged("usb_status_label", "Disconnected")
|
||||
_, _ = nativeInstance.UIObjSetState("usb_status", "LV_STATE_DISABLED")
|
||||
_, _ = nativeInstance.UIObjAddState("usb_status", "LV_STATE_DISABLED")
|
||||
_, _ = nativeInstance.UIObjRemoveState("usb_status", "LV_STATE_DEFAULT")
|
||||
}
|
||||
if lastVideoState.Ready {
|
||||
nativeInstance.UpdateLabelIfChanged("hdmi_status_label", "Connected")
|
||||
_, _ = nativeInstance.UIObjSetState("hdmi_status", "LV_STATE_DEFAULT")
|
||||
_, _ = nativeInstance.UIObjAddState("hdmi_status", "LV_STATE_DEFAULT")
|
||||
_, _ = nativeInstance.UIObjRemoveState("hdmi_status", "LV_STATE_DISABLED")
|
||||
} else {
|
||||
nativeInstance.UpdateLabelIfChanged("hdmi_status_label", "Disconnected")
|
||||
_, _ = nativeInstance.UIObjSetState("hdmi_status", "LV_STATE_DISABLED")
|
||||
_, _ = nativeInstance.UIObjAddState("hdmi_status", "LV_STATE_DISABLED")
|
||||
_, _ = nativeInstance.UIObjRemoveState("hdmi_status", "LV_STATE_DEFAULT")
|
||||
}
|
||||
nativeInstance.UpdateLabelIfChanged("cloud_status_label", fmt.Sprintf("%d active", actionSessions))
|
||||
|
||||
|
@ -124,7 +128,7 @@ var (
|
|||
waitDisplayUpdate = sync.Mutex{}
|
||||
)
|
||||
|
||||
func requestDisplayUpdate(shouldWakeDisplay bool) {
|
||||
func requestDisplayUpdate(shouldWakeDisplay bool, reason string) {
|
||||
displayUpdateLock.Lock()
|
||||
defer displayUpdateLock.Unlock()
|
||||
|
||||
|
@ -134,7 +138,7 @@ func requestDisplayUpdate(shouldWakeDisplay bool) {
|
|||
}
|
||||
go func() {
|
||||
if shouldWakeDisplay {
|
||||
wakeDisplay(false)
|
||||
wakeDisplay(false, reason)
|
||||
}
|
||||
displayLogger.Debug().Msg("display updating")
|
||||
//TODO: only run once regardless how many pending updates
|
||||
|
@ -142,12 +146,12 @@ func requestDisplayUpdate(shouldWakeDisplay bool) {
|
|||
}()
|
||||
}
|
||||
|
||||
func waitCtrlAndRequestDisplayUpdate(shouldWakeDisplay bool) {
|
||||
func waitCtrlAndRequestDisplayUpdate(shouldWakeDisplay bool, reason string) {
|
||||
waitDisplayUpdate.Lock()
|
||||
defer waitDisplayUpdate.Unlock()
|
||||
|
||||
// nativeInstance.WaitCtrlClientConnected()
|
||||
requestDisplayUpdate(shouldWakeDisplay)
|
||||
requestDisplayUpdate(shouldWakeDisplay, reason)
|
||||
}
|
||||
|
||||
func updateStaticContents() {
|
||||
|
@ -182,7 +186,7 @@ func updateStaticContents() {
|
|||
|
||||
// setDisplayBrightness sets /sys/class/backlight/backlight/brightness to alter
|
||||
// the backlight brightness of the JetKVM hardware's display.
|
||||
func setDisplayBrightness(brightness int) error {
|
||||
func setDisplayBrightness(brightness int, reason string) error {
|
||||
// NOTE: The actual maximum value for this is 255, but out-of-the-box, the value is set to 64.
|
||||
// The maximum set here is set to 100 to reduce the risk of drawing too much power (and besides, 255 is very bright!).
|
||||
if brightness > 100 || brightness < 0 {
|
||||
|
@ -201,14 +205,14 @@ func setDisplayBrightness(brightness int) error {
|
|||
return err
|
||||
}
|
||||
|
||||
displayLogger.Info().Int("brightness", brightness).Msg("set brightness")
|
||||
displayLogger.Info().Int("brightness", brightness).Str("reason", reason).Msg("set brightness")
|
||||
return nil
|
||||
}
|
||||
|
||||
// tick_displayDim() is called when when dim ticker expires, it simply reduces the brightness
|
||||
// of the display by half of the max brightness.
|
||||
func tick_displayDim() {
|
||||
err := setDisplayBrightness(config.DisplayMaxBrightness / 2)
|
||||
err := setDisplayBrightness(config.DisplayMaxBrightness/2, "tick_display_dim")
|
||||
if err != nil {
|
||||
displayLogger.Warn().Err(err).Msg("failed to dim display")
|
||||
}
|
||||
|
@ -221,7 +225,7 @@ func tick_displayDim() {
|
|||
// tick_displayOff() is called when the off ticker expires, it turns off the display
|
||||
// by setting the brightness to zero.
|
||||
func tick_displayOff() {
|
||||
err := setDisplayBrightness(0)
|
||||
err := setDisplayBrightness(0, "tick_display_off")
|
||||
if err != nil {
|
||||
displayLogger.Warn().Err(err).Msg("failed to turn off display")
|
||||
}
|
||||
|
@ -234,7 +238,7 @@ func tick_displayOff() {
|
|||
// wakeDisplay sets the display brightness back to config.DisplayMaxBrightness and stores the time the display
|
||||
// last woke, ready for displayTimeoutTick to put the display back in the dim/off states.
|
||||
// Set force to true to skip the backlight state check, this should be done if altering the tickers.
|
||||
func wakeDisplay(force bool) {
|
||||
func wakeDisplay(force bool, reason string) {
|
||||
if backlightState == 0 && !force {
|
||||
return
|
||||
}
|
||||
|
@ -244,7 +248,11 @@ func wakeDisplay(force bool) {
|
|||
return
|
||||
}
|
||||
|
||||
err := setDisplayBrightness(config.DisplayMaxBrightness)
|
||||
if reason == "" {
|
||||
reason = "wake_display"
|
||||
}
|
||||
|
||||
err := setDisplayBrightness(config.DisplayMaxBrightness, reason)
|
||||
if err != nil {
|
||||
displayLogger.Warn().Err(err).Msg("failed to wake display")
|
||||
}
|
||||
|
@ -266,7 +274,7 @@ func startBacklightTickers() {
|
|||
// Don't start the tickers if the display is switched off.
|
||||
// Set the display to off if that's the case.
|
||||
if config.DisplayMaxBrightness == 0 {
|
||||
_ = setDisplayBrightness(0)
|
||||
_ = setDisplayBrightness(0, "display_disabled")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -316,7 +324,6 @@ func initDisplay() {
|
|||
displayInited = true
|
||||
displayLogger.Info().Msg("display inited")
|
||||
startBacklightTickers()
|
||||
wakeDisplay(true)
|
||||
requestDisplayUpdate(true)
|
||||
requestDisplayUpdate(true, "init_display")
|
||||
}()
|
||||
}
|
||||
|
|
|
@ -348,7 +348,7 @@ func rpcSetBacklightSettings(params BacklightSettings) error {
|
|||
// are reset to the new settings, and will bring the display up to maxBrightness.
|
||||
// Calling with force set to true, to ignore the current state of the display, and force
|
||||
// it to reset the tickers.
|
||||
wakeDisplay(true)
|
||||
wakeDisplay(true, "backlight_settings_changed")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -19,11 +19,11 @@ func initNative(systemVersion *semver.Version, appVersion *semver.Version) {
|
|||
OnVideoStateChange: func(state native.VideoState) {
|
||||
lastVideoState = state
|
||||
triggerVideoStateUpdate()
|
||||
requestDisplayUpdate(true)
|
||||
requestDisplayUpdate(true, "video_state_changed")
|
||||
},
|
||||
OnIndevEvent: func(event string) {
|
||||
nativeLogger.Trace().Str("event", event).Msg("indev event received")
|
||||
wakeDisplay(false)
|
||||
wakeDisplay(false, "indev_event")
|
||||
},
|
||||
OnVideoFrameReceived: func(frame []byte, duration time.Duration) {
|
||||
if currentSession != nil {
|
||||
|
|
|
@ -18,7 +18,7 @@ var (
|
|||
|
||||
func networkStateChanged() {
|
||||
// do not block the main thread
|
||||
go waitCtrlAndRequestDisplayUpdate(true)
|
||||
go waitCtrlAndRequestDisplayUpdate(true, "network_state_changed")
|
||||
|
||||
// always restart mDNS when the network state changes
|
||||
if mDNS != nil {
|
||||
|
|
2
usb.go
2
usb.go
|
@ -81,6 +81,6 @@ func checkUSBState() {
|
|||
usbState = newState
|
||||
|
||||
usbLogger.Info().Str("from", usbState).Str("to", newState).Msg("USB state changed")
|
||||
requestDisplayUpdate(true)
|
||||
requestDisplayUpdate(true, "usb_state_changed")
|
||||
triggerUSBStateUpdate()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue