Make PrinterConnection.PrinterSettings private, use PrinterConfig
This commit is contained in:
parent
294dd4a812
commit
e1f3dec6b1
28 changed files with 540 additions and 550 deletions
|
|
@ -52,14 +52,14 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
private List<double> startingExtruderTemps = new List<double>();
|
||||
private Stopwatch timeHaveBeenWaiting = new Stopwatch();
|
||||
private bool waitingForUserInput = false;
|
||||
private PrinterConnection printerConnection;
|
||||
private PrinterConfig printer;
|
||||
QueuedCommandsStream queuedCommandsStream;
|
||||
|
||||
public MacroProcessingStream(QueuedCommandsStream queuedCommandsStream, PrinterConnection printerConnection)
|
||||
public MacroProcessingStream(QueuedCommandsStream queuedCommandsStream, PrinterConfig printer)
|
||||
: base(queuedCommandsStream)
|
||||
{
|
||||
this.queuedCommandsStream = queuedCommandsStream;
|
||||
this.printerConnection = printerConnection;
|
||||
this.printer = printer;
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
|
|
@ -148,15 +148,15 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
if (!runningMacro)
|
||||
{
|
||||
runningMacro = true;
|
||||
int extruderCount = printerConnection.PrinterSettings.GetValue<int>(SettingsKey.extruder_count);
|
||||
int extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
|
||||
for (int i = 0; i < extruderCount; i++)
|
||||
{
|
||||
startingExtruderTemps.Add(printerConnection.GetTargetHotendTemperature(i));
|
||||
startingExtruderTemps.Add(printer.Connection.GetTargetHotendTemperature(i));
|
||||
}
|
||||
|
||||
if (printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_heated_bed))
|
||||
if (printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed))
|
||||
{
|
||||
startingBedTemp = printerConnection.TargetBedTemperature;
|
||||
startingBedTemp = printer.Connection.TargetBedTemperature;
|
||||
}
|
||||
}
|
||||
int parensAfterCommand = lineToSend.IndexOf('(', MacroPrefix.Length);
|
||||
|
|
@ -207,7 +207,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
WizardWindow.Show(new RunningMacroPage(printerConnection, macroData));
|
||||
WizardWindow.Show(new RunningMacroPage(printer.Connection, macroData));
|
||||
});
|
||||
break;
|
||||
|
||||
|
|
@ -225,7 +225,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
WizardWindow.Show(new RunningMacroPage(printerConnection, macroData));
|
||||
WizardWindow.Show(new RunningMacroPage(printer.Connection, macroData));
|
||||
});
|
||||
|
||||
break;
|
||||
|
|
@ -248,12 +248,12 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
runningMacro = false;
|
||||
for (int i = 0; i < startingExtruderTemps.Count; i++)
|
||||
{
|
||||
printerConnection.SetTargetHotendTemperature(i, startingExtruderTemps[i]);
|
||||
printer.Connection.SetTargetHotendTemperature(i, startingExtruderTemps[i]);
|
||||
}
|
||||
|
||||
if (printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_heated_bed))
|
||||
if (printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed))
|
||||
{
|
||||
printerConnection.TargetBedTemperature = startingBedTemp;
|
||||
printer.Connection.TargetBedTemperature = startingBedTemp;
|
||||
}
|
||||
}
|
||||
waitingForUserInput = false;
|
||||
|
|
|
|||
|
|
@ -48,15 +48,15 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
private PrinterMove moveLocationAtEndOfPauseCode;
|
||||
private Stopwatch timeSinceLastEndstopRead = new Stopwatch();
|
||||
bool readOutOfFilament = false;
|
||||
PrinterConnection printerConnection;
|
||||
private PrinterConfig printer;
|
||||
|
||||
private EventHandler unregisterEvents;
|
||||
|
||||
public PauseHandlingStream(PrinterConnection printerConnection, GCodeStream internalStream)
|
||||
public PauseHandlingStream(PrinterConfig printer, GCodeStream internalStream)
|
||||
: base(internalStream)
|
||||
{
|
||||
this.printerConnection = printerConnection;
|
||||
printerConnection.ReadLine.RegisterEvent((s, e) =>
|
||||
this.printer = printer;
|
||||
printer.Connection.ReadLine.RegisterEvent((s, e) =>
|
||||
{
|
||||
StringEventArgs currentEvent = e as StringEventArgs;
|
||||
if (currentEvent != null)
|
||||
|
|
@ -105,18 +105,18 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
|
||||
case PauseReason.PauseLayerReached:
|
||||
case PauseReason.GCodeRequest:
|
||||
printerConnection.PauseOnLayer.CallEvents(printerConnection, new PrintItemWrapperEventArgs(printerConnection.activePrintItem));
|
||||
printer.Connection.PauseOnLayer.CallEvents(printer.Connection, new PrintItemWrapperEventArgs(printer.Connection.activePrintItem));
|
||||
UiThread.RunOnIdle(() => StyledMessageBox.ShowMessageBox(ResumePrint, layerPauseMessage.FormatWith(layerNumber), pauseCaption, StyledMessageBox.MessageType.YES_NO, "Ok".Localize(), "Resume".Localize()));
|
||||
break;
|
||||
|
||||
case PauseReason.FilamentRunout:
|
||||
printerConnection.FilamentRunout.CallEvents(printerConnection, new PrintItemWrapperEventArgs(printerConnection.activePrintItem));
|
||||
printer.Connection.FilamentRunout.CallEvents(printer.Connection, new PrintItemWrapperEventArgs(printer.Connection.activePrintItem));
|
||||
UiThread.RunOnIdle(() => StyledMessageBox.ShowMessageBox(ResumePrint, filamentPauseMessage, pauseCaption, StyledMessageBox.MessageType.YES_NO, "Ok".Localize(), "Resume".Localize()));
|
||||
break;
|
||||
}
|
||||
|
||||
// Add the pause_gcode to the loadedGCode.GCodeCommandQueue
|
||||
string pauseGCode = printerConnection.PrinterSettings.GetValue(SettingsKey.pause_gcode);
|
||||
string pauseGCode = printer.Settings.GetValue(SettingsKey.pause_gcode);
|
||||
|
||||
// put in the gcode for pausing (if any)
|
||||
InjectPauseGCode(pauseGCode);
|
||||
|
|
@ -130,9 +130,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
private void ResumePrint(bool clickedOk)
|
||||
{
|
||||
// They clicked either Resume or Ok
|
||||
if (!clickedOk && printerConnection.PrinterIsPaused)
|
||||
if (!clickedOk && printer.Connection.PrinterIsPaused)
|
||||
{
|
||||
printerConnection.Resume();
|
||||
printer.Connection.Resume();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
|
||||
if (lineToSend == null)
|
||||
{
|
||||
if (!printerConnection.PrinterIsPaused)
|
||||
if (!printer.Connection.PrinterIsPaused)
|
||||
{
|
||||
lineToSend = base.ReadLine();
|
||||
if (lineToSend == null)
|
||||
|
|
@ -160,12 +160,12 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
}
|
||||
|
||||
// We got a line from the gcode we are sending check if we should queue a request for filament runout
|
||||
if (printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.filament_runout_sensor))
|
||||
if (printer.Settings.GetValue<bool>(SettingsKey.filament_runout_sensor))
|
||||
{
|
||||
// request to read the endstop state
|
||||
if (!timeSinceLastEndstopRead.IsRunning || timeSinceLastEndstopRead.ElapsedMilliseconds > 5000)
|
||||
{
|
||||
printerConnection.SendLineToPrinterNow("M119");
|
||||
printer.Connection.SendLineToPrinterNow("M119");
|
||||
timeSinceLastEndstopRead.Restart();
|
||||
}
|
||||
}
|
||||
|
|
@ -194,10 +194,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
{
|
||||
moveLocationAtEndOfPauseCode = LastDestination;
|
||||
|
||||
if (printerConnection.PrinterIsPrinting)
|
||||
if (printer.Connection.PrinterIsPrinting)
|
||||
{
|
||||
// remember where we were after we ran the pause gcode
|
||||
printerConnection.CommunicationState = CommunicationStates.Paused;
|
||||
printer.Connection.CommunicationState = CommunicationStates.Paused;
|
||||
}
|
||||
|
||||
lineToSend = "";
|
||||
|
|
@ -225,11 +225,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
Vector3 positionBeforeActualPause = moveLocationAtEndOfPauseCode.position;
|
||||
InjectPauseGCode("G92 E{0:0.###}".FormatWith(moveLocationAtEndOfPauseCode.extrusion));
|
||||
Vector3 ensureAllAxisAreSent = positionBeforeActualPause + new Vector3(.01, .01, .01);
|
||||
var feedRates = printerConnection.PrinterSettings.Helpers.ManualMovementSpeeds();
|
||||
var feedRates = printer.Settings.Helpers.ManualMovementSpeeds();
|
||||
InjectPauseGCode("G1 X{0:0.###} Y{1:0.###} Z{2:0.###} F{3}".FormatWith(ensureAllAxisAreSent.x, ensureAllAxisAreSent.y, ensureAllAxisAreSent.z, feedRates.x + 1));
|
||||
InjectPauseGCode("G1 X{0:0.###} Y{1:0.###} Z{2:0.###} F{3}".FormatWith(positionBeforeActualPause.x, positionBeforeActualPause.y, positionBeforeActualPause.z, feedRates));
|
||||
|
||||
string resumeGCode = printerConnection.PrinterSettings.GetValue(SettingsKey.resume_gcode);
|
||||
string resumeGCode = printer.Settings.GetValue(SettingsKey.resume_gcode);
|
||||
InjectPauseGCode(resumeGCode);
|
||||
InjectPauseGCode("M114"); // make sure we know where we are after this resume code
|
||||
}
|
||||
|
|
@ -262,7 +262,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
{
|
||||
int layerNumber;
|
||||
|
||||
if (int.TryParse(layer, out layerNumber) && printerConnection.PrinterSettings.Helpers.LayerToPauseOn().Contains(layerNumber))
|
||||
if (int.TryParse(layer, out layerNumber) && printer.Settings.Helpers.LayerToPauseOn().Contains(layerNumber))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,15 +47,15 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
RectangleDouble boundsOfSkippedLayers = RectangleDouble.ZeroIntersection;
|
||||
|
||||
RecoveryState recoveryState = RecoveryState.RemoveHeating;
|
||||
PrinterConnection printerConnection;
|
||||
private PrinterConfig printer;
|
||||
|
||||
public PrintRecoveryStream(PrinterConnection printerConnection, GCodeFileStream internalStream, double percentDone)
|
||||
public PrintRecoveryStream(PrinterConfig printer, GCodeFileStream internalStream, double percentDone)
|
||||
{
|
||||
this.printerConnection = printerConnection;
|
||||
this.printer = printer;
|
||||
this.internalStream = internalStream;
|
||||
this.percentDone = percentDone;
|
||||
|
||||
recoverFeedRate = printerConnection.PrinterSettings.GetValue<double>(SettingsKey.recover_first_layer_speed);
|
||||
recoverFeedRate = printer.Settings.GetValue<double>(SettingsKey.recover_first_layer_speed);
|
||||
if (recoverFeedRate == 0)
|
||||
{
|
||||
recoverFeedRate = 10;
|
||||
|
|
@ -96,8 +96,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
queuedCommands.Add("G92 E0; reset the expected extruder position");
|
||||
queuedCommands.Add("M82; use absolute distance for extrusion");
|
||||
|
||||
bool hasHeatedBed = printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_heated_bed);
|
||||
double bedTemp = printerConnection.PrinterSettings.GetValue<double>(SettingsKey.bed_temperature);
|
||||
bool hasHeatedBed = printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed);
|
||||
double bedTemp = printer.Settings.GetValue<double>(SettingsKey.bed_temperature);
|
||||
if (hasHeatedBed && bedTemp > 0)
|
||||
{
|
||||
// start heating the bed
|
||||
|
|
@ -105,7 +105,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
}
|
||||
|
||||
// heat up the extruder
|
||||
queuedCommands.Add("M109 S{0}".FormatWith(printerConnection.PrinterSettings.Helpers.ExtruderTemperature(0)));
|
||||
queuedCommands.Add("M109 S{0}".FormatWith(printer.Settings.Helpers.ExtruderTemperature(0)));
|
||||
|
||||
if (hasHeatedBed && bedTemp > 0)
|
||||
{
|
||||
|
|
@ -122,14 +122,14 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
PrintLevelingStream.Enabled = false;
|
||||
queuedCommands.Add("M114 ; get current position");
|
||||
queuedCommands.Add("G91 ; move relative");
|
||||
queuedCommands.Add("G1 Z10 F{0}".FormatWith(printerConnection.PrinterSettings.ZSpeed()));
|
||||
queuedCommands.Add("G1 Z10 F{0}".FormatWith(printer.Settings.ZSpeed()));
|
||||
queuedCommands.Add("G90 ; move absolute");
|
||||
recoveryState = RecoveryState.Homing;
|
||||
return "";
|
||||
|
||||
// if top homing, home the extruder
|
||||
case RecoveryState.Homing:
|
||||
if (printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.z_homes_to_max))
|
||||
if (printer.Settings.GetValue<bool>(SettingsKey.z_homes_to_max))
|
||||
{
|
||||
queuedCommands.Add("G28");
|
||||
}
|
||||
|
|
@ -140,8 +140,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
// home y
|
||||
queuedCommands.Add("G28 Y0");
|
||||
// move to the place we can home z from
|
||||
Vector2 recoveryPositionXy = printerConnection.PrinterSettings.GetValue<Vector2>(SettingsKey.recover_position_before_z_home);
|
||||
queuedCommands.Add("G1 X{0:0.###}Y{1:0.###}F{2}".FormatWith(recoveryPositionXy.x, recoveryPositionXy.y, printerConnection.PrinterSettings.XSpeed()));
|
||||
Vector2 recoveryPositionXy = printer.Settings.GetValue<Vector2>(SettingsKey.recover_position_before_z_home);
|
||||
queuedCommands.Add("G1 X{0:0.###}Y{1:0.###}F{2}".FormatWith(recoveryPositionXy.x, recoveryPositionXy.y, printer.Settings.XSpeed()));
|
||||
// home z
|
||||
queuedCommands.Add("G28 Z0");
|
||||
}
|
||||
|
|
@ -219,25 +219,25 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
case RecoveryState.PrimingAndMovingToStart:
|
||||
{
|
||||
|
||||
if (printerConnection.PrinterSettings.GetValue("z_homes_to_max") == "0") // we are homed to the bed
|
||||
if (printer.Settings.GetValue("z_homes_to_max") == "0") // we are homed to the bed
|
||||
{
|
||||
// move to the height we can recover printing from
|
||||
Vector2 recoverPositionXy = printerConnection.PrinterSettings.GetValue<Vector2>(SettingsKey.recover_position_before_z_home);
|
||||
queuedCommands.Add(CreateMovementLine(new PrinterMove(new VectorMath.Vector3(recoverPositionXy.x, recoverPositionXy.y, lastDestination.position.z), 0, printerConnection.PrinterSettings.ZSpeed())));
|
||||
Vector2 recoverPositionXy = printer.Settings.GetValue<Vector2>(SettingsKey.recover_position_before_z_home);
|
||||
queuedCommands.Add(CreateMovementLine(new PrinterMove(new VectorMath.Vector3(recoverPositionXy.x, recoverPositionXy.y, lastDestination.position.z), 0, printer.Settings.ZSpeed())));
|
||||
}
|
||||
|
||||
double extruderWidth = printerConnection.PrinterSettings.GetValue<double>(SettingsKey.nozzle_diameter);
|
||||
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, printerConnection.PrinterSettings.XSpeed())));
|
||||
0, printer.Settings.XSpeed())));
|
||||
|
||||
// let's prime the extruder
|
||||
queuedCommands.Add("G1 E10 F{0}".FormatWith(printerConnection.PrinterSettings.EFeedRate(0))); // extrude 10
|
||||
queuedCommands.Add("G1 E10 F{0}".FormatWith(printer.Settings.EFeedRate(0))); // extrude 10
|
||||
queuedCommands.Add("G1 E9"); // and retract a bit
|
||||
|
||||
// move to the actual print position
|
||||
queuedCommands.Add(CreateMovementLine(new PrinterMove(lastDestination.position, 0, printerConnection.PrinterSettings.XSpeed())));
|
||||
queuedCommands.Add(CreateMovementLine(new PrinterMove(lastDestination.position, 0, printer.Settings.XSpeed())));
|
||||
|
||||
/// reset the printer to know where the filament should be
|
||||
queuedCommands.Add("G92 E{0}".FormatWith(lastDestination.extrusion));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue