From e29bd385734f64afa4c25f878e472b965c764aa5 Mon Sep 17 00:00:00 2001 From: Jacob Philpott Date: Fri, 29 Mar 2024 05:05:33 +0300 Subject: [PATCH] adding pause/wait commands --- .vscode/settings.json | 1 + serial/browser/sender.js | 6 +++++ src/polyslice.coffee | 51 ++++++++++++++++++++++++++++------------ src/polyslice.js | 34 +++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 15 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 83b5474..fddbf61 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "cura", "forkme", "gcode", + "interruptible", "polyslice", "srcset", "usbserial" diff --git a/serial/browser/sender.js b/serial/browser/sender.js index 67c8c1c..2c749bc 100644 --- a/serial/browser/sender.js +++ b/serial/browser/sender.js @@ -532,6 +532,12 @@ document.addEventListener("DOMContentLoaded", (event) => { if (command.includes("G21 ")) command += "📏" // Set length units to millimeters. if (command.includes("M149 ")) command += "📏🌡️" // Set temperature units to celsius [C], fahrenheit [F] or kelvin [K]. + // Pause/Wait + if (command.includes("G4 ")) command += "⏲️" // Uninterruptible pause command. + if (command.includes("M0 ")) command += "" // Interruptible pause command. + if (command.includes("M1 ")) command += "" // Interruptible pause command. + if (command.includes("M400 ")) command += "💤" // Wait for queue to finish. + // Fan if (command.includes("M106 ")) command += "🪭" // Set fan speed. if (command.includes("M107 ")) command += "🪭🚫" // Turn fan off. diff --git a/src/polyslice.coffee b/src/polyslice.coffee index 2b10c0f..99cf2b6 100644 --- a/src/polyslice.coffee +++ b/src/polyslice.coffee @@ -24,7 +24,9 @@ class Polyslice setWorkspacePlane: (plane = "XY") -> - if ["XY", "XZ", "YZ"].includes(plane) + plane = plane.toUpperCase().trim() + + if ["XY", "XZ", "YZ"].includes plane this.workspacePlane = String plane @@ -81,13 +83,7 @@ class Polyslice # https://marlinfw.org/docs/gcode/G000-G001.html codeLinearMovement: (x = null, y = null, z = null, e = null, f = null, s = null) -> - if e is null - - gcode = "G0" - - else - - gcode = "G1" + if e is null then gcode = "G0" else gcode = "G1" gcode += this.codeMovement x, y, z, e, f, s @@ -96,13 +92,7 @@ class Polyslice # https://marlinfw.org/docs/gcode/G002-G003.html codeArcMovement: (direction = "clockwise", x = null, y = null, z = null, e = null, f = null, s = null, i = null, j = null, r = null, p = null) -> - if direction is "clockwise" - - gcode = "G2" - - else - - gcode = "G3" + if direction is "clockwise" then gcode = "G2" else gcode = "G3" if (i isnt null or j isnt null) and r is null @@ -138,6 +128,37 @@ class Polyslice return gcode + this.newline + # https://marlinfw.org/docs/gcode/G004.html + # https://marlinfw.org/docs/gcode/M000-M001.html + codeDwell: (time = null, interruptible = true, message = "") -> + + if interruptible then gcode = "M0" else gcode = "G4" + + if time isnt null and typeof time is "number" and time > 0 + + gcode += " P" + time + + if message and typeof message is "string" + + gcode += " " + message + + return gcode + this.newline + + # https://marlinfw.org/docs/gcode/M108.html + codeInterrupt: -> + + return "M108" + this.newline + + # https://marlinfw.org/docs/gcode/M400.html + codeWait: -> + + return "M400" + this.newline + + # https://marlinfw.org/docs/gcode/M112.html + codeShutdown: -> + + return "M112" + this.newline + slice: (scene = {}) -> if this.getAutohome() diff --git a/src/polyslice.js b/src/polyslice.js index 1ac51a0..12cb916 100644 --- a/src/polyslice.js +++ b/src/polyslice.js @@ -23,6 +23,7 @@ Polyslice = class Polyslice { } setWorkspacePlane(plane = "XY") { + plane = plane.toUpperCase().trim(); if (["XY", "XZ", "YZ"].includes(plane)) { this.workspacePlane = String(plane); } @@ -114,6 +115,39 @@ Polyslice = class Polyslice { return gcode + this.newline; } + // https://marlinfw.org/docs/gcode/G004.html + // https://marlinfw.org/docs/gcode/M000-M001.html + codeDwell(time = null, interruptible = true, message = "") { + var gcode; + if (interruptible) { + gcode = "M0"; + } else { + gcode = "G4"; + } + if (time !== null && typeof time === "number" && time > 0) { + gcode += " P" + time; + } + if (message && typeof message === "string") { + gcode += " " + message; + } + return gcode + this.newline; + } + + // https://marlinfw.org/docs/gcode/M108.html + codeInterrupt() { + return "M108" + this.newline; + } + + // https://marlinfw.org/docs/gcode/M400.html + codeWait() { + return "M400" + this.newline; + } + + // https://marlinfw.org/docs/gcode/M112.html + codeShutdown() { + return "M112" + this.newline; + } + slice(scene = {}) { if (this.getAutohome()) { this.gcode += this.codeAutohome();