diff options
author | Devaev Maxim <[email protected]> | 2020-12-24 15:49:23 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-12-24 15:49:23 +0300 |
commit | edb967c633487c90846a6df69adb3842a91fd95c (patch) | |
tree | bca84753053372e66fff092ad1af24fc8da38a71 /kvmd/plugins | |
parent | 4b6d7605c515adb6b14875f48e7066b1ddcc8948 (diff) |
hid set_connected api
Diffstat (limited to 'kvmd/plugins')
-rw-r--r-- | kvmd/plugins/hid/__init__.py | 3 | ||||
-rw-r--r-- | kvmd/plugins/hid/_mcu/__init__.py | 19 | ||||
-rw-r--r-- | kvmd/plugins/hid/_mcu/proto.py | 9 | ||||
-rw-r--r-- | kvmd/plugins/hid/bt/__init__.py | 1 | ||||
-rw-r--r-- | kvmd/plugins/hid/otg/__init__.py | 1 |
5 files changed, 26 insertions, 7 deletions
diff --git a/kvmd/plugins/hid/__init__.py b/kvmd/plugins/hid/__init__.py index 8baceb28..0ba82e1b 100644 --- a/kvmd/plugins/hid/__init__.py +++ b/kvmd/plugins/hid/__init__.py @@ -73,6 +73,9 @@ class BaseHid(BasePlugin): def set_mouse_output(self, output: str) -> None: _ = output + def set_connected(self, connected: bool) -> None: + _ = connected + def clear_events(self) -> None: raise NotImplementedError diff --git a/kvmd/plugins/hid/_mcu/__init__.py b/kvmd/plugins/hid/_mcu/__init__.py index 424f0913..242de465 100644 --- a/kvmd/plugins/hid/_mcu/__init__.py +++ b/kvmd/plugins/hid/_mcu/__init__.py @@ -58,6 +58,7 @@ from .proto import RESPONSE_LEGACY_OK from .proto import BaseEvent from .proto import SetKeyboardOutputEvent from .proto import SetMouseOutputEvent +from .proto import SetConnectedEvent from .proto import ClearEvent from .proto import KeyEvent from .proto import MouseButtonEvent @@ -166,27 +167,27 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many- state = await self.__state_flags.get() online = bool(state["online"]) pong = (state["status"] >> 16) & 0xFF - outputs = (state["status"] >> 8) & 0xFF - features = state["status"] & 0xFF + outputs1 = (state["status"] >> 8) & 0xFF + outputs2 = state["status"] & 0xFF absolute = True - active_mouse = get_active_mouse(outputs) + active_mouse = get_active_mouse(outputs1) if online and active_mouse in ["usb_rel", "ps2"]: absolute = False keyboard_outputs: Dict = {"available": [], "active": ""} mouse_outputs: Dict = {"available": [], "active": ""} - if outputs & 0b10000000: # Dynamic - if features & 0b00000001: # USB + if outputs1 & 0b10000000: # Dynamic + if outputs2 & 0b00000001: # USB keyboard_outputs["available"].extend(["usb"]) mouse_outputs["available"].extend(["usb", "usb_rel"]) - if features & 0b00000010: # PS/2 + if outputs2 & 0b00000010: # PS/2 keyboard_outputs["available"].extend(["ps2"]) mouse_outputs["available"].extend(["ps2"]) - active_keyboard = get_active_keyboard(outputs) + active_keyboard = get_active_keyboard(outputs1) if active_keyboard in keyboard_outputs["available"]: keyboard_outputs["active"] = active_keyboard @@ -196,6 +197,7 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many- return { "online": online, "busy": bool(state["busy"]), + "connected": (bool(outputs2 & 0b01000000) if outputs2 & 0b10000000 else None), "keyboard": { "online": (online and not (pong & 0b00001000)), "leds": { @@ -256,6 +258,9 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many- def set_mouse_output(self, output: str) -> None: self.__queue_event(SetMouseOutputEvent(output), clear=True) + def set_connected(self, connected: bool) -> None: + self.__queue_event(SetConnectedEvent(connected), clear=True) + def clear_events(self) -> None: self.__queue_event(ClearEvent(), clear=True) diff --git a/kvmd/plugins/hid/_mcu/proto.py b/kvmd/plugins/hid/_mcu/proto.py index 7cfc3fd7..a0f83528 100644 --- a/kvmd/plugins/hid/_mcu/proto.py +++ b/kvmd/plugins/hid/_mcu/proto.py @@ -83,6 +83,15 @@ class SetMouseOutputEvent(BaseEvent): # ===== [email protected](frozen=True) +class SetConnectedEvent(BaseEvent): + connected: bool + + def make_request(self) -> bytes: + return _make_request(struct.pack(">BBxxx", 0x05, int(self.connected))) + + +# ===== class ClearEvent(BaseEvent): def make_request(self) -> bytes: return _make_request(b"\x10\x00\x00\x00\x00") diff --git a/kvmd/plugins/hid/bt/__init__.py b/kvmd/plugins/hid/bt/__init__.py index 72830d4f..83e7bf80 100644 --- a/kvmd/plugins/hid/bt/__init__.py +++ b/kvmd/plugins/hid/bt/__init__.py @@ -134,6 +134,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes return { "online": True, "busy": False, + "connected": None, "keyboard": { "online": state["online"], "leds": { diff --git a/kvmd/plugins/hid/otg/__init__.py b/kvmd/plugins/hid/otg/__init__.py index 3a3fc791..22a6b223 100644 --- a/kvmd/plugins/hid/otg/__init__.py +++ b/kvmd/plugins/hid/otg/__init__.py @@ -93,6 +93,7 @@ class Plugin(BaseHid): return { "online": True, "busy": False, + "connected": None, "keyboard": { "online": keyboard_state["online"], "leds": { |