413 lines
No EOL
14 KiB
C#
413 lines
No EOL
14 KiB
C#
/*
|
|
Copyright (c) 2014, Lars Brubaker
|
|
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 MatterHackers.Agg;
|
|
using MatterHackers.Agg.UI;
|
|
using MatterHackers.Localizations;
|
|
using MatterHackers.MatterControl.PrinterCommunication;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace MatterHackers.MatterControl.EeProm
|
|
{
|
|
public partial class EePromMarlinWindow : SystemWindow
|
|
{
|
|
private EePromMarlinSettings currentEePromSettings;
|
|
|
|
private MHNumberEdit stepsPerMmX;
|
|
private MHNumberEdit stepsPerMmY;
|
|
private MHNumberEdit stepsPerMmZ;
|
|
private MHNumberEdit stepsPerMmE;
|
|
|
|
private MHNumberEdit maxFeedrateMmPerSX;
|
|
private MHNumberEdit maxFeedrateMmPerSY;
|
|
private MHNumberEdit maxFeedrateMmPerSZ;
|
|
private MHNumberEdit maxFeedrateMmPerSE;
|
|
|
|
private MHNumberEdit maxAccelerationMmPerSSqrdX;
|
|
private MHNumberEdit maxAccelerationMmPerSSqrdY;
|
|
private MHNumberEdit maxAccelerationMmPerSSqrdZ;
|
|
private MHNumberEdit maxAccelerationMmPerSSqrdE;
|
|
|
|
private MHNumberEdit acceleration;
|
|
private MHNumberEdit retractAcceleration;
|
|
|
|
private MHNumberEdit pidP;
|
|
private MHNumberEdit pidI;
|
|
private MHNumberEdit pidD;
|
|
|
|
private MHNumberEdit homingOffsetX;
|
|
private MHNumberEdit homingOffsetY;
|
|
private MHNumberEdit homingOffsetZ;
|
|
|
|
private MHNumberEdit minFeedrate;
|
|
private MHNumberEdit minTravelFeedrate;
|
|
private MHNumberEdit minSegmentTime;
|
|
|
|
private MHNumberEdit maxXYJerk;
|
|
private MHNumberEdit maxZJerk;
|
|
|
|
private Button buttonAbort;
|
|
private Button buttonSetToFactorySettings;
|
|
private Button buttonSave;
|
|
|
|
private event EventHandler unregisterEvents;
|
|
|
|
private TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
|
|
private double maxWidthOfLeftStuff = 0;
|
|
private List<GuiWidget> leftStuffToSize = new List<GuiWidget>();
|
|
|
|
private int currentTabIndex = 0;
|
|
|
|
public EePromMarlinWindow()
|
|
: base(700, 480)
|
|
{
|
|
AlwaysOnTopOfMain = true;
|
|
Title = LocalizedString.Get("Marlin Firmware EEPROM Settings");
|
|
|
|
currentEePromSettings = new EePromMarlinSettings();
|
|
currentEePromSettings.eventAdded += SetUiToPrinterSettings;
|
|
|
|
FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
|
mainContainer.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight;
|
|
mainContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
|
|
mainContainer.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
|
mainContainer.Padding = new BorderDouble(3, 0);
|
|
|
|
FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
|
topToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight;
|
|
topToBottom.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
|
|
topToBottom.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
|
|
topToBottom.Padding = new BorderDouble(top: 3);
|
|
|
|
// the top button bar
|
|
{
|
|
FlowLayoutWidget topButtonBar = new FlowLayoutWidget();
|
|
topButtonBar.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
|
|
topButtonBar.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
|
|
|
topButtonBar.Margin = new BorderDouble(0, 3);
|
|
|
|
CreateMainButton(ref buttonSetToFactorySettings, topButtonBar, "Reset to Factory Defaults");
|
|
buttonSetToFactorySettings.Click += SetToFactorySettings;
|
|
|
|
mainContainer.AddChild(topButtonBar);
|
|
}
|
|
|
|
topToBottom.AddChild(Create4FieldSet("Steps per mm:",
|
|
"X:", ref stepsPerMmX,
|
|
"Y:", ref stepsPerMmY,
|
|
"Z:", ref stepsPerMmZ,
|
|
"E:", ref stepsPerMmE));
|
|
|
|
topToBottom.AddChild(Create4FieldSet("Maximum feedrates [mm/s]:",
|
|
"X:", ref maxFeedrateMmPerSX,
|
|
"Y:", ref maxFeedrateMmPerSY,
|
|
"Z:", ref maxFeedrateMmPerSZ,
|
|
"E:", ref maxFeedrateMmPerSE));
|
|
|
|
topToBottom.AddChild(Create4FieldSet("Maximum Acceleration [mm/s²]:",
|
|
"X:", ref maxAccelerationMmPerSSqrdX,
|
|
"Y:", ref maxAccelerationMmPerSSqrdY,
|
|
"Z:", ref maxAccelerationMmPerSSqrdZ,
|
|
"E:", ref maxAccelerationMmPerSSqrdE));
|
|
|
|
topToBottom.AddChild(CreateField("Acceleration:", ref acceleration));
|
|
topToBottom.AddChild(CreateField("Retract Acceleration:", ref retractAcceleration));
|
|
|
|
topToBottom.AddChild(Create3FieldSet("PID settings:",
|
|
"P:", ref pidP,
|
|
"I:", ref pidI,
|
|
"D:", ref pidD));
|
|
|
|
topToBottom.AddChild(Create3FieldSet("Homing Offset:",
|
|
"X:", ref homingOffsetX,
|
|
"Y:", ref homingOffsetY,
|
|
"Z:", ref homingOffsetZ));
|
|
|
|
topToBottom.AddChild(CreateField("Min feedrate [mm/s]:", ref minFeedrate));
|
|
topToBottom.AddChild(CreateField("Min travel feedrate [mm/s]:", ref minTravelFeedrate));
|
|
topToBottom.AddChild(CreateField("Minimum segment time [ms]:", ref minSegmentTime));
|
|
topToBottom.AddChild(CreateField("Maximum X-Y jerk [mm/s]:", ref maxXYJerk));
|
|
topToBottom.AddChild(CreateField("Maximum Z jerk [mm/s]:", ref maxZJerk));
|
|
|
|
GuiWidget topBottomSpacer = new GuiWidget(1, 1);
|
|
topBottomSpacer.VAnchor = VAnchor.ParentBottomTop;
|
|
topToBottom.AddChild(topBottomSpacer);
|
|
|
|
mainContainer.AddChild(topToBottom);
|
|
|
|
// the bottom button bar
|
|
{
|
|
FlowLayoutWidget bottomButtonBar = new FlowLayoutWidget();
|
|
bottomButtonBar.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
|
|
bottomButtonBar.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
|
bottomButtonBar.Margin = new BorderDouble(0, 3);
|
|
|
|
CreateMainButton(ref buttonSave, bottomButtonBar, "Save to EEProm");
|
|
buttonSave.Click += buttonSave_Click;
|
|
|
|
CreateSpacer(bottomButtonBar);
|
|
|
|
CreateMainButton(ref buttonAbort, bottomButtonBar, "Close");
|
|
buttonAbort.Click += buttonAbort_Click;
|
|
|
|
mainContainer.AddChild(bottomButtonBar);
|
|
}
|
|
|
|
PrinterConnectionAndCommunication.Instance.CommunicationUnconditionalFromPrinter.RegisterEvent(currentEePromSettings.Add, ref unregisterEvents);
|
|
|
|
#if __ANDROID__
|
|
TerminalWidget terminalWidget = new TerminalWidget(true);
|
|
this.AddChild(new SoftKeyboardContentOffset(mainContainer));
|
|
//mainContainer.Closed += (sender, e) => { Close(); };
|
|
#else
|
|
AddChild(mainContainer);
|
|
#endif
|
|
|
|
ShowAsSystemWindow();
|
|
|
|
// and ask the printer to send the settings
|
|
currentEePromSettings.Update();
|
|
|
|
foreach (GuiWidget widget in leftStuffToSize)
|
|
{
|
|
widget.Width = maxWidthOfLeftStuff;
|
|
}
|
|
}
|
|
|
|
private GuiWidget CreateMHNumEdit(ref MHNumberEdit numberEditToCreate)
|
|
{
|
|
numberEditToCreate = new MHNumberEdit(0, pixelWidth: 80, allowNegatives: true, allowDecimals: true);
|
|
numberEditToCreate.SelectAllOnFocus = true;
|
|
numberEditToCreate.VAnchor = Agg.UI.VAnchor.ParentCenter;
|
|
numberEditToCreate.Margin = new BorderDouble(3, 0);
|
|
return numberEditToCreate;
|
|
}
|
|
|
|
private GuiWidget CreateField(string label, ref MHNumberEdit field1)
|
|
{
|
|
MHNumberEdit none = null;
|
|
|
|
return Create4FieldSet(label,
|
|
"", ref field1,
|
|
null, ref none,
|
|
null, ref none,
|
|
null, ref none);
|
|
}
|
|
|
|
private GuiWidget Create3FieldSet(string label,
|
|
string field1Label, ref MHNumberEdit field1,
|
|
string field2Label, ref MHNumberEdit field2,
|
|
string field3Label, ref MHNumberEdit field3)
|
|
{
|
|
MHNumberEdit none = null;
|
|
|
|
return Create4FieldSet(label,
|
|
field1Label, ref field1,
|
|
field2Label, ref field2,
|
|
field3Label, ref field3,
|
|
null, ref none);
|
|
}
|
|
|
|
private GuiWidget CreateTextField(string label)
|
|
{
|
|
GuiWidget textWidget = new TextWidget(label, textColor: ActiveTheme.Instance.PrimaryTextColor);
|
|
textWidget.VAnchor = VAnchor.ParentCenter;
|
|
textWidget.HAnchor = HAnchor.ParentRight;
|
|
GuiWidget container = new GuiWidget(textWidget.Height, 24);
|
|
container.AddChild(textWidget);
|
|
return container;
|
|
}
|
|
|
|
private GuiWidget Create4FieldSet(string label,
|
|
string field1Label, ref MHNumberEdit field1,
|
|
string field2Label, ref MHNumberEdit field2,
|
|
string field3Label, ref MHNumberEdit field3,
|
|
string field4Label, ref MHNumberEdit field4)
|
|
{
|
|
FlowLayoutWidget row = new FlowLayoutWidget();
|
|
row.Margin = new BorderDouble(3);
|
|
row.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
|
|
|
|
TextWidget labelWidget = new TextWidget(LocalizedString.Get(label), textColor: ActiveTheme.Instance.PrimaryTextColor);
|
|
labelWidget.VAnchor = VAnchor.ParentCenter;
|
|
maxWidthOfLeftStuff = Math.Max(maxWidthOfLeftStuff, labelWidget.Width);
|
|
GuiWidget holder = new GuiWidget(labelWidget.Width, labelWidget.Height);
|
|
holder.Margin = new BorderDouble(3, 0);
|
|
holder.AddChild(labelWidget);
|
|
leftStuffToSize.Add(holder);
|
|
row.AddChild(holder);
|
|
|
|
{
|
|
row.AddChild(CreateTextField(field1Label));
|
|
GuiWidget nextTabIndex = CreateMHNumEdit(ref field1);
|
|
nextTabIndex.TabIndex = GetNextTabIndex();
|
|
row.AddChild(nextTabIndex);
|
|
}
|
|
|
|
if (field2Label != null)
|
|
{
|
|
row.AddChild(CreateTextField(field2Label));
|
|
GuiWidget nextTabIndex = CreateMHNumEdit(ref field2);
|
|
nextTabIndex.TabIndex = GetNextTabIndex();
|
|
row.AddChild(nextTabIndex);
|
|
}
|
|
|
|
if (field3Label != null)
|
|
{
|
|
row.AddChild(CreateTextField(field3Label));
|
|
GuiWidget nextTabIndex = CreateMHNumEdit(ref field3);
|
|
nextTabIndex.TabIndex = GetNextTabIndex();
|
|
row.AddChild(nextTabIndex);
|
|
}
|
|
|
|
if (field4Label != null)
|
|
{
|
|
row.AddChild(CreateTextField(field4Label));
|
|
GuiWidget nextTabIndex = CreateMHNumEdit(ref field4);
|
|
nextTabIndex.TabIndex = GetNextTabIndex();
|
|
row.AddChild(nextTabIndex);
|
|
}
|
|
|
|
return row;
|
|
}
|
|
|
|
private int GetNextTabIndex()
|
|
{
|
|
return currentTabIndex++;
|
|
}
|
|
|
|
private static void CreateSpacer(FlowLayoutWidget buttonBar)
|
|
{
|
|
GuiWidget spacer = new GuiWidget(1, 1);
|
|
spacer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
|
|
buttonBar.AddChild(spacer);
|
|
}
|
|
|
|
private void CreateMainButton(ref Button button, FlowLayoutWidget buttonBar, string text)
|
|
{
|
|
button = textImageButtonFactory.Generate(LocalizedString.Get(text));
|
|
buttonBar.AddChild(button);
|
|
}
|
|
|
|
private void SetToFactorySettings(object sender, EventArgs e)
|
|
{
|
|
currentEePromSettings.SetPrinterToFactorySettings();
|
|
currentEePromSettings.Update();
|
|
}
|
|
|
|
private void buttonAbort_Click(object sender, EventArgs e)
|
|
{
|
|
UiThread.RunOnIdle(Close);
|
|
}
|
|
|
|
public override void OnClosed(EventArgs e)
|
|
{
|
|
if (unregisterEvents != null)
|
|
{
|
|
unregisterEvents(this, null);
|
|
}
|
|
base.OnClosed(e);
|
|
}
|
|
|
|
private void SetUiToPrinterSettings(object sender, EventArgs e)
|
|
{
|
|
stepsPerMmX.Text = currentEePromSettings.SX;
|
|
stepsPerMmY.Text = currentEePromSettings.SY;
|
|
stepsPerMmZ.Text = currentEePromSettings.SZ;
|
|
stepsPerMmE.Text = currentEePromSettings.SE;
|
|
maxFeedrateMmPerSX.Text = currentEePromSettings.FX;
|
|
maxFeedrateMmPerSY.Text = currentEePromSettings.FY;
|
|
maxFeedrateMmPerSZ.Text = currentEePromSettings.FZ;
|
|
maxFeedrateMmPerSE.Text = currentEePromSettings.FE;
|
|
maxAccelerationMmPerSSqrdX.Text = currentEePromSettings.AX;
|
|
maxAccelerationMmPerSSqrdY.Text = currentEePromSettings.AY;
|
|
maxAccelerationMmPerSSqrdZ.Text = currentEePromSettings.AZ;
|
|
maxAccelerationMmPerSSqrdE.Text = currentEePromSettings.AE;
|
|
acceleration.Text = currentEePromSettings.ACC;
|
|
retractAcceleration.Text = currentEePromSettings.RACC;
|
|
minFeedrate.Text = currentEePromSettings.AVS;
|
|
minTravelFeedrate.Text = currentEePromSettings.AVT;
|
|
minSegmentTime.Text = currentEePromSettings.AVB;
|
|
maxXYJerk.Text = currentEePromSettings.AVX;
|
|
maxZJerk.Text = currentEePromSettings.AVZ;
|
|
pidP.Enabled = pidI.Enabled = pidD.Enabled = currentEePromSettings.hasPID;
|
|
pidP.Text = currentEePromSettings.PPID;
|
|
pidI.Text = currentEePromSettings.IPID;
|
|
pidD.Text = currentEePromSettings.DPID;
|
|
homingOffsetX.Text = currentEePromSettings.hox;
|
|
homingOffsetY.Text = currentEePromSettings.hoy;
|
|
homingOffsetZ.Text = currentEePromSettings.hoz;
|
|
}
|
|
|
|
private void buttonSave_Click(object sender, EventArgs e)
|
|
{
|
|
UiThread.RunOnIdle(DoButtonSave_Click);
|
|
}
|
|
|
|
private void DoButtonSave_Click()
|
|
{
|
|
SaveSettingsToActive();
|
|
currentEePromSettings.SaveToEeProm();
|
|
Close();
|
|
}
|
|
|
|
private void SaveSettingsToActive()
|
|
{
|
|
currentEePromSettings.SX = stepsPerMmX.Text;
|
|
currentEePromSettings.SY = stepsPerMmY.Text;
|
|
currentEePromSettings.SZ = stepsPerMmZ.Text;
|
|
currentEePromSettings.SE = stepsPerMmE.Text;
|
|
currentEePromSettings.FX = maxFeedrateMmPerSX.Text;
|
|
currentEePromSettings.FY = maxFeedrateMmPerSY.Text;
|
|
currentEePromSettings.FZ = maxFeedrateMmPerSZ.Text;
|
|
currentEePromSettings.FE = maxFeedrateMmPerSE.Text;
|
|
currentEePromSettings.AX = maxAccelerationMmPerSSqrdX.Text;
|
|
currentEePromSettings.AY = maxAccelerationMmPerSSqrdY.Text;
|
|
currentEePromSettings.AZ = maxAccelerationMmPerSSqrdZ.Text;
|
|
currentEePromSettings.AE = maxAccelerationMmPerSSqrdE.Text;
|
|
currentEePromSettings.ACC = acceleration.Text;
|
|
currentEePromSettings.RACC = retractAcceleration.Text;
|
|
currentEePromSettings.AVS = minFeedrate.Text;
|
|
currentEePromSettings.AVT = minTravelFeedrate.Text;
|
|
currentEePromSettings.AVB = minSegmentTime.Text;
|
|
currentEePromSettings.AVX = maxXYJerk.Text;
|
|
currentEePromSettings.AVZ = maxZJerk.Text;
|
|
currentEePromSettings.PPID = pidP.Text;
|
|
currentEePromSettings.IPID = pidI.Text;
|
|
currentEePromSettings.DPID = pidD.Text;
|
|
currentEePromSettings.HOX = homingOffsetX.Text;
|
|
currentEePromSettings.HOY = homingOffsetY.Text;
|
|
currentEePromSettings.HOZ = homingOffsetZ.Text;
|
|
|
|
currentEePromSettings.Save();
|
|
}
|
|
}
|
|
} |