summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hid/src/main.cpp26
-rw-r--r--kvmd/apps/kvmd/server.py20
-rw-r--r--kvmd/apps/otg/hid/keyboard.py4
-rw-r--r--kvmd/apps/otg/hid/mouse.py4
-rw-r--r--kvmd/plugins/hid/__init__.py4
-rw-r--r--kvmd/plugins/hid/serial.py32
6 files changed, 45 insertions, 45 deletions
diff --git a/hid/src/main.cpp b/hid/src/main.cpp
index 37957cc7..27520f97 100644
--- a/hid/src/main.cpp
+++ b/hid/src/main.cpp
@@ -45,8 +45,8 @@
#define PROTO_CMD_REPEAT 0x02
#define PROTO_CMD_RESET_HID 0x10
#define PROTO_CMD_KEY_EVENT 0x11
+#define PROTO_CMD_MOUSE_BUTTON_EVENT 0x13 // Legacy sequence
#define PROTO_CMD_MOUSE_MOVE_EVENT 0x12
-#define PROTO_CMD_MOUSE_BUTTON_EVENT 0x13
#define PROTO_CMD_MOUSE_WHEEL_EVENT 0x14
// -----------------------------------------
#define PROTO_CMD_MOUSE_BUTTON_LEFT_SELECT 0b10000000
@@ -75,16 +75,6 @@ INLINE void cmdKeyEvent(const uint8_t *buffer) { // 2 bytes
}
}
-INLINE void cmdMouseMoveEvent(const uint8_t *buffer) { // 4 bytes
- int x = (int)buffer[0] << 8;
- x |= (int)buffer[1];
-
- int y = (int)buffer[2] << 8;
- y |= (int)buffer[3];
-
- SingleAbsoluteMouse.moveTo(x, y);
-}
-
INLINE void cmdMouseButtonEvent(const uint8_t *buffer) { // 1 byte
uint8_t state = buffer[0];
@@ -105,6 +95,16 @@ INLINE void cmdMouseButtonEvent(const uint8_t *buffer) { // 1 byte
# undef PROCESS_BUTTON
}
+INLINE void cmdMouseMoveEvent(const uint8_t *buffer) { // 4 bytes
+ int x = (int)buffer[0] << 8;
+ x |= (int)buffer[1];
+
+ int y = (int)buffer[2] << 8;
+ y |= (int)buffer[3];
+
+ SingleAbsoluteMouse.moveTo(x, y);
+}
+
INLINE void cmdMouseWheelEvent(const uint8_t *buffer) { // 2 bytes
// delta_x is not supported by hid-project now
signed char delta_y = buffer[1];
@@ -114,7 +114,7 @@ INLINE void cmdMouseWheelEvent(const uint8_t *buffer) { // 2 bytes
// -----------------------------------------------------------------------------
-INLINE uint16_t makeCrc16(const uint8_t *buffer, const unsigned length) {
+INLINE uint16_t makeCrc16(const uint8_t *buffer, unsigned length) {
uint16_t crc = 0xFFFF;
for (unsigned byte_count = 0; byte_count < length; ++byte_count) {
@@ -192,8 +192,8 @@ void loop() {
switch (buffer[1]) {
case PROTO_CMD_RESET_HID: HANDLE(cmdResetHid);
case PROTO_CMD_KEY_EVENT: HANDLE(cmdKeyEvent);
- case PROTO_CMD_MOUSE_MOVE_EVENT: HANDLE(cmdMouseMoveEvent);
case PROTO_CMD_MOUSE_BUTTON_EVENT: HANDLE(cmdMouseButtonEvent);
+ case PROTO_CMD_MOUSE_MOVE_EVENT: HANDLE(cmdMouseMoveEvent);
case PROTO_CMD_MOUSE_WHEEL_EVENT: HANDLE(cmdMouseWheelEvent);
case PROTO_CMD_PING: sendCmdResponse(PROTO_RESP_OK); break;
diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py
index 6b68be37..81f2c0b4 100644
--- a/kvmd/apps/kvmd/server.py
+++ b/kvmd/apps/kvmd/server.py
@@ -383,10 +383,10 @@ class Server: # pylint: disable=too-many-instance-attributes
await ws.send_str(json.dumps({"msg_type": "pong"}))
elif event_type == "key":
await self.__handle_ws_key_event(event)
- elif event_type == "mouse_move":
- await self.__handle_ws_mouse_move_event(event)
elif event_type == "mouse_button":
await self.__handle_ws_mouse_button_event(event)
+ elif event_type == "mouse_move":
+ await self.__handle_ws_mouse_move_event(event)
elif event_type == "mouse_wheel":
await self.__handle_ws_mouse_wheel_event(event)
else:
@@ -403,14 +403,6 @@ class Server: # pylint: disable=too-many-instance-attributes
return
await self.__hid.send_key_event(key, state)
- async def __handle_ws_mouse_move_event(self, event: Dict) -> None:
- try:
- to_x = valid_hid_mouse_move(event["to"]["x"])
- to_y = valid_hid_mouse_move(event["to"]["y"])
- except Exception:
- return
- await self.__hid.send_mouse_move_event(to_x, to_y)
-
async def __handle_ws_mouse_button_event(self, event: Dict) -> None:
try:
button = valid_hid_mouse_button(event["button"])
@@ -419,6 +411,14 @@ class Server: # pylint: disable=too-many-instance-attributes
return
await self.__hid.send_mouse_button_event(button, state)
+ async def __handle_ws_mouse_move_event(self, event: Dict) -> None:
+ try:
+ to_x = valid_hid_mouse_move(event["to"]["x"])
+ to_y = valid_hid_mouse_move(event["to"]["y"])
+ except Exception:
+ return
+ await self.__hid.send_mouse_move_event(to_x, to_y)
+
async def __handle_ws_mouse_wheel_event(self, event: Dict) -> None:
try:
delta_x = valid_hid_mouse_wheel(event["delta"]["x"])
diff --git a/kvmd/apps/otg/hid/keyboard.py b/kvmd/apps/otg/hid/keyboard.py
index 274406fd..29b62e07 100644
--- a/kvmd/apps/otg/hid/keyboard.py
+++ b/kvmd/apps/otg/hid/keyboard.py
@@ -25,8 +25,8 @@ from . import Hid
# =====
KEYBOARD_HID = Hid(
- protocol=1,
- subclass=1,
+ protocol=1, # Keyboard protocol
+ subclass=1, # Boot interface subclass
report_length=8,
diff --git a/kvmd/apps/otg/hid/mouse.py b/kvmd/apps/otg/hid/mouse.py
index bed1ffb2..57e75e43 100644
--- a/kvmd/apps/otg/hid/mouse.py
+++ b/kvmd/apps/otg/hid/mouse.py
@@ -25,8 +25,8 @@ from . import Hid
# =====
MOUSE_HID = Hid(
- protocol=0,
- subclass=0,
+ protocol=0, # None protocol
+ subclass=0, # No subclass
report_length=7,
diff --git a/kvmd/plugins/hid/__init__.py b/kvmd/plugins/hid/__init__.py
index 5bc5ca52..4e0ce5ea 100644
--- a/kvmd/plugins/hid/__init__.py
+++ b/kvmd/plugins/hid/__init__.py
@@ -51,10 +51,10 @@ class BaseHid(BasePlugin):
async def send_key_event(self, key: str, state: bool) -> None:
raise NotImplementedError
- async def send_mouse_move_event(self, to_x: int, to_y: int) -> None:
+ async def send_mouse_button_event(self, button: str, state: bool) -> None:
raise NotImplementedError
- async def send_mouse_button_event(self, button: str, state: bool) -> None:
+ async def send_mouse_move_event(self, to_x: int, to_y: int) -> None:
raise NotImplementedError
async def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None:
diff --git a/kvmd/plugins/hid/serial.py b/kvmd/plugins/hid/serial.py
index 4a4346dc..3f9fe23b 100644
--- a/kvmd/plugins/hid/serial.py
+++ b/kvmd/plugins/hid/serial.py
@@ -82,19 +82,6 @@ class _KeyEvent(_BaseEvent):
@dataclasses.dataclass(frozen=True)
-class _MouseMoveEvent(_BaseEvent):
- to_x: int
- to_y: int
-
- def __post_init__(self) -> None:
- assert -32768 <= self.to_x <= 32767
- assert -32768 <= self.to_y <= 32767
-
- def make_command(self) -> bytes:
- return struct.pack(">Bhh", 0x12, self.to_x, self.to_y)
-
-
[email protected](frozen=True)
class _MouseButtonEvent(_BaseEvent):
name: str
state: bool
@@ -114,6 +101,19 @@ class _MouseButtonEvent(_BaseEvent):
@dataclasses.dataclass(frozen=True)
+class _MouseMoveEvent(_BaseEvent):
+ to_x: int
+ to_y: int
+
+ def __post_init__(self) -> None:
+ assert -32768 <= self.to_x <= 32767
+ assert -32768 <= self.to_y <= 32767
+
+ def make_command(self) -> bytes:
+ return struct.pack(">Bhh", 0x12, self.to_x, self.to_y)
+
+
[email protected](frozen=True)
class _MouseWheelEvent(_BaseEvent):
delta_x: int
delta_y: int
@@ -248,12 +248,12 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
async def send_key_event(self, key: str, state: bool) -> None:
await self.__queue_event(_KeyEvent(key, state))
- async def send_mouse_move_event(self, to_x: int, to_y: int) -> None:
- await self.__queue_event(_MouseMoveEvent(to_x, to_y))
-
async def send_mouse_button_event(self, button: str, state: bool) -> None:
await self.__queue_event(_MouseButtonEvent(button, state))
+ async def send_mouse_move_event(self, to_x: int, to_y: int) -> None:
+ await self.__queue_event(_MouseMoveEvent(to_x, to_y))
+
async def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None:
await self.__queue_event(_MouseWheelEvent(delta_x, delta_y))