Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added marlin gcode support and marlin fan pwm #1782

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
59 changes: 53 additions & 6 deletions LaserGRBL/Core/GrblCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace LaserGRBL
{
public enum Firmware
public enum Firmware
{ Grbl, Smoothie, Marlin, VigoWork }

/// <summary>
Expand Down Expand Up @@ -84,6 +84,29 @@ public enum DetectedIssue
MachineAlarm = 5,
}

public enum PwmMode
{
Spindle = 0,
Fan = 1,
}

public enum SpindleState
{
ON = 0,
OFF = 1,
}

public class SpindleConfig
{
public string lOn;
public string lOff;
public bool pwm;
public Firmware firmwareType;
public int dwelltime;
public int fanId;
public GrblCore.PwmMode pwmMode;
}

public enum MacStatus
{ Disconnected, Connecting, Idle, Run, Hold, Door, Home, Alarm, Check, Jog, Queue, Cooling, AutoHold, Tool } // "Tool" added in GrblHal

Expand Down Expand Up @@ -262,7 +285,7 @@ public int OrturFWVersionNumber
private System.Windows.Forms.Control syncro;
protected ComWrapper.IComWrapper com;
private GrblFile file;
private System.Collections.Generic.Queue<GrblCommand> mQueue; //vera coda di quelli da mandare
protected System.Collections.Generic.Queue<GrblCommand> mQueue; //vera coda di quelli da mandare
private GrblCommand mRetryQueue; //coda[1] di quelli in attesa di risposta
private System.Collections.Generic.Queue<GrblCommand> mPending; //coda di quelli in attesa di risposta
private System.Collections.Generic.List<IGrblRow> mSent; //lista di quelli mandati
Expand Down Expand Up @@ -316,9 +339,12 @@ public int OrturFWVersionNumber

public UsageStats.UsageCounters UsageCounters;

protected SpindleConfig mSpindleConfig;

private string mDetectedIP = null;



public GrblCore(System.Windows.Forms.Control syncroObject, PreviewForm cbform, JogForm jogform)
{
if (Type != Firmware.Grbl) Logger.LogMessage("Program", "Load {0} core", Type);
Expand Down Expand Up @@ -1167,8 +1193,17 @@ public void AbortProgram()

lock (this)
{
GrblCommand stop = null;
if(Settings.GetObject("Firmware Type", Firmware.Grbl) == Firmware.Marlin && Settings.GetObject("Pwm Selection", GrblCore.PwmMode.Spindle) == GrblCore.PwmMode.Fan)
{
stop = new GrblCommand("M107");
}
else
{
stop = new GrblCommand("M5");
}
mQueue.Clear(); //flush the queue of item to send
mQueue.Enqueue(new GrblCommand("M5")); //shut down laser
mQueue.Enqueue(stop); //shut down laser
}
}
catch (Exception ex)
Expand Down Expand Up @@ -1394,7 +1429,7 @@ public void CycleStartResume(bool auto)
}
}

public void FeedHold(bool cooling)
public virtual void FeedHold(bool cooling)
{
if (CanFeedHold)
{
Expand Down Expand Up @@ -2751,7 +2786,7 @@ internal void HKDisconnect()
internal void HelpOnLine()
{ Tools.Utils.OpenLink(@"https://lasergrbl.com/usage/"); }

internal void GrblHoming()
internal virtual void GrblHoming()
{ if (CanDoHoming) EnqueueCommand(new GrblCommand("$H")); }

internal void GrblUnlock()
Expand Down Expand Up @@ -2921,7 +2956,19 @@ private static IEnumerable<GrblCommand> StringToGCode(string input)
}
}

public virtual bool UIShowGrblConfig => true;
public void configureSpindle(SpindleConfig SpindleConfig)
{
mSpindleConfig = SpindleConfig;
}

public virtual List<String> getSpindleGcode(SpindleState state , int power)
{
List<string> LaserCmd = new List<string>();
LaserCmd.Add(String.Format("{0} S{1}", state == SpindleState.ON ? mSpindleConfig.lOn : mSpindleConfig.lOff, power));
return LaserCmd;
}

public virtual bool UIShowGrblConfig => true;
public virtual bool UIShowUnlockButtons => true;

public bool IsOrturBoard { get => GrblVersion != null && GrblVersion.IsOrtur; }
Expand Down
64 changes: 62 additions & 2 deletions LaserGRBL/Core/MarlinCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ protected override void ParseMachineStatus(string data)

if (data.Contains("ok"))
var = MacStatus.Idle;
if (data.Contains("echo:busy:") || data.Contains("echo: busy:"))
{
var = MacStatus.Run;
}

//try { var = (MacStatus)Enum.Parse(typeof(MacStatus), data); }
//catch (Exception ex) { Logger.LogException("ParseMachineStatus", ex); }
Expand All @@ -72,7 +76,38 @@ public override void RefreshMachineInfo()

}

protected override void DetectHang()
internal override void SendHomingCommand()
{
EnqueueCommand(new GrblCommand("G28"));
}

