diff --git a/prusa/link/const.py b/prusa/link/const.py index ba9a8a27..3772b4b7 100644 --- a/prusa/link/const.py +++ b/prusa/link/const.py @@ -100,6 +100,8 @@ PRINT_END_TIMEOUT = 11 KEEPALIVE_INTERVAL = 12 +PP_MOVES_DELAY = 45 + # --- Lcd queue --- LCD_QUEUE_SIZE = 30 diff --git a/prusa/link/printer_adapter/file_printer.py b/prusa/link/printer_adapter/file_printer.py index f8a04bad..8f3ebd95 100644 --- a/prusa/link/printer_adapter/file_printer.py +++ b/prusa/link/printer_adapter/file_printer.py @@ -223,6 +223,7 @@ def _print_end(self): if self.data.power_panic: return + os.remove(self.data.pp_file_path) self.do_instruction("M77") # stop printer's print timer self.data.printing = False @@ -365,6 +366,7 @@ def write_file_stats(self, file_path, message_number, gcode_number): connect_path=self.model.job.selected_file_path, message_number=message_number, gcode_number=gcode_number, + using_rip_port=self.model.serial_adapter.using_port.is_rpi_port, ) with open(self.data.pp_file_path, "w", encoding="UTF-8") as pp_file: pp_file.write(json.dumps(data.dict())) diff --git a/prusa/link/printer_adapter/prusa_link.py b/prusa/link/printer_adapter/prusa_link.py index ae310c80..e24d1857 100644 --- a/prusa/link/printer_adapter/prusa_link.py +++ b/prusa/link/printer_adapter/prusa_link.py @@ -45,6 +45,7 @@ get_print_stats_gcode, is_potato_cpu, make_fingerprint, + power_panic_delay, prctl_name, ) from .auto_telemetry import AutoTelemetry @@ -120,7 +121,6 @@ class TransferCallbackState(Enum): PRINTER_IN_ATTENTION = 3 -# TODO: Can i somehow make subcontrollers to isolate some of the components? class PrusaLink: """ This class is the controller for PrusaLink, more specifically the part @@ -147,6 +147,9 @@ def __init__(self, cfg: Config, settings: Settings) -> None: self.serial_parser = ThreadedSerialParser() + # Wait for power panic recovery to reach a stable state + power_panic_delay(cfg) + self.serial = SerialAdapter( self.serial_parser, self.model, diff --git a/prusa/link/printer_adapter/structures/model_classes.py b/prusa/link/printer_adapter/structures/model_classes.py index c9397e4d..de48fd0d 100644 --- a/prusa/link/printer_adapter/structures/model_classes.py +++ b/prusa/link/printer_adapter/structures/model_classes.py @@ -149,3 +149,4 @@ class PPData(BaseModel): connect_path: str message_number: int # N number on the printer gcode_number: int # From file printer + using_rip_port: bool = False diff --git a/prusa/link/util.py b/prusa/link/util.py index 5e943fff..19c8c2ed 100644 --- a/prusa/link/util.py +++ b/prusa/link/util.py @@ -1,5 +1,6 @@ """Contains functions that might be useful outside of their modules""" import datetime +import json import logging import multiprocessing import os @@ -10,16 +11,25 @@ from hashlib import sha256 from pathlib import Path from threading import Event, current_thread -from time import time +from time import sleep, time from typing import Callable import prctl # type: ignore import pyudev # type: ignore import unidecode -from .const import MMU_SLOTS, SD_STORAGE_NAME, SUPPORTED_PRINTERS +from .const import ( + MMU_SLOTS, + PP_MOVES_DELAY, + SD_STORAGE_NAME, + SUPPORTED_PRINTERS, +) from .multi_instance.const import VALID_SN_REGEX -from .printer_adapter.structures.model_classes import IndividualSlot, Slot +from .printer_adapter.structures.model_classes import ( + IndividualSlot, + PPData, + Slot, +) log = logging.getLogger(__name__) @@ -315,3 +325,20 @@ def _parse_little_endian_uint32(match): str_data = match.group("data").replace(" ", "") data = bytes.fromhex(str_data) return struct.unpack("