cleaning warnings

This commit is contained in:
Lars Brubaker 2019-04-30 18:16:56 -07:00
parent 6631f5742a
commit fbbd2b959c
3 changed files with 29 additions and 24 deletions

View file

@ -38,7 +38,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
public class SettingsHelpers
{
private PrinterSettings printerSettings;
private readonly PrinterSettings printerSettings;
private PrintLevelingData _printLevelingData = null;
public SettingsHelpers(PrinterSettings printerSettings)
@ -70,10 +70,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
string[] userValues = printerSettings.GetValue("layer_to_pause").Split(';');
int temp;
return userValues.Where(v => int.TryParse(v, out temp)).Select(v =>
return userValues.Where(v => int.TryParse(v, out int temp)).Select(v =>
{
//Convert from 0 based index to 1 based index
// Convert from 0 based index to 1 based index
int val = int.Parse(v);
// Special case for user entered zero that pushes 0 to 1, otherwise val = val - 1 for 1 based index
@ -132,7 +131,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
_printLevelingData = JsonConvert.DeserializeObject<PrintLevelingData>(jsonData);
}
// TODO: When this case is hit, it's certain to produce impossible to troubleshoot behavior where leveled printers suddenly act erratically.
// TODO: When this case is hit, it's certain to produce impossible to troubleshoot behavior where leveled printers suddenly act erratically.
// Investigate a better solution - ideally we'd mark that leveling is invalid and have a validation error preventing printing/export/general use
if (_printLevelingData == null)
{
@ -142,6 +141,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
return _printLevelingData;
}
set
{
// Store new reference
@ -152,12 +152,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
}
private List<(Regex Regex, string Replacement)> _writeLineReplacements = new List<(Regex Regex, string Replacement)>();
private readonly List<(Regex Regex, string Replacement)> _writeLineReplacements = new List<(Regex Regex, string Replacement)>();
private string writeRegexString = "";
private static Regex getQuotedParts = new Regex(@"([""'])(\\?.)*?\1", RegexOptions.Compiled);
private static readonly Regex GetQuotedParts = new Regex(@"([""'])(\\?.)*?\1", RegexOptions.Compiled);
public List<(Regex Regex, string Replacement)> WriteLineReplacements
{
@ -172,7 +171,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
foreach (string regExLine in writeRegexString.Split(new string[] { "\\n" }, StringSplitOptions.RemoveEmptyEntries))
{
var matches = getQuotedParts.Matches(regExLine);
var matches = GetQuotedParts.Matches(regExLine);
if (matches.Count == 2)
{
var search = matches[0].Value.Substring(1, matches[0].Value.Length - 2);
@ -187,7 +186,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
}
public void DoPrintLeveling(bool doLeveling)
{
// Early exit if already set
@ -245,6 +243,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
newValue += ",";
}
newValue += $"{offset.X:0.###}x{offset.Y:0.###}x{offset.Z:0.###}";
first = false;
}
@ -275,6 +274,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
return new Vector3(double.Parse(xyz[0]), double.Parse(xyz[1]), double.Parse(xyz[2]));
}
}
count++;
}

View file

@ -59,6 +59,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
recoverFeedRate = 10;
}
recoverFeedRate *= 60;
queuedCommands = new QueuedCommandsStream(printer, null);
@ -74,7 +75,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
internalStream.SetPrinterPosition(lastDestination);
}
public override string ReadLine()
public override string ReadLine()
{
// Send any commands that are queue before moving on to the internal stream.
string nextCommand = queuedCommands.ReadLine();
@ -83,7 +84,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
lastLine = nextCommand;
return nextCommand;
}
switch (RecoveryState)
{
// heat the extrude to remove it from the part
@ -95,7 +96,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
queuedCommands.Add("G90; use absolute coordinates");
queuedCommands.Add("G92 E0; reset the expected extruder position");
queuedCommands.Add("M82; use absolute distance for extrusion");
bool hasHeatedBed = printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed);
double bedTemp = printer.Settings.GetValue<double>(SettingsKey.bed_temperature);
if (hasHeatedBed && bedTemp > 0)
@ -147,12 +148,13 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
// home z
queuedCommands.Add("G28 Z0");
}
// We now know where the printer is re-enable print leveling
printer.Connection.AllowLeveling = true;
RecoveryState = RecoveryState.FindingRecoveryLayer;
return "";
// This is to recover printing if an out a filament occurs.
// This is to recover printing if an out a filament occurs.
// Help the user move the extruder down to just touching the part
case RecoveryState.FindingRecoveryLayer:
if (false) // help the user get the head to the right position
@ -176,17 +178,19 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
while (internalStream.GCodeFile.PercentComplete(internalStream.LineIndex) < percentDone)
{
string line = internalStream.ReadLine();
if(line == null)
if (line == null)
{
break;
}
commandCount++;
// make sure we don't parse comments
if(line.Contains(";"))
if (line.Contains(";"))
{
line = line.Split(';')[0];
}
lastDestination = GetPosition(line, lastDestination);
if (commandCount > 100)
@ -209,7 +213,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
return line;
}
}
RecoveryState = RecoveryState.PrimingAndMovingToStart;
// make sure we always- pick up the last movement
@ -218,7 +222,6 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
case RecoveryState.PrimingAndMovingToStart:
{
if (printer.Settings.GetValue("z_homes_to_max") == "0") // we are homed to the bed
{
// move to the height we can recover printing from
@ -229,9 +232,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
double extruderWidth = printer.Settings.GetValue<double>(SettingsKey.nozzle_diameter);
// move to a position outside the printed bounds
queuedCommands.Add(CreateMovementLine(new PrinterMove(
new Vector3(boundsOfSkippedLayers.Left - extruderWidth*2, boundsOfSkippedLayers.Bottom + boundsOfSkippedLayers.Height / 2, lastDestination.position.Z),
0, printer.Settings.XSpeed())));
new Vector3(boundsOfSkippedLayers.Left - extruderWidth * 2, boundsOfSkippedLayers.Bottom + boundsOfSkippedLayers.Height / 2, lastDestination.position.Z),
0,
printer.Settings.XSpeed())));
// let's prime the extruder
queuedCommands.Add("G1 E10 F{0}".FormatWith(printer.Settings.EFeedRate(0))); // extrude 10
queuedCommands.Add("G1 E9"); // and retract a bit
@ -239,10 +243,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
// move to the actual print position
queuedCommands.Add(CreateMovementLine(new PrinterMove(lastDestination.position, 0, printer.Settings.XSpeed())));
/// reset the printer to know where the filament should be
// reset the printer to know where the filament should be
queuedCommands.Add("G92 E{0}".FormatWith(lastDestination.extrusion));
RecoveryState = RecoveryState.PrintingSlow;
}
return "";
case RecoveryState.PrintingSlow:

@ -1 +1 @@
Subproject commit b6c9515a7f6df15e24d52d208ab3a2e943910548
Subproject commit 8cdfe6d0fa3c7a178ceefb9cc9d14425e30cb121