Move SetupWizards to dedicated folder
This commit is contained in:
parent
029f4fc0a7
commit
9d1170f118
6 changed files with 0 additions and 0 deletions
|
|
@ -0,0 +1,408 @@
|
|||
/*
|
||||
Copyright (c) 2019, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Markdig.Agg;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
|
||||
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
||||
{
|
||||
public class LoadFilamentWizard : PrinterSetupWizard
|
||||
{
|
||||
private bool showAlreadyLoadedButton;
|
||||
|
||||
public double TemperatureAtStart { get; private set; }
|
||||
private int extruderIndex;
|
||||
|
||||
public static void Start(PrinterConfig printer, ThemeConfig theme, int extruderIndex, bool showAlreadyLoadedButton)
|
||||
{
|
||||
var loadFilamentWizard = new LoadFilamentWizard(printer, extruderIndex, showAlreadyLoadedButton);
|
||||
|
||||
var dialogWindow = DialogWindow.Show(loadFilamentWizard.CurrentPage);
|
||||
dialogWindow.Closed += (s, e) =>
|
||||
{
|
||||
printer.Connection.SetTargetHotendTemperature(extruderIndex, loadFilamentWizard.TemperatureAtStart);
|
||||
};
|
||||
}
|
||||
|
||||
public LoadFilamentWizard(PrinterConfig printer, int extruderIndex, bool showAlreadyLoadedButton)
|
||||
: base(printer)
|
||||
{
|
||||
this.showAlreadyLoadedButton = showAlreadyLoadedButton;
|
||||
|
||||
pages = this.GetPages();
|
||||
pages.MoveNext();
|
||||
|
||||
TemperatureAtStart = printer.Connection.GetTargetHotendTemperature(extruderIndex);
|
||||
this.extruderIndex = extruderIndex;
|
||||
}
|
||||
|
||||
public static bool NeedsToBeRun0(PrinterConfig printer)
|
||||
{
|
||||
return !printer.Settings.GetValue<bool>(SettingsKey.filament_has_been_loaded);
|
||||
}
|
||||
|
||||
public static bool NeedsToBeRun1(PrinterConfig printer)
|
||||
{
|
||||
var extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
|
||||
return extruderCount > 1 && !printer.Settings.GetValue<bool>(SettingsKey.filament_1_has_been_loaded);
|
||||
}
|
||||
|
||||
private IEnumerator<WizardPage> GetPages()
|
||||
{
|
||||
var extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
|
||||
|
||||
var levelingStrings = new LevelingStrings();
|
||||
|
||||
var title = "Load Material".Localize();
|
||||
var instructions = "Please select the material you want to load.".Localize();
|
||||
if(extruderCount > 1)
|
||||
{
|
||||
instructions = "Please select the material you want to load into extruder {0}.".Localize().FormatWith(extruderIndex + 1);
|
||||
}
|
||||
|
||||
// select the material
|
||||
yield return new SelectMaterialPage(this, title, instructions, "Select".Localize(), extruderIndex, true, showAlreadyLoadedButton)
|
||||
{
|
||||
WindowTitle = $"{ApplicationController.Instance.ProductName} - " + "Load Filament Wizard".Localize()
|
||||
};
|
||||
|
||||
var theme = ApplicationController.Instance.Theme;
|
||||
|
||||
// show the trim filament message
|
||||
{
|
||||
var trimFilamentPage = new WizardPage(this, "Trim Filament".Localize(), "")
|
||||
{
|
||||
PageLoad = (page) =>
|
||||
{
|
||||
// start heating up the extruder
|
||||
printer.Connection.SetTargetHotendTemperature(extruderIndex, printer.Settings.GetValue<double>(SettingsKey.temperature));
|
||||
|
||||
var markdownText = printer.Settings.GetValue(SettingsKey.trim_filament_markdown);
|
||||
var markdownWidget = new MarkdownWidget(theme);
|
||||
markdownWidget.Markdown = markdownText = markdownText.Replace("\\n", "\n");
|
||||
page.ContentRow.AddChild(markdownWidget);
|
||||
}
|
||||
};
|
||||
yield return trimFilamentPage;
|
||||
}
|
||||
|
||||
if (extruderCount > 1)
|
||||
{
|
||||
// reset the extruder that was active
|
||||
printer.Connection.QueueLine($"T{extruderIndex}");
|
||||
}
|
||||
|
||||
// reset the extrusion amount so this is easier to debug
|
||||
printer.Connection.QueueLine("G92 E0");
|
||||
|
||||
// show the insert filament page
|
||||
{
|
||||
RunningInterval runningGCodeCommands = null;
|
||||
var insertFilamentPage = new WizardPage(this, "Insert Filament".Localize(), "")
|
||||
{
|
||||
PageLoad = (page) =>
|
||||
{
|
||||
var markdownText = printer.Settings.GetValue(SettingsKey.insert_filament_markdown2);
|
||||
if(extruderIndex == 1)
|
||||
{
|
||||
markdownText = printer.Settings.GetValue(SettingsKey.insert_filament_1_markdown);
|
||||
}
|
||||
var markdownWidget = new MarkdownWidget(theme);
|
||||
markdownWidget.Markdown = markdownText = markdownText.Replace("\\n", "\n");
|
||||
page.ContentRow.AddChild(markdownWidget);
|
||||
|
||||
// turn off the fan
|
||||
printer.Connection.FanSpeed0To255 = 0;
|
||||
// Allow extrusion at any temperature. S0 only works on Marlin S1 works on repetier and marlin
|
||||
printer.Connection.QueueLine("M302 S1");
|
||||
|
||||
int maxSecondsToStartLoading = 300;
|
||||
var runningTime = Stopwatch.StartNew();
|
||||
runningGCodeCommands = UiThread.SetInterval(() =>
|
||||
{
|
||||
if (printer.Connection.NumQueuedCommands == 0)
|
||||
{
|
||||
printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, 1, 80);
|
||||
// send a dwell to empty out the current move commands
|
||||
printer.Connection.QueueLine("G4 P1");
|
||||
|
||||
if (runningTime.ElapsedMilliseconds > maxSecondsToStartLoading * 1000)
|
||||
{
|
||||
UiThread.ClearInterval(runningGCodeCommands);
|
||||
}
|
||||
}
|
||||
},
|
||||
.1);
|
||||
},
|
||||
PageClose = () =>
|
||||
{
|
||||
if (runningGCodeCommands != null)
|
||||
{
|
||||
UiThread.ClearInterval(runningGCodeCommands);
|
||||
}
|
||||
}
|
||||
};
|
||||
insertFilamentPage.Closed += (s, e) =>
|
||||
{
|
||||
if (runningGCodeCommands != null)
|
||||
{
|
||||
UiThread.ClearInterval(runningGCodeCommands);
|
||||
}
|
||||
};
|
||||
|
||||
yield return insertFilamentPage;
|
||||
}
|
||||
|
||||
// show the loading filament progress bar
|
||||
{
|
||||
RunningInterval runningGCodeCommands = null;
|
||||
var loadingFilamentPage = new WizardPage(this, "Loading Filament".Localize(), "")
|
||||
{
|
||||
PageLoad = (page) =>
|
||||
{
|
||||
page.NextButton.Enabled = false;
|
||||
|
||||
// add the progress bar
|
||||
var holder = new FlowLayoutWidget()
|
||||
{
|
||||
Margin = new BorderDouble(3, 0, 0, 10),
|
||||
};
|
||||
var progressBar = new ProgressBar((int)(150 * GuiWidget.DeviceScale), (int)(15 * GuiWidget.DeviceScale))
|
||||
{
|
||||
FillColor = theme.PrimaryAccentColor,
|
||||
BorderColor = theme.TextColor,
|
||||
BackgroundColor = Color.White,
|
||||
VAnchor = VAnchor.Center,
|
||||
};
|
||||
var progressBarText = new TextWidget("", pointSize: 10, textColor: theme.TextColor)
|
||||
{
|
||||
AutoExpandBoundsToText = true,
|
||||
Margin = new BorderDouble(5, 0, 0, 0),
|
||||
VAnchor = VAnchor.Center,
|
||||
};
|
||||
holder.AddChild(progressBar);
|
||||
holder.AddChild(progressBarText);
|
||||
page.ContentRow.AddChild(holder);
|
||||
|
||||
// Allow extrusion at any temperature. S0 only works on Marlin S1 works on repetier and marlin
|
||||
printer.Connection.QueueLine("M302 S1");
|
||||
// send a dwell to empty out the current move commands
|
||||
printer.Connection.QueueLine("G4 P1");
|
||||
// put in a second one to use as a signal for the first being processed
|
||||
printer.Connection.QueueLine("G4 P1");
|
||||
// start heating up the extruder
|
||||
printer.Connection.SetTargetHotendTemperature(extruderIndex, printer.Settings.GetValue<double>(SettingsKey.temperature));
|
||||
|
||||
var loadingSpeedMmPerS = printer.Settings.GetValue<double>(SettingsKey.load_filament_speed);
|
||||
var loadLengthMm = Math.Max(1, printer.Settings.GetValue<double>(SettingsKey.load_filament_length));
|
||||
var remainingLengthMm = loadLengthMm;
|
||||
var maxSingleExtrudeLength = 20;
|
||||
|
||||
Stopwatch runningTime = null;
|
||||
var expectedTimeS = loadLengthMm / loadingSpeedMmPerS;
|
||||
|
||||
runningGCodeCommands = UiThread.SetInterval(() =>
|
||||
{
|
||||
if (printer.Connection.NumQueuedCommands == 0)
|
||||
{
|
||||
if(runningTime == null)
|
||||
{
|
||||
runningTime = Stopwatch.StartNew();
|
||||
}
|
||||
|
||||
if (progressBar.RatioComplete < 1
|
||||
|| remainingLengthMm >= .001)
|
||||
{
|
||||
var thisExtrude = Math.Min(remainingLengthMm, maxSingleExtrudeLength);
|
||||
var currentE = printer.Connection.CurrentExtruderDestination;
|
||||
printer.Connection.QueueLine("G1 E{0:0.###} F{1}".FormatWith(currentE + thisExtrude, loadingSpeedMmPerS * 60));
|
||||
// make sure we wait for this command to finish so we can cancel the unload at any time without delay
|
||||
printer.Connection.QueueLine("G4 P1");
|
||||
remainingLengthMm -= thisExtrude;
|
||||
var elapsedSeconds = runningTime.Elapsed.TotalSeconds;
|
||||
progressBar.RatioComplete = Math.Min(1, elapsedSeconds / expectedTimeS);
|
||||
progressBarText.Text = $"Loading Filament: {Math.Max(0, expectedTimeS - elapsedSeconds):0}";
|
||||
}
|
||||
}
|
||||
|
||||
if (progressBar.RatioComplete == 1
|
||||
&& remainingLengthMm <= .001)
|
||||
{
|
||||
UiThread.ClearInterval(runningGCodeCommands);
|
||||
page.NextButton.InvokeClick();
|
||||
}
|
||||
},
|
||||
.1);
|
||||
},
|
||||
PageClose = () =>
|
||||
{
|
||||
UiThread.ClearInterval(runningGCodeCommands);
|
||||
}
|
||||
};
|
||||
loadingFilamentPage.Closed += (s, e) =>
|
||||
{
|
||||
UiThread.ClearInterval(runningGCodeCommands);
|
||||
};
|
||||
|
||||
yield return loadingFilamentPage;
|
||||
}
|
||||
|
||||
// wait for extruder to heat
|
||||
{
|
||||
var targetHotendTemp = printer.Settings.Helpers.ExtruderTargetTemperature(extruderIndex);
|
||||
var temps = new double[4];
|
||||
temps[extruderIndex] = targetHotendTemp;
|
||||
yield return new WaitForTempPage(
|
||||
this,
|
||||
"Waiting For Printer To Heat".Localize(),
|
||||
"Waiting for the hotend to heat to ".Localize() + targetHotendTemp + "°C.\n"
|
||||
+ "This will ensure that filament is able to flow through the nozzle.".Localize() + "\n"
|
||||
+ "\n"
|
||||
+ "Warning! The tip of the nozzle will be HOT!".Localize() + "\n"
|
||||
+ "Avoid contact with your skin.".Localize(),
|
||||
0,
|
||||
temps);
|
||||
}
|
||||
|
||||
// extrude slowly so that we can prime the extruder
|
||||
{
|
||||
RunningInterval runningGCodeCommands = null;
|
||||
var runningCleanPage = new WizardPage(this, "Wait For Running Clean".Localize(), "")
|
||||
{
|
||||
PageLoad = (page) =>
|
||||
{
|
||||
var markdownText = printer.Settings.GetValue(SettingsKey.running_clean_markdown2);
|
||||
if(extruderIndex == 1)
|
||||
{
|
||||
markdownText = printer.Settings.GetValue(SettingsKey.running_clean_1_markdown);
|
||||
}
|
||||
var markdownWidget = new MarkdownWidget(theme);
|
||||
markdownWidget.Markdown = markdownText = markdownText.Replace("\\n", "\n");
|
||||
page.ContentRow.AddChild(markdownWidget);
|
||||
|
||||
var runningTime = Stopwatch.StartNew();
|
||||
runningGCodeCommands = UiThread.SetInterval(() =>
|
||||
{
|
||||
if (printer.Connection.NumQueuedCommands == 0)
|
||||
{
|
||||
printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, 2, 140);
|
||||
// make sure we wait for this command to finish so we can cancel the unload at any time without delay
|
||||
printer.Connection.QueueLine("G4 P1");
|
||||
int secondsToRun = 90;
|
||||
if (runningTime.ElapsedMilliseconds > secondsToRun * 1000)
|
||||
{
|
||||
UiThread.ClearInterval(runningGCodeCommands);
|
||||
}
|
||||
}
|
||||
},
|
||||
.1);
|
||||
},
|
||||
PageClose = () =>
|
||||
{
|
||||
UiThread.ClearInterval(runningGCodeCommands);
|
||||
}
|
||||
};
|
||||
runningCleanPage.Closed += (s, e) =>
|
||||
{
|
||||
switch (extruderIndex)
|
||||
{
|
||||
case 0:
|
||||
printer.Settings.SetValue(SettingsKey.filament_has_been_loaded, "1");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
printer.Settings.SetValue(SettingsKey.filament_1_has_been_loaded, "1");
|
||||
break;
|
||||
}
|
||||
printer.Settings.SetValue(SettingsKey.filament_has_been_loaded, "1");
|
||||
};
|
||||
|
||||
yield return runningCleanPage;
|
||||
}
|
||||
|
||||
// put up a success message
|
||||
yield return new DoneLoadingPage(this, extruderIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public class DoneLoadingPage : WizardPage
|
||||
{
|
||||
public DoneLoadingPage(PrinterSetupWizard setupWizard, int extruderIndex)
|
||||
: base(setupWizard, "Success".Localize(), "Success!\n\nYour filament should now be loaded".Localize())
|
||||
{
|
||||
if (printer.Connection.Paused)
|
||||
{
|
||||
var resumePrintingButton = new TextButton("Resume Printing".Localize(), theme)
|
||||
{
|
||||
Name = "Resume Printing Button",
|
||||
BackgroundColor = theme.MinimalShade,
|
||||
};
|
||||
resumePrintingButton.Click += (s, e) =>
|
||||
{
|
||||
resumePrintingButton.Parents<SystemWindow>().First().Close();
|
||||
printer.Connection.Resume();
|
||||
};
|
||||
|
||||
theme.ApplyPrimaryActionStyle(resumePrintingButton);
|
||||
this.AddPageAction(resumePrintingButton);
|
||||
}
|
||||
else if(extruderIndex == 0 && printer.Settings.GetValue<int>(SettingsKey.extruder_count) > 1)
|
||||
{
|
||||
var loadFilament2Button = new TextButton("Load Filament 2".Localize(), theme)
|
||||
{
|
||||
Name = "Load Filament 2",
|
||||
BackgroundColor = theme.MinimalShade,
|
||||
};
|
||||
loadFilament2Button.Click += (s, e) =>
|
||||
{
|
||||
loadFilament2Button.Parents<SystemWindow>().First().Close();
|
||||
LoadFilamentWizard.Start(printer, theme, 1, true);
|
||||
};
|
||||
theme.ApplyPrimaryActionStyle(loadFilament2Button);
|
||||
|
||||
this.AddPageAction(loadFilament2Button);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnLoad(EventArgs args)
|
||||
{
|
||||
this.ShowWizardFinished();
|
||||
|
||||
base.OnLoad(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,385 @@
|
|||
/*
|
||||
Copyright (c) 2019, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
||||
{
|
||||
public class PrintLevelingWizard : PrinterSetupWizard
|
||||
{
|
||||
private LevelingPlan levelingPlan;
|
||||
|
||||
public PrintLevelingWizard(LevelingPlan levelingPlan, PrinterConfig printer)
|
||||
: base(printer)
|
||||
{
|
||||
this.levelingPlan = levelingPlan;
|
||||
|
||||
pages = this.GetPages();
|
||||
pages.MoveNext();
|
||||
}
|
||||
|
||||
public bool WindowHasBeenClosed { get; private set; }
|
||||
|
||||
public static void Start(PrinterConfig printer, ThemeConfig theme)
|
||||
{
|
||||
// turn off print leveling
|
||||
printer.Connection.AllowLeveling = false;
|
||||
|
||||
// clear any data that we are going to be acquiring (sampled positions, after z home offset)
|
||||
var levelingData = new PrintLevelingData()
|
||||
{
|
||||
LevelingSystem = printer.Settings.GetValue<LevelingSystem>(SettingsKey.print_leveling_solution)
|
||||
};
|
||||
|
||||
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, "0");
|
||||
printer.Settings.SetValue(SettingsKey.baby_step_z_offset_1, "0");
|
||||
|
||||
printer.Connection.QueueLine("T0");
|
||||
|
||||
LevelingPlan levelingPlan;
|
||||
|
||||
switch (levelingData.LevelingSystem)
|
||||
{
|
||||
case LevelingSystem.Probe3Points:
|
||||
levelingPlan = new LevelWizard3Point(printer);
|
||||
break;
|
||||
|
||||
case LevelingSystem.Probe7PointRadial:
|
||||
levelingPlan = new LevelWizard7PointRadial(printer);
|
||||
break;
|
||||
|
||||
case LevelingSystem.Probe13PointRadial:
|
||||
levelingPlan = new LevelWizard13PointRadial(printer);
|
||||
break;
|
||||
|
||||
case LevelingSystem.Probe100PointRadial:
|
||||
levelingPlan = new LevelWizard100PointRadial(printer);
|
||||
break;
|
||||
|
||||
case LevelingSystem.Probe3x3Mesh:
|
||||
levelingPlan = new LevelWizardMesh(printer, 3, 3);
|
||||
break;
|
||||
|
||||
case LevelingSystem.Probe5x5Mesh:
|
||||
levelingPlan = new LevelWizardMesh(printer, 5, 5);
|
||||
break;
|
||||
|
||||
case LevelingSystem.Probe10x10Mesh:
|
||||
levelingPlan = new LevelWizardMesh(printer, 10, 10);
|
||||
break;
|
||||
|
||||
case LevelingSystem.ProbeCustom:
|
||||
levelingPlan = new LevelWizardCustom(printer);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
var levelingWizard = new PrintLevelingWizard(levelingPlan, printer);
|
||||
|
||||
var dialogWindow = DialogWindow.Show(levelingWizard.CurrentPage);
|
||||
dialogWindow.Closed += (s, e) =>
|
||||
{
|
||||
// If leveling was on when we started, make sure it is on when we are done.
|
||||
printer.Connection.AllowLeveling = true;
|
||||
|
||||
dialogWindow = null;
|
||||
levelingWizard.WindowHasBeenClosed = true;
|
||||
|
||||
// make sure we raise the probe on close
|
||||
if (printer.Settings.GetValue<bool>(SettingsKey.has_z_probe)
|
||||
&& printer.Settings.GetValue<bool>(SettingsKey.use_z_probe)
|
||||
&& printer.Settings.GetValue<bool>(SettingsKey.has_z_servo))
|
||||
{
|
||||
// make sure the servo is retracted
|
||||
var servoRetract = printer.Settings.GetValue<double>(SettingsKey.z_servo_retracted_angle);
|
||||
printer.Connection.QueueLine($"M280 P0 S{servoRetract}");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private IEnumerator<WizardPage> GetPages()
|
||||
{
|
||||
var probePositions = new List<ProbePosition>(levelingPlan.ProbeCount);
|
||||
for (int j = 0; j < levelingPlan.ProbeCount; j++)
|
||||
{
|
||||
probePositions.Add(new ProbePosition());
|
||||
}
|
||||
|
||||
var levelingStrings = new LevelingStrings();
|
||||
|
||||
// If no leveling data has been calculated
|
||||
bool showWelcomeScreen = printer.Settings.Helpers.GetPrintLevelingData().SampledPositions.Count == 0
|
||||
&& !ProbeCalibrationWizard.UsingZProbe(printer);
|
||||
|
||||
string windowTitle = string.Format("{0} - {1}", ApplicationController.Instance.ProductName, "Print Leveling Wizard".Localize());
|
||||
|
||||
if (showWelcomeScreen)
|
||||
{
|
||||
yield return new WizardPage(
|
||||
this,
|
||||
"Initial Printer Setup".Localize(),
|
||||
string.Format(
|
||||
"{0}\n\n{1}",
|
||||
"Congratulations on connecting to your printer. Before starting your first print we need to run a simple calibration procedure.".Localize(),
|
||||
"The next few screens will walk your through calibrating your printer.".Localize()))
|
||||
{
|
||||
WindowTitle = windowTitle
|
||||
};
|
||||
}
|
||||
|
||||
bool hasHeatedBed = printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed);
|
||||
bool useZProbe = printer.Settings.Helpers.UseZProbe();
|
||||
int zProbeSamples = printer.Settings.GetValue<int>(SettingsKey.z_probe_samples);
|
||||
|
||||
// Build welcome text for Print Leveling Overview page
|
||||
string buildWelcomeText()
|
||||
{
|
||||
var secondsPerManualSpot = 10 * 3;
|
||||
var secondsPerAutomaticSpot = 3 * zProbeSamples;
|
||||
var secondsToCompleteWizard = levelingPlan.ProbeCount * (useZProbe ? secondsPerAutomaticSpot : secondsPerManualSpot);
|
||||
secondsToCompleteWizard += (hasHeatedBed ? 60 * 3 : 0);
|
||||
|
||||
int numberOfSteps = levelingPlan.ProbeCount;
|
||||
int numberOfMinutes = (int)Math.Round(secondsToCompleteWizard / 60.0);
|
||||
|
||||
if (hasHeatedBed)
|
||||
{
|
||||
return "{0}\n\n\t• {1}\n\t• {2}\n\t• {3}\n\t• {4}\n\t• {5}\n\n{6}\n\n{7}".FormatWith(
|
||||
"Welcome to the print leveling wizard. Here is a quick overview on what we are going to do.".Localize(),
|
||||
"Select the material you are printing".Localize(),
|
||||
"Home the printer".Localize(),
|
||||
"Heat the bed".Localize(),
|
||||
"Sample the bed at {0} points".Localize().FormatWith(numberOfSteps),
|
||||
"Turn auto leveling on".Localize(),
|
||||
"We should be done in approximately {0} minutes.".Localize().FormatWith(numberOfMinutes),
|
||||
"Click 'Next' to continue.".Localize());
|
||||
}
|
||||
else
|
||||
{
|
||||
return "{0}\n\n\t• {1}\n\t• {2}\n\t• {3}\n\n{4}\n\n{5}".FormatWith(
|
||||
"Welcome to the print leveling wizard. Here is a quick overview on what we are going to do.".Localize(),
|
||||
"Home the printer".Localize(),
|
||||
"Sample the bed at {0} points".Localize().FormatWith(numberOfSteps),
|
||||
"Turn auto leveling on".Localize(),
|
||||
"We should be done in approximately {0} minutes.".Localize().FormatWith(numberOfMinutes),
|
||||
"Click 'Next' to continue.".Localize());
|
||||
}
|
||||
}
|
||||
|
||||
yield return new WizardPage(
|
||||
this,
|
||||
"Print Leveling Overview".Localize(),
|
||||
buildWelcomeText())
|
||||
{
|
||||
WindowTitle = windowTitle
|
||||
};
|
||||
|
||||
yield return new HomePrinterPage(
|
||||
this,
|
||||
"Homing The Printer".Localize(),
|
||||
levelingStrings.HomingPageInstructions(useZProbe, hasHeatedBed),
|
||||
useZProbe);
|
||||
|
||||
// figure out the heating requirements
|
||||
double targetBedTemp = 0;
|
||||
double targetHotendTemp = 0;
|
||||
if (hasHeatedBed)
|
||||
{
|
||||
targetBedTemp = printer.Settings.GetValue<double>(SettingsKey.bed_temperature);
|
||||
}
|
||||
|
||||
if (!useZProbe)
|
||||
{
|
||||
targetHotendTemp = printer.Settings.Helpers.ExtruderTargetTemperature(0);
|
||||
}
|
||||
|
||||
if (targetBedTemp > 0 || targetHotendTemp > 0)
|
||||
{
|
||||
string heatingInstructions = "";
|
||||
if (targetBedTemp > 0 && targetHotendTemp > 0)
|
||||
{
|
||||
// heating both the bed and the hotend
|
||||
heatingInstructions = "Waiting for the bed to heat to ".Localize() + targetBedTemp + "°C\n"
|
||||
+ "and the hotend to heat to ".Localize() + targetHotendTemp + "°C.\n"
|
||||
+ "\n"
|
||||
+ "This will improve the accuracy of print leveling ".Localize()
|
||||
+ "and ensure that no filament is stuck to your nozzle.".Localize() + "\n"
|
||||
+ "\n"
|
||||
+ "Warning! The tip of the nozzle will be HOT!".Localize() + "\n"
|
||||
+ "Avoid contact with your skin.".Localize();
|
||||
}
|
||||
else if (targetBedTemp > 0)
|
||||
{
|
||||
// only heating the bed
|
||||
heatingInstructions = "Waiting for the bed to heat to ".Localize() + targetBedTemp + "°C.\n"
|
||||
+ "This will improve the accuracy of print leveling.".Localize();
|
||||
}
|
||||
else // targetHotendTemp > 0
|
||||
{
|
||||
// only heating the hotend
|
||||
heatingInstructions += "Waiting for the hotend to heat to ".Localize() + targetHotendTemp + "°C.\n"
|
||||
+ "This will ensure that no filament is stuck to your nozzle.".Localize() + "\n"
|
||||
+ "\n"
|
||||
+ "Warning! The tip of the nozzle will be HOT!".Localize() + "\n"
|
||||
+ "Avoid contact with your skin.".Localize();
|
||||
}
|
||||
|
||||
yield return new WaitForTempPage(
|
||||
this,
|
||||
"Waiting For Printer To Heat".Localize(),
|
||||
heatingInstructions,
|
||||
targetBedTemp,
|
||||
new double[] { targetHotendTemp });
|
||||
}
|
||||
|
||||
double bedRadius = Math.Min(printer.Settings.GetValue<Vector2>(SettingsKey.bed_size).X, printer.Settings.GetValue<Vector2>(SettingsKey.bed_size).Y) / 2;
|
||||
double startProbeHeight = printer.Settings.GetValue<double>(SettingsKey.print_leveling_probe_start);
|
||||
|
||||
int i = 0;
|
||||
foreach (var goalProbePosition in levelingPlan.GetPrintLevelPositionToSample())
|
||||
{
|
||||
if(this.WindowHasBeenClosed)
|
||||
{
|
||||
// Make sure when the wizard is done we turn off the bed heating
|
||||
printer.Connection.TurnOffBedAndExtruders(TurnOff.AfterDelay);
|
||||
|
||||
if (printer.Settings.GetValue<bool>(SettingsKey.z_homes_to_max))
|
||||
{
|
||||
printer.Connection.HomeAxis(PrinterConnection.Axis.XYZ);
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
var validProbePosition = EnsureInPrintBounds(printer.Settings, goalProbePosition);
|
||||
|
||||
if (printer.Settings.Helpers.UseZProbe())
|
||||
{
|
||||
yield return new AutoProbeFeedback(
|
||||
this,
|
||||
new Vector3(validProbePosition, startProbeHeight),
|
||||
string.Format(
|
||||
"{0} {1} {2} - {3}",
|
||||
$"{"Step".Localize()} {i + 1} {"of".Localize()} {levelingPlan.ProbeCount}:",
|
||||
"Position".Localize(),
|
||||
i + 1,
|
||||
"Auto Calibrate".Localize()),
|
||||
probePositions,
|
||||
i);
|
||||
|
||||
if (this.WindowHasBeenClosed)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return new GetCoarseBedHeight(
|
||||
this,
|
||||
new Vector3(validProbePosition, startProbeHeight),
|
||||
string.Format(
|
||||
"{0} {1} {2} - {3}",
|
||||
levelingStrings.GetStepString(levelingPlan.TotalSteps),
|
||||
"Position".Localize(),
|
||||
i + 1,
|
||||
"Low Precision".Localize()),
|
||||
probePositions,
|
||||
i,
|
||||
levelingStrings);
|
||||
|
||||
yield return new GetFineBedHeight(
|
||||
this,
|
||||
string.Format(
|
||||
"{0} {1} {2} - {3}",
|
||||
levelingStrings.GetStepString(levelingPlan.TotalSteps),
|
||||
"Position".Localize(),
|
||||
i + 1,
|
||||
"Medium Precision".Localize()),
|
||||
probePositions,
|
||||
i,
|
||||
levelingStrings);
|
||||
|
||||
yield return new GetUltraFineBedHeight(
|
||||
this,
|
||||
string.Format(
|
||||
"{0} {1} {2} - {3}",
|
||||
levelingStrings.GetStepString(levelingPlan.TotalSteps),
|
||||
"Position".Localize(),
|
||||
i + 1,
|
||||
"High Precision".Localize()),
|
||||
probePositions,
|
||||
i,
|
||||
levelingStrings);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
yield return new LastPageInstructions(
|
||||
this,
|
||||
"Print Leveling Wizard".Localize(),
|
||||
useZProbe,
|
||||
probePositions);
|
||||
}
|
||||
|
||||
private Vector2 EnsureInPrintBounds(PrinterSettings printerSettings, Vector2 probePosition)
|
||||
{
|
||||
// check that the position is within the printing area and if not move it back in
|
||||
if (printerSettings.Helpers.UseZProbe())
|
||||
{
|
||||
var probeOffset = printer.Settings.GetValue<Vector2>(SettingsKey.z_probe_xy_offset);
|
||||
var actualNozzlePosition = probePosition - probeOffset;
|
||||
|
||||
// clamp this to the bed bounds
|
||||
Vector2 bedSize = printer.Settings.GetValue<Vector2>(SettingsKey.bed_size);
|
||||
Vector2 printCenter = printer.Settings.GetValue<Vector2>(SettingsKey.print_center);
|
||||
RectangleDouble bedBounds = new RectangleDouble(printCenter - bedSize / 2, printCenter + bedSize / 2);
|
||||
Vector2 adjustedPosition = bedBounds.Clamp(actualNozzlePosition);
|
||||
|
||||
// and push it back into the probePosition
|
||||
probePosition = adjustedPosition + probeOffset;
|
||||
}
|
||||
|
||||
return probePosition;
|
||||
}
|
||||
}
|
||||
|
||||
// this class is so that it is not passed by value
|
||||
public class ProbePosition
|
||||
{
|
||||
public Vector3 position;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
Copyright (c) 2019, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public abstract class PrinterSetupWizard : ISetupWizard
|
||||
{
|
||||
protected IEnumerator<WizardPage> pages;
|
||||
|
||||
protected PrinterConfig printer;
|
||||
|
||||
public PrinterConfig Printer => printer;
|
||||
|
||||
public PrinterSetupWizard(PrinterConfig printer)
|
||||
{
|
||||
this.printer = printer;
|
||||
}
|
||||
|
||||
public WizardPage CurrentPage => pages.Current;
|
||||
|
||||
|
||||
public WizardPage GetNextPage()
|
||||
{
|
||||
// Shutdown active page
|
||||
pages.Current?.Close();
|
||||
|
||||
// Advance
|
||||
pages.MoveNext();
|
||||
|
||||
return pages.Current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,279 @@
|
|||
/*
|
||||
Copyright (c) 2019, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
||||
{
|
||||
public class ProbeCalibrationWizard : PrinterSetupWizard
|
||||
{
|
||||
public ProbeCalibrationWizard(PrinterConfig printer)
|
||||
: base(printer)
|
||||
{
|
||||
pages = this.GetPages();
|
||||
pages.MoveNext();
|
||||
}
|
||||
|
||||
public static bool NeedsToBeRun(PrinterConfig printer)
|
||||
{
|
||||
// we have a probe that we are using and we have not done leveling yet
|
||||
return UsingZProbe(printer) && !printer.Settings.GetValue<bool>(SettingsKey.probe_has_been_calibrated);
|
||||
}
|
||||
|
||||
public static void Start(PrinterConfig printer, ThemeConfig theme)
|
||||
{
|
||||
// turn off print leveling
|
||||
printer.Connection.AllowLeveling = false;
|
||||
|
||||
var probeWizard = new ProbeCalibrationWizard(printer);
|
||||
|
||||
var dialogWindow = DialogWindow.Show(probeWizard.CurrentPage);
|
||||
dialogWindow.Closed += (s, e) =>
|
||||
{
|
||||
// If leveling was on when we started, make sure it is on when we are done.
|
||||
printer.Connection.AllowLeveling = true;
|
||||
|
||||
dialogWindow = null;
|
||||
|
||||
// make sure we raise the probe on close
|
||||
if (printer.Settings.GetValue<bool>(SettingsKey.has_z_probe)
|
||||
&& printer.Settings.GetValue<bool>(SettingsKey.use_z_probe)
|
||||
&& printer.Settings.GetValue<bool>(SettingsKey.has_z_servo))
|
||||
{
|
||||
// make sure the servo is retracted
|
||||
var servoRetract = printer.Settings.GetValue<double>(SettingsKey.z_servo_retracted_angle);
|
||||
printer.Connection.QueueLine($"M280 P0 S{servoRetract}");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static bool UsingZProbe(PrinterConfig printer)
|
||||
{
|
||||
var required = printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print);
|
||||
|
||||
// we have a probe that we are using and we have not done leveling yet
|
||||
return (required || printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled))
|
||||
&& printer.Settings.GetValue<bool>(SettingsKey.has_z_probe)
|
||||
&& printer.Settings.GetValue<bool>(SettingsKey.use_z_probe);
|
||||
}
|
||||
|
||||
private IEnumerator<WizardPage> GetPages()
|
||||
{
|
||||
var levelingStrings = new LevelingStrings();
|
||||
var autoProbePositions = new List<ProbePosition>(3);
|
||||
var manualProbePositions = new List<ProbePosition>(3);
|
||||
|
||||
autoProbePositions.Add(new ProbePosition());
|
||||
manualProbePositions.Add(new ProbePosition());
|
||||
|
||||
int totalSteps = 3;
|
||||
|
||||
string windowTitle = $"{ApplicationController.Instance.ProductName} - " + "Probe Calibration Wizard".Localize();
|
||||
|
||||
// make a welcome page if this is the first time calibrating the probe
|
||||
if (!printer.Settings.GetValue<bool>(SettingsKey.probe_has_been_calibrated))
|
||||
{
|
||||
yield return new WizardPage(
|
||||
this,
|
||||
"Initial Printer Setup".Localize(),
|
||||
string.Format(
|
||||
"{0}\n\n{1}",
|
||||
"Congratulations on connecting to your printer. Before starting your first print we need to run a simple calibration procedure.".Localize(),
|
||||
"The next few screens will walk your through calibrating your printer.".Localize()))
|
||||
{
|
||||
WindowTitle = windowTitle
|
||||
};
|
||||
}
|
||||
|
||||
// show what steps will be taken
|
||||
yield return new WizardPage(
|
||||
this,
|
||||
"Probe Calibration Overview".Localize(),
|
||||
string.Format(
|
||||
"{0}\n\n\t• {1}\n\t• {2}\n\t• {3}\n\n{4}\n\n{5}",
|
||||
"Welcome to the probe calibration wizard. Here is a quick overview on what we are going to do.".Localize(),
|
||||
"Home the printer".Localize(),
|
||||
"Probe the bed at the center".Localize(),
|
||||
"Manually measure the extruder at the center".Localize(),
|
||||
"We should be done in less than five minutes.".Localize(),
|
||||
"Click 'Next' to continue.".Localize()))
|
||||
{
|
||||
WindowTitle = windowTitle
|
||||
};
|
||||
|
||||
// add in the homing printer page
|
||||
yield return new HomePrinterPage(
|
||||
this,
|
||||
"Homing The Printer".Localize(),
|
||||
levelingStrings.HomingPageInstructions(true, false),
|
||||
false);
|
||||
|
||||
if (LevelingValidation.NeedsToBeRun(printer))
|
||||
{
|
||||
// start heating up the bed as that will be needed next
|
||||
var bedTemperature = printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed) ?
|
||||
printer.Settings.GetValue<double>(SettingsKey.bed_temperature)
|
||||
: 0;
|
||||
if (bedTemperature > 0)
|
||||
{
|
||||
printer.Connection.TargetBedTemperature = bedTemperature;
|
||||
}
|
||||
}
|
||||
|
||||
var extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
|
||||
|
||||
var temps = new double[4];
|
||||
for(int i=0; i< extruderCount; i++)
|
||||
{
|
||||
temps[i] = printer.Settings.Helpers.ExtruderTargetTemperature(i);
|
||||
}
|
||||
|
||||
yield return new WaitForTempPage(
|
||||
this,
|
||||
"Waiting For Printer To Heat".Localize(),
|
||||
((extruderCount == 1) ? "Waiting for the hotend to heat to ".Localize() + temps[0] + "°C.\n" : "Waiting for the hotends to heat up.".Localize())
|
||||
+ "This will ensure that no filament is stuck to your nozzle.".Localize() + "\n"
|
||||
+ "\n"
|
||||
+ "Warning! The tip of the nozzle will be HOT!".Localize() + "\n"
|
||||
+ "Avoid contact with your skin.".Localize(),
|
||||
0,
|
||||
temps);
|
||||
|
||||
double startProbeHeight = printer.Settings.GetValue<double>(SettingsKey.print_leveling_probe_start);
|
||||
Vector2 probePosition = LevelingPlan.ProbeOffsetSamplePosition(printer);
|
||||
|
||||
int extruderPriorToMeasure = printer.Connection.ActiveExtruderIndex;
|
||||
|
||||
if (extruderCount > 1)
|
||||
{
|
||||
// reset the extruder that was active
|
||||
printer.Connection.QueueLine($"T0");
|
||||
}
|
||||
|
||||
int numberOfSamples = printer.Settings.GetValue<int>(SettingsKey.z_probe_samples);
|
||||
// do the automatic probing of the center position
|
||||
yield return new AutoProbeFeedback(
|
||||
this,
|
||||
new Vector3(probePosition, startProbeHeight),
|
||||
$"{"Step".Localize()} 1 {"of".Localize()} {numberOfSamples}: {"Position".Localize()} 1 - {"Auto Calibrate".Localize()}",
|
||||
autoProbePositions,
|
||||
0);
|
||||
|
||||
// show what steps will be taken
|
||||
yield return new WizardPage(
|
||||
this,
|
||||
"Measure the nozzle offset".Localize(),
|
||||
"{0}:\n\n\t• {1}\n\n{2}\n\n{3}".FormatWith(
|
||||
"To complete the next few steps you will need".Localize(),
|
||||
"A standard sheet of paper".Localize(),
|
||||
"We will use this paper to measure the distance between the nozzle and the bed.".Localize(),
|
||||
"Click 'Next' to continue.".Localize()));
|
||||
|
||||
// we currently only support calibrating 2 extruders
|
||||
for (int i = 0; i < Math.Min(extruderCount, 2); i++)
|
||||
{
|
||||
if (extruderCount > 1)
|
||||
{
|
||||
// reset the extruder that was active
|
||||
printer.Connection.QueueLine($"T{i}");
|
||||
}
|
||||
|
||||
// do the manual prob of the same position
|
||||
yield return new GetCoarseBedHeight(
|
||||
this,
|
||||
new Vector3(probePosition, startProbeHeight),
|
||||
string.Format(
|
||||
"{0} {1} {2} - {3}",
|
||||
levelingStrings.GetStepString(totalSteps),
|
||||
"Position".Localize(),
|
||||
1,
|
||||
"Low Precision".Localize()),
|
||||
manualProbePositions,
|
||||
0,
|
||||
levelingStrings);
|
||||
|
||||
yield return new GetFineBedHeight(
|
||||
this,
|
||||
string.Format(
|
||||
"{0} {1} {2} - {3}",
|
||||
levelingStrings.GetStepString(totalSteps),
|
||||
"Position".Localize(),
|
||||
1,
|
||||
"Medium Precision".Localize()),
|
||||
manualProbePositions,
|
||||
0,
|
||||
levelingStrings);
|
||||
|
||||
yield return new GetUltraFineBedHeight(
|
||||
this,
|
||||
string.Format(
|
||||
"{0} {1} {2} - {3}",
|
||||
levelingStrings.GetStepString(totalSteps),
|
||||
"Position".Localize(),
|
||||
1,
|
||||
"High Precision".Localize()),
|
||||
manualProbePositions,
|
||||
0,
|
||||
levelingStrings);
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
// make sure we don't have leveling data
|
||||
double newProbeOffset = autoProbePositions[0].position.Z - manualProbePositions[0].position.Z;
|
||||
printer.Settings.SetValue(SettingsKey.z_probe_z_offset, newProbeOffset.ToString("0.###"));
|
||||
}
|
||||
else if (i == 1)
|
||||
{
|
||||
// store the offset into the extruder offset z position
|
||||
double newProbeOffset = autoProbePositions[0].position.Z - manualProbePositions[0].position.Z;
|
||||
var hotend0Offset = printer.Settings.GetValue<double>(SettingsKey.z_probe_z_offset);
|
||||
var newZOffset = newProbeOffset - hotend0Offset;
|
||||
printer.Settings.Helpers.SetExtruderZOffset(1, newZOffset);
|
||||
}
|
||||
}
|
||||
|
||||
printer.Settings.SetValue(SettingsKey.probe_has_been_calibrated, "1");
|
||||
|
||||
if (extruderCount > 1)
|
||||
{
|
||||
// reset the extruder that was active
|
||||
printer.Connection.QueueLine($"T{extruderPriorToMeasure}");
|
||||
}
|
||||
|
||||
yield return new CalibrateProbeLastPageInstructions(
|
||||
this,
|
||||
"Done".Localize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,253 @@
|
|||
/*
|
||||
Copyright (c) 2019, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Markdig.Agg;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
|
||||
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
||||
{
|
||||
public class UnloadFilamentWizard : PrinterSetupWizard
|
||||
{
|
||||
private int extruderIndex;
|
||||
|
||||
public static void Start(PrinterConfig printer, ThemeConfig theme, int extruderIndex)
|
||||
{
|
||||
// turn off print leveling
|
||||
var unloadWizard = new UnloadFilamentWizard(printer, extruderIndex);
|
||||
|
||||
var dialogWindow = DialogWindow.Show(unloadWizard.CurrentPage);
|
||||
dialogWindow.Closed += (s, e) =>
|
||||
{
|
||||
printer.Connection.TurnOffBedAndExtruders(TurnOff.AfterDelay);
|
||||
};
|
||||
}
|
||||
|
||||
public UnloadFilamentWizard(PrinterConfig printer, int extruderIndex)
|
||||
: base(printer)
|
||||
{
|
||||
pages = this.GetPages();
|
||||
pages.MoveNext();
|
||||
|
||||
this.extruderIndex = extruderIndex;
|
||||
}
|
||||
|
||||
private IEnumerator<WizardPage> GetPages()
|
||||
{
|
||||
var extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
|
||||
|
||||
var levelingStrings = new LevelingStrings();
|
||||
|
||||
var title = "Unload Material".Localize();
|
||||
var instructions = "Please select the material you want to unload.".Localize();
|
||||
if (extruderCount > 1)
|
||||
{
|
||||
instructions = "Please select the material you want to unload from extruder {0}.".Localize().FormatWith(extruderIndex + 1);
|
||||
}
|
||||
|
||||
// select the material
|
||||
yield return new SelectMaterialPage(this, title, instructions, "Unload".Localize(), extruderIndex, false, false)
|
||||
{
|
||||
WindowTitle = $"{ApplicationController.Instance.ProductName} - " + "Unload Filament Wizard".Localize()
|
||||
};
|
||||
|
||||
var theme = ApplicationController.Instance.Theme;
|
||||
|
||||
// wait for extruder to heat
|
||||
{
|
||||
var targetHotendTemp = printer.Settings.Helpers.ExtruderTargetTemperature(extruderIndex);
|
||||
var temps = new double[4];
|
||||
temps[extruderIndex] = targetHotendTemp;
|
||||
yield return new WaitForTempPage(
|
||||
this,
|
||||
"Waiting For Printer To Heat".Localize(),
|
||||
(extruderCount > 1 ? "Waiting for hotend {0} to heat to ".Localize().FormatWith(extruderIndex + 1) : "Waiting for the hotend to heat to ".Localize()) + targetHotendTemp + "°C.\n"
|
||||
+ "This will ensure that filament is able to flow through the nozzle.".Localize() + "\n"
|
||||
+ "\n"
|
||||
+ "Warning! The tip of the nozzle will be HOT!".Localize() + "\n"
|
||||
+ "Avoid contact with your skin.".Localize(),
|
||||
0,
|
||||
temps);
|
||||
}
|
||||
|
||||
// show the unloading filament progress bar
|
||||
{
|
||||
int extruderPriorToUnload = printer.Connection.ActiveExtruderIndex;
|
||||
|
||||
RunningInterval runningGCodeCommands = null;
|
||||
var unloadingFilamentPage = new WizardPage(this, "Unloading Filament".Localize(), "")
|
||||
{
|
||||
PageLoad = (page) =>
|
||||
{
|
||||
page.NextButton.Enabled = false;
|
||||
|
||||
// add the progress bar
|
||||
var holder = new FlowLayoutWidget()
|
||||
{
|
||||
Margin = new BorderDouble(3, 0, 0, 10),
|
||||
};
|
||||
var progressBar = new ProgressBar((int)(150 * GuiWidget.DeviceScale), (int)(15 * GuiWidget.DeviceScale))
|
||||
{
|
||||
FillColor = theme.PrimaryAccentColor,
|
||||
BorderColor = theme.TextColor,
|
||||
BackgroundColor = Color.White,
|
||||
VAnchor = VAnchor.Center,
|
||||
};
|
||||
var progressBarText = new TextWidget("", pointSize: 10, textColor: theme.TextColor)
|
||||
{
|
||||
AutoExpandBoundsToText = true,
|
||||
Margin = new BorderDouble(5, 0, 0, 0),
|
||||
VAnchor = VAnchor.Center,
|
||||
};
|
||||
holder.AddChild(progressBar);
|
||||
holder.AddChild(progressBarText);
|
||||
page.ContentRow.AddChild(holder);
|
||||
|
||||
if (extruderCount > 1)
|
||||
{
|
||||
// reset the extruder that was active
|
||||
printer.Connection.QueueLine($"T{extruderIndex}");
|
||||
}
|
||||
|
||||
// reset the extrusion amount so this is easier to debug
|
||||
printer.Connection.QueueLine("G92 E0");
|
||||
|
||||
// Allow extrusion at any temperature. S0 only works on Marlin S1 works on repetier and marlin
|
||||
printer.Connection.QueueLine("M302 S1");
|
||||
// send a dwell to empty out the current move commands
|
||||
printer.Connection.QueueLine("G4 P1");
|
||||
// put in a second one to use as a signal for the first being processed
|
||||
printer.Connection.QueueLine("G4 P1");
|
||||
// start heating up the extruder
|
||||
printer.Connection.SetTargetHotendTemperature(0, printer.Settings.GetValue<double>(SettingsKey.temperature));
|
||||
|
||||
var loadingSpeedMmPerS = printer.Settings.GetValue<double>(SettingsKey.load_filament_speed);
|
||||
var loadLengthMm = Math.Max(1, printer.Settings.GetValue<double>(SettingsKey.unload_filament_length));
|
||||
var remainingLengthMm = loadLengthMm;
|
||||
var maxSingleExtrudeLength = 20;
|
||||
|
||||
Stopwatch runningTime = null;
|
||||
var expectedTimeS = loadLengthMm / loadingSpeedMmPerS;
|
||||
|
||||
// push some out first
|
||||
var currentE = printer.Connection.CurrentExtruderDestination;
|
||||
printer.Connection.QueueLine("G1 E{0:0.###} F600".FormatWith(currentE + 15));
|
||||
|
||||
runningGCodeCommands = UiThread.SetInterval(() =>
|
||||
{
|
||||
if (printer.Connection.NumQueuedCommands == 0)
|
||||
{
|
||||
if (runningTime == null)
|
||||
{
|
||||
runningTime = Stopwatch.StartNew();
|
||||
}
|
||||
|
||||
if (progressBar.RatioComplete < 1
|
||||
|| remainingLengthMm >= .001)
|
||||
{
|
||||
var thisExtrude = Math.Min(remainingLengthMm, maxSingleExtrudeLength);
|
||||
currentE = printer.Connection.CurrentExtruderDestination;
|
||||
printer.Connection.QueueLine("G1 E{0:0.###} F{1}".FormatWith(currentE - thisExtrude, loadingSpeedMmPerS * 60));
|
||||
// make sure we wait for this command to finish so we can cancel the unload at any time without delay
|
||||
printer.Connection.QueueLine("G4 P1");
|
||||
remainingLengthMm -= thisExtrude;
|
||||
var elapsedSeconds = runningTime.Elapsed.TotalSeconds;
|
||||
progressBar.RatioComplete = Math.Min(1, elapsedSeconds / expectedTimeS);
|
||||
progressBarText.Text = $"Unloading Filament: {Math.Max(0, expectedTimeS - elapsedSeconds):0}";
|
||||
}
|
||||
}
|
||||
|
||||
if (progressBar.RatioComplete == 1
|
||||
&& remainingLengthMm <= .001)
|
||||
{
|
||||
UiThread.ClearInterval(runningGCodeCommands);
|
||||
page.NextButton.InvokeClick();
|
||||
}
|
||||
},
|
||||
.1);
|
||||
},
|
||||
PageClose = () =>
|
||||
{
|
||||
UiThread.ClearInterval(runningGCodeCommands);
|
||||
}
|
||||
};
|
||||
unloadingFilamentPage.Closed += (s, e) =>
|
||||
{
|
||||
UiThread.ClearInterval(runningGCodeCommands);
|
||||
if (extruderCount > 1)
|
||||
{
|
||||
// reset the extruder that was active
|
||||
printer.Connection.QueueLine($"T{extruderPriorToUnload}");
|
||||
}
|
||||
printer.Connection.QueueLine("G92 E0");
|
||||
};
|
||||
|
||||
yield return unloadingFilamentPage;
|
||||
}
|
||||
|
||||
// put up a success message
|
||||
yield return new DoneUnloadingPage(this, extruderIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public class DoneUnloadingPage : WizardPage
|
||||
{
|
||||
public DoneUnloadingPage(PrinterSetupWizard setupWizard, int extruderIndex)
|
||||
: base(setupWizard, "Success".Localize(), "Success!\n\nYour filament should now be unloaded".Localize())
|
||||
{
|
||||
var loadFilamentButton = new TextButton("Load Filament".Localize(), theme)
|
||||
{
|
||||
Name = "Load Filament",
|
||||
BackgroundColor = theme.MinimalShade,
|
||||
};
|
||||
loadFilamentButton.Click += (s, e) =>
|
||||
{
|
||||
loadFilamentButton.Parents<SystemWindow>().First().Close();
|
||||
LoadFilamentWizard.Start(printer, theme, extruderIndex, false);
|
||||
};
|
||||
theme.ApplyPrimaryActionStyle(loadFilamentButton);
|
||||
|
||||
this.AddPageAction(loadFilamentButton);
|
||||
}
|
||||
|
||||
public override void OnLoad(EventArgs args)
|
||||
{
|
||||
this.ShowWizardFinished();
|
||||
base.OnLoad(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue