From 5b75021a36e765e12402bffffc1a81c90038fee4 Mon Sep 17 00:00:00 2001 From: "Shell M. Shrader" Date: Sun, 14 Apr 2019 15:26:02 -0400 Subject: [PATCH 01/13] preliminary M8/M9 support --- octoprint_bettergrblsupport/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/octoprint_bettergrblsupport/__init__.py b/octoprint_bettergrblsupport/__init__.py index a94f42d..d8dd689 100644 --- a/octoprint_bettergrblsupport/__init__.py +++ b/octoprint_bettergrblsupport/__init__.py @@ -363,13 +363,23 @@ def on_event(self, event, payload): # #-- gcode sending hook def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs): - # rewrite M115 as M5 (hello) + # M8 processing - work in progress + if cmd.upper().strip() == "M8": + os.system("tplink_smartplug.py -t air-assist.shellware.com -c on") + return (None,) + + # M9 processing - work in progress + if cmd.upper().strip() == "M9": + os.system("tplink_smartplug.py -t air-assist.shellware.com -c off") + return (None,) + + # rewrite M115 as M5 (hello) if self.suppressM115 and cmd.upper().startswith('M115'): self._logger.debug('Rewriting M115 as %s' % self.helloCommand) # return (self.helloCommand, ) return "$$" - # suppress reset line #s + # suppress reset line #s if self.suppressM110 and cmd.upper().startswith('M110'): self._logger.debug('Ignoring %s', cmd) return (None, ) From 842bc0cb0526a0c61539f41cc1f02bca52d24978 Mon Sep 17 00:00:00 2001 From: "Shell M. Shrader" Date: Sun, 14 Apr 2019 16:05:34 -0400 Subject: [PATCH 02/13] testing M8/M9 --- octoprint_bettergrblsupport/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/octoprint_bettergrblsupport/__init__.py b/octoprint_bettergrblsupport/__init__.py index d8dd689..2180baf 100644 --- a/octoprint_bettergrblsupport/__init__.py +++ b/octoprint_bettergrblsupport/__init__.py @@ -8,6 +8,7 @@ import time import math import os +import subprocess import octoprint.plugin import re @@ -365,12 +366,14 @@ def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args, # M8 processing - work in progress if cmd.upper().strip() == "M8": - os.system("tplink_smartplug.py -t air-assist.shellware.com -c on") + self._logger.info('Turning ON Air Assist') + subprocess.call("tplink_smartplug.py -t air-assist.shellware.com -c on", shell=True) return (None,) # M9 processing - work in progress if cmd.upper().strip() == "M9": - os.system("tplink_smartplug.py -t air-assist.shellware.com -c off") + self._logger.info('Turning OFF Air Assist') + subprocess.call("tplink_smartplug.py -t air-assist.shellware.com -c off", shell=True) return (None,) # rewrite M115 as M5 (hello) From 85cbdc25e3c519657ec0d596def02386b28d50d7 Mon Sep 17 00:00:00 2001 From: "Shell M. Shrader" Date: Sun, 14 Apr 2019 16:48:47 -0400 Subject: [PATCH 03/13] more m8/m9 stuff --- octoprint_bettergrblsupport/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/octoprint_bettergrblsupport/__init__.py b/octoprint_bettergrblsupport/__init__.py index 2180baf..5bacaa2 100644 --- a/octoprint_bettergrblsupport/__init__.py +++ b/octoprint_bettergrblsupport/__init__.py @@ -43,6 +43,8 @@ def __init__(self): self.reOrderTabs = True self.disablePrinterSafety = True self.showZ = False + self.m8Command = "" + self.m9Command = "" self.grblState = None self.grblX = float(0) @@ -90,6 +92,9 @@ def on_after_startup(self): self.neverSendChecksum = self._settings.get_boolean(["neverSendChecksum"]) self.reOrderTabs = self._settings.get_boolean(["reOrderTabs"]) + self.m8Command = self._settings.get(["m8Command"]) + self.m9Command = self._settings.get(["m9Command"]) + # self._settings.global_set_boolean(["feature", "temperatureGraph"], not self.hideTempTab) # self._settings.global_set_boolean(["feature", "gCodeVisualizer"], not self.hideGCodeTab) # self._settings.global_set_boolean(["gcodeViewer", "enabled"], not self.hideGCodeTab) @@ -248,7 +253,9 @@ def get_settings_defaults(self): disablePrinterSafety = True, grblSettingsText = "This space intentionally left blank", grblSettingsBackup = "", - showZ = False + showZ = False, + m8Command = "/home/pi/bin/tplink_smartplug.py -t air-assist.shellware.com -c on", + m9Command = "/home/pi/bin/tplink_smartplug.py -t air-assist.shellware.com -c off" ) def on_settings_save(self, data): @@ -367,13 +374,13 @@ def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args, # M8 processing - work in progress if cmd.upper().strip() == "M8": self._logger.info('Turning ON Air Assist') - subprocess.call("tplink_smartplug.py -t air-assist.shellware.com -c on", shell=True) + subprocess.call(self.m8Command, shell=True) return (None,) # M9 processing - work in progress if cmd.upper().strip() == "M9": self._logger.info('Turning OFF Air Assist') - subprocess.call("tplink_smartplug.py -t air-assist.shellware.com -c off", shell=True) + subprocess.call(self.m9Command, shell=True) return (None,) # rewrite M115 as M5 (hello) @@ -705,7 +712,7 @@ def get_api_commands(self): def on_api_command(self, command, data): # catch-all (should revisit state management) for validating printer State - if not self._printer.is_ready(): + if not self._printer.is_ready() and self.grblState != "Idle": self._logger.info("ignoring command - printer is not available") return From 15789dede503d304f21df302a757afe6823756bc Mon Sep 17 00:00:00 2001 From: "Shell M. Shrader" Date: Sun, 14 Apr 2019 17:26:39 -0400 Subject: [PATCH 04/13] more M8/M9 stuff --- octoprint_bettergrblsupport/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octoprint_bettergrblsupport/__init__.py b/octoprint_bettergrblsupport/__init__.py index 5bacaa2..b16e485 100644 --- a/octoprint_bettergrblsupport/__init__.py +++ b/octoprint_bettergrblsupport/__init__.py @@ -613,10 +613,10 @@ def send_frame_init_gcode(self): self._printer.commands("G91") self._printer.commands("$32=0") self._printer.commands("M4 F1000 S1") - self._printer.commands("M8") + # self._printer.commands("M8") def send_frame_end_gcode(self): - self._printer.commands("M9") + # self._printer.commands("M9") self._printer.commands("G1S0") self._printer.commands("M4 F0 S0") self._printer.commands("$32=1") From 830bfe5355b4462fcbc897e6444ade92083b00a6 Mon Sep 17 00:00:00 2001 From: "Shell M. Shrader" Date: Sun, 14 Apr 2019 17:39:16 -0400 Subject: [PATCH 05/13] don't send api commands if state != Idle --- octoprint_bettergrblsupport/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octoprint_bettergrblsupport/__init__.py b/octoprint_bettergrblsupport/__init__.py index b16e485..56c6dd8 100644 --- a/octoprint_bettergrblsupport/__init__.py +++ b/octoprint_bettergrblsupport/__init__.py @@ -712,7 +712,7 @@ def get_api_commands(self): def on_api_command(self, command, data): # catch-all (should revisit state management) for validating printer State - if not self._printer.is_ready() and self.grblState != "Idle": + if not self._printer.is_ready() or self.grblState != "Idle": self._logger.info("ignoring command - printer is not available") return @@ -867,7 +867,7 @@ def toggleWeak(self): self._printer.commands("M4 F1000 S1") res = "Laser Off" else: - self._printer.commands("M9") + # self._printer.commands("M9") self._printer.commands("G1S0") self._printer.commands("M4 F0 S0") self._printer.commands("$32=1") From 0e9fc296fdcffd9da222984d8d872db8827ce48e Mon Sep 17 00:00:00 2001 From: "Shell M. Shrader" Date: Sun, 14 Apr 2019 18:08:02 -0400 Subject: [PATCH 06/13] fix state management --- octoprint_bettergrblsupport/__init__.py | 93 ++++++++++++------------- 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/octoprint_bettergrblsupport/__init__.py b/octoprint_bettergrblsupport/__init__.py index 56c6dd8..8146d3e 100644 --- a/octoprint_bettergrblsupport/__init__.py +++ b/octoprint_bettergrblsupport/__init__.py @@ -710,10 +710,55 @@ def get_api_commands(self): ) def on_api_command(self, command, data): + if command == "sleep": + self._printer.commands("$SLP") + return + + if command == "unlock": + self._printer.commands("$X") + return + + if command == "reset": + self._printer.commands("M999") + return + + if command == "homing": + if self.grblPowerLevel > 0 and self.grblState == "Idle": + self.toggleWeak(); + + self._printer.commands("$H") + return + + if command == "updateGrblSetting": + self._printer.commands("${}={}".format(data.get("id").strip(), data.get("value").strip())) + self.grblSettings.update({int(data.get("id")): [data.get("value").strip(), self.grblSettingsNames.get(int(data.get("id")))]}) + self._printer.commands("$$") + return + + if command == "backupGrblSettings": + self._settings.set(["grblSettingsBackup"], self.serializeGrblSettings()) + self._settings.save() + return + + if command == "restoreGrblSettings": + settings = self._settings.get(["grblSettingsBackup"]) + + if settings is None or len(settings.strip()) == 0: + return + + for setting in settings.split("||"): + if len(setting.strip()) > 0: + set = setting.split("|") + # self._logger.info("restoreGrblSettings: {}".format(set)) + command = "${}={}".format(set[0], set[1]) + self._printer.commands(command) + + time.sleep(1) + return flask.jsonify({'res' : settings}) # catch-all (should revisit state management) for validating printer State if not self._printer.is_ready() or self.grblState != "Idle": - self._logger.info("ignoring command - printer is not available") + self._logger.info("ignoring move related command - printer is not available") return if command == "frame": @@ -812,52 +857,6 @@ def on_api_command(self, command, data): if command == "toggleWeak": return flask.jsonify({'res' : self.toggleWeak()}) - if command == "sleep": - self._printer.commands("$SLP") - return - - if command == "unlock": - self._printer.commands("$X") - return - - if command == "reset": - self._printer.commands("M999") - return - - if command == "homing": - if self.grblPowerLevel > 0 and self.grblState == "Idle": - self.toggleWeak(); - - self._printer.commands("$H") - return - - if command == "updateGrblSetting": - self._printer.commands("${}={}".format(data.get("id").strip(), data.get("value").strip())) - self.grblSettings.update({int(data.get("id")): [data.get("value").strip(), self.grblSettingsNames.get(int(data.get("id")))]}) - self._printer.commands("$$") - return - - if command == "backupGrblSettings": - self._settings.set(["grblSettingsBackup"], self.serializeGrblSettings()) - self._settings.save() - return - - if command == "restoreGrblSettings": - settings = self._settings.get(["grblSettingsBackup"]) - - if settings is None or len(settings.strip()) == 0: - return - - for setting in settings.split("||"): - if len(setting.strip()) > 0: - set = setting.split("|") - # self._logger.info("restoreGrblSettings: {}".format(set)) - command = "${}={}".format(set[0], set[1]) - self._printer.commands(command) - - time.sleep(1) - return flask.jsonify({'res' : settings}) - def toggleWeak(self): # do laser stuff powerLevel = self.grblPowerLevel From 8aaaa830749cfbe976aa3311108bc2ef3ef3ba51 Mon Sep 17 00:00:00 2001 From: "Shell M. Shrader" Date: Sun, 14 Apr 2019 18:25:53 -0400 Subject: [PATCH 07/13] fixing error handling --- octoprint_bettergrblsupport/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octoprint_bettergrblsupport/__init__.py b/octoprint_bettergrblsupport/__init__.py index 8146d3e..569a28d 100644 --- a/octoprint_bettergrblsupport/__init__.py +++ b/octoprint_bettergrblsupport/__init__.py @@ -504,7 +504,7 @@ def hook_gcode_received(self, comm_instance, line, *args, **kwargs): self._logger.info("error received: {} = {}".format(error, self.grblErrors.get(error))) - return 'ok ' + line + return 'Error: ' + line # look for an alarm if line.lower().startswith('alarm:'): @@ -518,7 +518,7 @@ def hook_gcode_received(self, comm_instance, line, *args, **kwargs): self._logger.info("alarm received: {} = {}".format(error, self.grblAlarms.get(error))) - return 'ok ' + line + return 'Error: ' + line # auto reset if "reset to continue" in line.lower(): From 5a86361d36000620df832173e0f5ebc44eaf7bb7 Mon Sep 17 00:00:00 2001 From: "Shell M. Shrader" Date: Sun, 14 Apr 2019 20:01:25 -0400 Subject: [PATCH 08/13] set alarm / error message expiration fix blinking laser button --- octoprint_bettergrblsupport/__init__.py | 24 +++++++++---------- .../static/js/bettergrblsupport.js | 18 +++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/octoprint_bettergrblsupport/__init__.py b/octoprint_bettergrblsupport/__init__.py index 569a28d..1de361f 100644 --- a/octoprint_bettergrblsupport/__init__.py +++ b/octoprint_bettergrblsupport/__init__.py @@ -492,31 +492,31 @@ def hook_gcode_received(self, comm_instance, line, *args, **kwargs): # This makes Octoprint recognise the startup message as a successful connection. return 'ok ' + line - # look for an error - if not self.ignoreErrors and line.lower().startswith('error:'): - match = re.search(r'error:\ *(-?[\d.]+)', line.lower()) + # look for an alarm + if line.lower().startswith('alarm:'): + match = re.search(r'alarm:\ *(-?[\d.]+)', line.lower()) if not match is None: error = int(match.groups(1)[0]) - self._plugin_manager.send_plugin_message(self._identifier, dict(type="grbl_error", + self._plugin_manager.send_plugin_message(self._identifier, dict(type="grbl_alarm", code=error, - description=self.grblErrors.get(error))) + description=self.grblAlarms.get(error))) - self._logger.info("error received: {} = {}".format(error, self.grblErrors.get(error))) + self._logger.info("alarm received: {} = {}".format(error, self.grblAlarms.get(error))) return 'Error: ' + line - # look for an alarm - if line.lower().startswith('alarm:'): - match = re.search(r'alarm:\ *(-?[\d.]+)', line.lower()) + # look for an error + if not self.ignoreErrors and line.lower().startswith('error:'): + match = re.search(r'error:\ *(-?[\d.]+)', line.lower()) if not match is None: error = int(match.groups(1)[0]) - self._plugin_manager.send_plugin_message(self._identifier, dict(type="grbl_alarm", + self._plugin_manager.send_plugin_message(self._identifier, dict(type="grbl_error", code=error, - description=self.grblAlarms.get(error))) + description=self.grblErrors.get(error))) - self._logger.info("alarm received: {} = {}".format(error, self.grblAlarms.get(error))) + self._logger.info("error received: {} = {}".format(error, self.grblErrors.get(error))) return 'Error: ' + line diff --git a/octoprint_bettergrblsupport/static/js/bettergrblsupport.js b/octoprint_bettergrblsupport/static/js/bettergrblsupport.js index bcf6d69..24784d1 100644 --- a/octoprint_bettergrblsupport/static/js/bettergrblsupport.js +++ b/octoprint_bettergrblsupport/static/js/bettergrblsupport.js @@ -229,13 +229,15 @@ $(function() { self.zPos(Number.parseFloat(data.z).toFixed(2)); self.speed(data.speed); - if (data.power == "0" && self.power() != "0") { - var btn = document.getElementById("grblLaserButton"); - btn.innerHTML = btn.innerHTML.replace(btn.innerText, "Weak Laser"); - } else { - if (self.power() == "0" && data.power != "0") { + if (data.state != "Run") { + if (data.power == "0" && self.power() != "0") { var btn = document.getElementById("grblLaserButton"); - btn.innerHTML = btn.innerHTML.replace(btn.innerText, "Laser Off"); + btn.innerHTML = btn.innerHTML.replace(btn.innerText, "Weak Laser"); + } else { + if (self.power() == "0" && data.power != "0") { + var btn = document.getElementById("grblLaserButton"); + btn.innerHTML = btn.innerHTML.replace(btn.innerText, "Laser Off"); + } } } @@ -269,15 +271,13 @@ $(function() { new PNotify({ title: "Grbl Error #" + data.code + " Received", text: data.description, - hide: false, + hide: true, buttons: { sticker: true, closer: true }, type: "error" }); - - return } if (plugin == 'bettergrblsupport' && data.type == 'grbl_alarm') { From 9d46757996be8b25e816ed58295eb3494545d47f Mon Sep 17 00:00:00 2001 From: "Shell M. Shrader" Date: Sun, 14 Apr 2019 22:05:21 -0400 Subject: [PATCH 09/13] updates --- octoprint_bettergrblsupport/__init__.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/octoprint_bettergrblsupport/__init__.py b/octoprint_bettergrblsupport/__init__.py index 1de361f..5018dc6 100644 --- a/octoprint_bettergrblsupport/__init__.py +++ b/octoprint_bettergrblsupport/__init__.py @@ -613,6 +613,7 @@ def send_frame_init_gcode(self): self._printer.commands("G91") self._printer.commands("$32=0") self._printer.commands("M4 F1000 S1") + self._printer.commands("G91") # self._printer.commands("M8") def send_frame_end_gcode(self): @@ -624,14 +625,12 @@ def send_frame_end_gcode(self): self._printer.commands("M2") def send_bounding_box_upper_left(self, y, x): - self._printer.commands("G91") self._printer.commands("G0 X{:f} F2000 S1".format(x)) self._printer.commands("G0 Y{:f} F2000 S1".format(y * -1)) self._printer.commands("G0 X{:f} F2000 S1".format(x * -1)) self._printer.commands("G0 Y{:f} F2000 S1".format(y)) def send_bounding_box_upper_center(self, y, x): - self._printer.commands("G91") self._printer.commands("G0 X{:f} F2000 S1".format(x / 2)) self._printer.commands("G0 Y{:f} F2000 S1".format(y * -1)) self._printer.commands("G0 X{:f} F2000 S1".format(x * -1)) @@ -639,14 +638,12 @@ def send_bounding_box_upper_center(self, y, x): self._printer.commands("G0 X{:f} F2000 S1".format(x / 2)) def send_bounding_box_upper_right(self, y, x): - self._printer.commands("G91") self._printer.commands("G0 Y{:f} F2000 S1".format(y * -1)) self._printer.commands("G0 X{:f} F2000 S1".format(x * -1)) self._printer.commands("G0 Y{:f} F2000 S1".format(y)) self._printer.commands("G0 X{:f} F2000 S1".format(x)) def send_bounding_box_center_left(self, y, x): - self._printer.commands("G91") self._printer.commands("G0 Y{:f} F2000 S1".format(y / 2)) self._printer.commands("G0 X{:f} F2000 S1".format(x)) self._printer.commands("G0 Y{:f} F2000 S1".format(y * -1)) @@ -655,8 +652,6 @@ def send_bounding_box_center_left(self, y, x): def send_bounding_box_center(self, y, x): self._printer.commands("G0 X{:f} Y{:f} F4000".format(x / 2 * -1, y / 2)) - - self._printer.commands("G91") self._printer.commands("G0 X{} F2000 S1".format(x)) self._printer.commands("G0 Y{:f} S1".format(y * -1)) self._printer.commands("G0 X{} S1".format(x * -1)) @@ -664,7 +659,6 @@ def send_bounding_box_center(self, y, x): self._printer.commands("G0 X{:f} Y{:f} F4000".format(x / 2, y / 2 * -1)) def send_bounding_box_center_right(self, y, x): - self._printer.commands("G91") self._printer.commands("G0 Y{:f} F2000 S1".format(y / 2 * -1)) self._printer.commands("G0 X{:f} F2000 S1".format(x * -1)) self._printer.commands("G0 Y{:f} F2000 S1".format(y)) @@ -672,14 +666,12 @@ def send_bounding_box_center_right(self, y, x): self._printer.commands("G0 Y{:f} F2000 S1".format(y / 2 * -1)) def send_bounding_box_lower_left(self, y, x): - self._printer.commands("G91") self._printer.commands("G0 Y{:f} F2000 S1".format(y)) self._printer.commands("G0 X{:f} F2000 S1".format(x)) self._printer.commands("G0 Y{:f} F2000 S1".format(y * -1)) self._printer.commands("G0 X{:f} F2000 S1".format(x * -1)) def send_bounding_box_lower_center(self, y, x): - self._printer.commands("G91") self._printer.commands("G0 X{:f} F2000 S1".format(x / 2 * -1)) self._printer.commands("G0 Y{:f} F2000 S1".format(y)) self._printer.commands("G0 X{:f} F2000 S1".format(x)) @@ -688,7 +680,6 @@ def send_bounding_box_lower_center(self, y, x): def send_bounding_box_lower_right(self, y, x): - self._printer.commands("G91") self._printer.commands("G0 X{:f} F2000 S1".format(x * -1)) self._printer.commands("G0 Y{:f} F2000 S1".format(y)) self._printer.commands("G0 X{:f} F2000 S1".format(x)) From 67f41fe1e3666766ad376cb276fda2a4991aa6fe Mon Sep 17 00:00:00 2001 From: "Shell M. Shrader" Date: Mon, 15 Apr 2019 02:30:49 -0400 Subject: [PATCH 10/13] formating cleanup / etc --- octoprint_bettergrblsupport/__init__.py | 42 ++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/octoprint_bettergrblsupport/__init__.py b/octoprint_bettergrblsupport/__init__.py index 5018dc6..05766ae 100644 --- a/octoprint_bettergrblsupport/__init__.py +++ b/octoprint_bettergrblsupport/__init__.py @@ -189,10 +189,10 @@ def on_after_startup(self): self._settings.save() - self.loadGrblErrorsAndAlarms() + self.loadGrblDescriptions() self.deSerializeGrblSettings() - def loadGrblErrorsAndAlarms(self): + def loadGrblDescriptions(self): path = os.path.dirname(os.path.realpath(__file__)) + os.path.sep + "static" + os.path.sep + "txt" + os.path.sep f = open(path + "grbl_errors.txt", 'r') @@ -222,6 +222,24 @@ def loadGrblErrorsAndAlarms(self): # for k, v in self.grblAlarms.items(): # self._logger.info("alarm id={} desc={}".format(k, v)) + def deSerializeGrblSettings(self): + settings = self._settings.get(["grblSettingsText"]) + + for setting in settings.split("||"): + if len(setting.strip()) > 0: + # self._logger.info("deSerializeGrblSettings=[{}]".format(setting)) + set = setting.split("|") + if not set is None: + self.grblSettings.update({int(set[0]): [set[1], self.grblSettingsNames.get(int(set[0]))]}) + return + + def serializeGrblSettings(self): + ret = "" + for id, data in sorted(self.grblSettings.items(), key=lambda x: int(x[0])): + ret = ret + "{}|{}|{}||".format(id, data[0], data[1]) + + # self._logger.info("serializeGrblSettings=[\n{}\n]".format(ret)) + return ret # #~~ SettingsPlugin mixin def get_settings_defaults(self): @@ -285,25 +303,6 @@ def get_template_configs(self): # def get_template_vars(self): # return dict(grblSettingsText=self.serializeGrblSettings()) - def serializeGrblSettings(self): - ret = "" - for id, data in sorted(self.grblSettings.items(), key=lambda x: int(x[0])): - ret = ret + "{}|{}|{}||".format(id, data[0], data[1]) - - # self._logger.info("serializeGrblSettings=[\n{}\n]".format(ret)) - return ret - - def deSerializeGrblSettings(self): - settings = self._settings.get(["grblSettingsText"]) - - for setting in settings.split("||"): - if len(setting.strip()) > 0: - # self._logger.info("deSerializeGrblSettings=[{}]".format(setting)) - set = setting.split("|") - if not set is None: - self.grblSettings.update({int(set[0]): [set[1], self.grblSettingsNames.get(int(set[0]))]}) - return - # #-- EventHandlerPlugin mix-in def on_event(self, event, payload): subscribed_events = Events.FILE_SELECTED + Events.PRINT_STARTED + Events.PRINT_CANCELLED + Events.PRINT_DONE + Events.PRINT_FAILED @@ -428,6 +427,7 @@ def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args, # keep track of distance traveled if cmd.startswith("G0") or cmd.startswith("G1") or cmd.startswith("M4"): found = False + match = re.search(r"^G[01].*X\ *(-?[\d.]+).*", cmd) if not match is None: self.grblX = self.grblX + float(match.groups(1)[0]) From b191f52e0b344c3122711b3d86d0a6fb646a3af0 Mon Sep 17 00:00:00 2001 From: "Shell M. Shrader" Date: Mon, 15 Apr 2019 19:43:24 -0400 Subject: [PATCH 11/13] added M8/M9 suppress options to settings --- octoprint_bettergrblsupport/__init__.py | 81 ++++++++++--------- .../bettergrblsupport_settings.jinja2 | 24 +++++- 2 files changed, 66 insertions(+), 39 deletions(-) diff --git a/octoprint_bettergrblsupport/__init__.py b/octoprint_bettergrblsupport/__init__.py index 05766ae..74e7132 100644 --- a/octoprint_bettergrblsupport/__init__.py +++ b/octoprint_bettergrblsupport/__init__.py @@ -43,6 +43,9 @@ def __init__(self): self.reOrderTabs = True self.disablePrinterSafety = True self.showZ = False + + self.overrideM8 = False + self.overrideM9 = False self.m8Command = "" self.m9Command = "" @@ -64,6 +67,42 @@ def __init__(self): self.customControlsJson = r'[{"layout": "horizontal", "children": [{"commands": ["$10=0", "G28.1", "G92 X0 Y0 Z0"], "name": "Set Origin", "confirm": null}, {"command": "M999", "name": "Reset", "confirm": null}, {"commands": ["G1 F4000 S0", "M5", "$SLP"], "name": "Sleep", "confirm": null}, {"command": "$X", "name": "Unlock", "confirm": null}, {"commands": ["$32=0", "M4 S1"], "name": "Weak Laser", "confirm": null}, {"commands": ["$32=1", "M5"], "name": "Laser Off", "confirm": null}], "name": "Laser Commands"}, {"layout": "vertical", "type": "section", "children": [{"regex": "<([^,]+)[,|][WM]Pos:([+\\-\\d.]+,[+\\-\\d.]+,[+\\-\\d.]+)", "name": "State", "default": "", "template": "State: {0} - Position: {1}", "type": "feedback"}, {"regex": "F([\\d.]+) S([\\d.]+)", "name": "GCode State", "default": "", "template": "Speed: {0} Power: {1}", "type": "feedback"}], "name": "Realtime State"}]' + # #~~ SettingsPlugin mixin + def get_settings_defaults(self): + return dict( + hideTempTab = True, + hideControlTab = True, + hideGCodeTab = True, + helloCommand = "M5", + statusCommand = "?$G", + dwellCommand = "G4 P0", + positionCommand = "?", + suppressM114 = True, + suppressM400 = True, + suppressM105 = True, + suppressM115 = True, + suppressM110 = True, + disablePolling = True, + customControls = True, + frame_length = 100, + frame_width = 100, + frame_origin = None, + distance = 10, + distances = [.1, 1, 10, 100], + is_printing = False, + is_operational = False, + disableModelSizeDetection = True, + neverSendChecksum = True, + reOrderTabs = True, + disablePrinterSafety = True, + grblSettingsText = "This space intentionally left blank", + grblSettingsBackup = "", + showZ = False, + overrideM8 = False, + overrideM9 = False, + m8Command = "/home/pi/bin/tplink_smartplug.py -t air-assist.shellware.com -c on", + m9Command = "/home/pi/bin/tplink_smartplug.py -t air-assist.shellware.com -c off" + ) # def on_settings_initialized(self): # self.hideTempTab = self._settings.get_boolean(["hideTempTab"]) # self._logger.info("hideTempTab: %s" % self.hideTempTab) @@ -92,6 +131,8 @@ def on_after_startup(self): self.neverSendChecksum = self._settings.get_boolean(["neverSendChecksum"]) self.reOrderTabs = self._settings.get_boolean(["reOrderTabs"]) + self.overrideM8 = self._settings.get_boolean(["overrideM8"]) + self.overrideM9 = self._settings.get_boolean(["overrideM9"]) self.m8Command = self._settings.get(["m8Command"]) self.m9Command = self._settings.get(["m9Command"]) @@ -241,41 +282,6 @@ def serializeGrblSettings(self): # self._logger.info("serializeGrblSettings=[\n{}\n]".format(ret)) return ret - # #~~ SettingsPlugin mixin - def get_settings_defaults(self): - return dict( - hideTempTab = True, - hideControlTab = True, - hideGCodeTab = True, - helloCommand = "M5", - statusCommand = "?$G", - dwellCommand = "G4 P0", - positionCommand = "?", - suppressM114 = True, - suppressM400 = True, - suppressM105 = True, - suppressM115 = True, - suppressM110 = True, - disablePolling = True, - customControls = True, - frame_length = 100, - frame_width = 100, - frame_origin = None, - distance = 10, - distances = [.1, 1, 10, 100], - is_printing = False, - is_operational = False, - disableModelSizeDetection = True, - neverSendChecksum = True, - reOrderTabs = True, - disablePrinterSafety = True, - grblSettingsText = "This space intentionally left blank", - grblSettingsBackup = "", - showZ = False, - m8Command = "/home/pi/bin/tplink_smartplug.py -t air-assist.shellware.com -c on", - m9Command = "/home/pi/bin/tplink_smartplug.py -t air-assist.shellware.com -c off" - ) - def on_settings_save(self, data): self._logger.info("saving settings") octoprint.plugin.SettingsPlugin.on_settings_save(self, data) @@ -371,13 +377,13 @@ def on_event(self, event, payload): def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs): # M8 processing - work in progress - if cmd.upper().strip() == "M8": + if cmd.upper().strip() == "M8" and overrideM8: self._logger.info('Turning ON Air Assist') subprocess.call(self.m8Command, shell=True) return (None,) # M9 processing - work in progress - if cmd.upper().strip() == "M9": + if cmd.upper().strip() == "M9" and overrideM9: self._logger.info('Turning OFF Air Assist') subprocess.call(self.m9Command, shell=True) return (None,) @@ -868,7 +874,6 @@ def toggleWeak(self): return res # #~~ Softwareupdate hook - def get_update_information(self): # Define the configuration for your plugin to use with the Software Update diff --git a/octoprint_bettergrblsupport/templates/bettergrblsupport_settings.jinja2 b/octoprint_bettergrblsupport/templates/bettergrblsupport_settings.jinja2 index cf5b05e..1ccf1be 100644 --- a/octoprint_bettergrblsupport/templates/bettergrblsupport_settings.jinja2 +++ b/octoprint_bettergrblsupport/templates/bettergrblsupport_settings.jinja2 @@ -79,9 +79,31 @@
-

