Removed active printer static

issue: MatterHackers/MCCentral#4562
GCodeStream
This commit is contained in:
Lars Brubaker 2018-11-12 15:02:47 -08:00
parent 0e3225e529
commit 844f97a060
24 changed files with 4119 additions and 83 deletions

View file

@ -41,12 +41,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private MaxLengthStream maxLengthStream;
private OffsetStream offsetStream;
private EventHandler unregisterEvents;
private PrinterConfig printer;
public BabyStepsStream(PrinterConfig printer, GCodeStream internalStream, double startingMaxLength = 1)
: base(null)
: base(printer, internalStream)
{
this.printer = printer;
PrinterSettings.SettingChanged.RegisterEvent((s, e) =>
{
if ((e as StringEventArgs)?.Data == SettingsKey.baby_step_z_offset)
@ -55,8 +53,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
}
}, ref unregisterEvents);
maxLengthStream = new MaxLengthStream(internalStream, startingMaxLength);
offsetStream = new OffsetStream(maxLengthStream, new Vector3(0, 0, printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset)));
maxLengthStream = new MaxLengthStream(printer, internalStream, startingMaxLength);
offsetStream = new OffsetStream(maxLengthStream, printer, new Vector3(0, 0, printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset)));
base.internalStream = offsetStream;
}

View file

@ -36,8 +36,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private double currentActualExtrusionPosition = 0;
private double previousGcodeRequestedExtrusionPosition = 0;
public ExtrusionMultiplyerStream(GCodeStream internalStream)
: base(internalStream)
public ExtrusionMultiplyerStream(PrinterConfig printer, GCodeStream internalStream)
: base(printer, internalStream)
{
}

View file

@ -37,8 +37,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
public PrinterMove LastDestination { get; private set; }
public FeedRateMultiplyerStream(GCodeStream internalStream)
: base(internalStream)
public FeedRateMultiplyerStream(PrinterConfig printer, GCodeStream internalStream)
: base(printer, internalStream)
{
}

View file

