Move MatterControl source code into a subdirectory
This commit is contained in:
parent
2c6e34243a
commit
70af2d9ae8
2007 changed files with 13 additions and 8 deletions
679
original/MatterControlLib/EeProm/EePromMarlinSettings.cs
Normal file
679
original/MatterControlLib/EeProm/EePromMarlinSettings.cs
Normal file
|
|
@ -0,0 +1,679 @@
|
|||
/*
|
||||
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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
|
||||
namespace MatterHackers.MatterControl.EeProm
|
||||
{
|
||||
public class EePromMarlinSettings : EventArgs
|
||||
{
|
||||
public event EventHandler eventAdded = null;
|
||||
|
||||
public string sx = "0";
|
||||
public string sy = "0";
|
||||
public string sz = "0";
|
||||
public string se = "0";
|
||||
public string fx = "0";
|
||||
public string fy = "0";
|
||||
public string fz = "0";
|
||||
public string fe = "0";
|
||||
public string ax = "0";
|
||||
public string ay = "0";
|
||||
public string az = "0";
|
||||
public string ae = "0";
|
||||
public string acc_printing_moves_legacy = "0";
|
||||
public string acc_printing_moves = "0";
|
||||
public string acc_retraction = "0";
|
||||
public string acc_travel_moves = "0";
|
||||
public string avs = "0";
|
||||
public string avt = "0";
|
||||
public string avb = "0";
|
||||
public string avx = "0";
|
||||
public string avz = "0";
|
||||
public string avj = "0";
|
||||
public string ave = "0";
|
||||
public string ppid = "0";
|
||||
public string ipid = "0";
|
||||
public string dpid = "0";
|
||||
public string bed_ppid = "0";
|
||||
public string bed_ipid = "0";
|
||||
public string bed_dpid = "0";
|
||||
public string hox = "0";
|
||||
public string hoy = "0";
|
||||
public string hoz = "0";
|
||||
public bool hasPID = false;
|
||||
public bool bed_HasPID = false;
|
||||
|
||||
private bool changed = false;
|
||||
private PrinterConnection printerConnection;
|
||||
|
||||
public EePromMarlinSettings(PrinterConnection printerConnection)
|
||||
{
|
||||
this.printerConnection = printerConnection;
|
||||
}
|
||||
|
||||
public bool update(string line)
|
||||
{
|
||||
bool foundAnySetting = false;
|
||||
string[] splitOnSpace = line.Split(' ');
|
||||
string mode = "";
|
||||
bool foundFirstM92E = false;
|
||||
foreach (string token in splitOnSpace)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ((token == "M92") || (mode == "M92"))
|
||||
{
|
||||
foundAnySetting = true;
|
||||
if (mode != "M92")
|
||||
{
|
||||
foundFirstM92E = false;
|
||||
}
|
||||
|
||||
mode = "M92";
|
||||
if (token[0] == 'X')
|
||||
{
|
||||
sx = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'Y')
|
||||
{
|
||||
sy = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'Z')
|
||||
{
|
||||
sz = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'E' && !foundFirstM92E)
|
||||
{
|
||||
foundFirstM92E = true;
|
||||
se = token.Substring(1);
|
||||
}
|
||||
}
|
||||
if (((token == "M203") || (mode == "M203")))
|
||||
{
|
||||
foundAnySetting = true;
|
||||
mode = "M203";
|
||||
if (token[0] == 'X')
|
||||
{
|
||||
fx = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'Y')
|
||||
{
|
||||
fy = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'Z')
|
||||
{
|
||||
fz = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'E')
|
||||
{
|
||||
fe = token.Substring(1);
|
||||
}
|
||||
}
|
||||
if (((token == "M201") || (mode == "M201")))
|
||||
{
|
||||
foundAnySetting = true;
|
||||
mode = "M201";
|
||||
if (token[0] == 'X')
|
||||
{
|
||||
ax = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'Y')
|
||||
{
|
||||
ay = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'Z')
|
||||
{
|
||||
az = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'E')
|
||||
{
|
||||
ae = token.Substring(1);
|
||||
}
|
||||
}
|
||||
if (((token == "M204") || (mode == "M204")))
|
||||
{
|
||||
foundAnySetting = true;
|
||||
mode = "M204";
|
||||
if (token[0] == 'S') // legacy printing
|
||||
{
|
||||
acc_printing_moves_legacy = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'P') // printing
|
||||
{
|
||||
acc_printing_moves = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'T') // travel
|
||||
{
|
||||
acc_travel_moves = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'R') // retraction
|
||||
{
|
||||
acc_retraction = token.Substring(1);
|
||||
}
|
||||
}
|
||||
if (((token == "M205") || (mode == "M205")))
|
||||
{
|
||||
foundAnySetting = true;
|
||||
mode = "M205";
|
||||
if (token[0] == 'S')
|
||||
{
|
||||
avs = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'T')
|
||||
{
|
||||
avt = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'B')
|
||||
{
|
||||
avb = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'X')
|
||||
{
|
||||
avx = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'Z')
|
||||
{
|
||||
avz = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'J')
|
||||
{
|
||||
avj = token.Substring(1);
|
||||
}
|
||||
}
|
||||
if (((token == "M301") || (mode == "M301")))
|
||||
{
|
||||
foundAnySetting = true;
|
||||
mode = "M301";
|
||||
hasPID = true;
|
||||
if (token[0] == 'P')
|
||||
{
|
||||
ppid = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'I')
|
||||
{
|
||||
ipid = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'D')
|
||||
{
|
||||
dpid = token.Substring(1);
|
||||
}
|
||||
}
|
||||
if (((token == "M304") || (mode == "M304")))
|
||||
{
|
||||
foundAnySetting = true;
|
||||
mode = "M304";
|
||||
bed_HasPID = true;
|
||||
if (token[0] == 'P')
|
||||
{
|
||||
bed_ppid = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'I')
|
||||
{
|
||||
bed_ipid = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'D')
|
||||
{
|
||||
bed_dpid = token.Substring(1);
|
||||
}
|
||||
}
|
||||
if (((token == "M206") || (mode == "M206")))
|
||||
{
|
||||
foundAnySetting = true;
|
||||
mode = "M206";
|
||||
hasPID = true;
|
||||
if (token[0] == 'X')
|
||||
{
|
||||
hox = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'Y')
|
||||
{
|
||||
hoy = token.Substring(1);
|
||||
}
|
||||
if (token[0] == 'Z')
|
||||
{
|
||||
hoz = token.Substring(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
changed = false;
|
||||
|
||||
return foundAnySetting;
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
if (!changed) return; // nothing changed
|
||||
string cmdsteps = "M92 X" + sx + " Y" + sy + " Z" + sz + " E" + se;
|
||||
string cmdfeed = "M203 X" + fx + " Y" + fy + " Z" + fz + " E" + fe;
|
||||
string cmdmacc = "M201 X" + ax + " Y" + ay + " Z" + az + " E" + ae;
|
||||
|
||||
string cmdacc = "M204";
|
||||
if (acc_printing_moves_legacy != "0") cmdacc += $" S{acc_printing_moves_legacy}";
|
||||
if (acc_printing_moves != "0") cmdacc += $" P{acc_printing_moves}";
|
||||
if (acc_travel_moves != "0") cmdacc += $" T{acc_travel_moves}";
|
||||
if (acc_retraction != "0") cmdacc += $" R{acc_retraction}";
|
||||
|
||||
string cmdav = "M205 S" + avs + " T" + avt + " B" + avb + " X" + avx + " Z" + avz;
|
||||
if (avj != "0")
|
||||
{
|
||||
cmdav += " J" + avj;
|
||||
}
|
||||
string cmdho = "M206 X" + hox + " Y" + hoy + " Z" + hoz;
|
||||
string cmdpid = "M301 P" + ppid + " I" + ipid + " D" + dpid;
|
||||
// string cmdbed_pid = "M304 P" + bed_ppid + " I" + bed_ipid + " D" + bed_dpid;
|
||||
|
||||
printerConnection.QueueLine(cmdsteps);
|
||||
printerConnection.QueueLine(cmdfeed);
|
||||
printerConnection.QueueLine(cmdmacc);
|
||||
printerConnection.QueueLine(cmdacc);
|
||||
printerConnection.QueueLine(cmdav);
|
||||
printerConnection.QueueLine(cmdho);
|
||||
if (hasPID)
|
||||
{
|
||||
printerConnection.QueueLine(cmdpid);
|
||||
}
|
||||
|
||||
changed = false;
|
||||
}
|
||||
|
||||
public string SX
|
||||
{
|
||||
get { return sx; }
|
||||
set { if (sx.Equals(value)) return; sx = value; changed = true; }
|
||||
}
|
||||
|
||||
public string SY
|
||||
{
|
||||
get { return sy; }
|
||||
set { if (sy.Equals(value)) return; sy = value; changed = true; }
|
||||
}
|
||||
|
||||
public string SZ
|
||||
{
|
||||
get { return sz; }
|
||||
set { if (sz.Equals(value)) return; sz = value; changed = true; }
|
||||
}
|
||||
//This is it
|
||||
public string SE
|
||||
{
|
||||
|
||||
//String l
|
||||
get { return se; }
|
||||
set
|
||||
{
|
||||
if (se.Equals(value))
|
||||
return;
|
||||
se = value;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public string FX
|
||||
{
|
||||
get { return fx; }
|
||||
set { if (fx.Equals(value)) return; fx = value; changed = true; }
|
||||
}
|
||||
|
||||
public string FY
|
||||
{
|
||||
get { return fy; }
|
||||
set { if (fy.Equals(value)) return; fy = value; changed = true; }
|
||||
}
|
||||
|
||||
public string FZ
|
||||
{
|
||||
get { return fz; }
|
||||
set { if (fz.Equals(value)) return; fz = value; changed = true; }
|
||||
}
|
||||
|
||||
public string FE
|
||||
{
|
||||
get { return fe; }
|
||||
set { if (fe.Equals(value)) return; fe = value; changed = true; }
|
||||
}
|
||||
|
||||
public string AX
|
||||
{
|
||||
get { return ax; }
|
||||
set { if (ax.Equals(value)) return; ax = value; changed = true; }
|
||||
}
|
||||
|
||||
internal void Import(string fileName)
|
||||
{
|
||||
// read all the lines
|
||||
string[] allLines = File.ReadAllLines(fileName);
|
||||
// find all the descriptions we can
|
||||
foreach (string line in allLines)
|
||||
{
|
||||
if (line.Contains("|"))
|
||||
{
|
||||
string[] descriptionValue = line.Split('|');
|
||||
if (descriptionValue.Length == 2)
|
||||
{
|
||||
SetSetting(descriptionValue[0], descriptionValue[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void SetSetting(string keyToSet, string valueToSetTo)
|
||||
{
|
||||
valueToSetTo = valueToSetTo.Replace("\"", "").Trim();
|
||||
|
||||
FieldInfo[] fields;
|
||||
fields = this.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
|
||||
foreach (FieldInfo field in fields)
|
||||
{
|
||||
var possibleNames = new List<string>
|
||||
{
|
||||
field.Name
|
||||
};
|
||||
|
||||
if (possibleNames.Contains(keyToSet))
|
||||
{
|
||||
string name = field.Name;
|
||||
object value = field.GetValue(this);
|
||||
switch (field.FieldType.Name)
|
||||
{
|
||||
case "Int32":
|
||||
field.SetValue(this, (int)double.Parse(valueToSetTo));
|
||||
break;
|
||||
|
||||
case "Double":
|
||||
field.SetValue(this, double.Parse(valueToSetTo));
|
||||
break;
|
||||
|
||||
case "Boolean":
|
||||
field.SetValue(this, bool.Parse(valueToSetTo));
|
||||
break;
|
||||
|
||||
case "String":
|
||||
field.SetValue(this, valueToSetTo.Replace("\\n", "\n"));
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException("unknown type");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string AY
|
||||
{
|
||||
get { return ay; }
|
||||
set { if (ay.Equals(value)) return; ay = value; changed = true; }
|
||||
}
|
||||
|
||||
public string AZ
|
||||
{
|
||||
get { return az; }
|
||||
set { if (az.Equals(value)) return; az = value; changed = true; }
|
||||
}
|
||||
|
||||
public string AE
|
||||
{
|
||||
get { return ae; }
|
||||
set { if (ae.Equals(value)) return; ae = value; changed = true; }
|
||||
}
|
||||
|
||||
public string AccPrintingMoves
|
||||
{
|
||||
get
|
||||
{
|
||||
if(acc_printing_moves_legacy != "0")
|
||||
{
|
||||
return acc_printing_moves_legacy;
|
||||
}
|
||||
|
||||
return acc_printing_moves;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// prefer legacy
|
||||
if (acc_printing_moves_legacy != "0"
|
||||
&& acc_printing_moves_legacy != value)
|
||||
{
|
||||
acc_printing_moves_legacy = value;
|
||||
changed = true;
|
||||
}
|
||||
else if (acc_printing_moves != value)
|
||||
{
|
||||
acc_printing_moves = value;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string AccTravelMoves
|
||||
{
|
||||
get
|
||||
{
|
||||
return acc_travel_moves;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (acc_travel_moves != value)
|
||||
{
|
||||
acc_travel_moves = value;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string AccRetraction
|
||||
{
|
||||
get
|
||||
{
|
||||
return acc_retraction;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (acc_retraction != value)
|
||||
{
|
||||
acc_retraction = value;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string AVS
|
||||
{
|
||||
get { return avs; }
|
||||
set { if (avs.Equals(value)) return; avs = value; changed = true; }
|
||||
}
|
||||
|
||||
internal void Export(string fileName)
|
||||
{
|
||||
using (var sw = new StreamWriter(fileName))
|
||||
{
|
||||
FieldInfo[] fields;
|
||||
fields = this.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
|
||||
foreach (FieldInfo field in fields)
|
||||
{
|
||||
string name = field.Name;
|
||||
object value = field.GetValue(this);
|
||||
switch (field.FieldType.Name)
|
||||
{
|
||||
case "Int32":
|
||||
case "Double":
|
||||
case "Boolean":
|
||||
case "FMatrix3x3":
|
||||
case "String":
|
||||
// all these setting just output correctly with ToString() so we don't have to do anything special.
|
||||
sw.WriteLine("{0}|{1}".FormatWith(name, value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string AVT
|
||||
{
|
||||
get { return avt; }
|
||||
set { if (avt.Equals(value)) return; avt = value; changed = true; }
|
||||
}
|
||||
|
||||
public string AVB
|
||||
{
|
||||
get { return avb; }
|
||||
set { if (avb.Equals(value)) return; avb = value; changed = true; }
|
||||
}
|
||||
|
||||
public string AVX
|
||||
{
|
||||
get { return avx; }
|
||||
set { if (avx.Equals(value)) return; avx = value; changed = true; }
|
||||
}
|
||||
|
||||
public string AVZ
|
||||
{
|
||||
get { return avz; }
|
||||
set { if (avz.Equals(value)) return; avz = value; changed = true; }
|
||||
}
|
||||
|
||||
public string AVJ
|
||||
{
|
||||
get { return avj; }
|
||||
set { if (avj.Equals(value)) return; avj = value; changed = true; }
|
||||
}
|
||||
|
||||
public string AVE
|
||||
{
|
||||
get { return ave; }
|
||||
set { if (ave.Equals(value)) return; ave = value; changed = true; }
|
||||
}
|
||||
|
||||
public string PPID
|
||||
{
|
||||
get { return ppid; }
|
||||
set { if (ppid.Equals(value)) return; ppid = value; changed = true; }
|
||||
}
|
||||
|
||||
public string IPID
|
||||
{
|
||||
get { return ipid; }
|
||||
set { if (ipid.Equals(value)) return; ipid = value; changed = true; }
|
||||
}
|
||||
|
||||
public string DPID
|
||||
{
|
||||
get { return dpid; }
|
||||
set { if (dpid.Equals(value)) return; dpid = value; changed = true; }
|
||||
}
|
||||
|
||||
public string BED_PPID
|
||||
{
|
||||
get { return bed_ppid; }
|
||||
set { if (bed_ppid.Equals(value)) return; bed_ppid = value; changed = true; }
|
||||
}
|
||||
|
||||
public string BED_IPID
|
||||
{
|
||||
get { return bed_ipid; }
|
||||
set { if (bed_ipid.Equals(value)) return; bed_ipid = value; changed = true; }
|
||||
}
|
||||
|
||||
public string BED_DPID
|
||||
{
|
||||
get { return bed_dpid; }
|
||||
set { if (bed_dpid.Equals(value)) return; bed_dpid = value; changed = true; }
|
||||
}
|
||||
|
||||
public string HOX
|
||||
{
|
||||
get { return hox; }
|
||||
set { if (hox.Equals(value)) return; hox = value; changed = true; }
|
||||
}
|
||||
|
||||
public string HOY
|
||||
{
|
||||
get { return hoy; }
|
||||
set { if (hoy.Equals(value)) return; hoy = value; changed = true; }
|
||||
}
|
||||
|
||||
public string HOZ
|
||||
{
|
||||
get { return hoz; }
|
||||
set { if (hoz.Equals(value)) return; hoz = value; changed = true; }
|
||||
}
|
||||
|
||||
public void SaveToEeProm()
|
||||
{
|
||||
printerConnection.QueueLine("M500");
|
||||
}
|
||||
|
||||
// this does not save them to eeprom
|
||||
public void SetPrinterToFactorySettings()
|
||||
{
|
||||
hasPID = false;
|
||||
printerConnection.QueueLine("M502");
|
||||
}
|
||||
|
||||
public void Add(object sender, string line)
|
||||
{
|
||||
if (line == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (update(line))
|
||||
{
|
||||
if (eventAdded != null)
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
if (line != null)
|
||||
{
|
||||
eventAdded(this, new StringEventArgs(line));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
hasPID = false;
|
||||
printerConnection.QueueLine("M503");
|
||||
}
|
||||
}
|
||||
}
|
||||
442
original/MatterControlLib/EeProm/EePromMarlinWindow.cs
Normal file
442
original/MatterControlLib/EeProm/EePromMarlinWindow.cs
Normal file
|
|
@ -0,0 +1,442 @@
|
|||
/*
|
||||
Copyright (c) 2018, 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.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
||||
|
||||
namespace MatterHackers.MatterControl.EeProm
|
||||
{
|
||||
public class MarlinEEPromPage : EEPromPage
|
||||
{
|
||||
private EePromMarlinSettings currentEePromSettings;
|
||||
|
||||
private ThemedNumberEdit stepsPerMmX;
|
||||
private ThemedNumberEdit stepsPerMmY;
|
||||
private ThemedNumberEdit stepsPerMmZ;
|
||||
private ThemedNumberEdit stepsPerMmE;
|
||||
|
||||
private ThemedNumberEdit maxFeedrateMmPerSX;
|
||||
private ThemedNumberEdit maxFeedrateMmPerSY;
|
||||
private ThemedNumberEdit maxFeedrateMmPerSZ;
|
||||
private ThemedNumberEdit maxFeedrateMmPerSE;
|
||||
|
||||
private ThemedNumberEdit maxAccelerationMmPerSSqrdX;
|
||||
private ThemedNumberEdit maxAccelerationMmPerSSqrdY;
|
||||
private ThemedNumberEdit maxAccelerationMmPerSSqrdZ;
|
||||
private ThemedNumberEdit maxAccelerationMmPerSSqrdE;
|
||||
|
||||
private ThemedNumberEdit accelerationPrintingMoves;
|
||||
private ThemedNumberEdit accelerationRetraction;
|
||||
private ThemedNumberEdit accelerationTravelMoves;
|
||||
|
||||
private ThemedNumberEdit pidP;
|
||||
private ThemedNumberEdit pidI;
|
||||
private ThemedNumberEdit pidD;
|
||||
|
||||
private ThemedNumberEdit bedPidP;
|
||||
private ThemedNumberEdit bedPidI;
|
||||
private ThemedNumberEdit bedPidD;
|
||||
|
||||
private ThemedNumberEdit homingOffsetX;
|
||||
private ThemedNumberEdit homingOffsetY;
|
||||
private ThemedNumberEdit homingOffsetZ;
|
||||
|
||||
private ThemedNumberEdit minFeedrate;
|
||||
private ThemedNumberEdit minTravelFeedrate;
|
||||
private ThemedNumberEdit minSegmentTime;
|
||||
|
||||
private ThemedNumberEdit maxXYJerk;
|
||||
private ThemedNumberEdit maxZJerk;
|
||||
private ThemedNumberEdit maxEJerk;
|
||||
private ThemedNumberEdit maxDeviation;
|
||||
|
||||
private EventHandler unregisterEvents;
|
||||
|
||||
private double maxWidthOfLeftStuff = 0;
|
||||
private List<GuiWidget> leftStuffToSize = new List<GuiWidget>();
|
||||
|
||||
private int currentTabIndex = 0;
|
||||
|
||||
public MarlinEEPromPage(PrinterConfig printer)
|
||||
: base(printer)
|
||||
{
|
||||
AlwaysOnTopOfMain = true;
|
||||
this.WindowTitle = "Marlin Firmware EEPROM Settings".Localize();
|
||||
|
||||
currentEePromSettings = new EePromMarlinSettings(printer.Connection);
|
||||
currentEePromSettings.eventAdded += SetUiToPrinterSettings;
|
||||
|
||||
// the center content
|
||||
var conterContent = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
||||
{
|
||||
VAnchor = VAnchor.Fit | VAnchor.Top,
|
||||
HAnchor = HAnchor.Stretch
|
||||
};
|
||||
|
||||
// add a scroll container
|
||||
var settingsAreaScrollBox = new ScrollableWidget(true);
|
||||
settingsAreaScrollBox.ScrollArea.HAnchor |= HAnchor.Stretch;
|
||||
settingsAreaScrollBox.AnchorAll();
|
||||
contentRow.AddChild(settingsAreaScrollBox);
|
||||
|
||||
settingsAreaScrollBox.AddChild(conterContent);
|
||||
|
||||
conterContent.AddChild(Create4FieldSet("Steps per mm".Localize() + ":",
|
||||
"X:", ref stepsPerMmX,
|
||||
"Y:", ref stepsPerMmY,
|
||||
"Z:", ref stepsPerMmZ,
|
||||
"E:", ref stepsPerMmE));
|
||||
|
||||
conterContent.AddChild(Create4FieldSet("Maximum feedrates [mm/s]".Localize() + ":",
|
||||
"X:", ref maxFeedrateMmPerSX,
|
||||
"Y:", ref maxFeedrateMmPerSY,
|
||||
"Z:", ref maxFeedrateMmPerSZ,
|
||||
"E:", ref maxFeedrateMmPerSE));
|
||||
|
||||
conterContent.AddChild(Create4FieldSet("Maximum Acceleration [mm/s²]".Localize() + ":",
|
||||
"X:", ref maxAccelerationMmPerSSqrdX,
|
||||
"Y:", ref maxAccelerationMmPerSSqrdY,
|
||||
"Z:", ref maxAccelerationMmPerSSqrdZ,
|
||||
"E:", ref maxAccelerationMmPerSSqrdE));
|
||||
|
||||
conterContent.AddChild(CreateField("Acceleration Printing".Localize() + ":", ref accelerationPrintingMoves));
|
||||
conterContent.AddChild(CreateField("Acceleration Travel".Localize() + ":", ref accelerationTravelMoves));
|
||||
conterContent.AddChild(CreateField("Retract Acceleration".Localize() + ":", ref accelerationRetraction));
|
||||
|
||||
conterContent.AddChild(Create3FieldSet("PID Settings".Localize() + ":",
|
||||
"P:", ref pidP,
|
||||
"I:", ref pidI,
|
||||
"D:", ref pidD));
|
||||
|
||||
conterContent.AddChild(Create3FieldSet("Bed PID Settings".Localize() + ":",
|
||||
"P:", ref bedPidP,
|
||||
"I:", ref bedPidI,
|
||||
"D:", ref bedPidD));
|
||||
|
||||
conterContent.AddChild(Create3FieldSet("Homing Offset".Localize() + ":",
|
||||
"X:", ref homingOffsetX,
|
||||
"Y:", ref homingOffsetY,
|
||||
"Z:", ref homingOffsetZ));
|
||||
|
||||
conterContent.AddChild(CreateField("Min feedrate [mm/s]".Localize() + ":", ref minFeedrate));
|
||||
conterContent.AddChild(CreateField("Min travel feedrate [mm/s]".Localize() + ":", ref minTravelFeedrate));
|
||||
conterContent.AddChild(CreateField("Minimum segment time [ms]".Localize() + ":", ref minSegmentTime));
|
||||
conterContent.AddChild(CreateField("Maximum X-Y jerk [mm/s]".Localize() + ":", ref maxXYJerk));
|
||||
conterContent.AddChild(CreateField("Maximum Z jerk [mm/s]".Localize() + ":", ref maxZJerk));
|
||||
conterContent.AddChild(CreateField("Maximum E jerk [mm/s]".Localize() + ":", ref maxEJerk));
|
||||
conterContent.AddChild(CreateField("Junction Deviation [mm/s]".Localize() + ":", ref maxDeviation));
|
||||
|
||||
// the bottom button bar
|
||||
var buttonSave = theme.CreateDialogButton("Save to EEProm".Localize());
|
||||
buttonSave.Click += (s, e) =>
|
||||
{
|
||||
SaveSettingsToActive();
|
||||
currentEePromSettings.SaveToEeProm();
|
||||
this.DialogWindow.Close();
|
||||
};
|
||||
this.AddPageAction(buttonSave);
|
||||
|
||||
var exportButton = theme.CreateDialogButton("Export".Localize());
|
||||
exportButton.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(this.ExportSettings, .1);
|
||||
};
|
||||
this.AddPageAction(exportButton);
|
||||
|
||||
printer.Connection.LineReceived += currentEePromSettings.Add;
|
||||
|
||||
this.Closed += (s, e) =>
|
||||
{
|
||||
printer.Connection.LineReceived -= currentEePromSettings.Add;
|
||||
};
|
||||
|
||||
// and ask the printer to send the settings
|
||||
currentEePromSettings.Update();
|
||||
|
||||
if (headerRow is OverflowBar overflowBar)
|
||||
{
|
||||
overflowBar.ExtendOverflowMenu = (popupMenu) =>
|
||||
{
|
||||
var menuItem = popupMenu.CreateMenuItem("Import".Localize());
|
||||
menuItem.Name = "Import Menu Item";
|
||||
menuItem.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
AggContext.FileDialogs.OpenFileDialog(
|
||||
new OpenFileDialogParams("EEPROM Settings|*.ini")
|
||||
{
|
||||
ActionButtonLabel = "Import EEPROM Settings".Localize(),
|
||||
Title = "Import EEPROM".Localize(),
|
||||
},
|
||||
(openParams) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(openParams.FileName))
|
||||
{
|
||||
currentEePromSettings.Import(openParams.FileName);
|
||||
SetUiToPrinterSettings(null, null);
|
||||
}
|
||||
});
|
||||
}, .1);
|
||||
};
|
||||
|
||||
// put in the export button
|
||||
menuItem = popupMenu.CreateMenuItem("Export".Localize());
|
||||
menuItem.Name = "Export Menu Item";
|
||||
menuItem.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(this.ExportSettings, .1);
|
||||
};
|
||||
|
||||
popupMenu.CreateSeparator();
|
||||
|
||||
menuItem = popupMenu.CreateMenuItem("Reset to Factory Defaults".Localize());
|
||||
menuItem.Click += (s, e) =>
|
||||
{
|
||||
currentEePromSettings.SetPrinterToFactorySettings();
|
||||
currentEePromSettings.Update();
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
foreach (GuiWidget widget in leftStuffToSize)
|
||||
{
|
||||
widget.Width = maxWidthOfLeftStuff;
|
||||
}
|
||||
}
|
||||
|
||||
private void ExportSettings()
|
||||
{
|
||||
AggContext.FileDialogs.SaveFileDialog(
|
||||
new SaveFileDialogParams("EEPROM Settings|*.ini")
|
||||
{
|
||||
ActionButtonLabel = "Export EEPROM Settings".Localize(),
|
||||
Title = "Export EEPROM".Localize(),
|
||||
FileName = $"eeprom_settings_{base.GetSanitizedPrinterName()}"
|
||||
},
|
||||
(saveParams) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(saveParams.FileName))
|
||||
{
|
||||
currentEePromSettings.Export(saveParams.FileName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private GuiWidget CreateMHNumEdit(ref ThemedNumberEdit numberEditToCreate)
|
||||
{
|
||||
numberEditToCreate = new ThemedNumberEdit(0, theme, pixelWidth: 80 * GuiWidget.DeviceScale, allowNegatives: true, allowDecimals: true)
|
||||
{
|
||||
SelectAllOnFocus = true,
|
||||
VAnchor = VAnchor.Center,
|
||||
Margin = new BorderDouble(3, 0),
|
||||
TabIndex = GetNextTabIndex()
|
||||
};
|
||||
|
||||
return numberEditToCreate;
|
||||
}
|
||||
|
||||
private GuiWidget CreateField(string label, ref ThemedNumberEdit field1)
|
||||
{
|
||||
ThemedNumberEdit none = null;
|
||||
|
||||
return Create4FieldSet(label,
|
||||
"", ref field1,
|
||||
null, ref none,
|
||||
null, ref none,
|
||||
null, ref none);
|
||||
}
|
||||
|
||||
private GuiWidget Create3FieldSet(string label,
|
||||
string field1Label, ref ThemedNumberEdit field1,
|
||||
string field2Label, ref ThemedNumberEdit field2,
|
||||
string field3Label, ref ThemedNumberEdit field3)
|
||||
{
|
||||
ThemedNumberEdit none = null;
|
||||
|
||||
return Create4FieldSet(label,
|
||||
field1Label, ref field1,
|
||||
field2Label, ref field2,
|
||||
field3Label, ref field3,
|
||||
null, ref none);
|
||||
}
|
||||
|
||||
private GuiWidget CreateTextField(string label)
|
||||
{
|
||||
var textWidget = new TextWidget(label, pointSize: theme.FontSize10, textColor: theme.TextColor)
|
||||
{
|
||||
VAnchor = VAnchor.Center,
|
||||
HAnchor = HAnchor.Right
|
||||
};
|
||||
|
||||
var container = new GuiWidget(textWidget.Height, 24);
|
||||
container.AddChild(textWidget);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
private GuiWidget Create4FieldSet(string label,
|
||||
string field1Label, ref ThemedNumberEdit field1,
|
||||
string field2Label, ref ThemedNumberEdit field2,
|
||||
string field3Label, ref ThemedNumberEdit field3,
|
||||
string field4Label, ref ThemedNumberEdit field4)
|
||||
{
|
||||
var row = new FlowLayoutWidget
|
||||
{
|
||||
Margin = 3,
|
||||
HAnchor = HAnchor.Stretch
|
||||
};
|
||||
|
||||
var labelWidget = new TextWidget(label, pointSize: theme.FontSize10, textColor: theme.TextColor);
|
||||
maxWidthOfLeftStuff = Math.Max(maxWidthOfLeftStuff, labelWidget.Width);
|
||||
|
||||
var holder = new GuiWidget(labelWidget.Width, labelWidget.Height)
|
||||
{
|
||||
Margin = new BorderDouble(3, 0),
|
||||
VAnchor = VAnchor.Fit | VAnchor.Center
|
||||
};
|
||||
holder.AddChild(labelWidget);
|
||||
leftStuffToSize.Add(holder);
|
||||
row.AddChild(holder);
|
||||
|
||||
row.AddChild(CreateTextField(field1Label));
|
||||
row.AddChild(CreateMHNumEdit(ref field1));
|
||||
|
||||
if (field2Label != null)
|
||||
{
|
||||
row.AddChild(CreateTextField(field2Label));
|
||||
row.AddChild(CreateMHNumEdit(ref field2));
|
||||
}
|
||||
|
||||
if (field3Label != null)
|
||||
{
|
||||
row.AddChild(CreateTextField(field3Label));
|
||||
row.AddChild(CreateMHNumEdit(ref field3));
|
||||
}
|
||||
|
||||
if (field4Label != null)
|
||||
{
|
||||
row.AddChild(CreateTextField(field4Label));
|
||||
row.AddChild(CreateMHNumEdit(ref field4));
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
private int GetNextTabIndex()
|
||||
{
|
||||
return currentTabIndex++;
|
||||
}
|
||||
|
||||
public override void OnClosed(EventArgs e)
|
||||
{
|
||||
unregisterEvents?.Invoke(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;
|
||||
accelerationPrintingMoves.Text = currentEePromSettings.AccPrintingMoves;
|
||||
accelerationTravelMoves.Text = currentEePromSettings.AccTravelMoves;
|
||||
accelerationRetraction.Text = currentEePromSettings.AccRetraction;
|
||||
minFeedrate.Text = currentEePromSettings.AVS;
|
||||
minTravelFeedrate.Text = currentEePromSettings.AVT;
|
||||
minSegmentTime.Text = currentEePromSettings.AVB;
|
||||
maxXYJerk.Text = currentEePromSettings.AVX;
|
||||
maxZJerk.Text = currentEePromSettings.AVZ;
|
||||
maxEJerk.Text = currentEePromSettings.AVE;
|
||||
maxDeviation.Text = currentEePromSettings.AVJ;
|
||||
pidP.Enabled = pidI.Enabled = pidD.Enabled = currentEePromSettings.hasPID;
|
||||
pidP.Text = currentEePromSettings.PPID;
|
||||
pidI.Text = currentEePromSettings.IPID;
|
||||
pidD.Text = currentEePromSettings.DPID;
|
||||
bedPidP.Enabled = bedPidI.Enabled = bedPidD.Enabled = currentEePromSettings.bed_HasPID;
|
||||
bedPidP.Text = currentEePromSettings.BED_PPID;
|
||||
bedPidI.Text = currentEePromSettings.BED_IPID;
|
||||
bedPidD.Text = currentEePromSettings.BED_DPID;
|
||||
homingOffsetX.Text = currentEePromSettings.hox;
|
||||
homingOffsetY.Text = currentEePromSettings.hoy;
|
||||
homingOffsetZ.Text = currentEePromSettings.hoz;
|
||||
}
|
||||
|
||||
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.AccPrintingMoves = accelerationPrintingMoves.Text;
|
||||
currentEePromSettings.AccTravelMoves = accelerationTravelMoves.Text;
|
||||
currentEePromSettings.AccRetraction = accelerationRetraction.Text;
|
||||
currentEePromSettings.AVS = minFeedrate.Text;
|
||||
currentEePromSettings.AVT = minTravelFeedrate.Text;
|
||||
currentEePromSettings.AVB = minSegmentTime.Text;
|
||||
currentEePromSettings.AVX = maxXYJerk.Text;
|
||||
currentEePromSettings.AVZ = maxZJerk.Text;
|
||||
currentEePromSettings.AVE = maxEJerk.Text;
|
||||
currentEePromSettings.AVJ = maxDeviation.Text;
|
||||
currentEePromSettings.PPID = pidP.Text;
|
||||
currentEePromSettings.IPID = pidI.Text;
|
||||
currentEePromSettings.DPID = pidD.Text;
|
||||
currentEePromSettings.BED_PPID = bedPidP.Text;
|
||||
currentEePromSettings.BED_IPID = bedPidI.Text;
|
||||
currentEePromSettings.BED_DPID = bedPidD.Text;
|
||||
currentEePromSettings.HOX = homingOffsetX.Text;
|
||||
currentEePromSettings.HOY = homingOffsetY.Text;
|
||||
currentEePromSettings.HOZ = homingOffsetZ.Text;
|
||||
|
||||
currentEePromSettings.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
107
original/MatterControlLib/EeProm/EePromRepetierParameter.cs
Normal file
107
original/MatterControlLib/EeProm/EePromRepetierParameter.cs
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
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.MatterControl.PrinterCommunication;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace MatterHackers.MatterControl.EeProm
|
||||
{
|
||||
public class EePromRepetierParameter : EventArgs
|
||||
{
|
||||
public string description = "";
|
||||
public int type;
|
||||
public int position;
|
||||
public string value { get; private set; } = "";
|
||||
private bool changed = false;
|
||||
|
||||
public EePromRepetierParameter(string line)
|
||||
{
|
||||
update(line);
|
||||
}
|
||||
|
||||
public void update(string line)
|
||||
{
|
||||
if (line.Length > 4)
|
||||
{
|
||||
string[] lines = line.Substring(4).Split(' ');
|
||||
if (lines.Length > 2)
|
||||
{
|
||||
int.TryParse(lines[0], out type);
|
||||
int.TryParse(lines[1], out position);
|
||||
value = lines[2];
|
||||
int startPos = 7 + lines[0].Length + lines[1].Length + lines[2].Length;
|
||||
if (line.Length > startPos)
|
||||
{
|
||||
description = line.Substring(startPos);
|
||||
}
|
||||
changed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(PrinterConnection printerConnection)
|
||||
{
|
||||
if (!changed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string cmd = "M206 T" + type + " P" + position + " ";
|
||||
if (type == 3) cmd += "X" + value;
|
||||
else cmd += "S" + value;
|
||||
printerConnection.QueueLine(cmd);
|
||||
changed = false;
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get { return description; }
|
||||
set { description = value; }
|
||||
}
|
||||
|
||||
public string Value
|
||||
{
|
||||
get { return value; }
|
||||
set
|
||||
{
|
||||
value = value.Replace(',', '.').Trim();
|
||||
if (this.value.Equals(value)) return;
|
||||
this.value = value;
|
||||
MarkChanged();
|
||||
}
|
||||
}
|
||||
|
||||
internal void MarkChanged()
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
137
original/MatterControlLib/EeProm/EePromRepetierStorage.cs
Normal file
137
original/MatterControlLib/EeProm/EePromRepetierStorage.cs
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
Copyright (c) 2018, 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.IO;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
|
||||
namespace MatterHackers.MatterControl.EeProm
|
||||
{
|
||||
public class EePromRepetierStorage
|
||||
{
|
||||
public Dictionary<int, EePromRepetierParameter> eePromSettingsList;
|
||||
|
||||
public event EventHandler SettingAdded = null;
|
||||
|
||||
public EePromRepetierStorage()
|
||||
{
|
||||
eePromSettingsList = new Dictionary<int, EePromRepetierParameter>();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
lock (eePromSettingsList)
|
||||
{
|
||||
eePromSettingsList.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(PrinterConnection printerConnection)
|
||||
{
|
||||
lock (eePromSettingsList)
|
||||
{
|
||||
foreach (EePromRepetierParameter p in eePromSettingsList.Values)
|
||||
{
|
||||
p.Save(printerConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(object sender, string line)
|
||||
{
|
||||
if (line == null
|
||||
|| !line.StartsWith("EPR:"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var parameter = new EePromRepetierParameter(line);
|
||||
lock (eePromSettingsList)
|
||||
{
|
||||
if (eePromSettingsList.ContainsKey(parameter.position))
|
||||
{
|
||||
eePromSettingsList.Remove(parameter.position);
|
||||
}
|
||||
|
||||
eePromSettingsList.Add(parameter.position, parameter);
|
||||
}
|
||||
|
||||
this.SettingAdded?.Invoke(this, parameter);
|
||||
}
|
||||
|
||||
public void AskPrinterForSettings(PrinterConnection printerConnection)
|
||||
{
|
||||
printerConnection.QueueLine("M205");
|
||||
}
|
||||
|
||||
internal void Export(string fileName)
|
||||
{
|
||||
using (var sw = new StreamWriter(fileName))
|
||||
{
|
||||
lock (eePromSettingsList)
|
||||
{
|
||||
foreach (EePromRepetierParameter p in eePromSettingsList.Values)
|
||||
{
|
||||
sw.WriteLine("{0}|{1}", p.description, p.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void Import(string fileName)
|
||||
{
|
||||
// find all the descriptions we can
|
||||
foreach (string line in File.ReadAllLines(fileName))
|
||||
{
|
||||
if (line.Contains("|"))
|
||||
{
|
||||
string[] descriptionValue = line.Split('|');
|
||||
if (descriptionValue.Length == 2)
|
||||
{
|
||||
foreach (KeyValuePair<int, EePromRepetierParameter> keyValue in eePromSettingsList)
|
||||
{
|
||||
if (keyValue.Value.Description == descriptionValue[0])
|
||||
{
|
||||
if (keyValue.Value.Value != descriptionValue[1])
|
||||
{
|
||||
// push in the value
|
||||
keyValue.Value.Value = descriptionValue[1];
|
||||
keyValue.Value.MarkChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
333
original/MatterControlLib/EeProm/EePromRepetierWindow.cs
Normal file
333
original/MatterControlLib/EeProm/EePromRepetierWindow.cs
Normal file
|
|
@ -0,0 +1,333 @@
|
|||
/*
|
||||
Copyright (c) 2018, 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.
|
||||
*/
|
||||
//#define SIMULATE_CONNECTION
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
|
||||
namespace MatterHackers.MatterControl.EeProm
|
||||
{
|
||||
public class EEPromPage : DialogPage
|
||||
{
|
||||
private static Regex nameSanitizer = new Regex("[^_a-zA-Z0-9-]", RegexOptions.Compiled);
|
||||
|
||||
protected PrinterConfig printer;
|
||||
|
||||
public EEPromPage(PrinterConfig printer)
|
||||
: base("Close".Localize(), useOverflowBar: true)
|
||||
{
|
||||
this.HeaderText = "EEProm Settings".Localize();
|
||||
this.WindowSize = new VectorMath.Vector2(663, 575);
|
||||
this.printer = printer;
|
||||
|
||||
headerRow.Margin = this.headerRow.Margin.Clone(bottom: 0);
|
||||
|
||||
printer.Connection.CommunicationStateChanged += CommunicationStateChanged;
|
||||
}
|
||||
|
||||
public override void OnClosed(EventArgs e)
|
||||
{
|
||||
// Unregister listeners
|
||||
printer.Connection.CommunicationStateChanged -= CommunicationStateChanged;
|
||||
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
protected string GetSanitizedPrinterName()
|
||||
{
|
||||
// TODO: Determine best file name sanitization implementation: this, MakeValidFileName, something else?
|
||||
string printerName = printer.PrinterName.Replace(" ", "_");
|
||||
return nameSanitizer.Replace(printerName, "");
|
||||
}
|
||||
|
||||
private void CommunicationStateChanged(object s, EventArgs e)
|
||||
{
|
||||
if (!printer.Connection.IsConnected)
|
||||
{
|
||||
this.DialogWindow.CloseOnIdle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class RepetierEEPromPage : EEPromPage
|
||||
{
|
||||
private EePromRepetierStorage currentEePromSettings;
|
||||
private FlowLayoutWidget settingsColumn;
|
||||
|
||||
public RepetierEEPromPage(PrinterConfig printer)
|
||||
: base(printer)
|
||||
{
|
||||
AlwaysOnTopOfMain = true;
|
||||
|
||||
this.WindowTitle = "Firmware EEPROM Settings".Localize();
|
||||
|
||||
currentEePromSettings = new EePromRepetierStorage();
|
||||
|
||||
var topToBottom = contentRow;
|
||||
|
||||
var row = new FlowLayoutWidget
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
};
|
||||
|
||||
GuiWidget descriptionWidget = AddDescription("Description".Localize());
|
||||
descriptionWidget.Margin = new BorderDouble(left: 3);
|
||||
row.AddChild(descriptionWidget);
|
||||
|
||||
CreateSpacer(row);
|
||||
|
||||
row.AddChild(new TextWidget("Value".Localize(), pointSize: theme.FontSize10, textColor: theme.TextColor)
|
||||
{
|
||||
VAnchor = VAnchor.Center,
|
||||
Margin = new BorderDouble(left: 5, right: 60)
|
||||
});
|
||||
topToBottom.AddChild(row);
|
||||
|
||||
{
|
||||
var settingsAreaScrollBox = new ScrollableWidget(true);
|
||||
settingsAreaScrollBox.ScrollArea.HAnchor |= HAnchor.Stretch;
|
||||
settingsAreaScrollBox.AnchorAll();
|
||||
settingsAreaScrollBox.BackgroundColor = theme.MinimalShade;
|
||||
topToBottom.AddChild(settingsAreaScrollBox);
|
||||
|
||||
settingsColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
||||
{
|
||||
HAnchor = HAnchor.MaxFitOrStretch
|
||||
};
|
||||
|
||||
settingsAreaScrollBox.AddChild(settingsColumn);
|
||||
}
|
||||
|
||||
|
||||
if (headerRow is OverflowBar overflowBar)
|
||||
{
|
||||
overflowBar.ExtendOverflowMenu = (popupMenu) =>
|
||||
{
|
||||
var menuItem = popupMenu.CreateMenuItem("Import".Localize());
|
||||
menuItem.Name = "Import Menu Item";
|
||||
menuItem.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
AggContext.FileDialogs.OpenFileDialog(
|
||||
new OpenFileDialogParams("EEPROM Settings|*.ini")
|
||||
{
|
||||
ActionButtonLabel = "Import EEPROM Settings".Localize(),
|
||||
Title = "Import EEPROM".Localize(),
|
||||
},
|
||||
(openParams) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(openParams.FileName))
|
||||
{
|
||||
currentEePromSettings.Import(openParams.FileName);
|
||||
RebuildUi();
|
||||
}
|
||||
});
|
||||
}, .1);
|
||||
};
|
||||
|
||||
menuItem = popupMenu.CreateMenuItem("Export".Localize());
|
||||
menuItem.Name = "Export Menu Item";
|
||||
menuItem.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(this.ExportSettings, .1);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// put in the save button
|
||||
var buttonSave = theme.CreateDialogButton("Save To EEPROM".Localize());
|
||||
buttonSave.Click += (s, e) =>
|
||||
{
|
||||
currentEePromSettings.Save(printer.Connection);
|
||||
currentEePromSettings.Clear();
|
||||
this.DialogWindow.Close();
|
||||
};
|
||||
|
||||
this.AddPageAction(buttonSave);
|
||||
|
||||
var exportButton = theme.CreateDialogButton("Export".Localize());
|
||||
exportButton.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(this.ExportSettings, .1);
|
||||
};
|
||||
this.AddPageAction(exportButton);
|
||||
|
||||
currentEePromSettings.Clear();
|
||||
printer.Connection.LineReceived += currentEePromSettings.Add;
|
||||
currentEePromSettings.SettingAdded += NewSettingReadFromPrinter;
|
||||
currentEePromSettings.AskPrinterForSettings(printer.Connection);
|
||||
|
||||
this.Closed += (s, e) =>
|
||||
{
|
||||
printer.Connection.LineReceived -= currentEePromSettings.Add;
|
||||
currentEePromSettings.SettingAdded -= NewSettingReadFromPrinter;
|
||||
};
|
||||
|
||||
#if SIMULATE_CONNECTION
|
||||
UiThread.RunOnIdle(AddSimulatedItems);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void ExportSettings()
|
||||
{
|
||||
string defaultFileName = $"eeprom_settings_{base.GetSanitizedPrinterName()}.ini";
|
||||
|
||||
AggContext.FileDialogs.SaveFileDialog(
|
||||
new SaveFileDialogParams("EEPROM Settings|*.ini")
|
||||
{
|
||||
ActionButtonLabel = "Export EEPROM Settings".Localize(),
|
||||
Title = "Export EEPROM".Localize(),
|
||||
FileName = defaultFileName
|
||||
},
|
||||
(saveParams) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(saveParams.FileName))
|
||||
{
|
||||
currentEePromSettings.Export(saveParams.FileName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#if SIMULATE_CONNECTION
|
||||
int count;
|
||||
void AddSimulatedItems(object state)
|
||||
{
|
||||
NewSettingReadFromPrinter(this, new EePromRepetierParameter("this is a test line " + count.ToString()));
|
||||
|
||||
count++;
|
||||
if (count < 30)
|
||||
{
|
||||
UiThread.RunOnIdle(AddSimulatedItems);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private static void CreateSpacer(FlowLayoutWidget buttonBar)
|
||||
{
|
||||
buttonBar.AddChild(new GuiWidget(1, 1)
|
||||
{
|
||||
HAnchor = HAnchor.Stretch
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnClosed(EventArgs e)
|
||||
{
|
||||
if (currentEePromSettings != null)
|
||||
{
|
||||
currentEePromSettings.SettingAdded -= NewSettingReadFromPrinter;
|
||||
}
|
||||
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
bool waitingForUiUpdate = false;
|
||||
private void NewSettingReadFromPrinter(object sender, EventArgs e)
|
||||
{
|
||||
if (e is EePromRepetierParameter newSetting)
|
||||
{
|
||||
if (!waitingForUiUpdate)
|
||||
{
|
||||
waitingForUiUpdate = true;
|
||||
UiThread.RunOnIdle(RebuildUi, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int currentTabIndex = 0;
|
||||
|
||||
private void RebuildUi()
|
||||
{
|
||||
var tempList = new List<EePromRepetierParameter>();
|
||||
lock (currentEePromSettings.eePromSettingsList)
|
||||
{
|
||||
foreach (var keyValue in currentEePromSettings.eePromSettingsList)
|
||||
{
|
||||
tempList.Add(keyValue.Value);
|
||||
}
|
||||
}
|
||||
|
||||
settingsColumn.CloseChildren();
|
||||
|
||||
foreach (EePromRepetierParameter newSetting in tempList)
|
||||
{
|
||||
if (newSetting != null)
|
||||
{
|
||||
var row = new FlowLayoutWidget
|
||||
{
|
||||
HAnchor = HAnchor.MaxFitOrStretch,
|
||||
Padding = new BorderDouble(5, 0)
|
||||
};
|
||||
row.AddChild(AddDescription(newSetting.Description));
|
||||
|
||||
if ((settingsColumn.Children.Count % 2) == 1)
|
||||
{
|
||||
row.BackgroundColor = new Color(0, 0, 0, 30);
|
||||
}
|
||||
|
||||
CreateSpacer(row);
|
||||
|
||||
double.TryParse(newSetting.Value, out double currentValue);
|
||||
var valueEdit = new ThemedNumberEdit(currentValue, theme, pixelWidth: 80 * GuiWidget.DeviceScale, allowNegatives: true, allowDecimals: true)
|
||||
{
|
||||
SelectAllOnFocus = true,
|
||||
TabIndex = currentTabIndex++,
|
||||
VAnchor = VAnchor.Center
|
||||
};
|
||||
valueEdit.ActuallNumberEdit.EditComplete += (s, e) =>
|
||||
{
|
||||
newSetting.Value = valueEdit.ActuallNumberEdit.Value.ToString();
|
||||
};
|
||||
row.AddChild(valueEdit);
|
||||
|
||||
settingsColumn.AddChild(row);
|
||||
}
|
||||
}
|
||||
waitingForUiUpdate = false;
|
||||
}
|
||||
|
||||
private GuiWidget AddDescription(string description)
|
||||
{
|
||||
var holder = new GuiWidget(340, 40);
|
||||
holder.AddChild(new TextWidget(description, pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
|
||||
{
|
||||
VAnchor = VAnchor.Center
|
||||
});
|
||||
|
||||
return holder;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue