mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
kvmd-edidconf: monitor ID clonning option for V4
This commit is contained in:
parent
5014e82177
commit
2bdd349fbf
@ -61,6 +61,39 @@ def _print_edid(edid: Edid) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def _read_out2_edid() -> (Edid | None):
|
||||
card = os.path.basename(os.readlink("/dev/dri/by-path/platform-gpu-card"))
|
||||
path = f"/sys/devices/platform/gpu/drm/{card}/{card}-HDMI-A-2"
|
||||
with open(os.path.join(path, "status")) as file:
|
||||
if file.read().startswith("d"):
|
||||
return None
|
||||
with open(os.path.join(path, "edid"), "rb") as file:
|
||||
data = file.read()
|
||||
if len(data) == 0:
|
||||
return None
|
||||
return Edid.from_file(os.path.join(path, "edid"))
|
||||
|
||||
|
||||
def _adopt_out2_ids(dest: Edid) -> None:
|
||||
src = _read_out2_edid()
|
||||
if src is None:
|
||||
raise SystemExit("No display found")
|
||||
dest.set_monitor_name(src.get_monitor_name())
|
||||
try:
|
||||
dest.get_monitor_serial()
|
||||
except EdidNoBlockError:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
ser = src.get_monitor_serial()
|
||||
except EdidNoBlockError:
|
||||
ser = "{:08X}".format(src.get_serial())
|
||||
dest.set_monitor_serial(ser)
|
||||
dest.set_mfc_id(src.get_mfc_id())
|
||||
dest.set_product_id(src.get_product_id())
|
||||
dest.set_serial(src.get_serial())
|
||||
|
||||
|
||||
# =====
|
||||
def main(argv: (list[str] | None)=None) -> None: # pylint: disable=too-many-branches,too-many-statements
|
||||
# (parent_parser, argv, _) = init(
|
||||
@ -89,6 +122,8 @@ def main(argv: (list[str] | None)=None) -> None: # pylint: disable=too-many-bra
|
||||
help="Import the specified bin/hex EDID to the [--edid] file as a hex text", metavar="<file>")
|
||||
parser.add_argument("--import-preset", choices=presets,
|
||||
help="Restore default EDID or choose the preset", metavar=f"{{ {' | '.join(presets)} }}",)
|
||||
parser.add_argument("--import-display-ids", action="store_true",
|
||||
help="On PiKVM V4, import and adopt IDs from physical display connected to OUT2")
|
||||
parser.add_argument("--set-audio", type=valid_bool,
|
||||
help="Enable or disable audio", metavar="<yes|no>")
|
||||
parser.add_argument("--set-mfc-id",
|
||||
@ -128,6 +163,10 @@ def main(argv: (list[str] | None)=None) -> None: # pylint: disable=too-many-bra
|
||||
edid = Edid.from_file(options.edid_path)
|
||||
changed = False
|
||||
|
||||
if options.import_display_ids:
|
||||
_adopt_out2_ids(edid)
|
||||
changed = True
|
||||
|
||||
for cmd in dir(Edid):
|
||||
if cmd.startswith("set_"):
|
||||
value = getattr(options, cmd)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user