@ -36,7 +36,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private int printerCommandQueueLineIndex = -1;
public GCodeFile GCodeFile { get; }
public GCodeFileStream(GCodeFile fileStreaming, int startLine = 0)
public GCodeFileStream(GCodeFile fileStreaming, PrinterConfig printer, int startLine = 0)
: base(printer)
{
this.GCodeFile = fileStreaming;
printerCommandQueueLineIndex = startLine;

View file

@ -49,9 +49,15 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
bool useG0ForMovement = false;
public GCodeStream()
protected PrinterConfig printer { get; }
public GCodeStream(PrinterConfig printer)
{
useG0ForMovement = ApplicationController.Instance.ActivePrinter.Settings.GetValue<bool>(SettingsKey.g0);
this.printer = printer;
if (printer != null)
{
useG0ForMovement = printer.Settings.GetValue<bool>(SettingsKey.g0);
}
}
public string CreateMovementLine(PrinterMove currentDestination)

View file

@ -41,7 +41,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
protected GCodeStream internalStream;
public GCodeStreamProxy(GCodeStream internalStream)
public GCodeStreamProxy(PrinterConfig printer, GCodeStream internalStream)
: base(printer)
{
this.internalStream = internalStream;
}

View file

@ -38,13 +38,12 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
public class GCodeSwitcher : GCodeStream
{
private GCodeMemoryFile switchToGCode = null;
PrinterConnection printerConnection;
private object locker = new object();
private List<string> commandQueue = new List<string>();
public GCodeSwitcher(string gcodeFilename, PrinterConnection printerConnection, int startLine = 0)
public GCodeSwitcher(string gcodeFilename, PrinterConfig printer, int startLine = 0)
: base(printer)
{
this.printerConnection = printerConnection;
var fileStreaming = GCodeFile.Load(gcodeFilename,
new Vector4(),
new Vector4(),

View file

@ -39,8 +39,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private double maxSecondsPerSegment = 1.0 / 20.0;
private List<PrinterMove> movesToSend = new List<PrinterMove>();
public MaxLengthStream(GCodeStream internalStream, double maxSegmentLength)
: base(internalStream)
public MaxLengthStream(PrinterConfig printer, GCodeStream internalStream, double maxSegmentLength)
: base(printer, internalStream)
{
this.MaxSegmentLength = maxSegmentLength;
}

View file

@ -39,7 +39,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
public class NotPrintingStream : GCodeStream
{
public NotPrintingStream()
public NotPrintingStream(PrinterConfig printer)
: base(printer)
{
}

View file

@ -42,8 +42,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
protected PrinterMove lastDestination = new PrinterMove();
public PrinterMove LastDestination { get { return lastDestination; } }
public OffsetStream(GCodeStream internalStream, Vector3 offset)
: base(internalStream)
public OffsetStream(GCodeStream internalStream, PrinterConfig printer, Vector3 offset)
: base(printer, internalStream)
{
this.offset = offset;
}

View file

@ -48,14 +48,12 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private PrinterMove moveLocationAtEndOfPauseCode;
private Stopwatch timeSinceLastEndstopRead = new Stopwatch();
bool readOutOfFilament = false;
private PrinterConfig printer;
private EventHandler unregisterEvents;
public PauseHandlingStream(PrinterConfig printer, GCodeStream internalStream)
: base(internalStream)
: base(printer, internalStream)
{
this.printer = printer;
printer.Connection.LineReceived += (s, line) =>
{
if (line != null)

View file

@ -40,14 +40,12 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private double currentProbeOffset;
private bool wroteLevelingStatus = false;
private bool gcodeAlreadyLeveled = false;
private PrinterConfig printer;
public PrintLevelingStream(PrinterConfig printer, GCodeStream internalStream, bool activePrinting)
: base(internalStream)
: base(printer, internalStream)
{
// always reset this when we construct
AllowLeveling = true;
this.printer = printer;
this.activePrinting = activePrinting;
}

View file

@ -46,11 +46,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
RectangleDouble boundsOfSkippedLayers = RectangleDouble.ZeroIntersection;
public RecoveryState RecoveryState { get; private set; } = RecoveryState.RemoveHeating;
private PrinterConfig printer;
public PrintRecoveryStream(PrinterConfig printer, GCodeSwitcher internalStream, double percentDone)
public PrintRecoveryStream(GCodeSwitcher internalStream, PrinterConfig printer, double percentDone)
: base(printer)
{
this.printer = printer;
this.internalStream = internalStream;
this.percentDone = percentDone;
@ -61,7 +60,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
}
recoverFeedRate *= 60;
queuedCommands = new QueuedCommandsStream(null);
queuedCommands = new QueuedCommandsStream(printer, null);
}
public override void Dispose()

View file

@ -44,12 +44,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private QueuedCommandsStream queueStream;
private PrinterConfig printer;
public ProcessWriteRegexStream(PrinterConfig printer, GCodeStream internalStream, QueuedCommandsStream queueStream)
: base(internalStream)
: base(printer, internalStream)
{
this.printer = printer;
this.queueStream = queueStream;
}

View file

@ -45,8 +45,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private List<string> commandQueue = new List<string>();
private object locker = new object();
public QueuedCommandsStream(GCodeStream internalStream)
: base(internalStream)
public QueuedCommandsStream(PrinterConfig printer, GCodeStream internalStream)
: base(printer, internalStream)
{
}

View file

@ -44,8 +44,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
bool xyzAbsoluteMode = true;
bool eAbsoluteMode = true;
public RelativeToAbsoluteStream(GCodeStream internalStream)
: base(internalStream)
public RelativeToAbsoluteStream(PrinterConfig printer, GCodeStream internalStream)
: base(printer, internalStream)
{
}

View file

@ -35,20 +35,18 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
public class RequestTemperaturesStream : GCodeStreamProxy
{
private long nextReadTimeMs = 0;
PrinterConnection printerConnection;
public RequestTemperaturesStream(PrinterConnection printerConnection, GCodeStream internalStream)
: base(internalStream)
public RequestTemperaturesStream(PrinterConfig printer, GCodeStream internalStream)
: base(printer, internalStream)
{
this.printerConnection = printerConnection;
nextReadTimeMs = UiThread.CurrentTimerMs + 1000;
}
public override string ReadLine()
{
if (!printerConnection.WaitingForPositionRead
if (!printer.Connection.WaitingForPositionRead
&& nextReadTimeMs < UiThread.CurrentTimerMs
&& printerConnection.IsConnected)
&& printer.Connection.IsConnected)
{
nextReadTimeMs = UiThread.CurrentTimerMs + 1000;
return "M105";

View file

@ -36,12 +36,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
public class SendProgressStream : GCodeStreamProxy
{
private double nextPercent = -1;
PrinterConfig printer;
public SendProgressStream(PrinterConfig printer, GCodeStream internalStream)
: base(internalStream)
public SendProgressStream(GCodeStream internalStream, PrinterConfig printer)
: base(printer, internalStream)
{
this.printer = printer;
}
public override string ReadLine()

View file

@ -51,12 +51,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private Stopwatch timeHaveBeenAtTemp = new Stopwatch();
private bool waitWhenCooling = false;
PrinterConnection printerConnection;
public WaitForTempStream(PrinterConnection printerConnection, GCodeStream internalStream)
: base(internalStream)
public WaitForTempStream(PrinterConfig printer, GCodeStream internalStream)
: base(printer, internalStream)
{
this.printerConnection = printerConnection;
state = State.passthrough;
}
@ -142,7 +140,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
case State.waitingForExtruderTemp:
{
double extruderTemp = printerConnection.GetActualHotendTemperature((int)extruderIndex);
double extruderTemp = printer.Connection.GetActualHotendTemperature((int)extruderIndex);
bool tempWithinRange = extruderTemp >= targetTemp - sameTempRangeHotend
&& extruderTemp <= targetTemp + sameTempRangeHotend;
if (tempWithinRange && !timeHaveBeenAtTemp.IsRunning)
@ -151,7 +149,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
}
if (timeHaveBeenAtTemp.Elapsed.TotalSeconds > WaitAfterReachTempTime
|| printerConnection.PrintWasCanceled)
|| printer.Connection.PrintWasCanceled)
{
// switch to pass through and continue
state = State.passthrough;
@ -167,7 +165,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
case State.waitingForBedTemp:
{
double bedTemp = printerConnection.ActualBedTemperature;
double bedTemp = printer.Connection.ActualBedTemperature;
bool tempWithinRange;
if (waitWhenCooling)
{
@ -186,7 +184,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
}
if (timeHaveBeenAtTemp.Elapsed.TotalSeconds > WaitAfterReachTempTime
|| printerConnection.PrintWasCanceled)
|| printer.Connection.PrintWasCanceled)
{
// switch to pass through and continue
state = State.passthrough;

View file

@ -2063,19 +2063,19 @@ namespace MatterHackers.MatterControl.PrinterCommunication
GCodeStream firstStreamToRead = null;
if (gcodeFilename != null)
{
gCodeFileSwitcher0 = new GCodeSwitcher(gcodeFilename, this);
gCodeFileSwitcher0 = new GCodeSwitcher(gcodeFilename, printer);
if (this.RecoveryIsEnabled
&& activePrintTask != null) // We are resuming a failed print (do lots of interesting stuff).
{
sendProgressStream1 = new SendProgressStream(printer, new PrintRecoveryStream(printer, gCodeFileSwitcher0, activePrintTask.PercentDone));
sendProgressStream1 = new SendProgressStream(new PrintRecoveryStream(gCodeFileSwitcher0, printer, activePrintTask.PercentDone), printer);
// And increment the recovery count
activePrintTask.RecoveryCount++;
activePrintTask.Commit();
}
else
{
sendProgressStream1 = new SendProgressStream(printer, gCodeFileSwitcher0);
sendProgressStream1 = new SendProgressStream(gCodeFileSwitcher0, printer);
}
pauseHandlingStream2 = new PauseHandlingStream(printer, sendProgressStream1);
@ -2084,11 +2084,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication
else
{
gCodeFileSwitcher0 = null;
firstStreamToRead = new NotPrintingStream();
firstStreamToRead = new NotPrintingStream(printer);
}
queuedCommandStream3 = new QueuedCommandsStream(firstStreamToRead);
relativeToAbsoluteStream4 = new RelativeToAbsoluteStream(queuedCommandStream3);
queuedCommandStream3 = new QueuedCommandsStream(printer, firstStreamToRead);
relativeToAbsoluteStream4 = new RelativeToAbsoluteStream(printer, queuedCommandStream3);
bool enableLineSpliting = gcodeFilename != null && printer.Settings.GetValue<bool>(SettingsKey.enable_line_splitting);
babyStepsStream5 = new BabyStepsStream(printer, relativeToAbsoluteStream4, enableLineSpliting ? 1 : 2000);
if (activePrintTask != null)
@ -2097,10 +2097,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication
babyStepsStream5.Offset = new Vector3(activePrintTask.PrintingOffsetX, activePrintTask.PrintingOffsetY, activePrintTask.PrintingOffsetZ);
}
printLevelingStream6 = new PrintLevelingStream(printer, babyStepsStream5, true);
waitForTempStream7 = new WaitForTempStream(this, printLevelingStream6);
extrusionMultiplyerStream8 = new ExtrusionMultiplyerStream(waitForTempStream7);
feedrateMultiplyerStream9 = new FeedRateMultiplyerStream(extrusionMultiplyerStream8);
requestTemperaturesStream10 = new RequestTemperaturesStream(this, feedrateMultiplyerStream9);
waitForTempStream7 = new WaitForTempStream(printer, printLevelingStream6);
extrusionMultiplyerStream8 = new ExtrusionMultiplyerStream(printer, waitForTempStream7);
feedrateMultiplyerStream9 = new FeedRateMultiplyerStream(printer, extrusionMultiplyerStream8);
requestTemperaturesStream10 = new RequestTemperaturesStream(printer, feedrateMultiplyerStream9);
processWriteRegExStream11 = new ProcessWriteRegexStream(printer, requestTemperaturesStream10, queuedCommandStream3);
totalGCodeStream = processWriteRegExStream11;