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 <mdevaev@gmail.com>
This commit is contained in:
jacobbar
2023-03-14 21:27:44 +07:00
committed by Maxim Devaev
parent 6e24efc81e
commit 6689008840
2 changed files with 19 additions and 20 deletions

View File

@@ -256,11 +256,11 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
self.__set_state_online(True) self.__set_state_online(True)
return True return True
except Exception as err: except _ResError as err:
self.__set_state_online(False) self.__set_state_online(False)
get_logger(0).info(err) get_logger(0).info(err)
time.sleep(2)
error_retval = False error_retval = False
time.sleep(2)
return error_retval return error_retval

View File

@@ -27,8 +27,7 @@ from ....mouse import MouseRange
class Mouse: # pylint: disable=too-many-instance-attributes class Mouse: # pylint: disable=too-many-instance-attributes
def __init__(self) -> None: def __init__(self) -> None:
self.__active = "usb" self.__active = "usb"
self.__button = "" self.__buttons = 0x00
self.__clicked = False
self.__to_x = [0, 0] self.__to_x = [0, 0]
self.__to_y = [0, 0] self.__to_y = [0, 0]
self.__wheel_y = 0 self.__wheel_y = 0
@@ -36,8 +35,11 @@ class Mouse: # pylint: disable=too-many-instance-attributes
self.__delta_y = 0 self.__delta_y = 0
def button(self, button: str, clicked: bool) -> list[int]: def button(self, button: str, clicked: bool) -> list[int]:
self.__button = button code = self.__button_code(button)
self.__clicked = clicked if code and self.__buttons:
self.__buttons &= ~code
if clicked:
self.__buttons |= code
self.__wheel_y = 0 self.__wheel_y = 0
if self.__active != "usb": if self.__active != "usb":
self.__to_x = [0, 0] self.__to_x = [0, 0]
@@ -74,25 +76,22 @@ class Mouse: # pylint: disable=too-many-instance-attributes
self.__active = name self.__active = name
def __absolute(self) -> list[int]: def __absolute(self) -> list[int]:
code = 0x00 cmd = [
if self.__clicked: 0x00, 0x04, 0x07, 0x02,
code = self.__button_code(self.__button) self.__buttons,
cmd = [0x00, 0x04, 0x07, 0x02, code, 0x00, 0x00, 0x00, 0x00, 0x00] self.__to_x[1], self.__to_x[0],
if len(self.__to_x) == 2: self.__to_y[1], self.__to_y[0],
cmd[6] = self.__to_x[0] 0x00]
cmd[5] = self.__to_x[1]
if len(self.__to_y) == 2:
cmd[8] = self.__to_y[0]
cmd[7] = self.__to_y[1]
if self.__wheel_y: if self.__wheel_y:
cmd[9] = self.__wheel_y cmd[9] = self.__wheel_y
return cmd return cmd
def __relative(self) -> list[int]: def __relative(self) -> list[int]:
code = 0x00 cmd = [
if self.__clicked: 0x00, 0x05, 0x05, 0x01,
code = self.__button_code(self.__button) self.__buttons,
cmd = [0x00, 0x05, 0x05, 0x01, code, self.__delta_x, self.__delta_y, 0x00] self.__delta_x, self.__delta_y,
0x00]
return cmd return cmd
def __button_code(self, name: str) -> int: def __button_code(self, name: str) -> int: