From 6abc69bec03052319960eb698e486934bc89e67c Mon Sep 17 00:00:00 2001
From: Michael Adams <michael@michaeladams.org>
Date: Sun, 21 Feb 2016 23:54:21 +1300
Subject: [PATCH] Add configurable option to blank laser during G0 rapid moves.
 Fixes issues in PR #38 for Smoothie boards

---
 .../drivers/GenericGcodeDriver.java           | 29 +++++++++++++++++--
 .../t_oster/liblasercut/drivers/Marlin.java   |  2 ++
 .../liblasercut/drivers/SmoothieBoard.java    |  2 ++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/src/com/t_oster/liblasercut/drivers/GenericGcodeDriver.java b/src/com/t_oster/liblasercut/drivers/GenericGcodeDriver.java
index 7fe9b39..a6818dd 100644
--- a/src/com/t_oster/liblasercut/drivers/GenericGcodeDriver.java
+++ b/src/com/t_oster/liblasercut/drivers/GenericGcodeDriver.java
@@ -64,6 +64,7 @@ public class GenericGcodeDriver extends LaserCutter {
   protected static final String SETTING_WAIT_FOR_OK = "Wait for OK after each line (interactive mode)";
   protected static final String SETTING_INIT_DELAY = "Seconds to wait for board reset (Serial)";
   protected static final String SETTING_SERIAL_TIMEOUT = "Milliseconds to wait for response";
+  protected static final String SETTING_BLANK_LASER_DURING_RAPIDS = "Blank laser during non-laser moves";
   
   protected static Locale FORMAT_LOCALE = Locale.US;
   
@@ -294,6 +295,18 @@ public class GenericGcodeDriver extends LaserCutter {
     this.travel_speed = travel_speed;
   }
   
+  protected boolean blankLaserDuringRapids = false;
+  
+  public boolean getBlankLaserDuringRapids()
+  {
+    return blankLaserDuringRapids;
+  }
+  
+  public void setBlankLaserDuringRapids(boolean blankLaserDuringRapids)
+  {
+    this.blankLaserDuringRapids = blankLaserDuringRapids;
+  }
+  
   @Override
   /**
    * We do not support Frequency atm, so we return power,speed and focus
@@ -362,8 +375,15 @@ public class GenericGcodeDriver extends LaserCutter {
     x = isFlipXaxis() ? getBedWidth() - Util.px2mm(x, resolution) : Util.px2mm(x, resolution);
     y = isFlipYaxis() ? getBedHeight() - Util.px2mm(y, resolution) : Util.px2mm(y, resolution);
     currentSpeed = getTravel_speed();
-    currentPower = 0.0;
-    sendLine("G0 X%f Y%f S0 F%d", x, y, (int) (travel_speed));
+    if (blankLaserDuringRapids)
+    {
+      currentPower = 0.0;
+      sendLine("G0 X%f Y%f F%d S0", x, y, (int) (travel_speed));
+    }
+    else
+    {
+      sendLine("G0 X%f Y%f F%d", x, y, (int) (travel_speed));
+    }
   }
 
   protected void line(PrintStream out, double x, double y, double resolution) throws IOException {
@@ -790,6 +810,7 @@ public void saveJob(java.io.PrintStream fileOutputStream, LaserJob job) throws I
     SETTING_LINEEND,
     SETTING_MAX_SPEED,
     SETTING_TRAVEL_SPEED,
+    SETTING_BLANK_LASER_DURING_RAPIDS,
     SETTING_PRE_JOB_GCODE,
     SETTING_POST_JOB_GCODE,
     SETTING_RESOLUTIONS,
@@ -844,6 +865,8 @@ public void saveJob(java.io.PrintStream fileOutputStream, LaserJob job) throws I
       return this.isWaitForOKafterEachLine();
     } else if (SETTING_SERIAL_TIMEOUT.equals(attribute)) {
       return this.getSerialTimeout();
+    } else if (SETTING_BLANK_LASER_DURING_RAPIDS.equals(attribute)) {
+      return this.getBlankLaserDuringRapids();
     }
     
     return null;
@@ -891,6 +914,8 @@ public void saveJob(java.io.PrintStream fileOutputStream, LaserJob job) throws I
       this.setWaitForOKafterEachLine((Boolean) value);
     } else if (SETTING_SERIAL_TIMEOUT.equals(attribute)) {
       this.setSerialTimeout((Integer) value);
+    } else if (SETTING_BLANK_LASER_DURING_RAPIDS.equals(attribute)) {
+      this.setBlankLaserDuringRapids((Boolean) value);
     }
   }
 
diff --git a/src/com/t_oster/liblasercut/drivers/Marlin.java b/src/com/t_oster/liblasercut/drivers/Marlin.java
index 6c2a6dc..00b90e7 100644
--- a/src/com/t_oster/liblasercut/drivers/Marlin.java
+++ b/src/com/t_oster/liblasercut/drivers/Marlin.java
@@ -42,6 +42,7 @@ public class Marlin extends GenericGcodeDriver {
     setPreJobGcode(getPreJobGcode()+",G28 XY,M5");
     setPostJobGcode(getPostJobGcode()+",M5,G28 XY");
     setSerialTimeout(35000);
+    setBlankLaserDuringRapids(false);
     
     //Marlin has no way to upload over the network so remove the upload url text
     setHttpUploadUrl("");
@@ -65,6 +66,7 @@ public class Marlin extends GenericGcodeDriver {
     result.remove(GenericGcodeDriver.SETTING_INIT_DELAY);
     result.remove(GenericGcodeDriver.SETTING_HTTP_UPLOAD_URL);
     result.remove(GenericGcodeDriver.SETTING_HOST);
+    result.remove(GenericGcodeDriver.SETTING_BLANK_LASER_DURING_RAPIDS);
     return result.toArray(new String[0]);
   }
   
diff --git a/src/com/t_oster/liblasercut/drivers/SmoothieBoard.java b/src/com/t_oster/liblasercut/drivers/SmoothieBoard.java
index 6eef4cb..5609e32 100644
--- a/src/com/t_oster/liblasercut/drivers/SmoothieBoard.java
+++ b/src/com/t_oster/liblasercut/drivers/SmoothieBoard.java
@@ -40,6 +40,7 @@ public class SmoothieBoard extends GenericGcodeDriver {
     setInitDelay(0);
     setPreJobGcode(getPreJobGcode()+",M3");
     setPostJobGcode(getPostJobGcode()+",M5");
+    setBlankLaserDuringRapids(false);
   }
   
   @Override
@@ -77,6 +78,7 @@ public class SmoothieBoard extends GenericGcodeDriver {
     result.remove(GenericGcodeDriver.SETTING_BAUDRATE);
     result.remove(GenericGcodeDriver.SETTING_LINEEND);
     result.remove(GenericGcodeDriver.SETTING_INIT_DELAY);
+    result.remove(GenericGcodeDriver.SETTING_BLANK_LASER_DURING_RAPIDS);
     return result.toArray(new String[0]);
   }
 
-- 
GitLab