From 6689008840dca1a0d3587192d1087854b1d64e6e Mon Sep 17 00:00:00 2001 From: jacobbar Date: Tue, 14 Mar 2023 21:27:44 +0700 Subject: 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 --- kvmd/plugins/hid/ch9329/__init__.py | 4 ++-- kvmd/plugins/hid/ch9329/mouse.py | 35 +++++++++++++++++------------------ 2 files changed, 19 insertions(+), 20 deletions(-) (limited to 'kvmd') 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: -- cgit v1.2.3