Find the filament diameter in our gcode files

This commit is contained in:
Lars Brubaker 2018-06-12 11:11:28 -07:00
parent 85822cefd0
commit 790d68f8da
2 changed files with 22 additions and 5 deletions

View file

@ -882,22 +882,24 @@ namespace MatterControl.Printing
{
if (filamentDiameterCache == 0)
{
for (int i = 0; i < Math.Min(20, GCodeCommandQueue.Count); i++)
// check the beginning of the file for the filament diameter
for (int i = 0; i < Math.Min(100, GCodeCommandQueue.Count); i++)
{
if (GetFirstNumberAfter("filamentDiameter =", GCodeCommandQueue[i].Line, ref filamentDiameterCache))
if(FindDiameter(i, ref filamentDiameterCache))
{
break;
}
}
// check the end of the file for the filament diameter
if (filamentDiameterCache == 0)
{
// didn't find it, so look at the end of the file for filament_diameter =
string lookFor = "; filament_diameter =";// 2.85
for (int i = GCodeCommandQueue.Count - 1; i > Math.Max(0, GCodeCommandQueue.Count - 100); i--)
{
if (GetFirstNumberAfter(lookFor, GCodeCommandQueue[i].Line, ref filamentDiameterCache))
if (FindDiameter(i, ref filamentDiameterCache))
{
break;
}
}
}
@ -912,6 +914,21 @@ namespace MatterControl.Printing
return filamentDiameterCache;
}
private bool FindDiameter(int lineIndex, ref double filamentDiameterCache)
{
if (GetFirstNumberAfter("filamentDiameter = ", GCodeCommandQueue[lineIndex].Line, ref filamentDiameterCache, 0, ""))
{
return true;
}
if (GetFirstNumberAfter("; filament_diameter = ", GCodeCommandQueue[lineIndex].Line, ref filamentDiameterCache, 0, ""))
{
return true;
}
return false;
}
public override double GetLayerHeight(int layerIndex)
{
if (layerHeights.Count > 0)