From 219a26ec0b3735d55141e1d455ac6d2980d45940 Mon Sep 17 00:00:00 2001 From: Philipp Engel Date: Tue, 21 Oct 2014 19:39:15 -0500 Subject: [PATCH] applied grbl support changes from PxT | https://github.com/PxT/OctoPrint --- src/octoprint/server/api/settings.py | 4 +- src/octoprint/settings.py | 3 +- src/octoprint/util/comm.py | 63 +++++++++++++++++++--------- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 05f6dcec..6026a69d 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -69,7 +69,8 @@ def getSettings(): "sdSupport": s.getBoolean(["feature", "sdSupport"]), "sdAlwaysAvailable": s.getBoolean(["feature", "sdAlwaysAvailable"]), "swallowOkAfterResend": s.getBoolean(["feature", "swallowOkAfterResend"]), - "repetierTargetTemp": s.getBoolean(["feature", "repetierTargetTemp"]) + "repetierTargetTemp": s.getBoolean(["feature", "repetierTargetTemp"]), + "grbl": s.getBoolean(["feature", "grbl"]) }, "serial": { "port": connectionOptions["portPreference"], @@ -167,6 +168,7 @@ def setSettings(): if "sdAlwaysAvailable" in data["feature"].keys(): s.setBoolean(["feature", "sdAlwaysAvailable"], data["feature"]["sdAlwaysAvailable"]) if "swallowOkAfterResend" in data["feature"].keys(): s.setBoolean(["feature", "swallowOkAfterResend"], data["feature"]["swallowOkAfterResend"]) if "repetierTargetTemp" in data["feature"].keys(): s.setBoolean(["feature", "repetierTargetTemp"], data["feature"]["repetierTargetTemp"]) + if "grbl" in data["feature"].keys(): s.setBoolean(["feature", "grbl"], data["feature"]["grbl"]) if "serial" in data.keys(): if "autoconnect" in data["serial"].keys(): s.setBoolean(["serial", "autoconnect"], data["serial"]["autoconnect"]) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 8e99d797..be0294a1 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -83,7 +83,8 @@ default_settings = { "sdSupport": True, "sdAlwaysAvailable": False, "swallowOkAfterResend": True, - "repetierTargetTemp": False + "repetierTargetTemp": False, + "grbl": True }, "folder": { "uploads": None, diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 9292592c..f5015a11 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -152,6 +152,9 @@ class MachineCom(object): self._resendDelta = None self._lastLines = deque([], 50) + # enabled grbl mode if requested + self._grbl = settings().getBoolean(["feature", "grbl"]) + # hooks self._pluginManager = octoprint.plugin.plugin_manager() self._gcode_hooks = self._pluginManager.get_hooks("octoprint.comm.protocol.gcode") @@ -827,7 +830,11 @@ class MachineCom(object): self._baudrateDetectRetry -= 1 self._serial.write('\n') self._log("Baudrate test retry: %d" % (self._baudrateDetectRetry)) - self._sendCommand("M105") + # self._sendCommand("M105") + if self._grbl: + self._sendCommand("$") + else: + self._sendCommand("M105") self._testingBaudrate = True else: baudrate = self._baudrateDetectList.pop(0) @@ -839,10 +846,17 @@ class MachineCom(object): self._baudrateDetectTestOk = 0 timeout = getNewTimeout("communication") self._serial.write('\n') - self._sendCommand("M105") + # self._sendCommand("M105") + if self._grbl: + self._sendCommand("$") + else: + self._sendCommand("M105") self._testingBaudrate = True except: self._log("Unexpected error while setting baudrate: %d %s" % (baudrate, getExceptionString())) + elif self._grbl and '$$' in line: + self._log("Baudrate test ok: %d" % (self._baudrateDetectTestOk)) + self._changeState(self.STATE_OPERATIONAL) elif 'ok' in line and 'T:' in line: self._baudrateDetectTestOk += 1 if self._baudrateDetectTestOk < 10: @@ -862,19 +876,23 @@ class MachineCom(object): ### Connection attempt elif self._state == self.STATE_CONNECTING: - if (line == "" or "wait" in line) and startSeen: - self._sendCommand("M105") - elif "start" in line: - startSeen = True - elif "ok" in line and startSeen: - self._changeState(self.STATE_OPERATIONAL) - if self._sdAvailable: - self.refreshSdFiles() - else: - self.initSdCard() - eventManager().fire(Events.CONNECTED, {"port": self._port, "baudrate": self._baudrate}) - elif time.time() > timeout: - self.close() + if self._grbl: + if "Grbl" in line: + self._changeState(self.STATE_OPERATIONAL) + else: + if (line == "" or "wait" in line) and startSeen: + self._sendCommand("M105") + elif "start" in line: + startSeen = True + elif "ok" in line and startSeen: + self._changeState(self.STATE_OPERATIONAL) + if self._sdAvailable: + self.refreshSdFiles() + else: + self.initSdCard() + eventManager().fire(Events.CONNECTED, {"port": self._port, "baudrate": self._baudrate}) + elif time.time() > timeout: + self.close() ### Operational elif self._state == self.STATE_OPERATIONAL or self._state == self.STATE_PAUSED: @@ -885,7 +903,8 @@ class MachineCom(object): elif not self._commandQueue.empty(): self._sendCommand(self._commandQueue.get()) else: - self._sendCommand("M105") + if not self._grbl: + self._sendCommand("M105") tempRequestTimeout = getNewTimeout("temperature") # resend -> start resend procedure from requested line elif line.lower().startswith("resend") or line.lower().startswith("rs"): @@ -901,7 +920,8 @@ class MachineCom(object): if self.isSdPrinting(): if time.time() > tempRequestTimeout and not heatingUp: - self._sendCommand("M105") + if not self._grbl: + self._sendCommand("M105") tempRequestTimeout = getNewTimeout("temperature") if time.time() > sdStatusRequestTimeout and not heatingUp: @@ -910,7 +930,8 @@ class MachineCom(object): else: # Even when printing request the temperature every 5 seconds. if time.time() > tempRequestTimeout and not self.isStreaming(): - self._commandQueue.put("M105") + if not self._grbl: + self._commandQueue.put("M105") tempRequestTimeout = getNewTimeout("temperature") if "ok" in line and swallowOk: @@ -1118,7 +1139,11 @@ class MachineCom(object): lineNumber = self._currentLine self._addToLastLines(cmd) self._currentLine += 1 - self._doSendWithChecksum(cmd, lineNumber) + # self._doSendWithChecksum(cmd, lineNumber) + if self._grbl: + self._doSendWithoutChecksum(cmd) + else: + self._doSendWithChecksum(cmd, lineNumber) else: self._doSendWithoutChecksum(cmd)