2014-02-05 18:29:58 -08:00
/ *
2014-02-15 18:06:03 -08:00
Copyright ( c ) 2014 , Lars Brubaker
2014-01-29 19:09:30 -08:00
All rights reserved .
Redistribution and use in source and binary forms , with or without
2015-04-08 15:20:10 -07:00
modification , are permitted provided that the following conditions are met :
2014-01-29 19:09:30 -08:00
1. Redistributions of source code must retain the above copyright notice , this
2015-04-08 15:20:10 -07:00
list of conditions and the following disclaimer .
2014-01-29 19:09:30 -08:00
2. Redistributions in binary form must reproduce the above copyright notice ,
this list of conditions and the following disclaimer in the documentation
2015-04-08 15:20:10 -07:00
and / or other materials provided with the distribution .
2014-01-29 19:09:30 -08:00
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
2015-04-08 15:20:10 -07:00
of the authors and should not be interpreted as representing official policies ,
2014-01-29 19:09:30 -08:00
either expressed or implied , of the FreeBSD Project .
* /
2018-01-05 12:44:57 -08:00
using MatterControl.Printing ;
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg ;
2018-03-14 15:00:10 -07:00
using MatterHackers.Agg.Font ;
using MatterHackers.Agg.Image ;
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg.UI ;
2017-04-11 17:49:23 -07:00
using MatterHackers.GCodeVisualizer ;
2014-02-05 18:29:58 -08:00
using MatterHackers.Localizations ;
2014-06-11 14:52:58 -07:00
using MatterHackers.MatterControl.PrinterCommunication ;
2018-03-14 15:00:10 -07:00
using MatterHackers.MatterControl.PrinterCommunication.Io ;
2015-08-03 15:48:36 -07:00
using MatterHackers.MatterControl.SlicerConfiguration ;
2015-04-08 15:20:10 -07:00
using MatterHackers.VectorMath ;
using System ;
2016-10-11 14:56:36 -07:00
using System.Collections.Generic ;
2017-04-13 17:04:42 -07:00
using System.Linq ;
2014-01-29 19:09:30 -08:00
2014-06-06 16:05:18 -07:00
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
2014-01-29 19:09:30 -08:00
{
2015-04-08 15:20:10 -07:00
public class FirstPageInstructions : InstructionsPage
{
2017-09-15 12:08:00 -07:00
public FirstPageInstructions ( PrinterConfig printer , string pageDescription , string instructionsText )
: base ( printer , pageDescription , instructionsText )
2015-04-08 15:20:10 -07:00
{
}
}
2018-03-14 15:00:10 -07:00
public class CleanExtruderInstructionPage : InstructionsPage
{
public CleanExtruderInstructionPage ( PrinterConfig printer , string title , string body )
: base ( printer , title , body )
{
ImageBuffer imageBuffer = MacroProcessingStream . LoadImageAsset ( printer . Settings . GetValue ( "clean_nozzle_image" ) ) ;
var levelingStrings = new LevelingStrings ( printer . Settings ) ;
GuiWidget spacer = new GuiWidget ( 10 , 10 ) ;
topToBottomControls . AddChild ( spacer ) ;
topToBottomControls . AddChild ( new ImageWidget ( imageBuffer )
{
HAnchor = HAnchor . Center
} ) ;
AddTextField ( levelingStrings . ClickNext , 10 ) ;
}
}
2017-08-08 17:49:26 -07:00
public class SelectMaterialPage : InstructionsPage
{
2017-09-15 12:08:00 -07:00
public SelectMaterialPage ( PrinterConfig printer , string pageDescription , string instructionsText )
: base ( printer , pageDescription , instructionsText )
2017-08-08 17:49:26 -07:00
{
2018-01-10 12:55:41 -08:00
var materialSelector = new PresetSelectorWidget ( printer , "Material" . Localize ( ) , Color . Transparent , NamedSettingsLayers . Material ) ;
2017-10-31 11:43:25 -07:00
materialSelector . BackgroundColor = Color . Transparent ;
2017-08-08 17:49:26 -07:00
materialSelector . Margin = new BorderDouble ( 0 , 0 , 0 , 15 ) ;
topToBottomControls . AddChild ( materialSelector ) ;
}
}
public class WaitForTempPage : InstructionsPage
{
2017-09-01 11:48:43 -07:00
protected WizardControl container ;
2017-08-08 17:49:26 -07:00
private ProgressBar progressBar ;
private TextWidget progressBarText ;
2017-09-01 11:48:43 -07:00
private TextWidget doneText ;
2017-09-15 12:08:00 -07:00
private double startingTemp ;
2017-08-08 17:49:26 -07:00
2017-09-15 12:08:00 -07:00
public WaitForTempPage ( PrinterConfig printer , WizardControl container , LevelingStrings levelingStrings )
: base ( printer , levelingStrings . WaitingForTempPageStepText , levelingStrings . WaitingForTempPageInstructions )
2017-08-08 17:49:26 -07:00
{
2017-09-01 11:48:43 -07:00
this . container = container ;
var holder = new FlowLayoutWidget ( )
{
Margin = new BorderDouble ( 0 , 5 )
} ;
2017-08-08 17:49:26 -07:00
progressBar = new ProgressBar ( ( int ) ( 150 * GuiWidget . DeviceScale ) , ( int ) ( 15 * GuiWidget . DeviceScale ) )
{
FillColor = ActiveTheme . Instance . PrimaryAccentColor ,
BorderColor = ActiveTheme . Instance . PrimaryTextColor ,
2017-10-31 11:43:25 -07:00
BackgroundColor = Color . White ,
2017-09-01 11:48:43 -07:00
Margin = new BorderDouble ( 3 , 0 , 0 , 0 ) ,
VAnchor = VAnchor . Center
2017-08-08 17:49:26 -07:00
} ;
progressBarText = new TextWidget ( "" , pointSize : 10 , textColor : ActiveTheme . Instance . PrimaryTextColor )
{
AutoExpandBoundsToText = true ,
Margin = new BorderDouble ( 5 , 0 , 0 , 0 ) ,
2017-09-01 11:48:43 -07:00
VAnchor = VAnchor . Center
2017-08-08 17:49:26 -07:00
} ;
holder . AddChild ( progressBar ) ;
holder . AddChild ( progressBarText ) ;
topToBottomControls . AddChild ( holder ) ;
2017-09-01 11:48:43 -07:00
doneText = new TextWidget ( "Done!" , textColor : ActiveTheme . Instance . PrimaryTextColor )
{
AutoExpandBoundsToText = true ,
Visible = false ,
} ;
topToBottomControls . AddChild ( doneText ) ;
2017-08-08 17:49:26 -07:00
}
public override void PageIsBecomingActive ( )
{
2017-09-15 12:08:00 -07:00
startingTemp = printer . Connection . ActualBedTemperature ;
2018-03-20 18:25:40 -07:00
UiThread . SetInterval ( ShowTempChangeProgress , 1 , ( ) = > ! HasBeenClosed ) ;
2017-08-08 17:49:26 -07:00
// start heating the bed and show our progress
2017-09-15 12:08:00 -07:00
printer . Connection . TargetBedTemperature = printer . Settings . GetValue < double > ( SettingsKey . bed_temperature ) ;
2017-08-08 17:49:26 -07:00
2017-08-21 15:45:43 -07:00
// hook our parent so we can turn off the bed when we are done with leveling
2017-08-08 17:49:26 -07:00
Parent . Closed + = ( s , e ) = >
{
// Make sure when the wizard closes we turn off the bed heating
2018-03-21 14:20:43 -07:00
printer . Connection . TurnOffBedAndExtruders ( TurnOff . AfterDelay ) ;
2017-08-08 17:49:26 -07:00
} ;
2017-09-15 12:08:00 -07:00
if ( printer . Settings . Helpers . UseZProbe ( ) )
2017-09-01 11:48:43 -07:00
{
container . backButton . Enabled = false ;
container . nextButton . Enabled = false ;
}
2017-11-09 16:31:59 -08:00
// if we are trying to go to a temp of 0 than just move on to next window
if ( printer . Settings . GetValue < double > ( SettingsKey . bed_temperature ) = = 0 )
{
// advance to the next page
UiThread . RunOnIdle ( ( ) = > container . nextButton . OnClick ( null ) ) ;
}
2017-08-08 17:49:26 -07:00
base . PageIsBecomingActive ( ) ;
}
2017-09-01 11:48:43 -07:00
public override void PageIsBecomingInactive ( )
{
container . nextButton . Enabled = true ;
container . backButton . Enabled = true ;
base . PageIsBecomingInactive ( ) ;
}
2017-08-08 17:49:26 -07:00
private void ShowTempChangeProgress ( )
{
progressBar . Visible = true ;
2017-09-15 12:08:00 -07:00
double targetTemp = printer . Connection . TargetBedTemperature ;
double actualTemp = printer . Connection . ActualBedTemperature ;
2017-08-08 17:49:26 -07:00
double totalDelta = targetTemp - startingTemp ;
double currentDelta = actualTemp - startingTemp ;
double ratioDone = totalDelta ! = 0 ? ( currentDelta / totalDelta ) : 1 ;
progressBar . RatioComplete = Math . Min ( Math . Max ( 0 , ratioDone ) , 1 ) ;
progressBarText . Text = $"Temperature: {actualTemp:0} / {targetTemp:0}" ;
2017-09-01 11:48:43 -07:00
// if we are within 1 degree of our target
2018-04-04 13:45:10 -07:00
if ( Math . Abs ( targetTemp - actualTemp ) < 2
2017-09-01 11:48:43 -07:00
& & doneText . Visible = = false )
{
doneText . Visible = true ;
container . backButton . Enabled = true ;
container . nextButton . Enabled = true ;
2017-09-15 12:08:00 -07:00
if ( printer . Settings . Helpers . UseZProbe ( ) )
2017-09-01 11:48:43 -07:00
{
// advance to the next page
2017-09-22 14:06:52 -07:00
UiThread . RunOnIdle ( ( ) = > container . nextButton . OnClick ( null ) ) ;
2017-09-01 11:48:43 -07:00
}
}
2017-08-08 17:49:26 -07:00
}
}
2017-05-19 14:39:57 -07:00
public class LastPagelInstructions : InstructionsPage
2015-08-01 14:44:53 -07:00
{
2017-04-12 12:12:11 -07:00
protected WizardControl container ;
2016-10-11 14:56:36 -07:00
private List < ProbePosition > probePositions ;
2015-08-01 14:44:53 -07:00
2017-09-15 12:08:00 -07:00
public LastPagelInstructions ( PrinterConfig printer , WizardControl container , string pageDescription , string instructionsText , List < ProbePosition > probePositions )
: base ( printer , pageDescription , instructionsText )
2015-08-01 14:44:53 -07:00
{
this . probePositions = probePositions ;
2017-04-12 12:12:11 -07:00
this . container = container ;
2015-08-01 14:44:53 -07:00
}
public override void PageIsBecomingActive ( )
{
2017-09-15 12:08:00 -07:00
PrintLevelingData levelingData = printer . Settings . Helpers . GetPrintLevelingData ( ) ;
2016-10-13 14:18:30 -07:00
levelingData . SampledPositions . Clear ( ) ;
2016-10-11 14:56:36 -07:00
for ( int i = 0 ; i < probePositions . Count ; i + + )
2015-08-01 14:44:53 -07:00
{
2018-04-03 12:10:33 -07:00
levelingData . SampledPositions . Add ( probePositions [ i ] . position ) ;
2015-08-01 14:44:53 -07:00
}
2015-04-08 15:20:10 -07:00
2018-04-04 13:45:10 -07:00
levelingData . LevelingSystem = printer . Settings . GetValue < LevelingSystem > ( SettingsKey . print_leveling_solution ) ;
levelingData . CreationData = DateTime . Now ;
// record the temp the bed was when we measured it (or 0 if no heated bed)
levelingData . BedTemperature = printer . Settings . GetValue < bool > ( SettingsKey . has_heated_bed ) ?
printer . Settings . GetValue < double > ( SettingsKey . bed_temperature )
: 0 ;
2016-04-18 11:31:31 -07:00
// Invoke setter forcing persistence of leveling data
2017-09-15 12:08:00 -07:00
printer . Settings . Helpers . SetPrintLevelingData ( levelingData , true ) ;
2018-04-04 15:58:57 -07:00
PrintLevelingStream . AllowLeveling = true ;
2018-03-16 15:14:23 -07:00
printer . Settings . Helpers . DoPrintLeveling ( true ) ;
2017-01-18 14:44:49 -08:00
2017-09-15 12:08:00 -07:00
if ( printer . Settings . GetValue < bool > ( SettingsKey . z_homes_to_max ) )
2017-04-11 17:49:23 -07:00
{
2017-09-15 12:08:00 -07:00
printer . Connection . HomeAxis ( PrinterConnection . Axis . XYZ ) ;
2017-04-11 17:49:23 -07:00
}
2017-04-12 12:12:11 -07:00
container . backButton . Enabled = false ;
2018-01-31 12:32:25 -08:00
// Make sure when the wizard is done we turn off the bed heating
2018-03-21 14:20:43 -07:00
printer . Connection . TurnOffBedAndExtruders ( TurnOff . AfterDelay ) ;
2018-01-31 12:32:25 -08:00
2015-04-08 15:20:10 -07:00
base . PageIsBecomingActive ( ) ;
}
}
2018-03-09 18:22:38 -08:00
public class CalibrateProbeLastPagelInstructions : InstructionsPage
{
protected WizardControl container ;
private List < ProbePosition > autoProbePositions ;
private List < ProbePosition > manualProbePositions ;
public CalibrateProbeLastPagelInstructions ( PrinterConfig printer , WizardControl container , string pageDescription , string instructionsText ,
List < ProbePosition > autoProbePositions ,
List < ProbePosition > manualProbePositions )
: base ( printer , pageDescription , instructionsText )
{
this . autoProbePositions = autoProbePositions ;
this . manualProbePositions = manualProbePositions ;
this . container = container ;
}
public override void PageIsBecomingActive ( )
{
2018-03-12 16:36:51 -07:00
// make sure we don't have leveling data
2018-03-09 18:22:38 -08:00
double newProbeOffset = autoProbePositions [ 0 ] . position . Z - manualProbePositions [ 0 ] . position . Z ;
printer . Settings . SetValue ( SettingsKey . z_probe_z_offset , newProbeOffset . ToString ( "0.###" ) ) ;
2018-04-06 14:58:25 -07:00
printer . Settings . SetValue ( SettingsKey . probe_has_been_calibrated , "1" ) ;
2018-03-09 18:22:38 -08:00
if ( printer . Settings . GetValue < bool > ( SettingsKey . z_homes_to_max ) )
{
printer . Connection . HomeAxis ( PrinterConnection . Axis . XYZ ) ;
}
container . backButton . Enabled = false ;
2018-04-06 14:58:25 -07:00
Closed + = ( s , e ) = >
{
// move from this wizard to the print leveling wizard if needed
ApplicationController . Instance . RunAnyRequiredCalibration ( printer ) ;
} ;
2018-03-09 18:22:38 -08:00
base . PageIsBecomingActive ( ) ;
}
}
2015-04-08 15:20:10 -07:00
public class GettingThirdPointFor2PointCalibration : InstructionsPage
{
protected Vector3 probeStartPosition ;
private ProbePosition probePosition ;
protected WizardControl container ;
2017-09-15 12:08:00 -07:00
public GettingThirdPointFor2PointCalibration ( PrinterConfig printer , WizardControl container , string pageDescription , Vector3 probeStartPosition , string instructionsText , ProbePosition probePosition )
: base ( printer , pageDescription , instructionsText )
2015-04-08 15:20:10 -07:00
{
this . probeStartPosition = probeStartPosition ;
this . probePosition = probePosition ;
this . container = container ;
}
2016-12-29 06:55:12 -08:00
private EventHandler unregisterEvents ;
2015-04-08 15:20:10 -07:00
2017-02-03 13:06:08 -08:00
public override void OnClosed ( ClosedEventArgs e )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
unregisterEvents ? . Invoke ( this , null ) ;
2015-04-08 15:20:10 -07:00
base . OnClosed ( e ) ;
}
public override void PageIsBecomingActive ( )
{
// first make sure there is no leftover FinishedProbe event
2018-01-06 22:03:06 -08:00
printer . Connection . LineReceived . UnregisterEvent ( FinishedProbe , ref unregisterEvents ) ;
2015-04-08 15:20:10 -07:00
2017-09-15 12:08:00 -07:00
var feedRates = printer . Settings . Helpers . ManualMovementSpeeds ( ) ;
2016-06-17 09:29:11 -07:00
2017-10-31 12:51:16 -07:00
printer . Connection . MoveAbsolute ( PrinterConnection . Axis . Z , probeStartPosition . Z , feedRates . Z ) ;
printer . Connection . MoveAbsolute ( probeStartPosition , feedRates . X ) ;
2018-01-04 17:30:48 -08:00
printer . Connection . QueueLine ( "G30" ) ;
2018-01-06 22:03:06 -08:00
printer . Connection . LineReceived . RegisterEvent ( FinishedProbe , ref unregisterEvents ) ;
2015-04-08 15:20:10 -07:00
base . PageIsBecomingActive ( ) ;
container . nextButton . Enabled = false ;
container . backButton . Enabled = false ;
}
private void FinishedProbe ( object sender , EventArgs e )
{
StringEventArgs currentEvent = e as StringEventArgs ;
if ( currentEvent ! = null )
{
if ( currentEvent . Data . Contains ( "endstops hit" ) )
{
2018-01-06 22:03:06 -08:00
printer . Connection . LineReceived . UnregisterEvent ( FinishedProbe , ref unregisterEvents ) ;
2015-04-08 15:20:10 -07:00
int zStringPos = currentEvent . Data . LastIndexOf ( "Z:" ) ;
string zProbeHeight = currentEvent . Data . Substring ( zStringPos + 2 ) ;
2017-10-31 12:51:16 -07:00
probePosition . position = new Vector3 ( probeStartPosition . X , probeStartPosition . Y , double . Parse ( zProbeHeight ) ) ;
printer . Connection . MoveAbsolute ( probeStartPosition , printer . Settings . Helpers . ManualMovementSpeeds ( ) . Z ) ;
2017-09-15 12:08:00 -07:00
printer . Connection . ReadPosition ( ) ;
2015-04-08 15:20:10 -07:00
2017-09-22 14:06:52 -07:00
UiThread . RunOnIdle ( ( ) = > container . nextButton . OnClick ( null ) ) ;
2015-04-08 15:20:10 -07:00
}
}
}
}
public class HomePrinterPage : InstructionsPage
{
2017-09-01 11:48:43 -07:00
protected WizardControl container ;
private EventHandler unregisterEvents ;
2018-03-12 16:36:51 -07:00
bool autoAdvance ;
2017-09-01 11:48:43 -07:00
2018-03-12 16:36:51 -07:00
public HomePrinterPage ( PrinterConfig printer , WizardControl container , string pageDescription , string instructionsText , bool autoAdvance )
2017-09-15 12:08:00 -07:00
: base ( printer , pageDescription , instructionsText )
2015-04-08 15:20:10 -07:00
{
2018-03-12 16:36:51 -07:00
this . autoAdvance = autoAdvance ;
2017-09-01 11:48:43 -07:00
this . container = container ;
}
public override void OnClosed ( ClosedEventArgs e )
{
unregisterEvents ? . Invoke ( this , null ) ;
base . OnClosed ( e ) ;
2015-04-08 15:20:10 -07:00
}
public override void PageIsBecomingActive ( )
{
2017-09-01 11:48:43 -07:00
// make sure we don't have anything left over
unregisterEvents ? . Invoke ( this , null ) ;
2017-09-15 12:08:00 -07:00
printer . Connection . PrintingStateChanged . RegisterEvent ( CheckHomeFinished , ref unregisterEvents ) ;
2017-09-01 11:48:43 -07:00
2017-09-15 12:08:00 -07:00
printer . Connection . HomeAxis ( PrinterConnection . Axis . XYZ ) ;
2017-09-01 11:48:43 -07:00
2018-03-12 16:36:51 -07:00
if ( autoAdvance )
2017-09-01 11:48:43 -07:00
{
container . nextButton . Enabled = false ;
}
2015-04-08 15:20:10 -07:00
base . PageIsBecomingActive ( ) ;
}
2017-09-01 11:48:43 -07:00
private void CheckHomeFinished ( object sender , EventArgs e )
{
2017-09-15 12:08:00 -07:00
if ( printer . Connection . DetailedPrintingState ! = DetailedPrintingState . HomingAxis )
2017-09-01 11:48:43 -07:00
{
unregisterEvents ? . Invoke ( this , null ) ;
container . nextButton . Enabled = true ;
container . backButton . Enabled = true ;
2017-09-15 12:08:00 -07:00
if ( printer . Settings . Helpers . UseZProbe ( ) )
2017-09-01 11:48:43 -07:00
{
2017-09-22 14:06:52 -07:00
UiThread . RunOnIdle ( ( ) = > container . nextButton . OnClick ( null ) ) ;
2017-09-01 11:48:43 -07:00
}
}
}
public override void PageIsBecomingInactive ( )
{
unregisterEvents ? . Invoke ( this , null ) ;
container . nextButton . Enabled = true ;
container . backButton . Enabled = true ;
base . PageIsBecomingInactive ( ) ;
}
2015-04-08 15:20:10 -07:00
}
public class FindBedHeight : InstructionsPage
{
private Vector3 lastReportedPosition ;
2016-10-11 14:56:36 -07:00
private List < ProbePosition > probePositions ;
int probePositionsBeingEditedIndex ;
2015-04-08 15:20:10 -07:00
private double moveAmount ;
protected JogControls . MoveButton zPlusControl ;
protected JogControls . MoveButton zMinusControl ;
2017-04-14 09:50:51 -07:00
protected WizardControl container ;
2015-04-08 15:20:10 -07:00
2017-09-15 12:08:00 -07:00
public FindBedHeight ( PrinterConfig printer , WizardControl container , string pageDescription , string setZHeightCoarseInstruction1 , string setZHeightCoarseInstruction2 , double moveDistance , List < ProbePosition > probePositions , int probePositionsBeingEditedIndex )
: base ( printer , pageDescription , setZHeightCoarseInstruction1 )
2015-04-08 15:20:10 -07:00
{
2017-04-14 09:50:51 -07:00
this . container = container ;
2016-10-11 14:56:36 -07:00
this . probePositions = probePositions ;
2015-04-08 15:20:10 -07:00
this . moveAmount = moveDistance ;
2017-09-15 12:08:00 -07:00
this . lastReportedPosition = printer . Connection . LastReportedPosition ;
2016-10-11 14:56:36 -07:00
this . probePositionsBeingEditedIndex = probePositionsBeingEditedIndex ;
2015-04-08 15:20:10 -07:00
GuiWidget spacer = new GuiWidget ( 15 , 15 ) ;
topToBottomControls . AddChild ( spacer ) ;
FlowLayoutWidget zButtonsAndInfo = new FlowLayoutWidget ( ) ;
2017-08-07 15:47:27 -07:00
zButtonsAndInfo . HAnchor | = Agg . UI . HAnchor . Center ;
2015-04-08 15:20:10 -07:00
FlowLayoutWidget zButtons = CreateZButtons ( ) ;
zButtonsAndInfo . AddChild ( zButtons ) ;
zButtonsAndInfo . AddChild ( new GuiWidget ( 15 , 10 ) ) ;
2017-06-14 17:47:02 -07:00
//textFields
TextWidget zPosition = new TextWidget ( "Z: 0.0 " , pointSize : 12 , textColor : ActiveTheme . Instance . PrimaryTextColor )
{
2017-08-07 15:47:27 -07:00
VAnchor = VAnchor . Center ,
2017-06-14 17:47:02 -07:00
Margin = new BorderDouble ( 10 , 0 ) ,
} ;
2018-03-20 18:25:40 -07:00
UiThread . SetInterval ( ( ) = >
2017-06-14 17:47:02 -07:00
{
2017-09-15 12:08:00 -07:00
Vector3 destinationPosition = printer . Connection . CurrentDestination ;
2017-10-31 12:51:16 -07:00
zPosition . Text = "Z: {0:0.00}" . FormatWith ( destinationPosition . Z ) ;
2018-03-20 18:25:40 -07:00
} , . 3 , ( ) = > ! HasBeenClosed ) ;
2015-04-08 15:20:10 -07:00
2017-06-14 17:47:02 -07:00
zButtonsAndInfo . AddChild ( zPosition ) ;
2015-04-08 15:20:10 -07:00
topToBottomControls . AddChild ( zButtonsAndInfo ) ;
AddTextField ( setZHeightCoarseInstruction2 , 10 ) ;
}
public override void PageIsBecomingActive ( )
{
// always make sure we don't have print leveling turned on
2018-04-04 15:58:57 -07:00
PrintLevelingStream . AllowLeveling = false ;
2015-04-08 15:20:10 -07:00
base . PageIsBecomingActive ( ) ;
2017-04-14 09:50:51 -07:00
this . Parents < SystemWindow > ( ) . First ( ) . KeyDown + = TopWindowKeyDown ;
2018-04-06 17:11:51 -07:00
container . nextButton . ToolTipText = "[Right Arrow]" . Localize ( ) ;
container . backButton . ToolTipText = "[Left Arrow]" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
}
public override void PageIsBecomingInactive ( )
{
2017-04-14 09:50:51 -07:00
this . Parents < SystemWindow > ( ) . First ( ) . KeyDown - = TopWindowKeyDown ;
2017-09-15 12:08:00 -07:00
probePositions [ probePositionsBeingEditedIndex ] . position = printer . Connection . LastReportedPosition ;
2015-04-08 15:20:10 -07:00
base . PageIsBecomingInactive ( ) ;
2018-04-06 17:11:51 -07:00
container . nextButton . ToolTipText = "" ;
container . backButton . ToolTipText = "" ;
2015-04-08 15:20:10 -07:00
}
private FlowLayoutWidget CreateZButtons ( )
{
2017-10-31 11:43:25 -07:00
FlowLayoutWidget zButtons = JogControls . CreateZButtons ( printer , Color . White , 4 , out zPlusControl , out zMinusControl , true ) ;
2015-04-08 15:20:10 -07:00
// set these to 0 so the button does not do any movements by default (we will handle the movement on our click callback)
zPlusControl . MoveAmount = 0 ;
2018-04-06 17:11:51 -07:00
zPlusControl . ToolTipText + = " [Up Arrow]" . Localize ( ) ;
2017-01-17 14:47:04 -08:00
zPlusControl . Click + = zPlusControl_Click ;
2018-04-06 17:11:51 -07:00
zMinusControl . MoveAmount = 0 ;
zMinusControl . ToolTipText + = " [Down Arrow]" . Localize ( ) ;
2017-01-17 14:47:04 -08:00
zMinusControl . Click + = zMinusControl_Click ;
2015-04-08 15:20:10 -07:00
return zButtons ;
}
2017-04-14 09:50:51 -07:00
public void TopWindowKeyDown ( object s , KeyEventArgs keyEvent )
{
switch ( keyEvent . KeyCode )
{
case Keys . Up :
zPlusControl_Click ( null , null ) ;
container . nextButton . Enabled = true ;
break ;
case Keys . Down :
zMinusControl_Click ( null , null ) ;
container . nextButton . Enabled = true ;
break ;
case Keys . Right :
if ( container . nextButton . Enabled )
{
2017-09-22 14:06:52 -07:00
UiThread . RunOnIdle ( ( ) = > container . nextButton . OnClick ( null ) ) ;
2017-04-14 09:50:51 -07:00
}
break ;
case Keys . Left :
if ( container . backButton . Enabled )
{
2017-09-22 14:06:52 -07:00
UiThread . RunOnIdle ( ( ) = > container . backButton . OnClick ( null ) ) ;
2017-04-14 09:50:51 -07:00
}
break ;
}
base . OnKeyDown ( keyEvent ) ;
}
2015-04-08 15:20:10 -07:00
private void zMinusControl_Click ( object sender , EventArgs mouseEvent )
{
2017-10-31 12:51:16 -07:00
printer . Connection . MoveRelative ( PrinterConnection . Axis . Z , - moveAmount , printer . Settings . Helpers . ManualMovementSpeeds ( ) . Z ) ;
2017-09-15 12:08:00 -07:00
printer . Connection . ReadPosition ( ) ;
2015-04-08 15:20:10 -07:00
}
private void zPlusControl_Click ( object sender , EventArgs mouseEvent )
{
2017-10-31 12:51:16 -07:00
printer . Connection . MoveRelative ( PrinterConnection . Axis . Z , moveAmount , printer . Settings . Helpers . ManualMovementSpeeds ( ) . Z ) ;
2017-09-15 12:08:00 -07:00
printer . Connection . ReadPosition ( ) ;
2015-04-08 15:20:10 -07:00
}
}
2017-04-11 17:49:23 -07:00
public class AutoProbeFeedback : InstructionsPage
{
private Vector3 lastReportedPosition ;
private List < ProbePosition > probePositions ;
int probePositionsBeingEditedIndex ;
private EventHandler unregisterEvents ;
protected Vector3 probeStartPosition ;
protected WizardControl container ;
2017-09-15 12:08:00 -07:00
public AutoProbeFeedback ( PrinterConfig printer , WizardControl container , Vector3 probeStartPosition , string pageDescription , List < ProbePosition > probePositions , int probePositionsBeingEditedIndex )
: base ( printer , pageDescription , pageDescription )
2017-04-11 17:49:23 -07:00
{
this . container = container ;
this . probeStartPosition = probeStartPosition ;
this . probePositions = probePositions ;
2017-06-07 15:56:02 -07:00
2017-09-15 12:08:00 -07:00
this . lastReportedPosition = printer . Connection . LastReportedPosition ;
2017-04-11 17:49:23 -07:00
this . probePositionsBeingEditedIndex = probePositionsBeingEditedIndex ;
GuiWidget spacer = new GuiWidget ( 15 , 15 ) ;
topToBottomControls . AddChild ( spacer ) ;
FlowLayoutWidget textFields = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
}
private void GetZProbeHeight ( object sender , EventArgs e )
{
StringEventArgs currentEvent = e as StringEventArgs ;
if ( currentEvent ! = null )
{
2017-04-13 17:04:42 -07:00
double sampleRead = double . MinValue ;
2017-04-12 17:30:29 -07:00
if ( currentEvent . Data . StartsWith ( "Bed" ) ) // marlin G30 return code (looks like: 'Bed Position X:20 Y:32 Z:.01')
2017-04-11 17:49:23 -07:00
{
2017-10-31 12:51:16 -07:00
probePositions [ probePositionsBeingEditedIndex ] . position . X = probeStartPosition . X ;
probePositions [ probePositionsBeingEditedIndex ] . position . Y = probeStartPosition . Y ;
2017-04-13 17:04:42 -07:00
GCodeFile . GetFirstNumberAfter ( "Z:" , currentEvent . Data , ref sampleRead ) ;
2017-04-11 17:49:23 -07:00
}
2017-04-12 15:17:29 -07:00
else if ( currentEvent . Data . StartsWith ( "Z:" ) ) // smoothie G30 return code (looks like: 'Z:10.01')
{
2017-10-31 12:51:16 -07:00
probePositions [ probePositionsBeingEditedIndex ] . position . X = probeStartPosition . X ;
probePositions [ probePositionsBeingEditedIndex ] . position . Y = probeStartPosition . Y ;
2018-04-04 15:58:57 -07:00
// smoothie returns the position relative to the start position
2017-04-12 15:17:29 -07:00
double reportedProbeZ = 0 ;
GCodeFile . GetFirstNumberAfter ( "Z:" , currentEvent . Data , ref reportedProbeZ ) ;
2017-10-31 12:51:16 -07:00
sampleRead = probeStartPosition . Z - reportedProbeZ ;
2017-04-13 17:04:42 -07:00
}
if ( sampleRead ! = double . MinValue )
{
samples . Add ( sampleRead ) ;
2017-09-15 12:08:00 -07:00
int numberOfSamples = printer . Settings . GetValue < int > ( SettingsKey . z_probe_samples ) ;
2017-06-07 15:56:02 -07:00
if ( samples . Count = = numberOfSamples )
2017-04-13 17:04:42 -07:00
{
samples . Sort ( ) ;
if ( samples . Count > 3 )
{
// drop the high and low values
samples . RemoveAt ( 0 ) ;
samples . RemoveAt ( samples . Count - 1 ) ;
}
2017-10-31 12:51:16 -07:00
probePositions [ probePositionsBeingEditedIndex ] . position . Z = Math . Round ( samples . Average ( ) , 2 ) ;
2017-09-22 14:06:52 -07:00
UiThread . RunOnIdle ( ( ) = > container . nextButton . OnClick ( null ) ) ;
2017-04-13 17:04:42 -07:00
}
2017-04-12 15:17:29 -07:00
}
2017-04-11 17:49:23 -07:00
}
}
public override void OnClosed ( ClosedEventArgs e )
{
2017-09-01 11:48:43 -07:00
unregisterEvents ? . Invoke ( this , null ) ;
2017-04-11 17:49:23 -07:00
base . OnClosed ( e ) ;
}
2017-04-13 17:04:42 -07:00
List < double > samples = new List < double > ( ) ;
2017-04-11 17:49:23 -07:00
public override void PageIsBecomingActive ( )
{
// always make sure we don't have print leveling turned on
2018-04-04 15:58:57 -07:00
PrintLevelingStream . AllowLeveling = false ;
2017-04-11 17:49:23 -07:00
base . PageIsBecomingActive ( ) ;
2017-09-15 12:08:00 -07:00
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 ) )
2017-06-07 15:56:02 -07:00
{
// make sure the servo is deployed
2017-09-15 12:08:00 -07:00
var servoDeploy = printer . Settings . GetValue < double > ( SettingsKey . z_servo_depolyed_angle ) ;
2018-01-04 17:30:48 -08:00
printer . Connection . QueueLine ( $"M280 P0 S{servoDeploy}" ) ;
2017-06-07 15:56:02 -07:00
}
2017-09-15 12:08:00 -07:00
var feedRates = printer . Settings . Helpers . ManualMovementSpeeds ( ) ;
2017-04-11 17:49:23 -07:00
2017-06-07 15:56:02 -07:00
var adjustedProbePosition = probeStartPosition ;
// subtract out the probe offset
2017-09-15 12:08:00 -07:00
var probeOffset = printer . Settings . GetValue < Vector2 > ( SettingsKey . z_probe_xy_offset ) ;
2017-06-07 15:56:02 -07:00
adjustedProbePosition - = new Vector3 ( probeOffset ) ;
2017-10-31 12:51:16 -07:00
printer . Connection . MoveAbsolute ( PrinterConnection . Axis . Z , probeStartPosition . Z , feedRates . Z ) ;
printer . Connection . MoveAbsolute ( adjustedProbePosition , feedRates . X ) ;
2017-06-07 15:56:02 -07:00
2017-09-15 12:08:00 -07:00
int numberOfSamples = printer . Settings . GetValue < int > ( SettingsKey . z_probe_samples ) ;
2017-06-07 15:56:02 -07:00
for ( int i = 0 ; i < numberOfSamples ; i + + )
2017-04-13 17:04:42 -07:00
{
2017-06-21 12:09:55 -07:00
// probe the current position
2018-01-04 17:30:48 -08:00
printer . Connection . QueueLine ( "G30" ) ;
2017-06-21 12:09:55 -07:00
// raise the probe after each sample
2017-10-31 12:51:16 -07:00
printer . Connection . MoveAbsolute ( adjustedProbePosition , feedRates . X ) ;
2017-04-13 17:04:42 -07:00
}
2017-04-11 17:49:23 -07:00
container . backButton . Enabled = false ;
container . nextButton . Enabled = false ;
2018-02-01 14:51:44 -08:00
if ( printer . Connection . IsConnected
2017-09-15 12:08:00 -07:00
& & ! ( printer . Connection . PrinterIsPrinting
| | printer . Connection . PrinterIsPaused ) )
2017-04-11 17:49:23 -07:00
{
2018-01-06 22:03:06 -08:00
printer . Connection . LineReceived . RegisterEvent ( GetZProbeHeight , ref unregisterEvents ) ;
2017-04-11 17:49:23 -07:00
}
}
public override void PageIsBecomingInactive ( )
{
2018-01-06 22:03:06 -08:00
printer . Connection . LineReceived . UnregisterEvent ( GetZProbeHeight , ref unregisterEvents ) ;
2017-04-11 17:49:23 -07:00
base . PageIsBecomingInactive ( ) ;
}
}
2015-04-08 15:20:10 -07:00
public class GetCoarseBedHeight : FindBedHeight
{
protected Vector3 probeStartPosition ;
2017-12-04 14:14:12 -08:00
public GetCoarseBedHeight ( PrinterConfig printer , WizardControl container , Vector3 probeStartPosition , string pageDescription , List < ProbePosition > probePositions , int probePositionsBeingEditedIndex , LevelingStrings levelingStrings )
2018-04-03 18:17:27 -07:00
: base ( printer , container , pageDescription , "Using the [Z] controls on this screen, we will now take a coarse measurement of the extruder height at this position." . Localize ( ) ,
levelingStrings . CoarseInstruction2 , 1 , probePositions , probePositionsBeingEditedIndex )
2015-04-08 15:20:10 -07:00
{
this . probeStartPosition = probeStartPosition ;
}
public override void PageIsBecomingActive ( )
{
base . PageIsBecomingActive ( ) ;
2018-03-12 16:36:51 -07:00
// make sure the probe is not deployed
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}" ) ;
}
2017-09-15 12:08:00 -07:00
var feedRates = printer . Settings . Helpers . ManualMovementSpeeds ( ) ;
2016-06-17 09:29:11 -07:00
2017-10-31 12:51:16 -07:00
printer . Connection . MoveAbsolute ( PrinterConnection . Axis . Z , probeStartPosition . Z , feedRates . Z ) ;
printer . Connection . MoveAbsolute ( probeStartPosition , feedRates . X ) ;
2017-09-15 12:08:00 -07:00
printer . Connection . ReadPosition ( ) ;
2015-04-08 15:20:10 -07:00
2015-09-01 17:08:59 -07:00
container . backButton . Enabled = false ;
2015-04-08 15:20:10 -07:00
container . nextButton . Enabled = false ;
2017-01-17 14:47:04 -08:00
zPlusControl . Click + = zControl_Click ;
zMinusControl . Click + = zControl_Click ;
2015-04-08 15:20:10 -07:00
}
protected void zControl_Click ( object sender , EventArgs mouseEvent )
{
container . nextButton . Enabled = true ;
}
public override void PageIsBecomingInactive ( )
{
2015-09-01 17:08:59 -07:00
container . backButton . Enabled = true ;
2015-04-08 15:20:10 -07:00
container . nextButton . Enabled = true ;
2017-04-14 09:50:51 -07:00
base . PageIsBecomingInactive ( ) ;
2015-04-08 15:20:10 -07:00
}
}
public class GetFineBedHeight : FindBedHeight
{
2017-12-04 14:14:12 -08:00
public GetFineBedHeight ( PrinterConfig printer , WizardControl container , string pageDescription , List < ProbePosition > probePositions , int probePositionsBeingEditedIndex , LevelingStrings levelingStrings )
: base ( printer , container , pageDescription , levelingStrings . FineInstruction1 , levelingStrings . FineInstruction2 , . 1 , probePositions , probePositionsBeingEditedIndex )
2015-04-08 15:20:10 -07:00
{
}
}
public class GetUltraFineBedHeight : FindBedHeight
{
2017-12-04 14:14:12 -08:00
public GetUltraFineBedHeight ( PrinterConfig printer , WizardControl container , string pageDescription , List < ProbePosition > probePositions , int probePositionsBeingEditedIndex , LevelingStrings levelingStrings )
: base ( printer , container , pageDescription , levelingStrings . UltraFineInstruction1 , levelingStrings . FineInstruction2 , . 02 , probePositions , probePositionsBeingEditedIndex )
2015-04-08 15:20:10 -07:00
{
}
private bool haveDrawn = false ;
public override void OnDraw ( Graphics2D graphics2D )
{
haveDrawn = true ;
base . OnDraw ( graphics2D ) ;
}
public override void PageIsBecomingInactive ( )
{
if ( haveDrawn )
{
2017-10-31 12:51:16 -07:00
printer . Connection . MoveRelative ( PrinterConnection . Axis . Z , 2 , printer . Settings . Helpers . ManualMovementSpeeds ( ) . Z ) ;
2015-04-08 15:20:10 -07:00
}
base . PageIsBecomingInactive ( ) ;
}
}
}