* Server restart is required for this setting change to take effect

+
+
+ + + + +

+ + + + + +

+ +
+
+
+

* Server restart is required for this setting change to take effect

+

Grbl Settings


From 962a4a14915f2850e7bc1fd0501b268d4fbe4625 Mon Sep 17 00:00:00 2001 From: "Shell M. Shrader" Date: Mon, 15 Apr 2019 19:50:14 -0400 Subject: [PATCH 12/13] added self --- octoprint_bettergrblsupport/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octoprint_bettergrblsupport/__init__.py b/octoprint_bettergrblsupport/__init__.py index 74e7132..fac59d2 100644 --- a/octoprint_bettergrblsupport/__init__.py +++ b/octoprint_bettergrblsupport/__init__.py @@ -377,13 +377,13 @@ def on_event(self, event, payload): def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs): # M8 processing - work in progress - if cmd.upper().strip() == "M8" and overrideM8: + if cmd.upper().strip() == "M8" and self.overrideM8: self._logger.info('Turning ON Air Assist') subprocess.call(self.m8Command, shell=True) return (None,) # M9 processing - work in progress - if cmd.upper().strip() == "M9" and overrideM9: + if cmd.upper().strip() == "M9" and self.overrideM9: self._logger.info('Turning OFF Air Assist') subprocess.call(self.m9Command, shell=True) return (None,) From 5dbf4759f925d29b055a6e77e14f08f2361bc0cd Mon Sep 17 00:00:00 2001 From: "Shell M. Shrader" Date: Sat, 20 Apr 2019 02:52:52 -0400 Subject: [PATCH 13/13] 1.6.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index abe5743..7d3a0f4 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "Better Grbl Support" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.5.0" +plugin_version = "1.6.0" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module