From f866a0f59a2d0ad4634af567cd6c23b63d0c2f2e Mon Sep 17 00:00:00 2001 From: Gustavo Cevallos Date: Wed, 1 Jul 2020 23:07:04 -0500 Subject: [PATCH 01/10] Fix int concat to str --- octoprint_RewriteM600/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octoprint_RewriteM600/__init__.py b/octoprint_RewriteM600/__init__.py index 6933619..cd328c7 100644 --- a/octoprint_RewriteM600/__init__.py +++ b/octoprint_RewriteM600/__init__.py @@ -16,7 +16,7 @@ def rewrite_m600(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwar if gcode and gcode == "M600": self._plugin_manager.send_plugin_message(self._identifier, dict(type="popup", msg="Please change the filament and resume the print")) comm_instance.setPause(True) - cmd = [("M117 Filament Change",),"G91","M83", "G1 Z+"+self._settings.get(["zDistance"])+" E-0.8 F4500", "M82", "G90", "G1 X0 Y0"] + cmd = [("M117 Filament Change",),"G91","M83", "G1 Z+"+str(self._settings.get(["zDistance"]))+" E-0.8 F4500", "M82", "G90", "G1 X0 Y0"] return cmd def after_resume(self, comm_instance, phase, cmd, parameters, tags=None, *args, **kwargs): From 92fb4510eeb6e9b907ea57c918d5da1935d098c1 Mon Sep 17 00:00:00 2001 From: Gustavo Cevallos Date: Wed, 1 Jul 2020 23:11:37 -0500 Subject: [PATCH 02/10] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 467bb59..6e10ce2 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "RewriteM600" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.0.1" +plugin_version = "1.0.2" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module From 8c0db7fd8ff5466344e7351d3d15e3541b52ac4a Mon Sep 17 00:00:00 2001 From: Gustavo Cevallos Date: Sun, 5 Jul 2020 13:14:07 -0500 Subject: [PATCH 03/10] Update __init__.py --- octoprint_RewriteM600/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octoprint_RewriteM600/__init__.py b/octoprint_RewriteM600/__init__.py index cd328c7..e59d83e 100644 --- a/octoprint_RewriteM600/__init__.py +++ b/octoprint_RewriteM600/__init__.py @@ -23,9 +23,9 @@ def after_resume(self, comm_instance, phase, cmd, parameters, tags=None, *args, if cmd and cmd == "resume": if(comm_instance.pause_position.x): cmd = [] - cmd =["M83","G1 E-0.8 F4500", "G1 E0.8 F4500", "G1 E0.8 F4500", "M82", "G90", "G92 E"+comm_instance.pause_position.e, "M83", "G1 X"+comm_instance.pause_position.x+" Y"+comm_instance.pause_position.y+" Z"+comm_instance.pause_position.z+" F4500"] + cmd =["M83","G1 E-0.8 F4500", "G1 E0.8 F4500", "G1 E0.8 F4500", "M82", "G90", "G92 E"+str(comm_instance.pause_position.e), "M83", "G1 X"+str(comm_instance.pause_position.x+)" Y"+str(comm_instance.pause_position.y)+" Z"+str(comm_instance.pause_position.z)+" F4500"] if(comm_instance.pause_position.f): - cmd.append("G1 F" + comm_instance.pause_position.f) + cmd.append("G1 F" + str(comm_instance.pause_position.f)) comm_instance.commands(cmd) comm_instance.setPause(False) return From 8b301df879ec95fd47aa98478f746f2ef3f61aef Mon Sep 17 00:00:00 2001 From: Gustavo Cevallos Date: Sun, 5 Jul 2020 13:14:30 -0500 Subject: [PATCH 04/10] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6e10ce2..5c260ed 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "RewriteM600" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.0.2" +plugin_version = "1.0.3" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module From 1d26cf0363456eaea76153da331f2f134c00f577 Mon Sep 17 00:00:00 2001 From: Gustavo Cevallos Date: Sun, 5 Jul 2020 13:40:20 -0500 Subject: [PATCH 05/10] Update __init__.py --- octoprint_RewriteM600/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octoprint_RewriteM600/__init__.py b/octoprint_RewriteM600/__init__.py index e59d83e..7412dd4 100644 --- a/octoprint_RewriteM600/__init__.py +++ b/octoprint_RewriteM600/__init__.py @@ -23,7 +23,7 @@ def after_resume(self, comm_instance, phase, cmd, parameters, tags=None, *args, if cmd and cmd == "resume": if(comm_instance.pause_position.x): cmd = [] - cmd =["M83","G1 E-0.8 F4500", "G1 E0.8 F4500", "G1 E0.8 F4500", "M82", "G90", "G92 E"+str(comm_instance.pause_position.e), "M83", "G1 X"+str(comm_instance.pause_position.x+)" Y"+str(comm_instance.pause_position.y)+" Z"+str(comm_instance.pause_position.z)+" F4500"] + cmd =["M83","G1 E-0.8 F4500", "G1 E0.8 F4500", "G1 E0.8 F4500", "M82", "G90", "G92 E"+str(comm_instance.pause_position.e), "M83", "G1 X"+str(comm_instance.pause_position.x)+" Y"+str(comm_instance.pause_position.y)+" Z"+str(comm_instance.pause_position.z)+" F4500"] if(comm_instance.pause_position.f): cmd.append("G1 F" + str(comm_instance.pause_position.f)) comm_instance.commands(cmd) From 7c35bf18b8a8fad506a959a7f11d40206209c103 Mon Sep 17 00:00:00 2001 From: Gustavo Cevallos Date: Sun, 5 Jul 2020 13:40:43 -0500 Subject: [PATCH 06/10] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5c260ed..11ed0a2 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "RewriteM600" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.0.3" +plugin_version = "1.0.4" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module From aadf18a479de6d8d5e352bc1d6219d164a812a6c Mon Sep 17 00:00:00 2001 From: Gustavo Cevallos Date: Sun, 5 Jul 2020 13:58:20 -0500 Subject: [PATCH 07/10] update version 1.0.5 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 11ed0a2..298cb93 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "RewriteM600" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.0.4" +plugin_version = "1.0.5" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module From 64168f9b2631d13e3dca463b6e3333e4905b541a Mon Sep 17 00:00:00 2001 From: Gustavo Cevallos Date: Wed, 8 Jul 2020 19:09:40 -0500 Subject: [PATCH 08/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a96bc5..2351e3c 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,4 @@ Copy or manually using this URL: ) ## Support -You can help this project reporting issues, making PR or Sponsor it [PayPal](https://paypal.me/wgcvl). +You can help this project reporting issues, making PR or Sponsor it [PayPal](https://paypal.me/wgcv). From 06cfb73bda8de41d2ebe629f25935d57e5a32357 Mon Sep 17 00:00:00 2001 From: FrozenFOXX Date: Sat, 2 Oct 2021 11:21:49 -0700 Subject: [PATCH 09/10] Typo and formatting corrections to the README I've added some formatting and typo corrections to the README. --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2351e3c..b17719c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # RewriteM600 -Implement M600 for pinters that can't support M600 by default (TFT with out Marlin Mode support, like Artilelry X1 and Genius). You can use M600, is going to stop wait until you change and press resume. If you have a TFT 28 (Like the Artillery) i would recomend you to check [Rawr TFT Firmware](https://github.com/wgcv/RAWR-TFT-Firmware-Artillery3D) to implement M600 direct in the TFT and do not need Octoprint. +Implement M600 for pinters that can't support M600 by default (TFT with out Marlin Mode support, like the Artillery Sidewinder X1 and Genius). You can use M600, it will stop and wait until you change and press resume. If you have a TFT 28 (like the Artillery) I would recomend you check out [Rawr TFT Firmware](https://github.com/wgcv/RAWR-TFT-Firmware-Artillery3D) to implement M600 direct in the TFT then do not need Octoprint. ## Setup @@ -14,12 +14,11 @@ Copy or manually using this URL: https://github.com/wgcv/RewriteM600/archive/master.zip - - - ## Screenshots + ![Screenshot](https://github.com/wgcv/plugins.octoprint.org/raw/gh-pages/assets/img/plugins/RewriteM600/M600-in-action.png ) ## Support -You can help this project reporting issues, making PR or Sponsor it [PayPal](https://paypal.me/wgcv). + +You can help this project by reporting issues, making PR or Sponsor it [PayPal](https://paypal.me/wgcv). From 1174096562d84fd711d0dfe8eaaa40eaefd16711 Mon Sep 17 00:00:00 2001 From: kaenguruhs <79077545+kaenguruhs@users.noreply.github.com> Date: Sat, 11 Mar 2023 09:58:41 +0100 Subject: [PATCH 10/10] makes script editable for user --- README.md | 5 + octoprint_RewriteM600/__init__.py | 112 ++++++++++++++---- .../static/js/RewriteM600.js | 16 ++- .../templates/RewriteM600_settings.jinja2 | 75 +++++++++++- setup.py | 2 +- 5 files changed, 183 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index b17719c..90f29bf 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,11 @@ Copy or manually using this URL: https://github.com/wgcv/RewriteM600/archive/master.zip +## Configuration + +As this plugin only tries to recognize the correct pausing position as a response to the `M114`-marlin-command, it is possible to change the default behaviour. +The plugin provides the dict `cached_position` (with members `x`, `y`, `z` and `e`) to the GCODE-Script `beforePrintResumed`. You can access them via `{{plugins.RewriteM600.cached_position.(x|y|z|e)}}`. + ## Screenshots ![Screenshot](https://github.com/wgcv/plugins.octoprint.org/raw/gh-pages/assets/img/plugins/RewriteM600/M600-in-action.png diff --git a/octoprint_RewriteM600/__init__.py b/octoprint_RewriteM600/__init__.py index 7412dd4..aec04f8 100644 --- a/octoprint_RewriteM600/__init__.py +++ b/octoprint_RewriteM600/__init__.py @@ -1,5 +1,6 @@ # coding=utf-8 from __future__ import absolute_import +import re ### (Don't forget to remove me) # This is a basic skeleton for your plugin's __init__.py. You probably want to adjust the class name of your plugin @@ -12,40 +13,110 @@ import octoprint.plugin class Rewritem600Plugin(octoprint.plugin.AssetPlugin, octoprint.plugin.TemplatePlugin, octoprint.plugin.SettingsPlugin): + cached_position = {"x": "NOT SET", "y": "NOT SET", "z": "NOT SET", "e": "NOT SET"} + listening = False + waiting = False + waitingForPause = False; + waitingForResume = False; + resumeScript = None; + + def on_settings_initialized(self): + scripts = self._settings.listScripts("gcode") + if not "rewrite_m600_pause" in scripts: + self._settings.saveScript("gcode", "rewrite_m600_pause", u'' + self._settings.get(["pauseCommand"])) + if not "rewrite_m600_resume" in scripts: + self._settings.saveScript("gcode", "rewrite_m600_resume", u'' + self._settings.get(["resumeCommand"])) + + def on_settings_save(self, data): + if 'pauseCommand' in data: + script = data["pauseCommand"] + self._settings.saveScript("gcode", "rewrite_m600_pause", u'' + script.replace("\r\n", "\n").replace("\r", "\n")) + # data.pop('pauseCommand') + if 'resumeCommand' in data: + script = data["resumeCommand"] + self._settings.saveScript("gcode", "rewrite_m600_resume", u'' + script.replace("\r\n", "\n").replace("\r", "\n")) + octoprint.plugin.SettingsPlugin.on_settings_save(self, data) + def rewrite_m600(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs): if gcode and gcode == "M600": - self._plugin_manager.send_plugin_message(self._identifier, dict(type="popup", msg="Please change the filament and resume the print")) - comm_instance.setPause(True) - cmd = [("M117 Filament Change",),"G91","M83", "G1 Z+"+str(self._settings.get(["zDistance"]))+" E-0.8 F4500", "M82", "G90", "G1 X0 Y0"] + self._logger.info("rewrite_m600") + self._plugin_manager.send_plugin_message(self._identifier, + dict(type = "popup", + msg = "Please change the filament and resume the print")) + self.listening = True + cmd = ["G4 S" + str(self._settings.get(["timeG4"])), "M114", "G4 S" + str(self._settings.get(["timeG4"])), "@setpause"] + self._logger.info(cmd) + self._logger.info(self.cached_position) + self.waiting = True + self.waitingForPause = True; return cmd + + def toggle_pause(self, comm_instance, phase, command, parameters, tags=None, *args, **kwargs): + if command == "setpause" and self.waitingForPause: + self._logger.info("setpause") + if self._settings.get(["defaultPause"]): + comm_instance.setPause(True) + else: + comm_instance.setPause(True, local_handling = False) # sorgt dafür, dass das Pause-Script nicht ausgeführt wird! + self._printer.script("rewrite_m600_pause", must_be_set=False) + self.waitingForPause = False + if command == "afterResumed" and self.waitingForResume: + self._logger.info("afterResumed") + self._settings.saveScript("gcode", "beforePrintResumed", u'' + self.resumeScript) + self.waitingForResume = False + + def detect_position(self, comm_instance, line, *args, **kwargs): + # ok X:20.0 Y:20.0 Z:0.6 E:20.01306 Count: A:2000 B:2000 C:60 + # match = re.match("X:([0-9.]+) Y:([0-9.]+) Z:([0-9.]+) E:-?([0-9.]+) Count X|A:([0-9]+) Y|B:([0-9]+) Z|C:([0-9]+)", line) + match = re.search(self._settings.get(["regularExpression"]), line) + if match is not None and self.listening: + self._logger.info("DetectPosition: " + line) + self.cached_position["x"] = match.group(self._settings.get(["x"])) + self.cached_position["y"] = match.group(self._settings.get(["y"])) + self.cached_position["z"] = match.group(self._settings.get(["z"])) + self.cached_position["e"] = match.group(self._settings.get(["e"])) + self._logger.info("CachedPosition: " + self.cached_position["x"]) + self._plugin_manager.send_plugin_message(self._identifier, dict(type="popup", msg = "Saved location at X:" + + self.cached_position["x"] + " Y:" + self.cached_position["y"] + + " Z:" + self.cached_position["z"])) + self.listening = False # Reset so we don't listen to the update called on print pause + self._logger.info(self.cached_position) + return line + + def after_resume(self, comm_instance, script_type, script_name, *args, **kwargs): + self._logger.info("Received queued command: " + script_name) + if self.waiting and script_type == "gcode" and script_name == "beforePrintResumed": + self._logger.info("Resuming from Filament Change") + self.waiting = False + self._plugin_manager.send_plugin_message(self._identifier, dict(type = "popup", msg = "Resuming to location at X:" + + self.cached_position["x"] + " Y:" + self.cached_position["y"] + + " Z:" + self.cached_position["z"])) + variables = dict(cached=self.cached_position) + if not self._settings.get(["defaultResume"]): + # Script ausführen + self._printer.script("rewrite_m600_resume", context=variables, must_be_set=False) + # script laden & leeren + self.resumeScript = self._settings.loadScript("gcode", "beforePrintResumed", source=True) + self._settings.saveScript("gcode", "beforePrintResumed", u'') + self.waitingForResume = True + self.cached_position = {"x": "NOT SET", "y": "NOT SET", "z": "NOT SET", "e": "NOT SET"} + return None, ["@afterResumed"], variables - def after_resume(self, comm_instance, phase, cmd, parameters, tags=None, *args, **kwargs): - if cmd and cmd == "resume": - if(comm_instance.pause_position.x): - cmd = [] - cmd =["M83","G1 E-0.8 F4500", "G1 E0.8 F4500", "G1 E0.8 F4500", "M82", "G90", "G92 E"+str(comm_instance.pause_position.e), "M83", "G1 X"+str(comm_instance.pause_position.x)+" Y"+str(comm_instance.pause_position.y)+" Z"+str(comm_instance.pause_position.z)+" F4500"] - if(comm_instance.pause_position.f): - cmd.append("G1 F" + str(comm_instance.pause_position.f)) - comm_instance.commands(cmd) - comm_instance.setPause(False) - return def get_settings_defaults(self): - return dict(zDistance=80) + return dict(x = 1, y = 2, z = 3, e = 4, timeG4 = 5, pauseCommand = "", resumeCommand = "", defaultPause = True, defaultResume = True, regularExpression = "X:([0-9.]+) Y:([0-9.]+) Z:([0-9.]+) E:-?([0-9.]+) Count:? (X|A):([0-9]+) (Y|B):([0-9]+) (Z|C):([0-9]+)") def get_template_configs(self): return [ - dict(type="navbar", custom_bindings=False), dict(type="settings", custom_bindings=False) ] + ##~~ AssetPlugin mixin def get_assets(self): # Define your plugin's asset files to automatically include in the # core UI here. return dict( - js=["js/RewriteM600.js"], - css=["css/RewriteM600.css"], - less=["less/RewriteM600.less"] + js = ["js/RewriteM600.js"] ) ##~~ Softwareupdate hook @@ -91,6 +162,7 @@ def __plugin_load__(): __plugin_hooks__ = { "octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information, "octoprint.comm.protocol.gcode.queuing": __plugin_implementation__.rewrite_m600, - "octoprint.comm.protocol.atcommand.queuing": __plugin_implementation__.after_resume, + "octoprint.comm.protocol.scripts": __plugin_implementation__.after_resume, + "octoprint.comm.protocol.gcode.received": __plugin_implementation__.detect_position, + "octoprint.comm.protocol.atcommand.queuing": __plugin_implementation__.toggle_pause, } - diff --git a/octoprint_RewriteM600/static/js/RewriteM600.js b/octoprint_RewriteM600/static/js/RewriteM600.js index d0f7696..f52d186 100644 --- a/octoprint_RewriteM600/static/js/RewriteM600.js +++ b/octoprint_RewriteM600/static/js/RewriteM600.js @@ -7,10 +7,20 @@ $(function() { function Rewritem600ViewModel(parameters) { var self = this; + + self.settings = parameters[0]; + self.defaultPause = ko.observable(); + self.defaultResume = ko.observable(); // assign the injected parameters, e.g.: // self.loginStateViewModel = parameters[0]; // self.settingsViewModel = parameters[1]; + + self.onBeforeBinding = function() { + console.log(self.settings); + self.defaultPause(self.settings.settings.plugins.RewriteM600.defaultPause()); + self.defaultResume(self.settings.settings.plugins.RewriteM600.defaultResume()); + } // TODO: Implement your plugin's view model here. self.onDataUpdaterPluginMessage = function(plugin, data) { @@ -23,7 +33,7 @@ $(function() { title: 'M600', text: data.msg, type: "info", - hide: false + hide: true }); } } @@ -36,8 +46,8 @@ $(function() { OCTOPRINT_VIEWMODELS.push({ construct: Rewritem600ViewModel, // ViewModels your plugin depends on, e.g. loginStateViewModel, settingsViewModel, ... - dependencies: [ /* "loginStateViewModel", "settingsViewModel" */ ], + dependencies: [ "settingsViewModel"/* "loginStateViewModel", "settingsViewModel" */ ], // Elements to bind to, e.g. #settings_plugin_RewriteM600, #tab_plugin_RewriteM600, ... - elements: [ /* ... */ ] + elements: [ ] }); }); diff --git a/octoprint_RewriteM600/templates/RewriteM600_settings.jinja2 b/octoprint_RewriteM600/templates/RewriteM600_settings.jinja2 index 0909f6e..e7d460e 100644 --- a/octoprint_RewriteM600/templates/RewriteM600_settings.jinja2 +++ b/octoprint_RewriteM600/templates/RewriteM600_settings.jinja2 @@ -1,8 +1,77 @@ +

Rewrite M600

+
- +
- + + + sec + +
+ G4 is the dwell-command. It is used to make sure the M114 (report current position) reports the latest known position.
-
\ No newline at end of file + +
+ +
+ + If checked, default script afterPrintPaused (from GCODE Scripts) is sent to the printer. Otherwise, the gcode stated in the following textarea is used. +
+
+
+ +
+ +
+
+ +
+ +
+ + If checked, default script beforePrintResumed (from GCODE Scripts) is sent to the printer. Otherwise, the gcode stated in the following textarea is used. +
+
+
+ +
+ +
+
+
+ +
+
+ +
+ + Regular Expression to recognize the position as answer to M114. +
+
+
+ Match Groups +
+ + {{ _('X') }} + + + + {{ _('Y') }} + + + + {{ _('Z') }} + + + + {{ _('E') }} + + + Match groups for the regular expression above. +
+
+
+
+ diff --git a/setup.py b/setup.py index 298cb93..460026c 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module -plugin_description = """Implement M600 for pinters that can't support M600 by default (TFT with out marlin mode support, like Artilelry X1 and Genius)""" +plugin_description = """Implement M600 for pinters that can't support M600 by default (TFT with out marlin mode support, like Artillery X1 and Genius)""" # The plugin's author. Can be overwritten within OctoPrint's internal data via __plugin_author__ in the plugin module plugin_author = "Gustavo Cevallos"