From 4304ccbfbda59c49bb0813ae539c0a94122227e8 Mon Sep 17 00:00:00 2001 From: Tyler Anderson Date: Wed, 14 Mar 2018 13:49:57 -0700 Subject: [PATCH 1/2] Show print progress on printer's LCD screen --- MatterControl.csproj | 2 +- PrinterCommunication/Io/SendProgressStream.cs | 71 +++++++++++++++++++ PrinterCommunication/PrinterConnection.cs | 14 ++-- .../Settings/SettingsHelpers.cs | 1 + .../SlicerMapping/SliceEngineMapping.cs | 1 + StaticData/SliceSettings/Layouts.txt | 2 + StaticData/SliceSettings/Properties.json | 9 +++ 7 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 PrinterCommunication/Io/SendProgressStream.cs diff --git a/MatterControl.csproj b/MatterControl.csproj index ec65b4fdb..a1f373951 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -40,7 +40,6 @@ 2.0 v4.6.1 - 1.2.0 .\ @@ -474,6 +473,7 @@ + diff --git a/PrinterCommunication/Io/SendProgressStream.cs b/PrinterCommunication/Io/SendProgressStream.cs new file mode 100644 index 000000000..501300490 --- /dev/null +++ b/PrinterCommunication/Io/SendProgressStream.cs @@ -0,0 +1,71 @@ +/* +Copyright (c) 2015, 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.MatterControl.DataStorage; +using MatterHackers.MatterControl.SlicerConfiguration; +using System; + +namespace MatterHackers.MatterControl.PrinterCommunication.Io +{ + public class SendProgressStream : GCodeStreamProxy + { + private double nextPercent = -1; + PrinterConnection printerConnection; + PrinterSettings printerSettings; + PrintTask activePrintTask; + + public SendProgressStream(PrinterConnection printerConnection, PrinterSettings printerSettings, GCodeStream internalStream) + : base(internalStream) + { + this.printerConnection = printerConnection; + this.printerSettings = printerSettings; + } + + public override string ReadLine() + { + if (printerSettings.GetValue(SettingsKey.progress_reporting) != "None" + && printerConnection.CommunicationState == CommunicationStates.Printing + && printerConnection.activePrintTask != null + && printerConnection.activePrintTask.PercentDone > nextPercent) + { + nextPercent = Math.Round(printerConnection.activePrintTask.PercentDone) + 0.5; + if (printerSettings.GetValue(SettingsKey.progress_reporting) == "M73") + { + return String.Format("M73 P{0:0}", printerConnection.activePrintTask.PercentDone); + } + else + { + return String.Format("M117 Printing: {0:0}%", printerConnection.activePrintTask.PercentDone); + } + } + + return base.ReadLine(); + } + } +} diff --git a/PrinterCommunication/PrinterConnection.cs b/PrinterCommunication/PrinterConnection.cs index 1b59ee7bc..f89b33cb9 100644 --- a/PrinterCommunication/PrinterConnection.cs +++ b/PrinterCommunication/PrinterConnection.cs @@ -154,7 +154,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication private object locker = new object(); - private PrintTask activePrintTask; + public PrintTask activePrintTask; private double actualBedTemperature; @@ -197,7 +197,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication private ExtrusionMultiplyerStream extrusionMultiplyerStream8 = null; private FeedRateMultiplyerStream feedrateMultiplyerStream9 = null; private RequestTemperaturesStream requestTemperaturesStream10 = null; - private ProcessWriteRegexStream processWriteRegExStream11 = null; + private SendProgressStream sendProgressStream11 = null; + private ProcessWriteRegexStream processWriteRegExStream12 = null; private GCodeStream totalGCodeStream = null; @@ -2161,11 +2162,12 @@ namespace MatterHackers.MatterControl.PrinterCommunication extrusionMultiplyerStream8 = new ExtrusionMultiplyerStream(babyStepsStream7); feedrateMultiplyerStream9 = new FeedRateMultiplyerStream(extrusionMultiplyerStream8); requestTemperaturesStream10 = new RequestTemperaturesStream(this, feedrateMultiplyerStream9); - processWriteRegExStream11 = new ProcessWriteRegexStream(this.printer.Settings, requestTemperaturesStream10, queuedCommandStream2); - totalGCodeStream = processWriteRegExStream11; + sendProgressStream11 = new SendProgressStream(this, printer.Settings, requestTemperaturesStream10); + processWriteRegExStream12 = new ProcessWriteRegexStream(this.printer.Settings, sendProgressStream11, queuedCommandStream2); + totalGCodeStream = processWriteRegExStream12; // Force a reset of the printer checksum state (but allow it to be write regexed) - var transformedCommand = processWriteRegExStream11?.ProcessWriteRegEx("M110 N1"); + var transformedCommand = processWriteRegExStream12?.ProcessWriteRegEx("M110 N1"); if (transformedCommand != null) { foreach (var line in transformedCommand) @@ -2776,4 +2778,4 @@ namespace MatterHackers.MatterControl.PrinterCommunication public int Index0Based { get; } public double Temperature { get; } } -} \ No newline at end of file +} diff --git a/SlicerConfiguration/Settings/SettingsHelpers.cs b/SlicerConfiguration/Settings/SettingsHelpers.cs index 2feaf35b4..c99eb0d45 100644 --- a/SlicerConfiguration/Settings/SettingsHelpers.cs +++ b/SlicerConfiguration/Settings/SettingsHelpers.cs @@ -124,6 +124,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public const string print_leveling_required_to_print = nameof(print_leveling_required_to_print); public const string print_leveling_solution = nameof(print_leveling_solution); public const string printer_name = nameof(printer_name); + public const string progress_reporting = nameof(progress_reporting); public const string publish_bed_image = nameof(publish_bed_image); public const string read_regex = nameof(read_regex); public const string recover_first_layer_speed = nameof(recover_first_layer_speed); diff --git a/SlicerConfiguration/SlicerMapping/SliceEngineMapping.cs b/SlicerConfiguration/SlicerMapping/SliceEngineMapping.cs index 4bdddd50c..a2af1ff2d 100644 --- a/SlicerConfiguration/SlicerMapping/SliceEngineMapping.cs +++ b/SlicerConfiguration/SlicerMapping/SliceEngineMapping.cs @@ -105,6 +105,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration SettingsKey.max_acceleration, SettingsKey.ip_address, SettingsKey.ip_port, + SettingsKey.progress_reporting, "load_filament_length", "trim_image", "insert_image", diff --git a/StaticData/SliceSettings/Layouts.txt b/StaticData/SliceSettings/Layouts.txt index 28a44ee37..b35728edb 100644 --- a/StaticData/SliceSettings/Layouts.txt +++ b/StaticData/SliceSettings/Layouts.txt @@ -156,6 +156,8 @@ Printer recover_is_enabled recover_first_layer_speed recover_position_before_z_home + Other + progress_reporting Leveling Print Leveling print_leveling_solution diff --git a/StaticData/SliceSettings/Properties.json b/StaticData/SliceSettings/Properties.json index 095681271..555b1be94 100644 --- a/StaticData/SliceSettings/Properties.json +++ b/StaticData/SliceSettings/Properties.json @@ -1920,5 +1920,14 @@ "DataEditType": "STRING", "DefaultValue": "x,3000,y,3000,z,315,e0,150", "RebuildGCodeOnChange": false + }, + { + "SlicerConfigName": "progress_reporting", + "PresentationName": "Progress Reporting", + "HelpText": "Choose the command for showing the print progress on the printer's LCD screen, if it has one.", + "DataEditType": "LIST", + "ListValues": "None,M73,M117", + "DefaultValue": "M117", + "RebuildGCodeOnChange": false } ] From 167150a5c5d4717b0d809ad7565ed6fb110dd7c8 Mon Sep 17 00:00:00 2001 From: Tyler Anderson Date: Wed, 14 Mar 2018 16:39:07 -0700 Subject: [PATCH 2/2] Made suggested improvements --- PrinterCommunication/Io/SendProgressStream.cs | 24 +++--- PrinterCommunication/PrinterConnection.cs | 84 +++++++++---------- 2 files changed, 53 insertions(+), 55 deletions(-) diff --git a/PrinterCommunication/Io/SendProgressStream.cs b/PrinterCommunication/Io/SendProgressStream.cs index 501300490..d6d8eb33b 100644 --- a/PrinterCommunication/Io/SendProgressStream.cs +++ b/PrinterCommunication/Io/SendProgressStream.cs @@ -36,32 +36,30 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io public class SendProgressStream : GCodeStreamProxy { private double nextPercent = -1; - PrinterConnection printerConnection; - PrinterSettings printerSettings; + PrinterConfig printer; PrintTask activePrintTask; - public SendProgressStream(PrinterConnection printerConnection, PrinterSettings printerSettings, GCodeStream internalStream) + public SendProgressStream(PrinterConfig printer, GCodeStream internalStream) : base(internalStream) { - this.printerConnection = printerConnection; - this.printerSettings = printerSettings; + this.printer = printer; } public override string ReadLine() { - if (printerSettings.GetValue(SettingsKey.progress_reporting) != "None" - && printerConnection.CommunicationState == CommunicationStates.Printing - && printerConnection.activePrintTask != null - && printerConnection.activePrintTask.PercentDone > nextPercent) + if (printer.Settings.GetValue(SettingsKey.progress_reporting) != "None" + && printer.Connection.CommunicationState == CommunicationStates.Printing + && printer.Connection.activePrintTask != null + && printer.Connection.activePrintTask.PercentDone > nextPercent) { - nextPercent = Math.Round(printerConnection.activePrintTask.PercentDone) + 0.5; - if (printerSettings.GetValue(SettingsKey.progress_reporting) == "M73") + nextPercent = Math.Round(printer.Connection.activePrintTask.PercentDone) + 0.5; + if (printer.Settings.GetValue(SettingsKey.progress_reporting) == "M73") { - return String.Format("M73 P{0:0}", printerConnection.activePrintTask.PercentDone); + return String.Format("M73 P{0:0}", printer.Connection.activePrintTask.PercentDone); } else { - return String.Format("M117 Printing: {0:0}%", printerConnection.activePrintTask.PercentDone); + return String.Format("M117 Printing: {0:0}%", printer.Connection.activePrintTask.PercentDone); } } diff --git a/PrinterCommunication/PrinterConnection.cs b/PrinterCommunication/PrinterConnection.cs index f89b33cb9..03384c2f6 100644 --- a/PrinterCommunication/PrinterConnection.cs +++ b/PrinterCommunication/PrinterConnection.cs @@ -187,17 +187,17 @@ namespace MatterHackers.MatterControl.PrinterCommunication private PrinterMove lastReportedPosition; private GCodeFileStream gCodeFileStream0 = null; - private PauseHandlingStream pauseHandlingStream1 = null; - private QueuedCommandsStream queuedCommandStream2 = null; - private MacroProcessingStream macroProcessingStream3 = null; - private RelativeToAbsoluteStream relativeToAbsoluteStream4 = null; - private PrintLevelingStream printLevelingStream5 = null; - private WaitForTempStream waitForTempStream6 = null; - private BabyStepsStream babyStepsStream7 = null; - private ExtrusionMultiplyerStream extrusionMultiplyerStream8 = null; - private FeedRateMultiplyerStream feedrateMultiplyerStream9 = null; - private RequestTemperaturesStream requestTemperaturesStream10 = null; - private SendProgressStream sendProgressStream11 = null; + private SendProgressStream sendProgressStream1 = null; + private PauseHandlingStream pauseHandlingStream2 = null; + private QueuedCommandsStream queuedCommandStream3 = null; + private MacroProcessingStream macroProcessingStream4 = null; + private RelativeToAbsoluteStream relativeToAbsoluteStream5 = null; + private PrintLevelingStream printLevelingStream6 = null; + private WaitForTempStream waitForTempStream7 = null; + private BabyStepsStream babyStepsStream8 = null; + private ExtrusionMultiplyerStream extrusionMultiplyerStream9 = null; + private FeedRateMultiplyerStream feedrateMultiplyerStream10 = null; + private RequestTemperaturesStream requestTemperaturesStream11 = null; private ProcessWriteRegexStream processWriteRegExStream12 = null; private GCodeStream totalGCodeStream = null; @@ -1680,7 +1680,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication return; } - pauseHandlingStream1.DoPause(PauseHandlingStream.PauseReason.UserRequested); + pauseHandlingStream2.DoPause(PauseHandlingStream.PauseReason.UserRequested); } } @@ -1708,7 +1708,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication } else { - pauseHandlingStream1.Resume(); + pauseHandlingStream2.Resume(); CommunicationState = CommunicationStates.Printing; } } @@ -1772,7 +1772,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication if (lineToWrite.Trim().Length > 0) { // insert the command into the printing queue at the head - queuedCommandStream2?.Add(lineToWrite, forceTopOfQueue); + queuedCommandStream3?.Add(lineToWrite, forceTopOfQueue); } } } @@ -2130,17 +2130,18 @@ namespace MatterHackers.MatterControl.PrinterCommunication if (this.RecoveryIsEnabled && activePrintTask != null) // We are resuming a failed print (do lots of interesting stuff). { - pauseHandlingStream1 = new PauseHandlingStream(printer, new PrintRecoveryStream(printer, gCodeFileStream0, activePrintTask.PercentDone)); + sendProgressStream1 = new SendProgressStream(printer, new PrintRecoveryStream(printer, gCodeFileStream0, activePrintTask.PercentDone)); // And increment the recovery count activePrintTask.RecoveryCount++; activePrintTask.Commit(); } else { - pauseHandlingStream1 = new PauseHandlingStream(printer, gCodeFileStream0); + sendProgressStream1 = new SendProgressStream(printer, gCodeFileStream0); } - firstStream = pauseHandlingStream1; + pauseHandlingStream2 = new PauseHandlingStream(printer, sendProgressStream1); + firstStream = pauseHandlingStream2; } else { @@ -2148,22 +2149,21 @@ namespace MatterHackers.MatterControl.PrinterCommunication firstStream = new NotPrintingStream(); } - queuedCommandStream2 = new QueuedCommandsStream(firstStream); - macroProcessingStream3 = new MacroProcessingStream(queuedCommandStream2, printer); - relativeToAbsoluteStream4 = new RelativeToAbsoluteStream(macroProcessingStream3); - printLevelingStream5 = new PrintLevelingStream(printer.Settings, relativeToAbsoluteStream4, true); - waitForTempStream6 = new WaitForTempStream(this, printLevelingStream5); - babyStepsStream7 = new BabyStepsStream(printer.Settings, waitForTempStream6, gcodeFilename == null ? 2000 : 1); + queuedCommandStream3 = new QueuedCommandsStream(firstStream); + macroProcessingStream4 = new MacroProcessingStream(queuedCommandStream3, printer); + relativeToAbsoluteStream5 = new RelativeToAbsoluteStream(macroProcessingStream4); + printLevelingStream6 = new PrintLevelingStream(printer.Settings, relativeToAbsoluteStream5, true); + waitForTempStream7 = new WaitForTempStream(this, printLevelingStream6); + babyStepsStream8 = new BabyStepsStream(printer.Settings, waitForTempStream7, gcodeFilename == null ? 2000 : 1); if (activePrintTask != null) { // make sure we are in the position we were when we stopped printing - babyStepsStream7.Offset = new Vector3(activePrintTask.PrintingOffsetX, activePrintTask.PrintingOffsetY, activePrintTask.PrintingOffsetZ); + babyStepsStream8.Offset = new Vector3(activePrintTask.PrintingOffsetX, activePrintTask.PrintingOffsetY, activePrintTask.PrintingOffsetZ); } - extrusionMultiplyerStream8 = new ExtrusionMultiplyerStream(babyStepsStream7); - feedrateMultiplyerStream9 = new FeedRateMultiplyerStream(extrusionMultiplyerStream8); - requestTemperaturesStream10 = new RequestTemperaturesStream(this, feedrateMultiplyerStream9); - sendProgressStream11 = new SendProgressStream(this, printer.Settings, requestTemperaturesStream10); - processWriteRegExStream12 = new ProcessWriteRegexStream(this.printer.Settings, sendProgressStream11, queuedCommandStream2); + extrusionMultiplyerStream9 = new ExtrusionMultiplyerStream(babyStepsStream8); + feedrateMultiplyerStream10 = new FeedRateMultiplyerStream(extrusionMultiplyerStream9); + requestTemperaturesStream11 = new RequestTemperaturesStream(this, feedrateMultiplyerStream10); + processWriteRegExStream12 = new ProcessWriteRegexStream(this.printer.Settings, requestTemperaturesStream11, queuedCommandStream3); totalGCodeStream = processWriteRegExStream12; // Force a reset of the printer checksum state (but allow it to be write regexed) @@ -2200,13 +2200,13 @@ namespace MatterHackers.MatterControl.PrinterCommunication // Only update the amount done if it is greater than what is recorded. // We don't want to mess up the resume before we actually resume it. if (activePrintTask != null - && babyStepsStream7 != null + && babyStepsStream8 != null && activePrintTask.PercentDone < currentDone) { activePrintTask.PercentDone = currentDone; - activePrintTask.PrintingOffsetX = (float)babyStepsStream7.Offset.X; - activePrintTask.PrintingOffsetY = (float)babyStepsStream7.Offset.Y; - activePrintTask.PrintingOffsetZ = (float)babyStepsStream7.Offset.Z; + activePrintTask.PrintingOffsetX = (float)babyStepsStream8.Offset.X; + activePrintTask.PrintingOffsetY = (float)babyStepsStream8.Offset.Y; + activePrintTask.PrintingOffsetZ = (float)babyStepsStream8.Offset.Z; activePrintTask?.Commit(); // Interval looks to be ~10ms @@ -2295,11 +2295,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication { DetailedPrintingState = DetailedPrintingState.HomingAxis; } - else if (waitForTempStream6?.HeatingBed ?? false) + else if (waitForTempStream7?.HeatingBed ?? false) { DetailedPrintingState = DetailedPrintingState.HeatingBed; } - else if (waitForTempStream6?.HeatingExtruder ?? false) + else if (waitForTempStream7?.HeatingExtruder ?? false) { DetailedPrintingState = DetailedPrintingState.HeatingExtruder; } @@ -2622,21 +2622,21 @@ namespace MatterHackers.MatterControl.PrinterCommunication public void MacroStart() { - queuedCommandStream2?.Reset(); - macroProcessingStream3.Reset(); + queuedCommandStream3?.Reset(); + macroProcessingStream4.Reset(); } public void MacroCancel() { - babyStepsStream7?.CancelMoves(); - waitForTempStream6?.Cancel(); - queuedCommandStream2?.Cancel(); - macroProcessingStream3?.Cancel(); + babyStepsStream8?.CancelMoves(); + waitForTempStream7?.Cancel(); + queuedCommandStream3?.Cancel(); + macroProcessingStream4?.Cancel(); } public void MacroContinue() { - macroProcessingStream3?.Continue(); + macroProcessingStream4?.Continue(); } public class ReadThread