public override List<String> getSpindleGcode(SpindleState state, int power)
{
List<string> LaserCmd = new List<string>();
if (mSpindleConfig.pwmMode == GrblCore.PwmMode.Fan)
{
LaserCmd.Add(String.Format("G4 P0"));
if(state == SpindleState.ON)
LaserCmd.Add(String.Format("{0} S{1} P{2}", mSpindleConfig.lOn , power, mSpindleConfig.fanId)); //laser on and power to zero
else
LaserCmd.Add(String.Format("{0} P{1}", mSpindleConfig.lOff, mSpindleConfig.fanId)); //laser on and power to zero
if (state == SpindleState.ON && power > 0)
LaserCmd.Add(String.Format("G4 P{0}", mSpindleConfig.dwelltime));
}
else
{
if (state == SpindleState.ON)
LaserCmd.Add(String.Format("{0} S{1}", mSpindleConfig.lOn , power));
else
LaserCmd.Add(String.Format("{0}", mSpindleConfig.lOn));
}
return LaserCmd;
}

internal override void GrblHoming()
{ if (CanDoHoming) EnqueueCommand(new GrblCommand("G28")); }

protected override void DetectHang()
{
if (mTP.LastIssue == DetectedIssue.Unknown && MachineStatus == MacStatus.Run && InProgram)
{
Expand All @@ -91,10 +126,35 @@ protected override void DetectHang()
}
}

protected override void ManageReceivedLine(string rline)
public override void FeedHold(bool auto)
{
if (CanFeedHold)
{
mHoldByUserRequest = !auto;
GrblCommand stop = null;
if (Settings.GetObject("Firmware Type", Firmware.Grbl) == Firmware.Marlin && Settings.GetObject("Pwm Selection", GrblCore.PwmMode.Spindle) == GrblCore.PwmMode.Fan)
{
stop = new GrblCommand("M107");
}
else
{
stop = new GrblCommand("M5");
}
mQueue.Clear(); //flush the queue of item to send
mQueue.Enqueue(stop); //shut down laser
mQueue.Enqueue(new GrblCommand("M112"));
}
}

protected override void ManageReceivedLine(string rline)
{
if (IsMarlinRealTimeStatusMessage(rline))
ManageMarlinRealTimeStatus(rline);
else if(rline.Contains("echo:busy:") || rline.Contains("echo: busy:"))
{
SetStatus(MacStatus.Run);
debugLastStatusDelay.Start();
}
else
base.ManageReceivedLine(rline);
}
Expand Down
12 changes: 6 additions & 6 deletions LaserGRBL/CsPotrace/CsPotraceExportGCODE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class Potrace
/// <param name="Width">Width of the exportd cvg-File</param>
/// <param name="Height">Height of the exportd cvg-File</param>
/// <returns></returns>
public static List<string> Export2GCode(List<List<CsPotrace.Curve>> list, float oX, float oY, double scale, string lOn, string lOff, Size originalImageSize, string skipcmd)
public static List<string> Export2GCode(List<List<CsPotrace.Curve>> list, float oX, float oY, double scale, List<string> lOn, List<string> lOff, Size originalImageSize, string skipcmd)
{
bool debug = false;

Expand Down Expand Up @@ -55,7 +55,7 @@ public static List<string> Export2GCode(List<List<CsPotrace.Curve>> list, float
return rv;
}

private static List<string> GetPathGC(List<CsPotrace.Curve> Curves, string lOn, string lOff, double oX, double oY, double scale, Graphics g, string skipcmd)
private static List<string> GetPathGC(List<CsPotrace.Curve> Curves, List<string> lOn, List<string> lOff, double oX, double oY, double scale, Graphics g, string skipcmd)
{
List<string> rv = new List<string>();

Expand Down Expand Up @@ -125,22 +125,22 @@ private static void OnPathSegment(CsPotrace.Curve Curve, double oX, double oY, d
}
}

private static void OnPathBegin(List<CsPotrace.Curve> Curves, string lOn, double oX, double oY, double scale, List<string> rv, string skipcmd)
private static void OnPathBegin(List<CsPotrace.Curve> Curves, List<string> lOn, double oX, double oY, double scale, List<string> rv, string skipcmd)
{
if (Curves.Count > 0)
{
//fast go to position
rv.Add(String.Format("{0} X{1} Y{2}", skipcmd, formatnumber(Curves[0].A.X + oX, scale), formatnumber(Curves[0].A.Y + oY, scale)));
//turn on laser
rv.Add(lOn);
rv.AddRange(lOn);
}
}

private static void OnPathEnd(List<CsPotrace.Curve> Curves, string lOff, double oX, double oY, double scale, List<string> rv)
private static void OnPathEnd(List<CsPotrace.Curve> Curves, List<string> lOff, double oX, double oY, double scale, List<string> rv)
{
//turn off laser
if (Curves.Count > 0)
rv.Add(lOff);
rv.AddRange(lOff);
}

private static string GetArcGC(Arc arc, double oX, double oY, double scale, Graphics g)
Expand Down
Loading