Skip to content

Commit

Permalink
Support set ready / not ready toggle from the LCD menu
Browse files Browse the repository at this point in the history
  • Loading branch information
TojikCZ committed Nov 22, 2023
1 parent e5f61fa commit 8b9e3c2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Support the new multi-level telemetry data structure
* Don't send over serial when temperature calibration is running
* Periodically send a keepalive gcode to keep the printer in PrusaLink mode
* Support the set ready and cancel ready LCD menu toggle

0.7.1rc1 (2023-08-10)
* Fixed HTTP response status on HEAD request for non-existing files
Expand Down
15 changes: 9 additions & 6 deletions prusa/link/printer_adapter/command_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,14 +528,15 @@ class SetReady(Command):

def _run_command(self):
"""Sets the printer into ready, if it's IDLE"""
self.state_manager.expect_change(
StateChange(command_id=self.command_id,
default_source=self.source))
if self.state_manager.get_state() not in {State.IDLE, State.READY}:
raise CommandFailed(
"Cannot get into READY from anywhere other than IDLE")
self.state_manager.expect_change(
StateChange(command_id=self.command_id,
default_source=self.source))
self.state_manager.ready()
self.state_manager.stop_expecting_change()
self.do_instruction("M72 S1")


class CancelReady(Command):
Expand All @@ -544,11 +545,13 @@ class CancelReady(Command):

def _run_command(self):
"""Cancels the READY state"""
self.state_manager.expect_change(
StateChange(command_id=self.command_id,
default_source=self.source))
# Sets the LCD menu to reflect reality even if our state is not READY
self.do_instruction("M72 S0")

if self.model.state_manager.base_state != State.READY:
raise CommandFailed("Cannot cancel READY when not actually ready.")
self.state_manager.expect_change(
StateChange(command_id=self.command_id,
default_source=self.source))
self.state_manager.idle()
self.state_manager.stop_expecting_change()
19 changes: 19 additions & 0 deletions prusa/link/printer_adapter/prusa_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@
from .structures.regular_expressions import (
LCD_UPDATE_REGEX,
MBL_TRIGGER_REGEX,
NOT_READY_REGEX,
PAUSE_PRINT_REGEX,
PRINTER_BOOT_REGEX,
READY_REGEX,
RESUME_PRINT_REGEX,
TM_CAL_END_REGEX,
TM_CAL_START_REGEX,
Expand Down Expand Up @@ -190,6 +192,10 @@ def __init__(self, cfg: Config, settings: Settings) -> None:
PAUSE_PRINT_REGEX, lambda sender, match: self.fw_pause_print())
self.serial_parser.add_decoupled_handler(
RESUME_PRINT_REGEX, lambda sender, match: self.fw_resume_print())
self.serial_parser.add_decoupled_handler(
READY_REGEX, lambda sender, match: self.fw_set_ready())
self.serial_parser.add_decoupled_handler(
NOT_READY_REGEX, lambda sender, match: self.fw_cancel_ready())

# Init components first, so they all exist for signal binding stuff
# TODO: does not need printer, the transfer object should be
Expand Down Expand Up @@ -582,6 +588,18 @@ def fw_resume_print(self) -> None:
command = ResumePrint(source=Source.USER)
self.command_queue.enqueue_command(command)

def fw_set_ready(self) -> None:
"""Set printer ready from the printer LCD menu"""
prctl_name()
command = SetReady(source=Source.USER)
self.command_queue.enqueue_command(command)

def fw_cancel_ready(self) -> None:
"""Cancel printer ready from the printer LCD menu"""
prctl_name()
command = CancelReady(source=Source.USER)
self.command_queue.enqueue_command(command)

# --- Signal handlers ---
def layer_trigger(self, _):
"""Passes the call to trigger to the camera controller"""
Expand Down Expand Up @@ -829,6 +847,7 @@ def printer_reconnected(self, *_, **__) -> None:
self.file_printer.stop_print()
self.file_printer.wait_stopped()
self.serial_queue.printer_reconnected(was_printing)
self.command_queue.enqueue_command(CancelReady(source=Source.SERIAL))

# file printer stop print needs to happen before this
self.state_manager.reset()
Expand Down
2 changes: 2 additions & 0 deletions prusa/link/printer_adapter/structures/regular_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
RESUME_PRINT_REGEX = re.compile("^// action:resume$")
RESUMED_REGEX = re.compile("^// action:resumed$")
CANCEL_REGEX = re.compile("^// action:cancel$")
READY_REGEX = re.compile("^// action:ready$")
NOT_READY_REGEX = re.compile("^// action:not_ready$")
# This girthy regexp tries to capture all error messages requiring printer
# reset using M999 or manual button, with connect, only manual reset shall
# be accepted
Expand Down

0 comments on commit 8b9e3c2

Please sign in to comment.