Creating eePromSettings window for repetier firmware.

Put in detection of firmware.
Creating base window and data to construct it.
This commit is contained in:
larsbrubaker 2014-02-18 17:52:50 -08:00
parent c246b1c6a4
commit 9c8a0fa5a8
6 changed files with 393 additions and 1 deletions

View file

@ -0,0 +1,92 @@
/*
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.Linq;
using System.Text;
namespace MatterHackers.MatterControl.EeProm
{
public class EePromRepatierParameter
{
public string description;
public int type;
public int position;
string val = "";
bool changed = false;
public EePromRepatierParameter(string line)
{
update(line);
}
public void update(string line)
{
string[] lines = line.Substring(4).Split(' ');
int.TryParse(lines[0], out type);
int.TryParse(lines[1], out position);
val = lines[2];
description = line.Substring(7 + lines[0].Length + lines[1].Length + lines[2].Length);
changed = false;
}
public void save()
{
if (!changed)
{
return;
}
string cmd = "M206 T" + type + " P" + position + " ";
if (type == 3) cmd += "X" + val;
else cmd += "S" + val;
PrinterCommunication.Instance.QueueLineToPrinter(cmd);
changed = false;
}
public string Description
{
get { return description; }
set { description = value; }
}
public string Value
{
get { return val; }
set
{
value = value.Replace(',', '.').Trim();
if (val.Equals(value)) return;
val = value;
changed = true;
}
}
}
}

View file

@ -0,0 +1,87 @@
/*
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.Linq;
using System.Text;
namespace MatterHackers.MatterControl.EeProm
{
public delegate void OnEePromRepatierAdded(EePromRepatierParameter param);
public class EePromRepatierStorage
{
public Dictionary<int, EePromRepatierParameter> eePromSettingsList;
public event OnEePromRepatierAdded eventAdded = null;
public EePromRepatierStorage()
{
eePromSettingsList = new Dictionary<int, EePromRepatierParameter>();
}
public void Clear()
{
eePromSettingsList.Clear();
}
public void Save()
{
foreach (EePromRepatierParameter p in eePromSettingsList.Values)
{
p.save();
}
}
public void Add(string line)
{
if (!line.StartsWith("EPR:"))
{
return;
}
EePromRepatierParameter parameter = new EePromRepatierParameter(line);
if (eePromSettingsList.ContainsKey(parameter.position))
{
eePromSettingsList.Remove(parameter.position);
}
eePromSettingsList.Add(parameter.position, parameter);
if (eventAdded != null)
{
eventAdded(parameter);
}
}
public void AskPrinterForSettings()
{
PrinterCommunication.Instance.QueueLineToPrinter("M205");
}
}
}

View file

@ -0,0 +1,130 @@
/*
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.ComponentModel;
using System.Linq;
using System.Text;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
namespace MatterHackers.MatterControl.EeProm
{
public partial class EePromRepetierWidget : SystemWindow
{
EePromRepatierStorage storage;
BindingList<EePromRepatierParameter> data = new BindingList<EePromRepatierParameter>();
FlowLayoutWidget descriptionColmun;
FlowLayoutWidget valueColmun;
Button buttonCancel;
Button buttonSave;
bool reinit = true;
public EePromRepetierWidget()
: base(640, 480)
{
BackgroundColor = RGBA_Bytes.White;
storage = new EePromRepatierStorage();
FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
{
FlowLayoutWidget columnHolder = new FlowLayoutWidget();
descriptionColmun = new FlowLayoutWidget(FlowDirection.TopToBottom);
columnHolder.AddChild(descriptionColmun);
valueColmun = new FlowLayoutWidget(FlowDirection.TopToBottom);
columnHolder.AddChild(valueColmun);
descriptionColmun.AddChild(new TextWidget("Description"));
valueColmun.AddChild(new TextWidget("Value"));
topToBottom.AddChild(columnHolder);
}
buttonCancel = new Button(new LocalizedString("Cancel").Translated);
topToBottom.AddChild(buttonCancel);
buttonSave = new Button(new LocalizedString("Save To EEPROM").Translated);
topToBottom.AddChild(buttonSave);
//MatterControlApplication.Instance.LanguageChanged += translate;
this.AddChild(topToBottom);
translate();
ShowAsSystemWindow();
}
public void translate()
{
Title = new LocalizedString("Firmware EEPROM Settings").Translated;
buttonCancel.Text = new LocalizedString("Cancel").Translated;
buttonCancel.Click += buttonAbort_Click;
buttonSave.Text = new LocalizedString("Save to EEPROM").Translated;
buttonSave.Click += buttonSave_Click;
}
private void newline(EePromRepatierParameter p)
{
data.Add(p);
}
private void buttonSave_Click(object sender, EventArgs e)
{
storage.Save();
storage.Clear();
storage.eventAdded -= newline;
}
private void buttonAbort_Click(object sender, EventArgs e)
{
storage.Clear();
data.Clear();
storage.eventAdded -= newline;
}
private void EEPROMRepetier_Activated(object sender, EventArgs e)
{
if (reinit)
{
reinit = false;
storage.Clear();
storage.eventAdded += newline;
storage.AskPrinterForSettings();
}
}
}
}

View file

@ -75,6 +75,9 @@
<Compile Include="ActivePrinterProfile.cs" />
<Compile Include="CustomWidgets\ExportQueueItemWindow.cs" />
<Compile Include="CustomWidgets\ExportToFolderFeedbackWindow.cs" />
<Compile Include="EeProm\EePromRepatierParameter.cs" />
<Compile Include="EeProm\EePromRepatierStorage.cs" />
<Compile Include="EeProm\EePromRepatierWidget.cs" />
<Compile Include="FieldValidation.cs" />
<Compile Include="PartPreviewWindow\CreateDiscreteMeshes.cs" />
<Compile Include="CustomWidgets\EditableNumberDisplay.cs" />

View file

@ -98,6 +98,14 @@ namespace MatterHackers.MatterControl
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, int dwShareMode, IntPtr securityAttrs, int dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);
public enum FirmwareTypes { Unknown, Repetier, Marlin, Sprinter };
FirmwareTypes firmwareType = FirmwareTypes.Unknown;
public FirmwareTypes FirmwareType
{
get { return firmwareType; }
}
static PrinterCommunication globalInstance;
string connectionFailureMessage = "Unknown Reason";
@ -373,7 +381,7 @@ namespace MatterHackers.MatterControl
ReadLineStartCallBacks.AddCallBackToKey("ok", PrintingCanContinue);
ReadLineStartCallBacks.AddCallBackToKey("ok T:", ReadTemperatures); // marline
ReadLineStartCallBacks.AddCallBackToKey("ok T:", ReadTemperatures); // marlin
ReadLineStartCallBacks.AddCallBackToKey("T:", ReadTemperatures); // repatier
ReadLineStartCallBacks.AddCallBackToKey("C:", ReadPositions);
@ -381,6 +389,7 @@ namespace MatterHackers.MatterControl
ReadLineContainsCallBacks.AddCallBackToKey("RS:", PrinterRequestsResend);
ReadLineContainsCallBacks.AddCallBackToKey("Resend:", PrinterRequestsResend);
ReadLineContainsCallBacks.AddCallBackToKey("FIRMWARE_NAME:", PrinterStatesFirmware);
WriteLineStartCallBacks.AddCallBackToKey("G28", HomeWasWritenToPrinter);
@ -933,6 +942,29 @@ namespace MatterHackers.MatterControl
firstLineToResendIndex = int.Parse(splitOnColon[1]) - 1;
}
public void PrinterStatesFirmware(object sender, EventArgs e)
{
FoundStringEventArgs foundStringEventArgs = e as FoundStringEventArgs;
string firmwareName = "";
if (GCodeFile.GetFirstStringAfter("FIRMWARE_NAME:", foundStringEventArgs.LineToCheck, " ", ref firmwareName))
{
firmwareName = firmwareName.ToLower();
if (firmwareName.Contains("repetier"))
{
firmwareType = FirmwareTypes.Repetier;
}
else if (firmwareName.Contains("marlin"))
{
firmwareType = FirmwareTypes.Marlin;
}
else if (firmwareName.Contains("sprinter"))
{
firmwareType = FirmwareTypes.Sprinter;
}
}
}
public void FoundStart(object sender, EventArgs e)
{
FoundStringEventArgs foundStringEventArgs = e as FoundStringEventArgs;
@ -1029,6 +1061,7 @@ namespace MatterHackers.MatterControl
//Attempt connecting to a specific printer
CommunicationState = CommunicationStates.AttemptingToConnect;
this.stopTryingToConnect = false;
firmwareType = FirmwareTypes.Unknown;
if (SerialPortIsAvailable(this.ActivePrinter.ComPort))
{

View file

@ -123,6 +123,7 @@ namespace MatterHackers.MatterControl
DisablablableWidget bedTemperatureControlWidget;
DisablablableWidget movementControlsContainer;
DisablablableWidget fanControlsContainer;
DisablablableWidget eePromControlsContainer;
DisablablableWidget tuningAdjustmentControlsContainer;
DisablablableWidget terminalCommunicationsContainer;
DisablablableWidget sdCardManagerContainer;
@ -221,6 +222,8 @@ namespace MatterHackers.MatterControl
controlsTopToBottomLayout.AddChild(macroControls);
PutInFanControls(controlsTopToBottomLayout);
PutInEePromControls(controlsTopToBottomLayout);
AddAdjustmentControls(controlsTopToBottomLayout);
this.AddChild(controlsTopToBottomLayout);
@ -260,6 +263,45 @@ namespace MatterHackers.MatterControl
}
}
private void PutInEePromControls(FlowLayoutWidget controlsTopToBottomLayout)
{
GroupBox eePromControlsGroupBox = new GroupBox(new LocalizedString("EEProm Settings").Translated);
eePromControlsGroupBox.Margin = new BorderDouble(0);
eePromControlsGroupBox.TextColor = ActiveTheme.Instance.PrimaryTextColor;
eePromControlsGroupBox.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
eePromControlsGroupBox.HAnchor |= Agg.UI.HAnchor.ParentLeftRight;
eePromControlsGroupBox.VAnchor = Agg.UI.VAnchor.FitToChildren;
{
FlowLayoutWidget eePromControlsLayout = new FlowLayoutWidget(FlowDirection.TopToBottom);
eePromControlsLayout.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
eePromControlsLayout.VAnchor = Agg.UI.VAnchor.FitToChildren;
eePromControlsLayout.Padding = new BorderDouble(3, 5, 3, 0);
{
Button openEePromWindow = textImageButtonFactory.Generate(new LocalizedString("CONFIGURE").Translated);
openEePromWindow.Margin = new BorderDouble(left: 6);
//openEePromWindow.VAnchor = VAnchor.ParentCenter;
openEePromWindow.Click += (sender, e) =>
{
if (PrinterCommunication.Instance.FirmwareType == PrinterCommunication.FirmwareTypes.Repetier)
{
new MatterHackers.MatterControl.EeProm.EePromRepetierWidget();
}
};
eePromControlsLayout.AddChild(openEePromWindow);
}
eePromControlsGroupBox.AddChild(eePromControlsLayout);
}
eePromControlsContainer = new DisablablableWidget();
eePromControlsContainer.AddChild(eePromControlsGroupBox);
controlsTopToBottomLayout.AddChild(eePromControlsContainer);
}
private void AddMovementControls(FlowLayoutWidget controlsTopToBottomLayout)
{
Button editButton;
@ -650,6 +692,7 @@ namespace MatterHackers.MatterControl
bedTemperatureControlWidget.SetEnableLevel(DisablablableWidget.EnableLevel.Disabled);
movementControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Disabled);
fanControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Disabled);
eePromControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Disabled);
tuningAdjustmentControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Disabled);
terminalCommunicationsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
printLevelContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Disabled);
@ -669,6 +712,7 @@ namespace MatterHackers.MatterControl
bedTemperatureControlWidget.SetEnableLevel(DisablablableWidget.EnableLevel.ConfigOnly);
movementControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.ConfigOnly);
fanControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Disabled);
eePromControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Disabled);
tuningAdjustmentControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Disabled);
terminalCommunicationsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
printLevelContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Disabled);
@ -682,6 +726,7 @@ namespace MatterHackers.MatterControl
bedTemperatureControlWidget.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
movementControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
fanControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
eePromControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
terminalCommunicationsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
printLevelContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
sdCardManagerContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
@ -701,6 +746,7 @@ namespace MatterHackers.MatterControl
bedTemperatureControlWidget.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
movementControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.ConfigOnly);
fanControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
eePromControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Disabled);
tuningAdjustmentControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
terminalCommunicationsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
printLevelContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Disabled);
@ -718,6 +764,7 @@ namespace MatterHackers.MatterControl
bedTemperatureControlWidget.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
movementControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
fanControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
eePromControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
tuningAdjustmentControlsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
terminalCommunicationsContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Enabled);
printLevelContainer.SetEnableLevel(DisablablableWidget.EnableLevel.Disabled);