summaryrefslogtreecommitdiff
path: root/kvmd/plugins/hid/_mcu/proto.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-11-20 05:05:20 +0300
committerDevaev Maxim <[email protected]>2020-11-20 05:05:20 +0300
commit649a57e842928f5e1da100ea62545445ee51eb88 (patch)
tree7c07745db633aa41fcb25773b476ed38ce84522f /kvmd/plugins/hid/_mcu/proto.py
parent7f43440cae47b69d27358ad168f53b647bd23b21 (diff)
next
Diffstat (limited to 'kvmd/plugins/hid/_mcu/proto.py')
-rw-r--r--kvmd/plugins/hid/_mcu/proto.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/kvmd/plugins/hid/_mcu/proto.py b/kvmd/plugins/hid/_mcu/proto.py
index fa76932a..6c8b0735 100644
--- a/kvmd/plugins/hid/_mcu/proto.py
+++ b/kvmd/plugins/hid/_mcu/proto.py
@@ -32,6 +32,44 @@ class BaseEvent:
raise NotImplementedError
+KEYBOARD_NAMES_TO_CODES = {
+ "usb": 0b00000001,
+ "ps2": 0b00000011,
+}
+KEYBOARD_CODES_TO_NAMES = {value: key for (key, value) in KEYBOARD_NAMES_TO_CODES.items()}
+
+
[email protected](frozen=True)
+class SetKeyboardOutputEvent(BaseEvent):
+ keyboard: str
+
+ def __post_init__(self) -> None:
+ assert not self.keyboard or self.keyboard in KEYBOARD_NAMES_TO_CODES
+
+ def make_request(self) -> bytes:
+ code = KEYBOARD_NAMES_TO_CODES.get(self.keyboard, 0)
+ return _make_request(struct.pack(">BBxxx", 0x03, code))
+
+
+MOUSE_NAMES_TO_CODES = {
+ "usb": 0b00001000,
+ "usb_rel": 0b00010000,
+ "ps2": 0b00011000,
+}
+MOUSE_CODES_TO_NAMES = {value: key for (key, value) in MOUSE_NAMES_TO_CODES.items()}
+
+
[email protected](frozen=True)
+class SetMouseOutputEvent(BaseEvent):
+ mouse: str
+
+ def __post_init__(self) -> None:
+ assert not self.mouse or self.mouse in MOUSE_NAMES_TO_CODES
+
+ def make_request(self) -> bytes:
+ return _make_request(struct.pack(">BBxxx", 0x04, MOUSE_NAMES_TO_CODES.get(self.mouse, 0)))
+
+
class ClearEvent(BaseEvent):
def make_request(self) -> bytes:
return _make_request(b"\x10\x00\x00\x00\x00")