summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-10-05 20:30:49 +0300
committerDevaev Maxim <[email protected]>2018-10-05 20:30:49 +0300
commit125a56e5546976ae2389c1dd04ccd11f169ff66b (patch)
treeed942697b07f22743f0d9f1c3e8f0a1cf95112b6
parenta87963e300b489831c3809c4321c8747752fc6c6 (diff)
hid pinout
-rw-r--r--configs/kvmd/v1.yaml4
-rw-r--r--configs/kvmd/v2.yaml4
-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
-rw-r--r--testenv/kvmd.yaml4
-rw-r--r--web/index.html1
-rw-r--r--web/js/hid.js18
9 files changed, 52 insertions, 5 deletions
diff --git a/configs/kvmd/v1.yaml b/configs/kvmd/v1.yaml
index 26a2dbba..a01435e2 100644
--- a/configs/kvmd/v1.yaml
+++ b/configs/kvmd/v1.yaml
@@ -5,8 +5,12 @@ kvmd:
heartbeat: 3.0
hid:
+ pinout:
+ reset: 4
+
device: /dev/ttyAMA0
speed: 115200
+ reset_delay: 0.1
atx:
pinout:
diff --git a/configs/kvmd/v2.yaml b/configs/kvmd/v2.yaml
index 99683b11..b7eb4f29 100644
--- a/configs/kvmd/v2.yaml
+++ b/configs/kvmd/v2.yaml
@@ -5,8 +5,12 @@ kvmd:
heartbeat: 3.0
hid:
+ pinout:
+ reset: 4
+
device: /dev/ttyAMA0
speed: 115200
+ reset_delay: 0.1
atx:
pinout:
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:
diff --git a/testenv/kvmd.yaml b/testenv/kvmd.yaml
index 4428cde5..37306593 100644
--- a/testenv/kvmd.yaml
+++ b/testenv/kvmd.yaml
@@ -5,8 +5,12 @@ kvmd:
heartbeat: 3.0
hid:
+ pinout:
+ reset: 4
+
device: /dev/ttyS10
speed: 115200
+ reset_delay: 0.1
atx:
pinout:
diff --git a/web/index.html b/web/index.html
index 52e08f45..35fae241 100644
--- a/web/index.html
+++ b/web/index.html
@@ -89,6 +89,7 @@
<hr>
<div class="ctl-dropdown-content-buttons">
<button disabled id="stream-reset-button">&bull; Reset stream</button>
+ <button disabled id="hid-reset-button">&bull; Reset keyboard &amp; mouse</button>
<button disabled id="msd-reset-button">&bull; Reset mass storage</button>
</div>
</div>
diff --git a/web/js/hid.js b/web/js/hid.js
index 24f5bfbc..26529b32 100644
--- a/web/js/hid.js
+++ b/web/js/hid.js
@@ -42,7 +42,9 @@ function Hid() {
window.onblur = __releaseAll;
__chars_to_codes = __buildCharsToCodes();
- tools.setOnClick($("pak-button"), __pasteAsKeys);
+ tools.setOnClick($("pak-button"), __clickPasteAsKeysButton);
+
+ tools.setOnClick($("hid-reset-button"), __clickResetButton);
Array.prototype.forEach.call(document.querySelectorAll("[data-shortcut]"), function(el_shortcut) {
tools.setOnClick(el_shortcut, () => __emitShortcut(el_shortcut.getAttribute("data-shortcut").split(" ")));
@@ -55,7 +57,7 @@ function Hid() {
__ws = ws;
__keyboard.setSocket(ws);
__mouse.setSocket(ws);
- $("pak-text").disabled = $("pak-button").disabled = !ws;
+ $("pak-text").disabled = $("pak-button").disabled = $("hid-reset-button").disabled = !ws;
};
var __releaseAll = function() {
@@ -127,7 +129,7 @@ function Hid() {
return chars_to_codes;
};
- var __pasteAsKeys = function() {
+ var __clickPasteAsKeysButton = function() {
var text = $("pak-text").value.replace(/[^\x00-\x7F]/g, ""); // eslint-disable-line no-control-regex
if (text) {
var clipboard_codes = [];
@@ -179,5 +181,15 @@ function Hid() {
}
};
+ var __clickResetButton = function() {
+ var http = tools.makeRequest("POST", "/kvmd/hid/reset", function() {
+ if (http.readyState === 4) {
+ if (http.status !== 200) {
+ ui.error("HID reset error:<br>", http.responseText);
+ }
+ }
+ });
+ };
+
__init__();
}