diff --git a/ChangeLog b/ChangeLog index e535e2cb..24754fba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ * Add a way to download logs even on systemd journal based systems * Bump the API version so it is the same as the xBuddy reported one * Support the new multi-level telemetry data structure + * Don't send over serial when temperature calibration is running 0.7.1rc1 (2023-08-10) * Fixed HTTP response status on HEAD request for non-existing files diff --git a/prusa/link/printer_adapter/prusa_link.py b/prusa/link/printer_adapter/prusa_link.py index 544d7325..f2037ea7 100644 --- a/prusa/link/printer_adapter/prusa_link.py +++ b/prusa/link/printer_adapter/prusa_link.py @@ -85,6 +85,8 @@ PAUSE_PRINT_REGEX, PRINTER_BOOT_REGEX, RESUME_PRINT_REGEX, + TM_CAL_END_REGEX, + TM_CAL_START_REGEX, TM_ERROR_LOG_REGEX, ) from .telemetry_passer import TelemetryPasser @@ -225,6 +227,10 @@ def __init__(self, cfg: Config, settings: Settings) -> None: self.serial_parser.add_decoupled_handler( MBL_TRIGGER_REGEX, lambda sender, match: self.printer_polling.invalidate_mbl()) + self.serial_parser.add_decoupled_handler( + TM_CAL_START_REGEX, self.block_serial_queue) + self.serial_parser.add_decoupled_handler( + TM_CAL_END_REGEX, self.unblock_serial_queue) self.print_stat_doubler = PrintStatDoubler(self.serial_parser, self.printer_polling) @@ -796,6 +802,14 @@ def instruction_confirmed(self, _) -> None: """ self.state_manager.instruction_confirmed() + def block_serial_queue(self, *_, **__) -> None: + """Blocks the serial queue""" + self.serial_queue.block_sending() + + def unblock_serial_queue(self, *_, **__) -> None: + """Unblocks the serial queue""" + self.serial_queue.unblock_sending() + def printer_reconnected(self, *_, **__) -> None: """ Connects the printer reconnect (reset) to many other components. diff --git a/prusa/link/printer_adapter/structures/regular_expressions.py b/prusa/link/printer_adapter/structures/regular_expressions.py index 1a529746..b4255e98 100644 --- a/prusa/link/printer_adapter/structures/regular_expressions.py +++ b/prusa/link/printer_adapter/structures/regular_expressions.py @@ -145,3 +145,7 @@ TM_ERROR_CLEARED = re.compile(r"^TM: error cleared$") URLS_FOR_WIZARD = re.compile(r"/(\d{1,3})?/?") + +TM_CAL_START_REGEX = re.compile(r"^TM: calibration start$") +TM_CAL_END_REGEX = re.compile(r"^(TM: calibr\. failed!)|" + r"(Thermal Model settings:)$") diff --git a/prusa/link/serial/serial_queue.py b/prusa/link/serial/serial_queue.py index d19f7eac..a35e6e30 100644 --- a/prusa/link/serial/serial_queue.py +++ b/prusa/link/serial/serial_queue.py @@ -108,6 +108,9 @@ def __init__(self, self.m110_workaround_slot = None self.worked_around_m110 = False + # Allows to temporarily block sending to the serial queue + self._block_sending = False + self.serial_parser.add_handler(CONFIRMATION_REGEX, self._confirmation_handler, priority=float("inf")) @@ -131,6 +134,8 @@ def _keep_sending(self): if self.quit_evt.is_set(): break self.send_event.clear() + if self._block_sending: + continue with self.write_lock: if not self.can_write(): continue @@ -141,6 +146,16 @@ def _keep_sending(self): "reader to fix the problem. In the meantime " "waiting for a nudge to send again.") + def block_sending(self): + """Block sending of instructions until we unblock again""" + self._block_sending = True + + def unblock_sending(self): + """Unblock sending of instructions""" + if self._block_sending: + self._block_sending = False + self._try_writing() + def _try_writing(self): """ Nudge the sender thread to send an instruction @@ -550,6 +565,7 @@ def _printer_reconnected(self, was_printing): prctl_name() with self.write_lock: self._flush_queues() + self._block_sending = False final_instruction = None