mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
hid pinout
This commit is contained in:
parent
a87963e300
commit
125a56e554
@ -5,8 +5,12 @@ kvmd:
|
|||||||
heartbeat: 3.0
|
heartbeat: 3.0
|
||||||
|
|
||||||
hid:
|
hid:
|
||||||
|
pinout:
|
||||||
|
reset: 4
|
||||||
|
|
||||||
device: /dev/ttyAMA0
|
device: /dev/ttyAMA0
|
||||||
speed: 115200
|
speed: 115200
|
||||||
|
reset_delay: 0.1
|
||||||
|
|
||||||
atx:
|
atx:
|
||||||
pinout:
|
pinout:
|
||||||
|
|||||||
@ -5,8 +5,12 @@ kvmd:
|
|||||||
heartbeat: 3.0
|
heartbeat: 3.0
|
||||||
|
|
||||||
hid:
|
hid:
|
||||||
|
pinout:
|
||||||
|
reset: 4
|
||||||
|
|
||||||
device: /dev/ttyAMA0
|
device: /dev/ttyAMA0
|
||||||
speed: 115200
|
speed: 115200
|
||||||
|
reset_delay: 0.1
|
||||||
|
|
||||||
atx:
|
atx:
|
||||||
pinout:
|
pinout:
|
||||||
|
|||||||
@ -23,8 +23,10 @@ def main() -> None:
|
|||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
hid = Hid(
|
hid = Hid(
|
||||||
|
reset=int(config["hid"]["pinout"]["reset"]),
|
||||||
device_path=str(config["hid"]["device"]),
|
device_path=str(config["hid"]["device"]),
|
||||||
speed=int(config["hid"]["speed"]),
|
speed=int(config["hid"]["speed"]),
|
||||||
|
reset_delay=float(config["hid"]["reset_delay"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
atx = Atx(
|
atx = Atx(
|
||||||
|
|||||||
@ -16,6 +16,7 @@ def main() -> None:
|
|||||||
logger.info("Cleaning up ...")
|
logger.info("Cleaning up ...")
|
||||||
with gpio.bcm():
|
with gpio.bcm():
|
||||||
for (name, pin) in [
|
for (name, pin) in [
|
||||||
|
("hid_reset", config["hid"]["pinout"]["reset"]),
|
||||||
("msd_target", config["msd"]["pinout"]["target"]),
|
("msd_target", config["msd"]["pinout"]["target"]),
|
||||||
("msd_reset", config["msd"]["pinout"]["reset"]),
|
("msd_reset", config["msd"]["pinout"]["reset"]),
|
||||||
("atx_power_switch", config["atx"]["pinout"]["power_switch"]),
|
("atx_power_switch", config["atx"]["pinout"]["power_switch"]),
|
||||||
|
|||||||
15
kvmd/hid.py
15
kvmd/hid.py
@ -14,6 +14,8 @@ import yaml
|
|||||||
import serial
|
import serial
|
||||||
import setproctitle
|
import setproctitle
|
||||||
|
|
||||||
|
from . import gpio
|
||||||
|
|
||||||
from .logging import get_logger
|
from .logging import get_logger
|
||||||
|
|
||||||
|
|
||||||
@ -44,17 +46,21 @@ class _MouseWheelEvent(NamedTuple):
|
|||||||
delta_y: int
|
delta_y: int
|
||||||
|
|
||||||
|
|
||||||
class Hid(multiprocessing.Process):
|
class Hid(multiprocessing.Process): # pylint: disable=too-many-instance-attributes
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
reset: int,
|
||||||
device_path: str,
|
device_path: str,
|
||||||
speed: int,
|
speed: int,
|
||||||
|
reset_delay: float,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
super().__init__(daemon=True)
|
super().__init__(daemon=True)
|
||||||
|
|
||||||
|
self.__reset = gpio.set_output(reset)
|
||||||
self.__device_path = device_path
|
self.__device_path = device_path
|
||||||
self.__speed = speed
|
self.__speed = speed
|
||||||
|
self.__reset_delay = reset_delay
|
||||||
|
|
||||||
self.__pressed_keys: Set[str] = set()
|
self.__pressed_keys: Set[str] = set()
|
||||||
self.__pressed_mouse_buttons: Set[str] = set()
|
self.__pressed_mouse_buttons: Set[str] = set()
|
||||||
@ -67,7 +73,11 @@ class Hid(multiprocessing.Process):
|
|||||||
get_logger().info("Starting HID daemon ...")
|
get_logger().info("Starting HID daemon ...")
|
||||||
super().start()
|
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:
|
async def send_key_event(self, key: str, state: bool) -> None:
|
||||||
if not self.__stop_event.is_set():
|
if not self.__stop_event.is_set():
|
||||||
@ -114,6 +124,7 @@ class Hid(multiprocessing.Process):
|
|||||||
else:
|
else:
|
||||||
get_logger().warning("Emergency cleaning up HID events ...")
|
get_logger().warning("Emergency cleaning up HID events ...")
|
||||||
self.__emergency_clear_events()
|
self.__emergency_clear_events()
|
||||||
|
gpio.write(self.__reset, False)
|
||||||
|
|
||||||
def __unsafe_clear_events(self) -> None:
|
def __unsafe_clear_events(self) -> None:
|
||||||
for button in self.__pressed_mouse_buttons:
|
for button in self.__pressed_mouse_buttons:
|
||||||
|
|||||||
@ -141,6 +141,8 @@ class Server: # pylint: disable=too-many-instance-attributes
|
|||||||
|
|
||||||
app.router.add_get("/ws", self.__ws_handler)
|
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_get("/atx", self.__atx_state_handler)
|
||||||
app.router.add_post("/atx/click", self.__atx_click_handler)
|
app.router.add_post("/atx/click", self.__atx_click_handler)
|
||||||
|
|
||||||
@ -228,6 +230,12 @@ class Server: # pylint: disable=too-many-instance-attributes
|
|||||||
return
|
return
|
||||||
await self.__hid.send_mouse_wheel_event(delta_y)
|
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
|
# ===== ATX
|
||||||
|
|
||||||
async def __atx_state_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
|
async def __atx_state_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
|
||||||
|
|||||||
@ -5,8 +5,12 @@ kvmd:
|
|||||||
heartbeat: 3.0
|
heartbeat: 3.0
|
||||||
|
|
||||||
hid:
|
hid:
|
||||||
|
pinout:
|
||||||
|
reset: 4
|
||||||
|
|
||||||
device: /dev/ttyS10
|
device: /dev/ttyS10
|
||||||
speed: 115200
|
speed: 115200
|
||||||
|
reset_delay: 0.1
|
||||||
|
|
||||||
atx:
|
atx:
|
||||||
pinout:
|
pinout:
|
||||||
|
|||||||
@ -89,6 +89,7 @@
|
|||||||
<hr>
|
<hr>
|
||||||
<div class="ctl-dropdown-content-buttons">
|
<div class="ctl-dropdown-content-buttons">
|
||||||
<button disabled id="stream-reset-button">• Reset stream</button>
|
<button disabled id="stream-reset-button">• Reset stream</button>
|
||||||
|
<button disabled id="hid-reset-button">• Reset keyboard & mouse</button>
|
||||||
<button disabled id="msd-reset-button">• Reset mass storage</button>
|
<button disabled id="msd-reset-button">• Reset mass storage</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -42,7 +42,9 @@ function Hid() {
|
|||||||
window.onblur = __releaseAll;
|
window.onblur = __releaseAll;
|
||||||
|
|
||||||
__chars_to_codes = __buildCharsToCodes();
|
__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) {
|
Array.prototype.forEach.call(document.querySelectorAll("[data-shortcut]"), function(el_shortcut) {
|
||||||
tools.setOnClick(el_shortcut, () => __emitShortcut(el_shortcut.getAttribute("data-shortcut").split(" ")));
|
tools.setOnClick(el_shortcut, () => __emitShortcut(el_shortcut.getAttribute("data-shortcut").split(" ")));
|
||||||
@ -55,7 +57,7 @@ function Hid() {
|
|||||||
__ws = ws;
|
__ws = ws;
|
||||||
__keyboard.setSocket(ws);
|
__keyboard.setSocket(ws);
|
||||||
__mouse.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() {
|
var __releaseAll = function() {
|
||||||
@ -127,7 +129,7 @@ function Hid() {
|
|||||||
return chars_to_codes;
|
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
|
var text = $("pak-text").value.replace(/[^\x00-\x7F]/g, ""); // eslint-disable-line no-control-regex
|
||||||
if (text) {
|
if (text) {
|
||||||
var clipboard_codes = [];
|
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__();
|
__init__();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user