summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorjacobbar <[email protected]>2023-03-14 21:27:44 +0700
committerMaxim Devaev <[email protected]>2023-07-10 03:02:28 +0300
commit6689008840dca1a0d3587192d1087854b1d64e6e (patch)
treea1479aa677f3b0de2cd70a01858b0d269454df5e /kvmd
parent6e24efc81e9a99605e39ae22a775553b9aad0f5c (diff)
Adds CH9329 Serial to HID Plugin Support (#122)
* Add ch9329 plugin * refactoring ch9329 * refactor ch9329 and cleanup * refactoring * fixing lint errors * clarifying list type * fix mouse multiple buttons * remove unused var --------- Co-authored-by: Maxim Devaev <[email protected]>
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/plugins/hid/ch9329/__init__.py4
-rw-r--r--kvmd/plugins/hid/ch9329/mouse.py35
2 files changed, 19 insertions, 20 deletions
diff --git a/kvmd/plugins/hid/ch9329/__init__.py b/kvmd/plugins/hid/ch9329/__init__.py
index 0b4d4a14..d8fea2de 100644
--- a/kvmd/plugins/hid/ch9329/__init__.py
+++ b/kvmd/plugins/hid/ch9329/__init__.py
@@ -256,11 +256,11 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
self.__set_state_online(True)
return True
- except Exception as err:
+ except _ResError as err:
self.__set_state_online(False)
get_logger(0).info(err)
- time.sleep(2)
error_retval = False
+ time.sleep(2)
return error_retval
diff --git a/kvmd/plugins/hid/ch9329/mouse.py b/kvmd/plugins/hid/ch9329/mouse.py
index 034aff92..da2259c4 100644
--- a/kvmd/plugins/hid/ch9329/mouse.py
+++ b/kvmd/plugins/hid/ch9329/mouse.py
@@ -27,8 +27,7 @@ from ....mouse import MouseRange
class Mouse: # pylint: disable=too-many-instance-attributes
def __init__(self) -> None:
self.__active = "usb"
- self.__button = ""
- self.__clicked = False
+ self.__buttons = 0x00
self.__to_x = [0, 0]
self.__to_y = [0, 0]
self.__wheel_y = 0
@@ -36,8 +35,11 @@ class Mouse: # pylint: disable=too-many-instance-attributes
self.__delta_y = 0
def button(self, button: str, clicked: bool) -> list[int]:
- self.__button = button
- self.__clicked = clicked
+ code = self.__button_code(button)
+ if code and self.__buttons:
+ self.__buttons &= ~code
+ if clicked:
+ self.__buttons |= code
self.__wheel_y = 0
if self.__active != "usb":
self.__to_x = [0, 0]
@@ -74,25 +76,22 @@ class Mouse: # pylint: disable=too-many-instance-attributes
self.__active = name
def __absolute(self) -> list[int]:
- code = 0x00
- if self.__clicked:
- code = self.__button_code(self.__button)
- cmd = [0x00, 0x04, 0x07, 0x02, code, 0x00, 0x00, 0x00, 0x00, 0x00]
- if len(self.__to_x) == 2:
- cmd[6] = self.__to_x[0]
- cmd[5] = self.__to_x[1]
- if len(self.__to_y) == 2:
- cmd[8] = self.__to_y[0]
- cmd[7] = self.__to_y[1]
+ cmd = [
+ 0x00, 0x04, 0x07, 0x02,
+ self.__buttons,
+ self.__to_x[1], self.__to_x[0],
+ self.__to_y[1], self.__to_y[0],
+ 0x00]
if self.__wheel_y:
cmd[9] = self.__wheel_y
return cmd
def __relative(self) -> list[int]:
- code = 0x00
- if self.__clicked:
- code = self.__button_code(self.__button)
- cmd = [0x00, 0x05, 0x05, 0x01, code, self.__delta_x, self.__delta_y, 0x00]
+ cmd = [
+ 0x00, 0x05, 0x05, 0x01,
+ self.__buttons,
+ self.__delta_x, self.__delta_y,
+ 0x00]
return cmd
def __button_code(self, name: str) -> int: