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.
This commit is contained in:
Cameron Fleming 2025-01-03 11:23:32 +00:00 committed by Cameron Fleming
parent 8ffe66a1bc
commit 3271a1796b
1 changed files with 26 additions and 0 deletions

View File

@ -4,6 +4,9 @@ import (
"fmt" "fmt"
"log" "log"
"time" "time"
"os"
"errors"
"strconv"
) )
var currentScreen = "ui_Boot_Screen" var currentScreen = "ui_Boot_Screen"
@ -83,6 +86,29 @@ func updateStaticContents() {
updateLabelIfChanged("ui_Status_Content_Device_Id_Content_Label", GetDeviceID()) updateLabelIfChanged("ui_Status_Content_Device_Id_Content_Label", GetDeviceID())
} }
// setDisplayBrightness sets /sys/class/backlight/backlight/brightness to alter
// the backlight brightness of the JetKVM hardware's display.
func setDisplayBrightness(brightness int) (error) {
if brightness > 100 || brightness < 0 {
return errors.New("brightness value out of bounds, must be between 0 and 100")
}
// Check the display backlight class is available
if _, err := os.Stat("/sys/class/backlight/backlight/brightness"); errors.Is(err, os.ErrNotExist) {
return errors.New("brightness value cannot be set, possibly not running on JetKVM hardware.")
}
// Set the value
bs := []byte(strconv.Itoa(brightness))
err := os.WriteFile("/sys/class/backlight/backlight/brightness", bs, 0644)
if err != nil {
return err
}
fmt.Print("display: set brightness to %v", brightness)
return nil
}
func init() { func init() {
go func() { go func() {
waitCtrlClientConnected() waitCtrlClientConnected()