mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
allow short edids, import full edid on with kvmd-edidconf
This commit is contained in:
@@ -61,23 +61,17 @@ def _print_edid(edid: Edid) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def _read_out2_edid() -> (Edid | None):
|
||||
def _find_out2_edid_path() -> str:
|
||||
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"), allow_short=True)
|
||||
raise SystemExit("No display found")
|
||||
return 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")
|
||||
src = Edid.from_file(_find_out2_edid_path())
|
||||
dest.set_monitor_name(src.get_monitor_name())
|
||||
try:
|
||||
dest.get_monitor_serial()
|
||||
@@ -123,7 +117,9 @@ def main(argv: (list[str] | None)=None) -> None: # pylint: disable=too-many-bra
|
||||
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")
|
||||
help="On PiKVM V4, import and adopt IDs from a physical display connected to the OUT2 port")
|
||||
parser.add_argument("--import-display", action="store_true",
|
||||
help="On PiKVM V4, import full EDID from a physical display connected to the OUT2 port")
|
||||
parser.add_argument("--set-audio", type=valid_bool,
|
||||
help="Enable or disable audio", metavar="<yes|no>")
|
||||
parser.add_argument("--set-mfc-id",
|
||||
@@ -155,6 +151,9 @@ def main(argv: (list[str] | None)=None) -> None: # pylint: disable=too-many-bra
|
||||
imp = f"_{imp}"
|
||||
options.imp = os.path.join(options.presets_path, f"{imp}.hex")
|
||||
|
||||
if options.import_display:
|
||||
options.imp = _find_out2_edid_path()
|
||||
|
||||
orig_edid_path = options.edid_path
|
||||
if options.imp:
|
||||
options.export_hex = options.edid_path
|
||||
|
||||
@@ -59,31 +59,37 @@ class EdidInfo:
|
||||
except ParsedEdidNoBlockError:
|
||||
pass
|
||||
|
||||
audio: bool = False
|
||||
try:
|
||||
audio = parsed.get_audio()
|
||||
except ParsedEdidNoBlockError:
|
||||
pass
|
||||
|
||||
return EdidInfo(
|
||||
mfc_id=parsed.get_mfc_id(),
|
||||
product_id=parsed.get_product_id(),
|
||||
serial=parsed.get_serial(),
|
||||
monitor_name=monitor_name,
|
||||
monitor_serial=monitor_serial,
|
||||
audio=parsed.get_audio(),
|
||||
audio=audio,
|
||||
)
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Edid:
|
||||
name: str
|
||||
data: bytes
|
||||
crc: int = dataclasses.field(default=0)
|
||||
valid: bool = dataclasses.field(default=False)
|
||||
info: (EdidInfo | None) = dataclasses.field(default=None)
|
||||
|
||||
__HEADER = b"\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00"
|
||||
name: str
|
||||
data: bytes
|
||||
crc: int = dataclasses.field(default=0)
|
||||
valid: bool = dataclasses.field(default=False)
|
||||
info: (EdidInfo | None) = dataclasses.field(default=None)
|
||||
_packed: bytes = dataclasses.field(default=b"")
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
assert len(self.name) > 0
|
||||
assert len(self.data) == 256
|
||||
object.__setattr__(self, "crc", bitbang.make_crc16(self.data))
|
||||
object.__setattr__(self, "valid", self.data.startswith(self.__HEADER))
|
||||
assert len(self.data) in [128, 256]
|
||||
object.__setattr__(self, "_packed", (self.data + (b"\x00" * 128))[:256])
|
||||
object.__setattr__(self, "crc", bitbang.make_crc16(self._packed)) # Calculate CRC for filled data
|
||||
object.__setattr__(self, "valid", ParsedEdid.is_header_valid(self.data))
|
||||
try:
|
||||
object.__setattr__(self, "info", EdidInfo.from_data(self.data))
|
||||
except Exception:
|
||||
@@ -93,7 +99,7 @@ class Edid:
|
||||
return "".join(f"{item:0{2}X}" for item in self.data)
|
||||
|
||||
def pack(self) -> bytes:
|
||||
return self.data
|
||||
return self._packed
|
||||
|
||||
@classmethod
|
||||
def from_data(cls, name: str, data: (str | bytes | None)) -> "Edid":
|
||||
@@ -101,14 +107,14 @@ class Edid:
|
||||
return Edid(name, b"\x00" * 256)
|
||||
|
||||
if isinstance(data, bytes):
|
||||
if data.startswith(cls.__HEADER):
|
||||
if ParsedEdid.is_header_valid(cls.data):
|
||||
return Edid(name, data) # Бинарный едид
|
||||
data_hex = data.decode() # Текстовый едид, прочитанный как бинарный из файла
|
||||
else: # isinstance(data, str)
|
||||
data_hex = str(data) # Текстовый едид
|
||||
|
||||
data_hex = re.sub(r"\s", "", data_hex)
|
||||
assert len(data_hex) == 512
|
||||
assert len(data_hex) in [256, 512]
|
||||
data = bytes([
|
||||
int(data_hex[index:index + 2], 16)
|
||||
for index in range(0, len(data_hex), 2)
|
||||
|
||||
Reference in New Issue
Block a user