From 0b5033f798e6179775a02eb50bba837b7f6fa2e8 Mon Sep 17 00:00:00 2001 From: Cameron Fleming Date: Thu, 13 Feb 2025 13:42:07 +0000 Subject: [PATCH] feat: restore EDID on reboot (#34) This commit adds the config entry "EdidString" and saves the EDID string when it's modified via the RPC. The EDID is restored when the jetkvm_native control socket connects (usually at boot) Signed-off-by: Cameron Fleming --- config.go | 1 + jsonrpc.go | 6 ++++++ native.go | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/config.go b/config.go index 1636434..ceacfe5 100644 --- a/config.go +++ b/config.go @@ -22,6 +22,7 @@ type Config struct { LocalAuthToken string `json:"local_auth_token"` LocalAuthMode string `json:"localAuthMode"` //TODO: fix it with migration WakeOnLanDevices []WakeOnLanDevice `json:"wake_on_lan_devices"` + EdidString string `json:"hdmi_edid_string"` } const configPath = "/userdata/kvm_config.json" diff --git a/jsonrpc.go b/jsonrpc.go index 2ce5f18..4f6519b 100644 --- a/jsonrpc.go +++ b/jsonrpc.go @@ -183,6 +183,12 @@ func rpcSetEDID(edid string) error { if err != nil { return err } + + // Save EDID to config, allowing it to be restored on reboot. + LoadConfig() + config.EdidString = edid + SaveConfig() + return nil } diff --git a/native.go b/native.go index d34ab07..1bd8429 100644 --- a/native.go +++ b/native.go @@ -152,6 +152,9 @@ func handleCtrlClient(conn net.Conn) { ctrlSocketConn = conn + // Restore HDMI EDID if applicable + go restoreHdmiEdid() + readBuf := make([]byte, 4096) for { n, err := conn.Read(readBuf) @@ -304,3 +307,16 @@ func ensureBinaryUpdated(destPath string) error { return nil } + +// Restore the HDMI EDID value from the config. +// Called after successful connection to jetkvm_native. +func restoreHdmiEdid() { + LoadConfig() + if config.EdidString != "" { + logger.Infof("Restoring HDMI EDID to %v", config.EdidString) + _, err := CallCtrlAction("set_edid", map[string]interface{}{"edid": config.EdidString}) + if err != nil { + logger.Errorf("Failed to restore HDMI EDID: %v", err) + } + } +}