2018-11-02 16:14:37 -07:00
|
|
|
|
/*
|
2019-02-15 20:25:07 -08:00
|
|
|
|
Copyright (c) 2019, Lars Brubaker, John Lewin
|
2018-11-02 16:14:37 -07:00
|
|
|
|
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;
|
2019-01-18 09:49:38 -08:00
|
|
|
|
using System.Linq;
|
2018-11-02 16:14:37 -07:00
|
|
|
|
using Markdig.Agg;
|
|
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
2019-01-18 09:49:38 -08:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2018-11-02 16:14:37 -07:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
|
|
|
|
|
{
|
|
|
|
|
|
public class LoadFilamentWizard : PrinterSetupWizard
|
|
|
|
|
|
{
|
2019-05-07 17:10:07 -07:00
|
|
|
|
private readonly bool showAlreadyLoadedButton;
|
2019-02-07 14:28:22 -08:00
|
|
|
|
|
2020-08-30 08:29:15 -07:00
|
|
|
|
private readonly int extruderIndex;
|
2018-11-02 16:14:37 -07:00
|
|
|
|
|
2019-02-07 14:28:22 -08:00
|
|
|
|
public LoadFilamentWizard(PrinterConfig printer, int extruderIndex, bool showAlreadyLoadedButton)
|
2018-11-02 16:14:37 -07:00
|
|
|
|
: base(printer)
|
|
|
|
|
|
{
|
2019-02-07 14:28:22 -08:00
|
|
|
|
this.showAlreadyLoadedButton = showAlreadyLoadedButton;
|
2019-05-11 08:20:58 -07:00
|
|
|
|
if (printer.Settings.GetValue<int>(SettingsKey.extruder_count) == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Title = "Load Filament".Localize();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-05-30 09:52:12 -07:00
|
|
|
|
this.Title = "Load Extruder".Localize() + $" {extruderIndex + 1}";
|
2019-05-11 08:20:58 -07:00
|
|
|
|
}
|
2019-02-16 00:44:35 -08:00
|
|
|
|
|
2019-02-05 11:22:22 -08:00
|
|
|
|
this.extruderIndex = extruderIndex;
|
2019-02-16 09:11:20 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-15 16:00:07 -07:00
|
|
|
|
public override bool Completed
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (extruderIndex == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return printer.Settings.GetValue<bool>(SettingsKey.filament_has_been_loaded);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return printer.Settings.GetValue<bool>(SettingsKey.filament_1_has_been_loaded);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-22 12:19:09 -07:00
|
|
|
|
public double TemperatureAtStart { get; private set; }
|
|
|
|
|
|
|
2019-05-15 16:00:07 -07:00
|
|
|
|
public override bool Visible
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (extruderIndex == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return !printer.Settings.GetValue<bool>(SettingsKey.filament_has_been_loaded);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return !printer.Settings.GetValue<bool>(SettingsKey.filament_1_has_been_loaded)
|
|
|
|
|
|
&& printer.Settings.GetValue<int>(SettingsKey.extruder_count) > 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-03-20 17:05:31 -07:00
|
|
|
|
|
2020-11-13 17:24:15 -08:00
|
|
|
|
public override bool Enabled => printer.Connection.IsConnected && !printer.Connection.Printing && !printer.Connection.Paused;
|
2019-03-20 17:05:31 -07:00
|
|
|
|
|
2019-02-16 09:11:20 -08:00
|
|
|
|
public override void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
printer.Connection.SetTargetHotendTemperature(extruderIndex, this.TemperatureAtStart);
|
2019-02-16 00:59:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-15 11:13:04 -07:00
|
|
|
|
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);
|
2019-05-15 16:00:07 -07:00
|
|
|
|
return extruderCount > 1
|
2019-05-14 18:20:02 -07:00
|
|
|
|
&& !printer.Settings.GetValue<bool>(SettingsKey.filament_1_has_been_loaded)
|
|
|
|
|
|
&& Slicer.T1OrGreaterUsed(printer);
|
2019-04-15 11:13:04 -07:00
|
|
|
|
}
|
2019-04-15 15:10:19 -07:00
|
|
|
|
|
2019-05-09 15:17:32 -07:00
|
|
|
|
public override bool SetupRequired
|
|
|
|
|
|
{
|
|
|
|
|
|
// Defer to NeedsToBeRun methods for status
|
|
|
|
|
|
get => (extruderIndex == 0) ? NeedsToBeRun0(printer) : NeedsToBeRun1(printer);
|
|
|
|
|
|
}
|
2019-02-07 14:28:22 -08:00
|
|
|
|
|
2019-03-20 13:19:55 -07:00
|
|
|
|
protected override IEnumerator<WizardPage> GetPages()
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2019-03-22 12:19:09 -07:00
|
|
|
|
// Initialize - store startup temp and extruder index
|
|
|
|
|
|
this.TemperatureAtStart = printer.Connection.GetTargetHotendTemperature(extruderIndex);
|
|
|
|
|
|
|
2019-02-05 14:51:38 -08:00
|
|
|
|
var extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
|
|
|
|
|
|
|
2019-02-15 08:56:45 -08:00
|
|
|
|
var levelingStrings = new LevelingStrings();
|
2018-11-02 16:14:37 -07:00
|
|
|
|
|
2019-05-30 09:52:12 -07:00
|
|
|
|
var title = "Load Material".Localize();
|
2019-02-05 11:22:22 -08:00
|
|
|
|
var instructions = "Please select the material you want to load.".Localize();
|
2019-05-07 17:10:07 -07:00
|
|
|
|
|
|
|
|
|
|
if (extruderCount > 1)
|
2019-02-07 14:28:22 -08:00
|
|
|
|
{
|
2019-05-30 09:52:12 -07:00
|
|
|
|
title = "Load Extruder {0}".Localize().FormatWith(extruderIndex + 1);
|
2019-02-07 14:28:22 -08:00
|
|
|
|
instructions = "Please select the material you want to load into extruder {0}.".Localize().FormatWith(extruderIndex + 1);
|
|
|
|
|
|
}
|
2018-11-02 16:14:37 -07:00
|
|
|
|
|
|
|
|
|
|
// select the material
|
2019-05-30 09:52:12 -07:00
|
|
|
|
yield return new SelectMaterialPage(this, title, instructions, "Select".Localize(), extruderIndex, true, showAlreadyLoadedButton)
|
2019-02-16 00:44:35 -08:00
|
|
|
|
{
|
2019-03-19 18:14:03 -07:00
|
|
|
|
WindowTitle = Title
|
2019-02-16 00:44:35 -08:00
|
|
|
|
};
|
2018-11-02 16:14:37 -07:00
|
|
|
|
|
|
|
|
|
|
var theme = ApplicationController.Instance.Theme;
|
|
|
|
|
|
|
|
|
|
|
|
// show the trim filament message
|
|
|
|
|
|
{
|
2019-02-15 20:46:07 -08:00
|
|
|
|
var trimFilamentPage = new WizardPage(this, "Trim Filament".Localize(), "")
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2019-02-15 20:25:07 -08:00
|
|
|
|
PageLoad = (page) =>
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2018-11-02 17:21:32 -07:00
|
|
|
|
// start heating up the extruder
|
2019-02-05 11:22:22 -08:00
|
|
|
|
printer.Connection.SetTargetHotendTemperature(extruderIndex, printer.Settings.GetValue<double>(SettingsKey.temperature));
|
2018-11-02 17:21:32 -07:00
|
|
|
|
|
2018-11-02 16:14:37 -07:00
|
|
|
|
var markdownText = printer.Settings.GetValue(SettingsKey.trim_filament_markdown);
|
2020-08-30 08:29:15 -07:00
|
|
|
|
var markdownWidget = new MarkdownWidget(theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
Markdown = markdownText = markdownText.Replace("\\n", "\n")
|
|
|
|
|
|
};
|
2019-02-15 20:25:07 -08:00
|
|
|
|
page.ContentRow.AddChild(markdownWidget);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
yield return trimFilamentPage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-05 14:51:38 -08:00
|
|
|
|
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");
|
2020-08-30 08:29:15 -07:00
|
|
|
|
var extrusionMultiplierStream = printer.Connection.ExtrusionMultiplierStream;
|
|
|
|
|
|
var oldExtrusionMultiplier = extrusionMultiplierStream.ExtrusionRatio;
|
2019-02-05 14:51:38 -08:00
|
|
|
|
|
2018-11-05 12:44:28 -08:00
|
|
|
|
// show the insert filament page
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
|
|
|
|
|
RunningInterval runningGCodeCommands = null;
|
2019-02-15 20:46:07 -08:00
|
|
|
|
var insertFilamentPage = new WizardPage(this, "Insert Filament".Localize(), "")
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2019-02-15 20:25:07 -08:00
|
|
|
|
PageLoad = (page) =>
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2020-08-30 08:29:15 -07:00
|
|
|
|
extrusionMultiplierStream.ExtrusionRatio = 1;
|
|
|
|
|
|
|
2018-11-06 09:27:25 -08:00
|
|
|
|
var markdownText = printer.Settings.GetValue(SettingsKey.insert_filament_markdown2);
|
2019-05-07 17:10:07 -07:00
|
|
|
|
|
|
|
|
|
|
if (extruderIndex == 1)
|
2019-02-05 11:22:22 -08:00
|
|
|
|
{
|
|
|
|
|
|
markdownText = printer.Settings.GetValue(SettingsKey.insert_filament_1_markdown);
|
|
|
|
|
|
}
|
2019-05-07 17:10:07 -07:00
|
|
|
|
|
2020-08-30 08:29:15 -07:00
|
|
|
|
var markdownWidget = new MarkdownWidget(theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
Markdown = markdownText = markdownText.Replace("\\n", "\n")
|
|
|
|
|
|
};
|
2019-02-15 20:25:07 -08:00
|
|
|
|
page.ContentRow.AddChild(markdownWidget);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
|
|
|
|
|
|
// turn off the fan
|
2020-05-05 09:26:09 -07:00
|
|
|
|
printer.Connection.SetFanSpeed0To255(extruderIndex, 0);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
// Allow extrusion at any temperature. S0 only works on Marlin S1 works on repetier and marlin
|
|
|
|
|
|
printer.Connection.QueueLine("M302 S1");
|
|
|
|
|
|
|
2019-02-05 14:51:38 -08:00
|
|
|
|
int maxSecondsToStartLoading = 300;
|
2018-11-02 16:14:37 -07:00
|
|
|
|
var runningTime = Stopwatch.StartNew();
|
|
|
|
|
|
runningGCodeCommands = UiThread.SetInterval(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (printer.Connection.NumQueuedCommands == 0)
|
|
|
|
|
|
{
|
2020-08-30 08:29:15 -07:00
|
|
|
|
// Pulse mode
|
|
|
|
|
|
printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, 1, 150);
|
|
|
|
|
|
printer.Connection.QueueLine("G4 P10"); // empty buffer - allow for cancel
|
2019-02-05 14:51:38 -08:00
|
|
|
|
|
|
|
|
|
|
if (runningTime.ElapsedMilliseconds > maxSecondsToStartLoading * 1000)
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2018-11-13 16:52:23 -08:00
|
|
|
|
UiThread.ClearInterval(runningGCodeCommands);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
.1);
|
|
|
|
|
|
},
|
2019-02-15 20:09:48 -08:00
|
|
|
|
PageClose = () =>
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2020-08-30 08:29:15 -07:00
|
|
|
|
extrusionMultiplierStream.ExtrusionRatio = oldExtrusionMultiplier;
|
|
|
|
|
|
|
2018-11-13 16:52:23 -08:00
|
|
|
|
if (runningGCodeCommands != null)
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2018-11-13 16:52:23 -08:00
|
|
|
|
UiThread.ClearInterval(runningGCodeCommands);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
insertFilamentPage.Closed += (s, e) =>
|
|
|
|
|
|
{
|
2018-11-13 16:52:23 -08:00
|
|
|
|
if (runningGCodeCommands != null)
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2018-11-13 16:52:23 -08:00
|
|
|
|
UiThread.ClearInterval(runningGCodeCommands);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
yield return insertFilamentPage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// show the loading filament progress bar
|
|
|
|
|
|
{
|
|
|
|
|
|
RunningInterval runningGCodeCommands = null;
|
2019-02-15 20:46:07 -08:00
|
|
|
|
var loadingFilamentPage = new WizardPage(this, "Loading Filament".Localize(), "")
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2019-02-15 20:25:07 -08:00
|
|
|
|
PageLoad = (page) =>
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2020-08-30 08:29:15 -07:00
|
|
|
|
extrusionMultiplierStream.ExtrusionRatio = 1;
|
|
|
|
|
|
|
2019-02-15 20:25:07 -08:00
|
|
|
|
page.NextButton.Enabled = false;
|
2018-11-02 16:14:37 -07:00
|
|
|
|
|
|
|
|
|
|
// add the progress bar
|
2018-11-06 09:27:25 -08:00
|
|
|
|
var holder = new FlowLayoutWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(3, 0, 0, 10),
|
|
|
|
|
|
};
|
2020-08-05 10:07:40 -07:00
|
|
|
|
var progressBar = new ProgressBar(150 * GuiWidget.DeviceScale, 15 * GuiWidget.DeviceScale)
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
|
|
|
|
|
FillColor = theme.PrimaryAccentColor,
|
2018-11-03 09:13:07 -07:00
|
|
|
|
BorderColor = theme.TextColor,
|
2018-11-02 16:14:37 -07:00
|
|
|
|
BackgroundColor = Color.White,
|
2018-11-06 09:27:25 -08:00
|
|
|
|
VAnchor = VAnchor.Center,
|
2018-11-02 16:14:37 -07:00
|
|
|
|
};
|
2018-11-03 09:13:07 -07:00
|
|
|
|
var progressBarText = new TextWidget("", pointSize: 10, textColor: theme.TextColor)
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
|
|
|
|
|
AutoExpandBoundsToText = true,
|
|
|
|
|
|
Margin = new BorderDouble(5, 0, 0, 0),
|
2018-11-06 09:27:25 -08:00
|
|
|
|
VAnchor = VAnchor.Center,
|
2018-11-02 16:14:37 -07:00
|
|
|
|
};
|
|
|
|
|
|
holder.AddChild(progressBar);
|
|
|
|
|
|
holder.AddChild(progressBarText);
|
2019-02-15 20:25:07 -08:00
|
|
|
|
page.ContentRow.AddChild(holder);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
|
|
|
|
|
|
// Allow extrusion at any temperature. S0 only works on Marlin S1 works on repetier and marlin
|
|
|
|
|
|
printer.Connection.QueueLine("M302 S1");
|
2018-11-29 13:41:24 -08:00
|
|
|
|
// send a dwell to empty out the current move commands
|
2018-11-05 11:08:21 -08:00
|
|
|
|
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");
|
2018-11-02 16:14:37 -07:00
|
|
|
|
// start heating up the extruder
|
2019-02-05 11:22:22 -08:00
|
|
|
|
printer.Connection.SetTargetHotendTemperature(extruderIndex, printer.Settings.GetValue<double>(SettingsKey.temperature));
|
2018-11-02 16:14:37 -07:00
|
|
|
|
|
2018-11-03 12:10:49 -07:00
|
|
|
|
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;
|
2018-11-02 16:14:37 -07:00
|
|
|
|
|
2018-11-05 11:08:21 -08:00
|
|
|
|
Stopwatch runningTime = null;
|
2018-11-03 12:10:49 -07:00
|
|
|
|
var expectedTimeS = loadLengthMm / loadingSpeedMmPerS;
|
2018-11-05 11:08:21 -08:00
|
|
|
|
|
2018-11-02 16:14:37 -07:00
|
|
|
|
runningGCodeCommands = UiThread.SetInterval(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (printer.Connection.NumQueuedCommands == 0)
|
|
|
|
|
|
{
|
2019-05-07 17:10:07 -07:00
|
|
|
|
if (runningTime == null)
|
2018-11-05 11:08:21 -08:00
|
|
|
|
{
|
|
|
|
|
|
runningTime = Stopwatch.StartNew();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-05 14:51:38 -08:00
|
|
|
|
if (progressBar.RatioComplete < 1
|
|
|
|
|
|
|| remainingLengthMm >= .001)
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2018-11-03 12:10:49 -07:00
|
|
|
|
var thisExtrude = Math.Min(remainingLengthMm, maxSingleExtrudeLength);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
var currentE = printer.Connection.CurrentExtruderDestination;
|
2018-11-05 11:08:21 -08:00
|
|
|
|
printer.Connection.QueueLine("G1 E{0:0.###} F{1}".FormatWith(currentE + thisExtrude, loadingSpeedMmPerS * 60));
|
2019-02-05 14:51:38 -08:00
|
|
|
|
// 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");
|
2018-11-03 12:10:49 -07:00
|
|
|
|
remainingLengthMm -= thisExtrude;
|
|
|
|
|
|
var elapsedSeconds = runningTime.Elapsed.TotalSeconds;
|
|
|
|
|
|
progressBar.RatioComplete = Math.Min(1, elapsedSeconds / expectedTimeS);
|
|
|
|
|
|
progressBarText.Text = $"Loading Filament: {Math.Max(0, expectedTimeS - elapsedSeconds):0}";
|
2018-11-02 16:14:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-08 07:42:57 -08:00
|
|
|
|
if (progressBar.RatioComplete == 1
|
2018-11-05 11:08:21 -08:00
|
|
|
|
&& remainingLengthMm <= .001)
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2018-11-13 16:52:23 -08:00
|
|
|
|
UiThread.ClearInterval(runningGCodeCommands);
|
2019-02-15 20:25:07 -08:00
|
|
|
|
page.NextButton.InvokeClick();
|
2018-11-02 16:14:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
.1);
|
|
|
|
|
|
},
|
2019-02-15 20:09:48 -08:00
|
|
|
|
PageClose = () =>
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2020-08-30 08:29:15 -07:00
|
|
|
|
extrusionMultiplierStream.ExtrusionRatio = oldExtrusionMultiplier;
|
|
|
|
|
|
|
2018-11-13 16:52:23 -08:00
|
|
|
|
UiThread.ClearInterval(runningGCodeCommands);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
loadingFilamentPage.Closed += (s, e) =>
|
|
|
|
|
|
{
|
2018-11-13 16:52:23 -08:00
|
|
|
|
UiThread.ClearInterval(runningGCodeCommands);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
yield return loadingFilamentPage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// wait for extruder to heat
|
|
|
|
|
|
{
|
2019-02-05 11:22:22 -08:00
|
|
|
|
var targetHotendTemp = printer.Settings.Helpers.ExtruderTargetTemperature(extruderIndex);
|
|
|
|
|
|
var temps = new double[4];
|
|
|
|
|
|
temps[extruderIndex] = targetHotendTemp;
|
2018-11-02 16:14:37 -07:00
|
|
|
|
yield return new WaitForTempPage(
|
|
|
|
|
|
this,
|
|
|
|
|
|
"Waiting For Printer To Heat".Localize(),
|
2021-12-20 12:19:32 -08:00
|
|
|
|
"Waiting for the hotend to heat to".Localize() + " " + targetHotendTemp + "°C.\n"
|
2018-11-02 16:14:37 -07:00
|
|
|
|
+ "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,
|
2019-02-05 11:22:22 -08:00
|
|
|
|
temps);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// extrude slowly so that we can prime the extruder
|
|
|
|
|
|
{
|
|
|
|
|
|
RunningInterval runningGCodeCommands = null;
|
2019-02-15 20:46:07 -08:00
|
|
|
|
var runningCleanPage = new WizardPage(this, "Wait For Running Clean".Localize(), "")
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2019-02-15 20:25:07 -08:00
|
|
|
|
PageLoad = (page) =>
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2020-08-30 08:29:15 -07:00
|
|
|
|
extrusionMultiplierStream.ExtrusionRatio = 1;
|
|
|
|
|
|
|
2018-11-06 09:27:25 -08:00
|
|
|
|
var markdownText = printer.Settings.GetValue(SettingsKey.running_clean_markdown2);
|
2019-05-07 17:10:07 -07:00
|
|
|
|
|
|
|
|
|
|
if (extruderIndex == 1)
|
2019-02-05 11:22:22 -08:00
|
|
|
|
{
|
|
|
|
|
|
markdownText = printer.Settings.GetValue(SettingsKey.running_clean_1_markdown);
|
|
|
|
|
|
}
|
2019-05-07 17:10:07 -07:00
|
|
|
|
|
2020-08-30 08:29:15 -07:00
|
|
|
|
var markdownWidget = new MarkdownWidget(theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
Markdown = markdownText = markdownText.Replace("\\n", "\n")
|
|
|
|
|
|
};
|
2019-02-15 20:25:07 -08:00
|
|
|
|
page.ContentRow.AddChild(markdownWidget);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
|
|
|
|
|
|
var runningTime = Stopwatch.StartNew();
|
|
|
|
|
|
runningGCodeCommands = UiThread.SetInterval(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (printer.Connection.NumQueuedCommands == 0)
|
|
|
|
|
|
{
|
2020-08-30 08:29:15 -07:00
|
|
|
|
// Pulse mode
|
|
|
|
|
|
printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, 2, 150);
|
|
|
|
|
|
printer.Connection.QueueLine("G4 P10"); // empty buffer - allow for cancel
|
2019-06-06 12:25:14 -07:00
|
|
|
|
|
2018-11-02 16:14:37 -07:00
|
|
|
|
int secondsToRun = 90;
|
|
|
|
|
|
if (runningTime.ElapsedMilliseconds > secondsToRun * 1000)
|
|
|
|
|
|
{
|
2018-11-13 16:52:23 -08:00
|
|
|
|
UiThread.ClearInterval(runningGCodeCommands);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
.1);
|
|
|
|
|
|
},
|
2019-02-15 20:09:48 -08:00
|
|
|
|
PageClose = () =>
|
2018-11-02 16:14:37 -07:00
|
|
|
|
{
|
2020-08-30 08:29:15 -07:00
|
|
|
|
extrusionMultiplierStream.ExtrusionRatio = oldExtrusionMultiplier;
|
|
|
|
|
|
|
2018-11-13 16:52:23 -08:00
|
|
|
|
UiThread.ClearInterval(runningGCodeCommands);
|
2018-11-02 16:14:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
yield return runningCleanPage;
|
|
|
|
|
|
}
|
2018-11-05 11:08:21 -08:00
|
|
|
|
|
|
|
|
|
|
// put up a success message
|
2019-02-05 11:22:22 -08:00
|
|
|
|
yield return new DoneLoadingPage(this, extruderIndex);
|
2019-01-18 09:49:38 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-30 08:29:15 -07:00
|
|
|
|
public class DoneLoadingPage : WizardPage
|
2019-01-18 09:49:38 -08:00
|
|
|
|
{
|
2020-08-30 08:29:15 -07:00
|
|
|
|
private readonly int extruderIndex;
|
2019-05-29 08:10:01 -07:00
|
|
|
|
|
2020-08-30 08:29:15 -07:00
|
|
|
|
public DoneLoadingPage(PrinterSetupWizard setupWizard, int extruderIndex)
|
|
|
|
|
|
: base(setupWizard, "Filament Loaded".Localize(), "Success!\n\nYour filament should now be loaded".Localize())
|
2018-11-05 11:08:21 -08:00
|
|
|
|
{
|
2020-08-30 08:29:15 -07:00
|
|
|
|
this.extruderIndex = extruderIndex;
|
|
|
|
|
|
|
|
|
|
|
|
if (printer.Connection.Paused)
|
2019-01-18 09:49:38 -08:00
|
|
|
|
{
|
2022-07-16 07:46:44 -07:00
|
|
|
|
var resumePrintingButton = new ThemedTextButton("Resume Printing".Localize(), theme)
|
2020-08-30 08:29:15 -07:00
|
|
|
|
{
|
|
|
|
|
|
Name = "Resume Printing Button",
|
|
|
|
|
|
BackgroundColor = theme.MinimalShade,
|
|
|
|
|
|
};
|
|
|
|
|
|
resumePrintingButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
printer.Connection.Resume();
|
|
|
|
|
|
this.DialogWindow.ClosePage();
|
|
|
|
|
|
};
|
2019-01-18 09:49:38 -08:00
|
|
|
|
|
2020-08-30 08:29:15 -07:00
|
|
|
|
this.AcceptButton = resumePrintingButton;
|
|
|
|
|
|
this.AddPageAction(resumePrintingButton);
|
|
|
|
|
|
}
|
2019-01-18 09:49:38 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-30 08:29:15 -07:00
|
|
|
|
public override void OnLoad(EventArgs args)
|
2019-05-29 08:10:01 -07:00
|
|
|
|
{
|
2020-08-30 08:29:15 -07:00
|
|
|
|
switch (extruderIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
printer.Settings.SetValue(SettingsKey.filament_has_been_loaded, "1");
|
|
|
|
|
|
break;
|
2019-05-29 08:10:01 -07:00
|
|
|
|
|
2020-08-30 08:29:15 -07:00
|
|
|
|
case 1:
|
|
|
|
|
|
printer.Settings.SetValue(SettingsKey.filament_1_has_been_loaded, "1");
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2019-05-29 08:10:01 -07:00
|
|
|
|
|
2020-08-30 08:29:15 -07:00
|
|
|
|
this.ShowWizardFinished();
|
2018-11-05 11:08:21 -08:00
|
|
|
|
|
2020-08-30 08:29:15 -07:00
|
|
|
|
base.OnLoad(args);
|
|
|
|
|
|
}
|
2018-11-02 16:14:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|