summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/__init__.py2
-rw-r--r--kvmd/extras/cleanup/__init__.py1
-rw-r--r--kvmd/hid.py15
-rw-r--r--kvmd/server.py8
4 files changed, 24 insertions, 2 deletions
diff --git a/kvmd/__init__.py b/kvmd/__init__.py
index da430634..77c49ad0 100644
--- a/kvmd/__init__.py
+++ b/kvmd/__init__.py
@@ -23,8 +23,10 @@ def main() -> None:
loop = asyncio.get_event_loop()
hid = Hid(
+ reset=int(config["hid"]["pinout"]["reset"]),
device_path=str(config["hid"]["device"]),
speed=int(config["hid"]["speed"]),
+ reset_delay=float(config["hid"]["reset_delay"]),
)
atx = Atx(
diff --git a/kvmd/extras/cleanup/__init__.py b/kvmd/extras/cleanup/__init__.py
index 75b35562..60446c2b 100644
--- a/kvmd/extras/cleanup/__init__.py
+++ b/kvmd/extras/cleanup/__init__.py
@@ -16,6 +16,7 @@ def main() -> None:
logger.info("Cleaning up ...")
with gpio.bcm():
for (name, pin) in [
+ ("hid_reset", config["hid"]["pinout"]["reset"]),
("msd_target", config["msd"]["pinout"]["target"]),
("msd_reset", config["msd"]["pinout"]["reset"]),
("atx_power_switch", config["atx"]["pinout"]["power_switch"]),
diff --git a/kvmd/hid.py b/kvmd/hid.py
index e5d4de78..776e6f0e 100644
--- a/kvmd/hid.py
+++ b/kvmd/hid.py
@@ -14,6 +14,8 @@ import yaml
import serial
import setproctitle
+from . import gpio
+
from .logging import get_logger
@@ -44,17 +46,21 @@ class _MouseWheelEvent(NamedTuple):
delta_y: int
-class Hid(multiprocessing.Process):
+class Hid(multiprocessing.Process): # pylint: disable=too-many-instance-attributes
def __init__(
self,
+ reset: int,
device_path: str,
speed: int,
+ reset_delay: float,
) -> None:
super().__init__(daemon=True)
+ self.__reset = gpio.set_output(reset)
self.__device_path = device_path
self.__speed = speed
+ self.__reset_delay = reset_delay
self.__pressed_keys: Set[str] = set()
self.__pressed_mouse_buttons: Set[str] = set()
@@ -67,7 +73,11 @@ class Hid(multiprocessing.Process):
get_logger().info("Starting HID daemon ...")
super().start()
- # TODO: add reset or power switching
+ async def reset(self) -> None:
+ async with self.__lock:
+ gpio.write(self.__reset, True)
+ await asyncio.sleep(self.__reset_delay)
+ gpio.write(self.__reset, False)
async def send_key_event(self, key: str, state: bool) -> None:
if not self.__stop_event.is_set():
@@ -114,6 +124,7 @@ class Hid(multiprocessing.Process):
else:
get_logger().warning("Emergency cleaning up HID events ...")
self.__emergency_clear_events()
+ gpio.write(self.__reset, False)
def __unsafe_clear_events(self) -> None:
for button in self.__pressed_mouse_buttons:
diff --git a/kvmd/server.py b/kvmd/server.py
index efdb48c0..47dddf78 100644
--- a/kvmd/server.py
+++ b/kvmd/server.py
@@ -141,6 +141,8 @@ class Server: # pylint: disable=too-many-instance-attributes
app.router.add_get("/ws", self.__ws_handler)
+ app.router.add_post("/hid/reset", self.__hid_reset_handler)
+
app.router.add_get("/atx", self.__atx_state_handler)
app.router.add_post("/atx/click", self.__atx_click_handler)
@@ -228,6 +230,12 @@ class Server: # pylint: disable=too-many-instance-attributes
return
await self.__hid.send_mouse_wheel_event(delta_y)
+ # ===== HID
+
+ async def __hid_reset_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
+ await self.__hid.reset()
+ return _json()
+
# ===== ATX
async def __atx_state_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response: