diff options
author | Devaev Maxim <[email protected]> | 2021-02-05 18:57:17 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2021-02-05 18:57:17 +0300 |
commit | 707512a586087ce545aa62c770c8561dec93e78a (patch) | |
tree | 65276c41490822d4907833b71fc168c855f46dd9 /kvmd/plugins | |
parent | 1a3fea916b33d083bb42bc32563fc578e7438108 (diff) |
reset mcu hid before the loop
Diffstat (limited to 'kvmd/plugins')
-rw-r--r-- | kvmd/plugins/hid/_mcu/__init__.py | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/kvmd/plugins/hid/_mcu/__init__.py b/kvmd/plugins/hid/_mcu/__init__.py index e805664d..bd9c9a77 100644 --- a/kvmd/plugins/hid/_mcu/__init__.py +++ b/kvmd/plugins/hid/_mcu/__init__.py @@ -293,14 +293,10 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many- time.sleep(1) def __hid_loop(self) -> None: - logger = get_logger(0) while not self.__stop_event.is_set(): try: - if not self.__phy.has_device(): - logger.error("Missing HID device") - time.sleep(1) + if not self.__hid_loop_wait_device(): continue - with self.__phy.connected() as conn: while not (self.__stop_event.is_set() and self.__events_queue.qsize() == 0): if self.__reset_required_event.is_set(): @@ -320,9 +316,25 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many- self.clear_events() except Exception: self.clear_events() - logger.exception("Unexpected error in the HID loop") + get_logger(0).exception("Unexpected error in the HID loop") time.sleep(1) + def __hid_loop_wait_device(self) -> bool: + logger = get_logger(0) + logger.info("Initial HID reset and wait ...") + self.__gpio.reset() + # На самом деле SPI и Serial-девайсы не пропадают, просто резет и ожидание + # логичнее всего делать именно здесь. Ну и на будущее, да + for _ in range(10): + if self.__phy.has_device(): + logger.info("HID found") + return True + if self.__stop_event.is_set(): + break + time.sleep(1) + logger.error("Missing HID") + return False + def __process_request(self, conn: BasePhyConnection, request: bytes) -> bool: # pylint: disable=too-many-branches logger = get_logger() error_messages: List[str] = [] |