From 3e412588f9db1860742a348e66f1abac3b77e998 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Mon, 7 Sep 2020 13:00:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20EDID=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/calculate/lib/utils/device.py | 1 + pym/calculate/lib/utils/video.py | 68 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 pym/calculate/lib/utils/video.py diff --git a/pym/calculate/lib/utils/device.py b/pym/calculate/lib/utils/device.py index b381759..837bbb0 100644 --- a/pym/calculate/lib/utils/device.py +++ b/pym/calculate/lib/utils/device.py @@ -685,6 +685,7 @@ class Sysfs(DeviceFs): Input = "class/input" Block = "block" Dmi = "class/dmi/id" + Drm = "class/drm" Module = "module" BlockScheduler = "queue/scheduler" diff --git a/pym/calculate/lib/utils/video.py b/pym/calculate/lib/utils/video.py new file mode 100644 index 0000000..406011d --- /dev/null +++ b/pym/calculate/lib/utils/video.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- + +# Copyright 2020 Mir Calculate. http://www.calculate-linux.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import sys +import re +from calculate.lib.cl_lang import setLocalTranslate +import calculate.lib.utils.device as device +from calculate.lib.utils.files import process, getProgPath + +_ = lambda x: x +setLocalTranslate('cl_lib3', sys.modules[__name__]) + +def get_edid_data(): + for fn in device.sysfs.glob(device.sysfs.Path.Drm,"*/edid"): + ediddata = device.sysfs.read(fn) + if ediddata: + return ediddata + return None + +class EdidInfoError(Exception): + pass + +class EdidInfo(object): + reBaseEDID = re.compile("\nBlock \d, Base EDID:.*?\nChecksum:", + re.S) + reDTD = re.compile(r"DTD\s+\d+:\s*(\d+x\d+)\s+(?:[0-9.]+\s+Hz)" + "\s+(\d+:\d+)\s+[^(]+\((\d+) mm x (\d+) mm\)") + + def __init__(self): + self.edid_decode = getProgPath('/usr/bin/edid-decode') + if not self.edid_decode: + raise EdidInfoError(_("{} not found")) + self.resolution = None + self.ratio = None + self.screensize = None + + def set_data(self, data): + p = process(self.edid_decode, "-") + p.write(data) + if p.failed(): + raise EdidInfoError( + _("Failed to parse EDID information: {}").format(p.readerr())) + self.parse(p.read()) + + def parse(self, edid_decode_data): + m = self.reBaseEDID.search(edid_decode_data) + if not m: + raise EdidInfoError(_("Failed to get Base EDID block")) + base_edid = m.group() + m = self.reDTD.search(base_edid) + if not m: + raise EdidInfoError(_("Failed to get DTD record")) + self.resolution, self.ratio, sizex, sizey = m.groups() + self.screensize = "{}x{}".format(sizex, sizey)