diff --git a/EeProm/EePromRepatierParameter.cs b/EeProm/EePromRepatierParameter.cs new file mode 100644 index 000000000..612ae5c5b --- /dev/null +++ b/EeProm/EePromRepatierParameter.cs @@ -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; + } + } + } +} diff --git a/EeProm/EePromRepatierStorage.cs b/EeProm/EePromRepatierStorage.cs new file mode 100644 index 000000000..6417157f1 --- /dev/null +++ b/EeProm/EePromRepatierStorage.cs @@ -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 eePromSettingsList; + public event OnEePromRepatierAdded eventAdded = null; + + public EePromRepatierStorage() + { + eePromSettingsList = new Dictionary(); + } + + 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"); + } + } +} \ No newline at end of file diff --git a/EeProm/EePromRepatierWidget.cs b/EeProm/EePromRepatierWidget.cs new file mode 100644 index 000000000..23512b7c6 --- /dev/null +++ b/EeProm/EePromRepatierWidget.cs @@ -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 data = new BindingList(); + 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(); + } + } + } +} diff --git a/MatterControl.csproj b/MatterControl.csproj index f89b1bf9d..16e9f3747 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -75,6 +75,9 @@ + + + diff --git a/PrinterCommunication.cs b/PrinterCommunication.cs index e0a60933e..f7057fcdc 100644 --- a/PrinterCommunication.cs +++ b/PrinterCommunication.cs @@ -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)) { diff --git a/PrinterControls/ManualPrinterControls.cs b/PrinterControls/ManualPrinterControls.cs index e5c03f2f3..f820b6d21 100644 --- a/PrinterControls/ManualPrinterControls.cs +++ b/PrinterControls/ManualPrinterControls.cs @@ -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);