mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-02-01 02:21:53 +08:00
@@ -41,8 +41,6 @@ from ....validators.basic import valid_float_f01
|
||||
from ....validators.os import valid_abs_path
|
||||
from ....validators.hw import valid_tty_speed
|
||||
|
||||
from ....lanuages import Lanuages
|
||||
|
||||
from .. import BaseHid
|
||||
|
||||
from .chip import ChipResponseError
|
||||
@@ -84,8 +82,6 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
||||
self.__keyboard = Keyboard()
|
||||
self.__mouse = Mouse()
|
||||
|
||||
self.gettext=Lanuages().gettext
|
||||
|
||||
@classmethod
|
||||
def get_plugin_options(cls) -> dict:
|
||||
return {
|
||||
@@ -96,7 +92,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
||||
}
|
||||
|
||||
def sysprep(self) -> None:
|
||||
get_logger(0).info(self.gettext("Starting HID daemon ..."))
|
||||
get_logger(0).info("Starting HID daemon ...")
|
||||
self.start()
|
||||
|
||||
async def get_state(self) -> dict:
|
||||
@@ -138,7 +134,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
||||
@aiotools.atomic_fg
|
||||
async def cleanup(self) -> None:
|
||||
if self.is_alive():
|
||||
get_logger(0).info(self.gettext("Stopping HID daemon ..."))
|
||||
get_logger(0).info("Stopping HID daemon ...")
|
||||
self.__stop_event.set()
|
||||
if self.is_alive() or self.exitcode is not None:
|
||||
self.join()
|
||||
@@ -175,7 +171,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
||||
|
||||
_ = keyboard_output
|
||||
if mouse_output is not None:
|
||||
get_logger(0).info(self.gettext("HID : mouse output = %s"), mouse_output)
|
||||
get_logger(0).info("HID : mouse output = %s", mouse_output)
|
||||
absolute = (mouse_output == "usb")
|
||||
self.__mouse.set_absolute(absolute)
|
||||
self._set_jiggler_absolute(absolute)
|
||||
@@ -205,7 +201,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
||||
try:
|
||||
self.__hid_loop()
|
||||
except Exception:
|
||||
logger.exception(self.gettext("Unexpected error in the run loop"))
|
||||
logger.exception("Unexpected error in the run loop")
|
||||
time.sleep(1)
|
||||
|
||||
def __hid_loop(self) -> None:
|
||||
@@ -228,7 +224,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
||||
self.__process_cmd(conn, cmd)
|
||||
except Exception:
|
||||
self.clear_events()
|
||||
get_logger(0).exception(self.gettext("Unexpected error in the HID loop"))
|
||||
get_logger(0).exception("Unexpected error in the HID loop")
|
||||
time.sleep(2)
|
||||
|
||||
def __process_cmd(self, conn: ChipConnection, cmd: bytes) -> bool: # pylint: disable=too-many-branches
|
||||
|
||||
@@ -25,8 +25,6 @@ import contextlib
|
||||
|
||||
from typing import Generator
|
||||
|
||||
from ....lanuages import Lanuages
|
||||
|
||||
|
||||
# =====
|
||||
class ChipResponseError(Exception):
|
||||
@@ -37,7 +35,6 @@ class ChipResponseError(Exception):
|
||||
class ChipConnection:
|
||||
def __init__(self, tty: serial.Serial) -> None:
|
||||
self.__tty = tty
|
||||
self.gettext=Lanuages().gettext
|
||||
|
||||
def xfer(self, cmd: bytes) -> int:
|
||||
self.__send(cmd)
|
||||
@@ -55,16 +52,16 @@ class ChipConnection:
|
||||
def __recv(self) -> int:
|
||||
data = self.__tty.read(5)
|
||||
if len(data) < 5:
|
||||
raise ChipResponseError(self.gettext("Too short response, HID might be disconnected"))
|
||||
raise ChipResponseError("Too short response, HID might be disconnected")
|
||||
|
||||
if data and data[4]:
|
||||
data += self.__tty.read(data[4] + 1)
|
||||
|
||||
if self.__make_checksum(data[:-1]) != data[-1]:
|
||||
raise ChipResponseError(self.gettext("Invalid response checksum"))
|
||||
raise ChipResponseError("Invalid response checksum")
|
||||
|
||||
if data[4] == 1 and data[5] != 0:
|
||||
raise ChipResponseError(self.gettext(f"Response error code = {data[5]!r}"))
|
||||
raise ChipResponseError(f"Response error code = {data[5]!r}")
|
||||
|
||||
# led_byte (info) response
|
||||
return (data[7] if data[3] == 0x81 else -1)
|
||||
|
||||
Reference in New Issue
Block a user