Skip to content

Commit 3271a17

Browse files
committed
feat(display.go): impl setDisplayBrightness()
Implements setDisplayBrightness(brightness int) which allows setting the backlight brightness on JetKVM's hardware. Needs to be implemented into the RPC, config and frontend.
1 parent 8ffe66a commit 3271a17

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

display.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"fmt"
55
"log"
66
"time"
7+
"os"
8+
"errors"
9+
"strconv"
710
)
811

912
var currentScreen = "ui_Boot_Screen"
@@ -83,6 +86,29 @@ func updateStaticContents() {
8386
updateLabelIfChanged("ui_Status_Content_Device_Id_Content_Label", GetDeviceID())
8487
}
8588

89+
// setDisplayBrightness sets /sys/class/backlight/backlight/brightness to alter
90+
// the backlight brightness of the JetKVM hardware's display.
91+
func setDisplayBrightness(brightness int) (error) {
92+
if brightness > 100 || brightness < 0 {
93+
return errors.New("brightness value out of bounds, must be between 0 and 100")
94+
}
95+
96+
// Check the display backlight class is available
97+
if _, err := os.Stat("/sys/class/backlight/backlight/brightness"); errors.Is(err, os.ErrNotExist) {
98+
return errors.New("brightness value cannot be set, possibly not running on JetKVM hardware.")
99+
}
100+
101+
// Set the value
102+
bs := []byte(strconv.Itoa(brightness))
103+
err := os.WriteFile("/sys/class/backlight/backlight/brightness", bs, 0644)
104+
if err != nil {
105+
return err
106+
}
107+
108+
fmt.Print("display: set brightness to %v", brightness)
109+
return nil
110+
}
111+
86112
func init() {
87113
go func() {
88114
waitCtrlClientConnected()

0 commit comments

Comments
 (0)