Skip to content

Commit

Permalink
Merge pull request #1117 from jamawa/spindle-dwell-support-for-M4
Browse files Browse the repository at this point in the history
Spindle dwell support for m4
  • Loading branch information
winder committed Sep 4, 2018
2 parents ef884b9 + 51bec31 commit 4da7db7
Show file tree
Hide file tree
Showing 26 changed files with 73 additions and 58 deletions.
Expand Up @@ -29,24 +29,24 @@ This file is part of Universal Gcode Sender (UGS).
import java.util.regex.Pattern;

/**
* Adds a dwell command after an M3.
* Adds a dwell command after an M3 or M4.
*
* @author wwinder
*/
public class M3Dweller implements CommandProcessor {
public class SpindleOnDweller implements CommandProcessor {
private final String dwellCommand;

// Contains an M3 not followed by another digit (i.e. M30)
private Pattern m3Pattern = Pattern.compile(".*[mM]3(?!\\d)(\\D.*)?");
private Pattern spindleOnPattern = Pattern.compile(".*[mM][34](?!\\d)(\\D.*)?");

public M3Dweller(double dwellDuration) {
public SpindleOnDweller(double dwellDuration) {
this.dwellCommand = String.format(Locale.ROOT, "G4P%.2f", dwellDuration);
}

@Override
public List<String> processCommand(String command, GcodeState state) throws GcodeParserException {
String noComments = GcodePreprocessorUtils.removeComment(command);
if (m3Pattern.matcher(noComments).matches()) {
if (spindleOnPattern.matcher(noComments).matches()) {
return Arrays.asList(command, dwellCommand);
}
return Collections.singletonList(command);
Expand Down
Expand Up @@ -28,7 +28,7 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.universalgcodesender.gcode.processors.DecimalProcessor;
import com.willwinder.universalgcodesender.gcode.processors.FeedOverrideProcessor;
import com.willwinder.universalgcodesender.gcode.processors.M30Processor;
import com.willwinder.universalgcodesender.gcode.processors.M3Dweller;
import com.willwinder.universalgcodesender.gcode.processors.SpindleOnDweller;
import com.willwinder.universalgcodesender.gcode.processors.PatternRemover;
import com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor;
import com.willwinder.universalgcodesender.i18n.Localization;
Expand Down Expand Up @@ -82,10 +82,10 @@ public class CommandProcessorLoader {
* name: "WhitespaceProcessor",
* "enabled": <enabled>,
* "optional": <optional>,
* "args": {}
* },{
* name: "M3Dweller",
* "enabled": <enabled>,
"args": {}
},{
name: "SpindleOnDweller",
"enabled": <enabled>,
* "optional": <optional>,
* "args": {}
* }
Expand Down Expand Up @@ -166,9 +166,9 @@ static private List<ProcessorConfig> getConfigFrom(String jsonConfig) {
* name: "WhitespaceProcessor",
* "enabled": <enabled>
* "optional": <optional>,
* },{
* name: "M3Dweller",
* "enabled": <enabled>,
},{
name: "SpindleOnDweller",
"enabled": <enabled>,
* "optional": <optional>,
* "args": {
* "duraion": <double>
Expand Down Expand Up @@ -220,9 +220,9 @@ static public List<CommandProcessor> initializeWithProcessors(List<ProcessorConf
case "WhitespaceProcessor":
p = new WhitespaceProcessor();
break;
case "M3Dweller":
case "SpindleOnDweller":
double duration = pc.args.get("duration").getAsDouble();
p = new M3Dweller(duration);
p = new SpindleOnDweller(duration);
break;
default:
throw new IllegalArgumentException("Unknown processor: " + pc.name);
Expand Down Expand Up @@ -272,9 +272,9 @@ static public String getHelpForConfig(ProcessorConfig pc) {
case "WhitespaceProcessor":
p = new WhitespaceProcessor();
break;
case "M3Dweller":
case "SpindleOnDweller":
int duration = pc.args.get("duration").getAsInt();
p = new M3Dweller(duration);
p = new SpindleOnDweller(duration);
break;
default:
throw new IllegalArgumentException("Unknown processor: " + pc.name);
Expand Down
2 changes: 1 addition & 1 deletion ugs-core/src/resources/MessagesBundle_af_ZA.properties
Expand Up @@ -365,7 +365,7 @@ parser.gcode.multiple-axis-commands =
parser.gcode.missing-axis-commands =
sender.nightly-warning =
sender.help.spindle-dwell =
M3Dweller =
SpindleOnDweller =
platform.window.dowel-module =
platform.window.dowel-module.tooltip =
platform.plugin.dowel-module.generate =
Expand Down
4 changes: 2 additions & 2 deletions ugs-core/src/resources/MessagesBundle_de_DE.properties
Expand Up @@ -376,8 +376,8 @@ probe.visualizer.z-preview = Z antasten Vorschau
parser.gcode.multiple-axis-commands = Mehrere Programme erfordern Achsangaben auf einer Zeile
parser.gcode.missing-axis-commands = Achsangabe für Bewegungsbefehl fehlt
sender.nightly-warning = Zeige ein Warnpopup für Nightly Builds
sender.help.spindle-dwell = Einstellbare Verzögerung (in Sekunden) nach Aktivierung der Spindel mit ainem "M3" Kommando
M3Dweller = Spindle Start verzögert
sender.help.spindle-dwell = Einstellbare Verzögerung (in Sekunden) nach Aktivierung der Spindel mit einem "M3" oder "M4" Kommando
SpindleOnDweller = Spindle Start verzögert
platform.window.dowel-module =
platform.window.dowel-module.tooltip =
platform.plugin.dowel-module.generate = Erzeuge G-Code
Expand Down
2 changes: 1 addition & 1 deletion ugs-core/src/resources/MessagesBundle_el_EL.properties
Expand Up @@ -364,7 +364,7 @@ parser.gcode.multiple-axis-commands =
parser.gcode.missing-axis-commands =
sender.nightly-warning =
sender.help.spindle-dwell =
M3Dweller =
SpindleOnDweller =
platform.window.dowel-module =
platform.window.dowel-module.tooltip =
platform.plugin.dowel-module.generate =
Expand Down
4 changes: 2 additions & 2 deletions ugs-core/src/resources/MessagesBundle_en_US.properties
Expand Up @@ -415,8 +415,8 @@ probe.visualizer.z-preview = Z probe preview
parser.gcode.multiple-axis-commands = Multiple codes requiring axis words on one line
parser.gcode.missing-axis-commands = Axis words missing for motion command
sender.nightly-warning = Show warning popup for Nightly Builds
sender.help.spindle-dwell = Add a configurable delay (in seconds) after enabling the spindle with a "M3" command.
M3Dweller = Spindle start delay
sender.help.spindle-dwell = Add a configurable delay (in seconds) after enabling the spindle with a "M3" or "M4" command.
SpindleOnDweller = Spindle start delay
platform.window.dowel-module = Dowel Maker
platform.window.dowel-module.tooltip = Generate gcode for making dowels in various shapes and sizes.
platform.plugin.dowel-module.generate = Generate gcode
Expand Down
4 changes: 2 additions & 2 deletions ugs-core/src/resources/MessagesBundle_es_ES.properties
Expand Up @@ -367,8 +367,8 @@ probe.visualizer.z-preview = Vista previa de la sonda en Z
parser.gcode.multiple-axis-commands = Múltiples códigos que requieren palabras de eje en una línea
parser.gcode.missing-axis-commands = Faltan comandos de movimiento
sender.nightly-warning = Mostrar ventana emergente de advertencia para versiones de desarrollo
sender.help.spindle-dwell = Agregue un retraso configurable (en segundos) después de habilitar el eje con un comando "M3"
M3Dweller = Retraso de inicio del Spindle
sender.help.spindle-dwell = Agregue un retraso configurable (en segundos) después de habilitar el eje con un comando "M3" o "M4"
SpindleOnDweller = Retraso de inicio del Spindle
platform.window.dowel-module = Fresadora
platform.window.dowel-module.tooltip = Generar gcode para hacer puntos en varias formas y tamaños.
platform.plugin.dowel-module.generate = Genera G-code
Expand Down
2 changes: 1 addition & 1 deletion ugs-core/src/resources/MessagesBundle_fr_FR.properties
Expand Up @@ -368,7 +368,7 @@ parser.gcode.multiple-axis-commands =
parser.gcode.missing-axis-commands =
sender.nightly-warning =
sender.help.spindle-dwell =
M3Dweller =
SpindleOnDweller =
platform.window.dowel-module =
platform.window.dowel-module.tooltip =
platform.plugin.dowel-module.generate =
Expand Down
4 changes: 2 additions & 2 deletions ugs-core/src/resources/MessagesBundle_it_IT.properties
Expand Up @@ -367,8 +367,8 @@ probe.visualizer.z-preview = Anteprima della sonda dell'asse Z.
parser.gcode.multiple-axis-commands = Codici multipli che richiedono parole di assi su una riga
parser.gcode.missing-axis-commands = Parole sull'asse mancanti per il comando di movimento
sender.nightly-warning = Mostra popup di avviso per Nightly Builds
sender.help.spindle-dwell = Aggiungere un ritardo configurabile (in secondi) dopo aver abilitato il mandrino con un comando "M3".
M3Dweller = Ritardo dell'avvio del mandrino
sender.help.spindle-dwell = Aggiungere un ritardo configurabile (in secondi) dopo aver abilitato il mandrino con un comando "M3" o "M4".
SpindleOnDweller = Ritardo dell'avvio del mandrino
platform.window.dowel-module = Creatore di Tasselli (Dowel)
platform.window.dowel-module.tooltip = Genera gcode per realizzare tasselli di varie forme e dimensioni.
platform.plugin.dowel-module.generate = Genera gcode
Expand Down
2 changes: 1 addition & 1 deletion ugs-core/src/resources/MessagesBundle_jp_JA.properties
Expand Up @@ -360,7 +360,7 @@ parser.gcode.multiple-axis-commands = Multiple codes requiring axis words on one
parser.gcode.missing-axis-commands = Axis words missing for motion command
sender.nightly-warning =
sender.help.spindle-dwell =
M3Dweller =
SpindleOnDweller =
platform.window.dowel-module =
platform.window.dowel-module.tooltip =
platform.plugin.dowel-module.generate =
Expand Down
4 changes: 2 additions & 2 deletions ugs-core/src/resources/MessagesBundle_lt_LT.properties
Expand Up @@ -358,8 +358,8 @@ probe.visualizer.z-preview = Z nulinimo rodymas
parser.gcode.multiple-axis-commands = Multiple codes requiring axis words on one line
parser.gcode.missing-axis-commands = Nenurodytas ašies ženklas faile
sender.nightly-warning = Nightly Builds įspėjimas
sender.help.spindle-dwell = Add a configurable delay (in seconds) after enabling the spindle with a "M3" command.
M3Dweller = Špindelio paleidimo uždelsimas
sender.help.spindle-dwell = Add a configurable delay (in seconds) after enabling the spindle with a "M3" or "M4" command.
SpindleOnDweller = Špindelio paleidimo uždelsimas
platform.window.dowel-module = Dowel Modulis
platform.window.dowel-module.tooltip = Generate gcode for making dowels in various shapes and sizes.
platform.plugin.dowel-module.generate = Generuoti gcode
Expand Down
2 changes: 1 addition & 1 deletion ugs-core/src/resources/MessagesBundle_nb_NO.properties
Expand Up @@ -359,7 +359,7 @@ parser.gcode.multiple-axis-commands =
parser.gcode.missing-axis-commands =
sender.nightly-warning =
sender.help.spindle-dwell =
M3Dweller =
SpindleOnDweller =
platform.window.dowel-module =
platform.window.dowel-module.tooltip =
platform.plugin.dowel-module.generate =
Expand Down
4 changes: 2 additions & 2 deletions ugs-core/src/resources/MessagesBundle_nl_NL.properties
Expand Up @@ -368,8 +368,8 @@ probe.visualizer.z-preview = Z sonde voorvertoning
parser.gcode.multiple-axis-commands = Meerdere kodes met asaanduidingen per lijn
parser.gcode.missing-axis-commands = Asaanduiding ontbreekt voor bewegingskommando
sender.nightly-warning = Vertoon waarschuwings popup voor Nightly Builds
sender.help.spindle-dwell = Voeg een configureerbare vertraging toe (in seconden) na inschakelen van spindle met "M3" kommando.
M3Dweller = Spindle startvertraging
sender.help.spindle-dwell = Voeg een configureerbare vertraging toe (in seconden) na inschakelen van spindle met "M3" of "M4" kommando.
SpindleOnDweller = Spindle startvertraging
platform.window.dowel-module = Paspen maker
platform.window.dowel-module.tooltip = Genereer Gcode voor paspennen in verschillende vormen en maten
platform.plugin.dowel-module.generate = Genereer Gcode
Expand Down
2 changes: 1 addition & 1 deletion ugs-core/src/resources/MessagesBundle_pl_PL.properties
Expand Up @@ -359,7 +359,7 @@ parser.gcode.multiple-axis-commands = parser.gcode.multiple-axis-commands
parser.gcode.missing-axis-commands = parser.gcode.missing-axis-commands
sender.nightly-warning = sender.nightly-warning
sender.help.spindle-dwell = sender.help.spindle-dwell
M3Dweller = M3Dweller
SpindleOnDweller = M3Dweller
platform.window.dowel-module = platform.window.dowel-module
platform.window.dowel-module.tooltip = platform.window.dowel-module.tooltip
platform.plugin.dowel-module.generate = platform.plugin.dowel-module.generate
Expand Down
4 changes: 2 additions & 2 deletions ugs-core/src/resources/MessagesBundle_pt_BR.properties
Expand Up @@ -357,8 +357,8 @@ probe.visualizer.z-preview = Visualizar probe eixo Z
parser.gcode.multiple-axis-commands = Múltiplos códigos precisam da definição do eixo em uma linha
parser.gcode.missing-axis-commands = Faltam comandos no eixo para se mover
sender.nightly-warning = Mostrar popup de aviso para Builds Nightly
sender.help.spindle-dwell = Adiciona um atraso configurável (em segundos) após ativar o spindle com um comando "M3".
M3Dweller = Atraso no começo do spindle
sender.help.spindle-dwell = Adiciona um atraso configurável (em segundos) após ativar o spindle com um comando "M3" ou "M4".
SpindleOnDweller = Atraso no começo do spindle
platform.window.dowel-module = Fabricante de Cavilha
platform.window.dowel-module.tooltip = Gerar gcode para criar cavilha em várias formas e tamanhos
platform.plugin.dowel-module.generate = Gerar gcode
Expand Down
2 changes: 1 addition & 1 deletion ugs-core/src/resources/MessagesBundle_ru_RU.properties
Expand Up @@ -367,7 +367,7 @@ parser.gcode.multiple-axis-commands =
parser.gcode.missing-axis-commands =
sender.nightly-warning =
sender.help.spindle-dwell =
M3Dweller =
SpindleOnDweller =
platform.window.dowel-module =
platform.window.dowel-module.tooltip =
platform.plugin.dowel-module.generate =
Expand Down
4 changes: 2 additions & 2 deletions ugs-core/src/resources/MessagesBundle_sv_SE.properties
Expand Up @@ -362,8 +362,8 @@ probe.visualizer.z-preview = Förhandsgranskning av Z-probning
parser.gcode.multiple-axis-commands = Multipla kommandon kräver axis-ord på en rad
parser.gcode.missing-axis-commands = Axis-ord saknas för förflyttnings-kommando
sender.nightly-warning = Visa varningsrutan för Nightly Builds
sender.help.spindle-dwell = Lägg till en konfigurerbar fördröjning (i sekunder) efter att spindeln aktiveras med ett "M3"-kommando.
M3Dweller = Startfördröjning för spindel
sender.help.spindle-dwell = Lägg till en konfigurerbar fördröjning (i sekunder) efter att spindeln aktiveras med ett "M3" eller "M4"-kommando.
SpindleOnDweller = Startfördröjning för spindel
platform.window.dowel-module = Träpluggsskapare
platform.window.dowel-module.tooltip = Generera gcode för att skapa träplugg i olika former och storlekar.
platform.plugin.dowel-module.generate = Generera GCode
Expand Down
2 changes: 1 addition & 1 deletion ugs-core/src/resources/MessagesBundle_tr_TR.properties
Expand Up @@ -363,7 +363,7 @@ parser.gcode.multiple-axis-commands =
parser.gcode.missing-axis-commands =
sender.nightly-warning =
sender.help.spindle-dwell =
M3Dweller =
SpindleOnDweller =
platform.window.dowel-module =
platform.window.dowel-module.tooltip =
platform.plugin.dowel-module.generate = G Kod Oluştur
Expand Down
2 changes: 1 addition & 1 deletion ugs-core/src/resources/MessagesBundle_zh_CN.properties
Expand Up @@ -366,7 +366,7 @@ parser.gcode.multiple-axis-commands =
parser.gcode.missing-axis-commands =
sender.nightly-warning =
sender.help.spindle-dwell =
M3Dweller =
SpindleOnDweller =
platform.window.dowel-module =
platform.window.dowel-module.tooltip =
platform.plugin.dowel-module.generate =
Expand Down
4 changes: 2 additions & 2 deletions ugs-core/src/resources/firmware_config/grbl.json
@@ -1,6 +1,6 @@
{
"Name": "GRBL",
"Version": 4,
"Version": 5,
"Controller": {
"name": "GRBL",
"args": null
Expand Down Expand Up @@ -47,7 +47,7 @@
"enabled": true,
"optional": true
},{
"name": "M3Dweller",
"name": "SpindleOnDweller",
"enabled": false,
"optional": true,
"args": {
Expand Down
4 changes: 2 additions & 2 deletions ugs-core/src/resources/firmware_config/smoothieboard.json
@@ -1,6 +1,6 @@
{
"Name": "Smoothie Board",
"Version": 4,
"Version": 5,
"Controller": {
"name": "SmoothieBoard",
"args": null
Expand Down Expand Up @@ -47,7 +47,7 @@
"enabled": true,
"optional": true
},{
"name": "M3Dweller",
"name": "SpindleOnDweller",
"enabled": false,
"optional": true,
"args": {
Expand Down
4 changes: 2 additions & 2 deletions ugs-core/src/resources/firmware_config/test_1.json
@@ -1,6 +1,6 @@
{
"Name": "Testing",
"Version": 4,
"Version": 5,
"Controller": {
"name": "Loopback",
"args": null
Expand Down Expand Up @@ -47,7 +47,7 @@
"enabled": true,
"optional": true
},{
"name": "M3Dweller",
"name": "SpindleOnDweller",
"enabled": false,
"optional": true,
"args": {
Expand Down
4 changes: 2 additions & 2 deletions ugs-core/src/resources/firmware_config/test_2.json
@@ -1,6 +1,6 @@
{
"Name": "Testing (Delay)",
"Version": 4,
"Version": 5,
"Controller": {
"name": "Loopback_Slow",
"args": null
Expand Down Expand Up @@ -47,7 +47,7 @@
"enabled": true,
"optional": true
},{
"name": "M3Dweller",
"name": "SpindleOnDweller",
"enabled": false,
"optional": true,
"args": {
Expand Down
4 changes: 2 additions & 2 deletions ugs-core/src/resources/firmware_config/tinyg.json
@@ -1,6 +1,6 @@
{
"Name": "TinyG",
"Version": 4,
"Version": 5,
"Controller": {
"name": "TinyG",
"args": null
Expand Down Expand Up @@ -47,7 +47,7 @@
"enabled": true,
"optional": true
},{
"name": "M3Dweller",
"name": "SpindleOnDweller",
"enabled": false,
"optional": true,
"args": {
Expand Down
Expand Up @@ -25,14 +25,14 @@ This file is part of Universal Gcode Sender (UGS).
*
* @author wwinder
*/
public class M3DwellerTest {
public class SpindleOnDwellerTest {

public M3DwellerTest() {
public SpindleOnDwellerTest() {
}

@Test
public void testReplaces() throws Exception {
M3Dweller dweller = new M3Dweller(2.5);
SpindleOnDweller dweller = new SpindleOnDweller(2.5);
String command;

command = "M3";
Expand All @@ -49,11 +49,26 @@ public void testReplaces() throws Exception {

command = "(this is ignored) M3 S1000";
Assertions.assertThat(dweller.processCommand(command, null)).containsExactly(command,"G4P2.50");

command = "M4";
Assertions.assertThat(dweller.processCommand(command, null)).containsExactly(command,"G4P2.50");

command = "m4";
Assertions.assertThat(dweller.processCommand(command, null)).containsExactly(command,"G4P2.50");

command = "M4 S1000";
Assertions.assertThat(dweller.processCommand(command, null)).containsExactly(command,"G4P2.50");

command = "m4 S1000";
Assertions.assertThat(dweller.processCommand(command, null)).containsExactly(command,"G4P2.50");

command = "(this is ignored) M4 S1000";
Assertions.assertThat(dweller.processCommand(command, null)).containsExactly(command,"G4P2.50");
}

@Test
public void testNoOp() throws Exception {
M3Dweller dweller = new M3Dweller(2.5);
SpindleOnDweller dweller = new SpindleOnDweller(2.5);
String command;
command = "anything else";
Assertions.assertThat(dweller.processCommand(command, null)).containsExactly(command);
Expand Down

0 comments on commit 4da7db7

Please sign in to comment.