From 57b7774ffb4332be9a9637147893ae8f2376abde Mon Sep 17 00:00:00 2001 From: Ali Hatami Tajik Date: Sat, 11 Mar 2023 14:28:33 +0330 Subject: [PATCH] Add get_egalax_edid_path --- src/scripts/python/util/common.py | 6 +++++- src/scripts/python/util/egalax.py | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/scripts/python/util/common.py b/src/scripts/python/util/common.py index 6d40ee7..6e2bd91 100644 --- a/src/scripts/python/util/common.py +++ b/src/scripts/python/util/common.py @@ -17,10 +17,14 @@ def max_match(a: str, b: str) -> str: b (str): second string Returns: - str: intersection of two strings + str: intersection of two strings OR None if one or both strings are + empty or None """ i = 0 + if not a or not b: + return None + if len(b) < len(a): a, b = b, a diff --git a/src/scripts/python/util/egalax.py b/src/scripts/python/util/egalax.py index 074735a..9a9f31d 100644 --- a/src/scripts/python/util/egalax.py +++ b/src/scripts/python/util/egalax.py @@ -5,6 +5,8 @@ touchpannel's drm output and its overal status. """ from pathlib import Path +from x import get_edid_dev_path +from common import max_match VENDOR_ID = "0EEF" DEVICE_ID = "C000" @@ -38,3 +40,28 @@ def is_egalax_connected() -> bool: """ devpath = get_egalax_path() return bool(devpath) + + +def get_egalax_edid_path() -> Path: + """return EDID path of touchpannel rdm + + This function will find intersection of the edid pathes and eGalax hid + device and if this intersection and returns the maximum match. + + Runtime: 160ms on average -> Not efficient + + Returns: + Path: edid path of eGalax OR None if not found or device is'nt connected + """ + egalax_dev = get_egalax_path() + if not egalax_dev: + return None + max_dir = "/sys/devices" + max_path = None + for path in get_edid_dev_path(): + base_dir = max_match(str(path), str(egalax_dev)) + if len(max_dir) < len(base_dir): + max_dir = base_dir + max_path = path + # TODO add sanity check (both edid and VENDOR:DEVICE are in that base) + return max_path