diff options
author | Maxim Devaev <[email protected]> | 2022-04-02 10:19:29 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-04-02 10:39:50 +0300 |
commit | bd8984dd0633d953f09a9f09e0d6bf9999e9c4db (patch) | |
tree | a4afcc37b6118671ee04992ab5f3ab3750d8c2ef /kvmd/plugins/ugpio/otgbind.py | |
parent | f1e9f33c137ef7f46563b69e892959435425b498 (diff) |
otgconf gpio plugin
Diffstat (limited to 'kvmd/plugins/ugpio/otgbind.py')
-rw-r--r-- | kvmd/plugins/ugpio/otgbind.py | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/kvmd/plugins/ugpio/otgbind.py b/kvmd/plugins/ugpio/otgbind.py deleted file mode 100644 index 4be96aeb..00000000 --- a/kvmd/plugins/ugpio/otgbind.py +++ /dev/null @@ -1,107 +0,0 @@ -# ========================================================================== # -# # -# KVMD - The main PiKVM daemon. # -# # -# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <https://www.gnu.org/licenses/>. # -# # -# ========================================================================== # - - -import os -import asyncio - -from typing import Callable -from typing import Any - -from ...logging import get_logger - -from ...inotify import InotifyMask -from ...inotify import Inotify - -from ... import aiotools -from ... import usb - -from . import BaseUserGpioDriver - - -# ===== -class Plugin(BaseUserGpioDriver): - def __init__( - self, - instance_name: str, - notifier: aiotools.AioNotifier, - - udc: str, # XXX: Not from options, see /kvmd/apps/kvmd/__init__.py for details - gadget: str, # ditto - ) -> None: - - super().__init__(instance_name, notifier) - - self.__udc = udc - - self.__udc_path = usb.get_gadget_path(gadget, usb.G_UDC) - - @classmethod - def get_pin_validator(cls) -> Callable[[Any], Any]: - return str - - def prepare(self) -> None: - self.__udc = usb.find_udc(self.__udc) - get_logger().info("Using UDC %s", self.__udc) - - async def run(self) -> None: - logger = get_logger(0) - while True: - try: - while True: - await self._notifier.notify() - if os.path.isfile(self.__udc_path): - break - await asyncio.sleep(5) - - with Inotify() as inotify: - inotify.watch(os.path.dirname(self.__udc_path), InotifyMask.ALL_MODIFY_EVENTS) - await self._notifier.notify() - while True: - need_restart = False - need_notify = False - for event in (await inotify.get_series(timeout=1)): - need_notify = True - if event.mask & (InotifyMask.DELETE_SELF | InotifyMask.MOVE_SELF | InotifyMask.UNMOUNT): - logger.warning("Got fatal inotify event: %s; reinitializing OTG-bind ...", event) - need_restart = True - break - if need_restart: - break - if need_notify: - await self._notifier.notify() - except Exception: - logger.exception("Unexpected OTG-bind watcher error") - - async def read(self, pin: str) -> bool: - _ = pin - with open(self.__udc_path) as udc_file: - return bool(udc_file.read().strip()) - - async def write(self, pin: str, state: bool) -> None: - _ = pin - with open(self.__udc_path, "w") as udc_file: - udc_file.write(self.__udc if state else "\n") - - def __str__(self) -> str: - return f"GPIO({self._instance_name})" - - __repr__ = __str__ |