From b973587b0610d83e7e1ee203c82556f6aba4ac06 Mon Sep 17 00:00:00 2001 From: duk3luk3 Date: Fri, 22 Dec 2023 20:23:04 +1100 Subject: [PATCH 1/3] Add line operations --- printrun/printcore.py | 79 +++++++++++++++++++++++++++---------------- printrun/pronsole.py | 26 ++++++++++++-- 2 files changed, 73 insertions(+), 32 deletions(-) diff --git a/printrun/printcore.py b/printrun/printcore.py index 44b190701..fc5901dc0 100644 --- a/printrun/printcore.py +++ b/printrun/printcore.py @@ -155,7 +155,7 @@ def __init__(self, port = None, baud = None, dtr=None): self.startcb = None # impl () self.endcb = None # impl () self.onlinecb = None # impl () - self.loud = False # emit sent and received lines to terminal + self.loud = True # emit sent and received lines to terminal self.tcp_streaming_mode = False self.greetings = ['start', 'Grbl '] self.wait = 0 # default wait period for send(), send_now() @@ -536,7 +536,7 @@ def _sender(self): def _checksum(self, command): return reduce(lambda x, y: x ^ y, map(ord, command)) - def startprint(self, gcode, startindex = 0): + def startprint(self, gcode, startindex = 0, really_start=True): """Start a print. The `mainqueue` is populated and then commands are gradually sent to @@ -575,10 +575,14 @@ def startprint(self, gcode, startindex = 0): self._send("M110 N-1") resuming = (startindex != 0) - self.print_thread = threading.Thread(target = self._print, - name = 'print thread', - kwargs = {"resuming": resuming}) - self.print_thread.start() + + if really_start: + self.print_thread = threading.Thread(target = self._print, + name = 'print thread', + kwargs = {"resuming": resuming}) + self.print_thread.start() + else: + self.pause() return True def cancelprint(self): @@ -600,6 +604,21 @@ def runSmallScript(self, filename): except: pass + def current_line(self, context=5): + if self.mainqueue and self.mainqueue.has_index(self.queueindex): + lines = [] + index = self.queueindex - context + while index < self.queueindex + context: + (layer, line) = self.mainqueue.idxs(index) + gline = self.mainqueue.all_layers[layer][line] + + prefix = "> " if index == self.queueindex else " " + suffix = " <" if index == self.queueindex else "" + + lines.append((index, layer, prefix + gline.raw + suffix)) + index = index + 1 + return lines + def pause(self): """Pauses an ongoing print. @@ -616,12 +635,13 @@ def pause(self): self.paused = True self.printing = False - # ';@pause' in the gcode file calls pause from the print thread - if not threading.current_thread() is self.print_thread: - try: - self.print_thread.join() - except: - self.logError(traceback.format_exc()) + if self.print_thread: + # ';@pause' in the gcode file calls pause from the print thread + if not threading.current_thread() is self.print_thread: + try: + self.print_thread.join() + except: + self.logError(traceback.format_exc()) self.print_thread = None @@ -634,7 +654,7 @@ def pause(self): self.pauseRelative = self.analyzer.relative self.pauseRelativeE = self.analyzer.relative_e - def resume(self): + def resume(self, restore=True): """Resumes a paused print. `printcore` will first attempt to set the position and conditions it @@ -649,22 +669,23 @@ def resume(self): """ if not self.paused: return False # restores the status - self.send_now("G90") # go to absolute coordinates - - xyFeed = '' if self.xy_feedrate is None else ' F' + str(self.xy_feedrate) - zFeed = '' if self.z_feedrate is None else ' F' + str(self.z_feedrate) - - self.send_now("G1 X%s Y%s%s" % (self.pauseX, self.pauseY, xyFeed)) - self.send_now("G1 Z" + str(self.pauseZ) + zFeed) - self.send_now("G92 E" + str(self.pauseE)) - - # go back to relative if needed - if self.pauseRelative: - self.send_now("G91") - if self.pauseRelativeE: - self.send_now('M83') - # reset old feed rate - self.send_now("G1 F" + str(self.pauseF)) + if restore: + self.send_now("G90") # go to absolute coordinates + + xyFeed = '' if self.xy_feedrate is None else ' F' + str(self.xy_feedrate) + zFeed = '' if self.z_feedrate is None else ' F' + str(self.z_feedrate) + + self.send_now("G1 X%s Y%s%s" % (self.pauseX, self.pauseY, xyFeed)) + self.send_now("G1 Z" + str(self.pauseZ) + zFeed) + self.send_now("G92 E" + str(self.pauseE)) + + # go back to relative if needed + if self.pauseRelative: + self.send_now("G91") + if self.pauseRelativeE: + self.send_now('M83') + # reset old feed rate + self.send_now("G1 F" + str(self.pauseF)) self.paused = False self.printing = True diff --git a/printrun/pronsole.py b/printrun/pronsole.py index 7650b30cf..9bd9b70d3 100644 --- a/printrun/pronsole.py +++ b/printrun/pronsole.py @@ -1,4 +1,4 @@ -# This file is part of the Printrun suite. +# file is part of the Printrun suite. # # Printrun is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -932,6 +932,16 @@ def statuschecker(self): # File loading handling # -------------------------------------------------------------- + def do_line(self, l=''): + lines = self.p.current_line() + for line in lines: + self.log("%04d: %s" % (line[0], line[2])) + + def do_skip(self, l): + skip = int(l) + self.p.queueindex = self.p.queueindex + skip + + def do_load(self, filename): self._do_load(filename) @@ -1094,7 +1104,16 @@ def do_print(self, l): self.log(_("Printing %s") % self.filename) self.log(_("You can monitor the print with the monitor command.")) self.sdprinting = False - self.p.startprint(self.fgcode) + really = not (l and l == 'pause') + self.p.startprint(self.fgcode, really_start=really) + if not really: + self.paused = True + + def do_next(self, l): + if self.paused: + self.p.printing = True + self.p._sendnext() + self.p.printing = False def do_pause(self, l): if self.sdprinting: @@ -1121,7 +1140,8 @@ def do_resume(self, l): self.p.send_now("M24") return else: - self.p.resume() + do_restore = not l or l != 'direct' + self.p.resume(do_restore) def help_resume(self): self.log(_("Resumes a paused print.")) From ed190f588327409bec41d82bbe9391fbfae29ab3 Mon Sep 17 00:00:00 2001 From: duk3luk3 Date: Fri, 22 Dec 2023 20:30:35 +1100 Subject: [PATCH 2/3] Add setting for stepping mode --- printrun/printcore.py | 2 +- printrun/pronsole.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/printrun/printcore.py b/printrun/printcore.py index fc5901dc0..19e72097d 100644 --- a/printrun/printcore.py +++ b/printrun/printcore.py @@ -155,7 +155,7 @@ def __init__(self, port = None, baud = None, dtr=None): self.startcb = None # impl () self.endcb = None # impl () self.onlinecb = None # impl () - self.loud = True # emit sent and received lines to terminal + self.loud = False # emit sent and received lines to terminal self.tcp_streaming_mode = False self.greetings = ['start', 'Grbl '] self.wait = 0 # default wait period for send(), send_now() diff --git a/printrun/pronsole.py b/printrun/pronsole.py index 9bd9b70d3..8e15a54ef 100644 --- a/printrun/pronsole.py +++ b/printrun/pronsole.py @@ -38,7 +38,7 @@ get_home_pos, parse_build_dimensions, parse_temperature_report, \ setup_logging install_locale('pronterface') -from .settings import Settings, BuildDimensionsSetting +from .settings import Settings, BuildDimensionsSetting, BooleanSetting from .power import powerset_print_start, powerset_print_stop from printrun import gcoder from .rpc import ProntRPC @@ -180,6 +180,7 @@ def __init__(self): self.processing_args = False self.settings = Settings(self) self.settings._add(BuildDimensionsSetting("build_dimensions", "200x200x100+0+0+0+0+0+0", _("Build Dimensions:"), _("Dimensions of Build Platform\n & optional offset of origin\n & optional switch position\n\nExamples:\n XXXxYYY\n XXX,YYY,ZZZ\n XXXxYYYxZZZ+OffX+OffY+OffZ\nXXXxYYYxZZZ+OffX+OffY+OffZ+HomeX+HomeY+HomeZ"), "Printer"), self.update_build_dimensions) + self.settings._add(BooleanSetting("stepping_mode", False, "GCode Stepping Mode: When true, will go into paused mode when starting and disable restore on resume")) self.settings._port_list = self.scanserial self.update_build_dimensions(None, self.settings.build_dimensions) self.update_tcp_streaming_mode(None, self.settings.tcp_streaming_mode) @@ -1104,7 +1105,7 @@ def do_print(self, l): self.log(_("Printing %s") % self.filename) self.log(_("You can monitor the print with the monitor command.")) self.sdprinting = False - really = not (l and l == 'pause') + really = not (l and l == 'pause') and not self.settings.stepping_mode self.p.startprint(self.fgcode, really_start=really) if not really: self.paused = True @@ -1140,7 +1141,7 @@ def do_resume(self, l): self.p.send_now("M24") return else: - do_restore = not l or l != 'direct' + do_restore = not l or l != 'direct' or self.settings.stepping_mode self.p.resume(do_restore) def help_resume(self): From a646e84bda5774d93840b56718b3c979d8bb7c90 Mon Sep 17 00:00:00 2001 From: duk3luk3 Date: Thu, 28 Dec 2023 13:57:59 +1100 Subject: [PATCH 3/3] fixes --- printrun/pronsole.py | 13 +++++++------ pronsole.py | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/printrun/pronsole.py b/printrun/pronsole.py index 8e15a54ef..c88db4c36 100644 --- a/printrun/pronsole.py +++ b/printrun/pronsole.py @@ -590,8 +590,8 @@ def set(self, var, str): def do_set(self, argl): args = argl.split(None, 1) if len(args) < 1: - for k in [kk for kk in dir(self.settings) if not kk.startswith("_")]: - self.log("%s = %s" % (k, str(getattr(self.settings, k)))) + for k in self.settings._all_settings(): + self.log("%s = %s" % (k.name, k.value)) return if len(args) < 2: # Try getting the default value of the setting to check whether it @@ -935,8 +935,9 @@ def statuschecker(self): def do_line(self, l=''): lines = self.p.current_line() - for line in lines: - self.log("%04d: %s" % (line[0], line[2])) + if lines: + for line in lines: + self.log("%04d: %s" % (line[0], line[2])) def do_skip(self, l): skip = int(l) @@ -1141,7 +1142,7 @@ def do_resume(self, l): self.p.send_now("M24") return else: - do_restore = not l or l != 'direct' or self.settings.stepping_mode + do_restore = (not l or l != 'direct') and not self.settings.stepping_mode self.p.resume(do_restore) def help_resume(self): @@ -1530,7 +1531,7 @@ def do_monitor(self, l): elif self.sdprinting: preface = _("SD print progress: ") progress = self.percentdone - prev_msg = preface + "%.1f%%" % progress + prev_msg = preface + "%3.1f%% - %d" % (progress, self.p.queueindex) if self.silent is False: sys.stdout.write("\r" + prev_msg.ljust(prev_msg_len)) sys.stdout.flush() diff --git a/pronsole.py b/pronsole.py index f1d95a3ab..d2d6fbb63 100755 --- a/pronsole.py +++ b/pronsole.py @@ -58,3 +58,4 @@ logging.error(_("Caught an exception, exiting:") + "\n" + traceback.format_exc()) interp.p.disconnect() + import pdb; pdb.post_mortem()