Skip to content

Commit

Permalink
thread used in loading now exit...
Browse files Browse the repository at this point in the history
grbl command dispose managed
  • Loading branch information
GabeMx5 committed Jun 16, 2024
1 parent d3cb467 commit c81d63e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 67 deletions.
9 changes: 7 additions & 2 deletions LaserGRBL/GrblCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static void LoadAppropriateErrors(GrblCore.GrblVersionInfo value)
}
}

public partial class GrblCommand : ICloneable, IGrblRow
public partial class GrblCommand : ICloneable, IGrblRow, IDisposable
{
public class Element
{
Expand Down Expand Up @@ -474,7 +474,12 @@ public int ImageIndex

public override string ToString()
{ return this.mLine; }
}

public void Dispose()
{
LinkedDisplayList = null;
}
}

public class GrblMessage : IGrblRow
{
Expand Down
139 changes: 74 additions & 65 deletions LaserGRBL/GrblFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public enum CartesianQuadrant { I, II, III, IV, Mix, Unknown }
private ProgramRange mRange = new ProgramRange();
private TimeSpan mEstimatedTotalTime;
public List<GrblCommand> Commands => list;
private Tools.ThreadObject mLoadingThread = null;
private Thread mLoadingThread = null;

public GrblFile()
{
Expand All @@ -44,9 +44,18 @@ public GrblFile(decimal x, decimal y, decimal x1, decimal y1)
{
mRange.UpdateXYRange(new GrblCommand.Element('X', x), new GrblCommand.Element('Y', y), false);
mRange.UpdateXYRange(new GrblCommand.Element('X', x1), new GrblCommand.Element('Y', y1), false);
}
}

private void ClearList()
{
foreach (GrblCommand command in list)
{
command.Dispose();
}
list.Clear();
}

public void SaveGCODE(string filename, bool header, bool footer, bool between, int cycles, bool useLFLineEndings, GrblCore core)
public void SaveGCODE(string filename, bool header, bool footer, bool between, int cycles, bool useLFLineEndings, GrblCore core)
{
try
{
Expand Down Expand Up @@ -98,7 +107,7 @@ private void SafeLoadFile(ThreadStart loadFileAction)
MessageBox.Show(Strings.AlreadyLoading);
return;
}
mLoadingThread = new Tools.ThreadObject(null, 10, true, "SafeLoadFile", () =>
mLoadingThread = new Thread(new ThreadStart(() =>
{
try
{
Expand All @@ -112,7 +121,7 @@ private void SafeLoadFile(ThreadStart loadFileAction)
{
mLoadingThread = null;
}
}, ThreadPriority.Normal);
}));
mLoadingThread.Start();
}

Expand All @@ -125,7 +134,7 @@ public void LoadFile(string filename, bool append)
long start = Tools.HiResTimer.TotalMilliseconds;

if (!append)
list.Clear();
ClearList();

mRange.ResetRange();
if (System.IO.File.Exists(filename))
Expand Down Expand Up @@ -158,7 +167,7 @@ public void LoadImportedSVG(string filename, bool append, GrblCore core, ColorFi
long start = Tools.HiResTimer.TotalMilliseconds;

if (!append)
list.Clear();
ClearList();

mRange.ResetRange();

Expand Down Expand Up @@ -345,7 +354,7 @@ public void LoadImagePotrace(Bitmap bmp, string filename, bool UseSpotRemoval, i
long start = Tools.HiResTimer.TotalMilliseconds;

if (!append)
list.Clear();
ClearList();

//list.Add(new GrblCommand("G90")); //absolute (Moved to custom Header)

Expand Down Expand Up @@ -504,7 +513,7 @@ public void LoadImageL2L(Bitmap bmp, string filename, L2LConf c, bool append, Gr
long start = Tools.HiResTimer.TotalMilliseconds;

if (!append)
list.Clear();
ClearList();

mRange.ResetRange();

Expand Down Expand Up @@ -551,7 +560,7 @@ internal void GenerateCuttingTest(int f_col, int f_start, int f_end, int p_start

long start = Tools.HiResTimer.TotalMilliseconds;

list.Clear();
ClearList();
mRange.ResetRange();

double f_delta = f_col > 1 ? (f_end - f_start) / (double)(f_col - 1) : 0;
Expand Down Expand Up @@ -629,7 +638,7 @@ public void GenerateGreyscaleTest(int f_row, int s_col, int f_start, int f_end,

long start = Tools.HiResTimer.TotalMilliseconds;

list.Clear();
ClearList();
mRange.ResetRange();

bool forward = true;
Expand Down Expand Up @@ -745,7 +754,7 @@ internal void GenerateShakeTest(string axis, int flimit, int axislen, int cpower

long start = Tools.HiResTimer.TotalMilliseconds;

list.Clear();
ClearList();
mRange.ResetRange();

list.Add(new GrblCommand("M5")); //laser OFF
Expand Down Expand Up @@ -800,58 +809,58 @@ private void GenerateShakeTest2(string axis, int flimit, int axislen, int o, int
}
}

//internal void GenerateShakeTest(string axis, int flimit, int axislen, int cpower, int cspeed)
//{
// string filename = $"Shake Test {axis}";

// RiseOnFileLoading(filename);

// long start = Tools.HiResTimer.TotalMilliseconds;

// list.Clear();
// mRange.ResetRange();

// list.Add(new GrblCommand("M5")); //laser OFF
// list.Add(new GrblCommand("G1 F1000 X0 Y0 S0")); //move to origin (slowly)
// list.Add(new GrblCommand($"G1 F{cspeed} X7 Y10")); //positioning
// list.Add(new GrblCommand("M4")); //laser ON
// list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X13 Y10")); //drow cross
// list.Add(new GrblCommand("M5")); //laser OFF
// list.Add(new GrblCommand($"G1 F{cspeed} X10 Y7")); //positioning
// list.Add(new GrblCommand("M4")); //laser ON
// list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X10 Y13")); //drow cross
// list.Add(new GrblCommand("M5")); //laser OFF
// list.Add(new GrblCommand("G1 F1000 X10 Y10 S0")); //move to cross center (slowly)

// int ca = 10;
// int da = 1;
// while ((ca + da) < axislen)
// {
// ca += da;
// list.Add(new GrblCommand($"G1 F{flimit} {axis}{ca}"));
// ca -= da;
// list.Add(new GrblCommand($"G1 F{flimit} {axis}{ca}"));
// da += 5;
// }

// list.Add(new GrblCommand($"G1 F{cspeed} X7 Y10")); //positioning
// list.Add(new GrblCommand("M4")); //laser ON
// list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X13 Y10")); //drow cross
// list.Add(new GrblCommand("M5")); //laser OFF
// list.Add(new GrblCommand($"G1 F{cspeed} X10 Y7")); //positioning
// list.Add(new GrblCommand("M4")); //laser ON
// list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X10 Y13")); //drow cross
// list.Add(new GrblCommand("M5")); //laser OFF

// Analyze();
// long elapsed = Tools.HiResTimer.TotalMilliseconds - start;

// RiseOnFileLoaded(filename, elapsed);
//}

// For Marlin, as we sen M106 command, we need to know last color send
//private int lastColorSend = 0;
private void ImageLine2Line(Bitmap bmp, L2LConf c)
//internal void GenerateShakeTest(string axis, int flimit, int axislen, int cpower, int cspeed)
//{
// string filename = $"Shake Test {axis}";

// RiseOnFileLoading(filename);

// long start = Tools.HiResTimer.TotalMilliseconds;

// ClearList();
// mRange.ResetRange();

// list.Add(new GrblCommand("M5")); //laser OFF
// list.Add(new GrblCommand("G1 F1000 X0 Y0 S0")); //move to origin (slowly)
// list.Add(new GrblCommand($"G1 F{cspeed} X7 Y10")); //positioning
// list.Add(new GrblCommand("M4")); //laser ON
// list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X13 Y10")); //drow cross
// list.Add(new GrblCommand("M5")); //laser OFF
// list.Add(new GrblCommand($"G1 F{cspeed} X10 Y7")); //positioning
// list.Add(new GrblCommand("M4")); //laser ON
// list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X10 Y13")); //drow cross
// list.Add(new GrblCommand("M5")); //laser OFF
// list.Add(new GrblCommand("G1 F1000 X10 Y10 S0")); //move to cross center (slowly)

// int ca = 10;
// int da = 1;
// while ((ca + da) < axislen)
// {
// ca += da;
// list.Add(new GrblCommand($"G1 F{flimit} {axis}{ca}"));
// ca -= da;
// list.Add(new GrblCommand($"G1 F{flimit} {axis}{ca}"));
// da += 5;
// }

// list.Add(new GrblCommand($"G1 F{cspeed} X7 Y10")); //positioning
// list.Add(new GrblCommand("M4")); //laser ON
// list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X13 Y10")); //drow cross
// list.Add(new GrblCommand("M5")); //laser OFF
// list.Add(new GrblCommand($"G1 F{cspeed} X10 Y7")); //positioning
// list.Add(new GrblCommand("M4")); //laser ON
// list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X10 Y13")); //drow cross
// list.Add(new GrblCommand("M5")); //laser OFF

// Analyze();
// long elapsed = Tools.HiResTimer.TotalMilliseconds - start;

// RiseOnFileLoaded(filename, elapsed);
//}

// For Marlin, as we sen M106 command, we need to know last color send
//private int lastColorSend = 0;
private void ImageLine2Line(Bitmap bmp, L2LConf c)
{
bool fast = true;
List<ColorSegment> segments = GetSegments(bmp, c);
Expand Down Expand Up @@ -1377,7 +1386,7 @@ internal void LoadImageCenterline(Bitmap bmp, string filename, bool useCornerThr
long start = Tools.HiResTimer.TotalMilliseconds;

if (!append)
list.Clear();
ClearList();

mRange.ResetRange();

Expand Down

0 comments on commit c81d63e

Please sign in to comment.