diff options
author | Devaev Maxim <[email protected]> | 2019-09-29 05:39:25 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-09-29 05:48:16 +0300 |
commit | 8f43d23089140ded59e49beaeebb01eb3ff7972c (patch) | |
tree | 5082b2de28d77730711b91b2f3eed0e08647ef44 /kvmd | |
parent | 1968aca5c4a22e90af8edce047dc037a203a3827 (diff) |
hid fixes
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/plugins/hid/otg/__init__.py | 8 | ||||
-rw-r--r-- | kvmd/plugins/hid/otg/hid.py | 63 | ||||
-rw-r--r-- | kvmd/plugins/hid/otg/keyboard.py | 1 |
3 files changed, 28 insertions, 44 deletions
diff --git a/kvmd/plugins/hid/otg/__init__.py b/kvmd/plugins/hid/otg/__init__.py index defceba6..d17ad179 100644 --- a/kvmd/plugins/hid/otg/__init__.py +++ b/kvmd/plugins/hid/otg/__init__.py @@ -58,10 +58,10 @@ class Plugin(BaseHid): def get_plugin_options(cls) -> Dict: return { "keyboard": { - "device": Option("", type=valid_abs_path, unpack_as="device_path"), - "timeout": Option(1.0, type=valid_float_f01), - "retries": Option(5, type=valid_int_f1), - "retries_delay": Option(1.0, type=valid_float_f01), + "device": Option("", type=valid_abs_path, unpack_as="device_path"), + "select_timeout": Option(1.0, type=valid_float_f01), + "write_retries": Option(5, type=valid_int_f1), + "write_retries_delay": Option(0.1, type=valid_float_f01), }, "noop": Option(False, type=valid_bool), diff --git a/kvmd/plugins/hid/otg/hid.py b/kvmd/plugins/hid/otg/hid.py index c8376149..a90cd094 100644 --- a/kvmd/plugins/hid/otg/hid.py +++ b/kvmd/plugins/hid/otg/hid.py @@ -44,9 +44,9 @@ class DeviceProcess(multiprocessing.Process): # pylint: disable=too-many-instan self, name: str, device_path: str, - timeout: float, - retries: int, - retries_delay: float, + select_timeout: float, + write_retries: int, + write_retries_delay: float, noop: bool, ) -> None: @@ -55,9 +55,9 @@ class DeviceProcess(multiprocessing.Process): # pylint: disable=too-many-instan self.__name = name self.__device_path = device_path - self.__timeout = timeout - self.__retries = retries - self.__retries_delay = retries_delay + self.__select_timeout = select_timeout + self.__write_retries = write_retries + self.__write_retries_delay = write_retries_delay self.__noop = noop self.__fd = -1 @@ -118,7 +118,7 @@ class DeviceProcess(multiprocessing.Process): # pylint: disable=too-many-instan assert self.__fd >= 0 logger = get_logger() - retries = self.__retries + retries = self.__write_retries while retries: try: written = os.write(self.__fd, report) @@ -128,23 +128,19 @@ class DeviceProcess(multiprocessing.Process): # pylint: disable=too-many-instan else: logger.error("HID-%s write error: written (%s) != report length (%d)", self.__name, written, len(report)) - self._close_device() except Exception as err: - if isinstance(err, OSError) and errno == errno.EAGAIN: - msg = "Can't write report to HID-%s {}: %s: %s" - msg.format(" (maybe unplugged)" if retries == 1 else "") - logger.error(msg, self.__name, type(err).__name__, err) # TODO: debug + if isinstance(err, OSError) and err.errno == errno.EAGAIN: # pylint: disable=no-member + logger.error("HID-%s is busy/unplugged: %s: %s", self.__name, type(err).__name__, err) # TODO debug else: logger.exception("Can't write report to HID-%s", self.__name) - self._close_device() retries -= 1 - self.__online_shared.value = 0 if retries: - logger.error("Retries left (HID-%s, write_report): %d", self.__name, retries) - time.sleep(self.__retries_delay) + logger.error("HID-%s write retries left: %d", self.__name, retries) # TODO debug + time.sleep(self.__write_retries_delay) + self._close_device() return False def _ensure_device(self) -> bool: @@ -158,33 +154,22 @@ class DeviceProcess(multiprocessing.Process): # pylint: disable=too-many-instan self.__fd = os.open(self.__device_path, os.O_WRONLY|os.O_NONBLOCK) except FileNotFoundError: logger.error("Missing HID-%s device: %s", self.__name, self.__device_path) - except Exception: - logger.exception("Can't open HID-%s device: %s", self.__name, self.__device_path) + except Exception as err: + logger.error("Can't open HID-%s device: %s: %s: %s", + self.__name, self.__device_path, type(err).__name__, err) if self.__fd >= 0: - retries = self.__retries - while retries: - try: - if select.select([], [self.__fd], [], self.__timeout)[1]: - self.__online_shared.value = 1 - return True - else: - msg = "HID-%s is unavailable for writing" - if retries == 1: - msg += " (maybe unplugged)" - logger.error(msg, self.__name) # TODO: debug - except Exception as err: - logger.error("Can't select() HID-%s: %s: %s", self.__name, type(err).__name__, err) - - retries -= 1 - self.__online_shared.value = 0 - - if retries: - logger.error("Retries left (HID-%s, ensure_device): %d", self.__name, retries) - time.sleep(self.__retries_delay) - + try: + if select.select([], [self.__fd], [], self.__select_timeout)[1]: + self.__online_shared.value = 1 + return True + else: + logger.error("HID-%s is busy/unplugged", self.__name) # TODO debug + except Exception as err: + logger.error("Can't select() HID-%s: %s: %s", self.__name, type(err).__name__, err) self._close_device() + self.__online_shared.value = 0 return False def _close_device(self) -> None: diff --git a/kvmd/plugins/hid/otg/keyboard.py b/kvmd/plugins/hid/otg/keyboard.py index ed94ac19..94313a2f 100644 --- a/kvmd/plugins/hid/otg/keyboard.py +++ b/kvmd/plugins/hid/otg/keyboard.py @@ -136,7 +136,6 @@ class KeyboardProcess(DeviceProcess): for key in self.__pressed_keys ] - print(self.__pressed_modifiers, self.__pressed_keys) ok = self._write_report(bytes([modifiers, 0] + keys)) if not ok: |