diff options
author | Maxim Devaev <[email protected]> | 2022-03-31 04:25:37 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-03-31 04:40:24 +0300 |
commit | c4ca7011bfdb0f24621ef4474eeec4d8d878bf84 (patch) | |
tree | 3cae868fa54e8b9cd5b44bbd23c696673f61b4ac /kvmd/plugins | |
parent | 94dca7d7c677b62b1e8645afcf721118c7a60833 (diff) |
removed UsbDeviceController() class
Diffstat (limited to 'kvmd/plugins')
-rw-r--r-- | kvmd/plugins/hid/otg/__init__.py | 22 | ||||
-rw-r--r-- | kvmd/plugins/hid/otg/device.py | 17 |
2 files changed, 22 insertions, 17 deletions
diff --git a/kvmd/plugins/hid/otg/__init__.py b/kvmd/plugins/hid/otg/__init__.py index e4fca123..cc4e0969 100644 --- a/kvmd/plugins/hid/otg/__init__.py +++ b/kvmd/plugins/hid/otg/__init__.py @@ -27,6 +27,8 @@ from typing import AsyncGenerator from typing import Optional from typing import Any +from ....logging import get_logger + from .... import aiomulti from .... import usb @@ -54,16 +56,13 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes udc: str, # XXX: Not from options, see /kvmd/apps/kvmd/__init__.py for details ) -> None: - self.__notifier = aiomulti.AioProcessNotifier() + self.__udc = udc - self.__udc = usb.UsbDeviceController(udc) + self.__notifier = aiomulti.AioProcessNotifier() win98_fix = mouse.pop("absolute_win98_fix") - common = { - "udc": self.__udc, - "noop": noop, - "notifier": self.__notifier, - } + common = {"notifier": self.__notifier, "noop": noop} + self.__keyboard_proc = KeyboardProcess(**common, **keyboard) self.__mouse_current = self.__mouse_proc = MouseProcess(**common, **mouse) @@ -115,11 +114,12 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes } def sysprep(self) -> None: - self.__udc.find() - self.__keyboard_proc.start() - self.__mouse_proc.start() + udc = usb.find_udc(self.__udc) + get_logger().info("Using UDC %s", udc) + self.__keyboard_proc.start(udc) + self.__mouse_proc.start(udc) if self.__mouse_alt_proc: - self.__mouse_alt_proc.start() + self.__mouse_alt_proc.start(udc) async def get_state(self) -> Dict: keyboard_state = await self.__keyboard_proc.get_state() diff --git a/kvmd/plugins/hid/otg/device.py b/kvmd/plugins/hid/otg/device.py index 1c92a4eb..6a02d5e8 100644 --- a/kvmd/plugins/hid/otg/device.py +++ b/kvmd/plugins/hid/otg/device.py @@ -32,10 +32,10 @@ from typing import Generator from ....logging import get_logger +from .... import env from .... import tools from .... import aiomulti from .... import aioproc -from .... import usb from .events import BaseEvent @@ -49,8 +49,6 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in initial_state: Dict, notifier: aiomulti.AioProcessNotifier, - udc: usb.UsbDeviceController, - device_path: str, select_timeout: float, queue_timeout: float, @@ -63,19 +61,22 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in self.__name = name self.__read_size = read_size - self.__udc = udc - self.__device_path = device_path self.__select_timeout = select_timeout self.__queue_timeout = queue_timeout self.__write_retries = write_retries self.__noop = noop + self.__udc_state_path = "" self.__fd = -1 self.__events_queue: "multiprocessing.Queue[BaseEvent]" = multiprocessing.Queue() self.__state_flags = aiomulti.AioSharedFlags({"online": True, **initial_state}, notifier) self.__stop_event = multiprocessing.Event() + def start(self, udc: str) -> None: # type: ignore # pylint: disable=arguments-differ + self.__udc_state_path = os.path.join(f"{env.SYSFS_PREFIX}/sys/class/udc", udc, "state") + super().start() + def run(self) -> None: # pylint: disable=too-many-branches logger = aioproc.settle(f"HID-{self.__name}", f"hid-{self.__name}") report = b"" @@ -95,7 +96,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in # - https://github.com/raspberrypi/linux/pull/3151 # Так что нам нужно проверять состояние контроллера, чтобы не спамить # в устройство и отслеживать его состояние. - if not self.__udc.can_operate(): + if not self.__is_udc_configured(): self.__state_flags.update(online=False) else: # Посылка свежих репортов важнее старого @@ -160,6 +161,10 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in # ===== + def __is_udc_configured(self) -> bool: + with open(self.__udc_state_path) as udc_state_file: + return (udc_state_file.read().strip().lower() == "configured") + def __write_report(self, report: bytes) -> bool: assert report |