From 37e6f3bd446c672db2c41883a676222c98f890ba Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Tue, 5 May 2020 09:26:09 -0700 Subject: [PATCH] Put in per extruder fan controls --- .../Settings/PrinterSettings.cs | 1 + .../Settings/SettingsKey.cs | 1 + .../Settings/SliceSettingsFields.cs | 10 +++ .../SetupWizards/LoadFilamentWizard.cs | 2 +- .../PrinterCommunication/PrinterConnection.cs | 64 +++++++++++++++---- .../ControlWidgets/FanControlsRow.cs | 19 +++--- .../ControlWidgets/TemperatureControls.cs | 13 +++- StaticData/SliceSettings/Layouts.txt | 1 + Submodules/agg-sharp | 2 +- 9 files changed, 89 insertions(+), 24 deletions(-) diff --git a/MatterControl.Printing/Settings/PrinterSettings.cs b/MatterControl.Printing/Settings/PrinterSettings.cs index 60ae86dbe..52b3c7b7b 100644 --- a/MatterControl.Printing/Settings/PrinterSettings.cs +++ b/MatterControl.Printing/Settings/PrinterSettings.cs @@ -178,6 +178,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration SettingsKey.firmware_type, SettingsKey.has_c_axis, SettingsKey.has_fan, + SettingsKey.has_fan_per_extruder, SettingsKey.has_hardware_leveling, SettingsKey.has_heated_bed, SettingsKey.has_power_control, diff --git a/MatterControl.Printing/Settings/SettingsKey.cs b/MatterControl.Printing/Settings/SettingsKey.cs index 58ed4cae1..a1613d99e 100644 --- a/MatterControl.Printing/Settings/SettingsKey.cs +++ b/MatterControl.Printing/Settings/SettingsKey.cs @@ -111,6 +111,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public const string gcode_output_type = nameof(gcode_output_type); public const string has_c_axis = nameof(has_c_axis); public const string has_fan = nameof(has_fan); + public const string has_fan_per_extruder = nameof(has_fan_per_extruder); public const string has_hardware_leveling = nameof(has_hardware_leveling); public const string has_heated_bed = nameof(has_heated_bed); public const string has_power_control = nameof(has_power_control); diff --git a/MatterControl.Printing/Settings/SliceSettingsFields.cs b/MatterControl.Printing/Settings/SliceSettingsFields.cs index fb68dff93..75efbfdc0 100644 --- a/MatterControl.Printing/Settings/SliceSettingsFields.cs +++ b/MatterControl.Printing/Settings/SliceSettingsFields.cs @@ -1142,6 +1142,16 @@ namespace MatterHackers.MatterControl.SlicerConfiguration ReloadUiWhenChanged = true }, new SliceSettingData() + { + SlicerConfigName = SettingsKey.has_fan_per_extruder, + PresentationName = "Each Extruder Has Fan".Localize(), + HelpText = "Each extruder has a separate part cooling fan that is controlled independently.".Localize(), + DataEditType = DataEditTypes.CHECK_BOX, + ShowIfSet = "!sla_printer&has_fan&extruder_count>1", + DefaultValue = "0", + ReloadUiWhenChanged = true + }, + new SliceSettingData() { SlicerConfigName = SettingsKey.enable_fan, PresentationName = "Enable Fan".Localize(), diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/LoadFilamentWizard.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/LoadFilamentWizard.cs index f3481e62f..b11f8f673 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/LoadFilamentWizard.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/LoadFilamentWizard.cs @@ -193,7 +193,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling page.ContentRow.AddChild(markdownWidget); // turn off the fan - printer.Connection.FanSpeed0To255 = 0; + printer.Connection.SetFanSpeed0To255(extruderIndex, 0); // Allow extrusion at any temperature. S0 only works on Marlin S1 works on repetier and marlin printer.Connection.QueueLine("M302 S1"); diff --git a/MatterControlLib/PrinterCommunication/PrinterConnection.cs b/MatterControlLib/PrinterCommunication/PrinterConnection.cs index d1db8b3b1..a7dd1579e 100644 --- a/MatterControlLib/PrinterCommunication/PrinterConnection.cs +++ b/MatterControlLib/PrinterCommunication/PrinterConnection.cs @@ -220,7 +220,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication private double currentSdBytes = 0; - private double fanSpeed; + private double[] fanSpeed = new double[MaxExtruders]; private int currentLineIndexToSend = 0; @@ -676,16 +676,34 @@ namespace MatterHackers.MatterControl.PrinterCommunication public bool Disconnecting => CommunicationState == CommunicationStates.Disconnecting; - public double FanSpeed0To255 + public double GetFanSpeed0To255(int fanIndex) { - get => fanSpeed; - set + if (fanIndex >= ExtruderCount) { - fanSpeed = Math.Max(0, Math.Min(255, value)); - OnFanSpeedSet(null); - if (this.IsConnected) + fanIndex = 0; + } + + return fanSpeed[fanIndex]; + } + + public void SetFanSpeed0To255(int fanIndex, double value) + { + if (fanIndex >= ExtruderCount) + { + fanIndex = 0; + } + + fanSpeed[fanIndex] = Math.Max(0, Math.Min(255, value)); + OnFanSpeedSet(null); + if (this.IsConnected) + { + if (Printer.Settings.GetValue(SettingsKey.has_fan_per_extruder)) { - QueueLine("M106 S{0}".FormatWith((int)(fanSpeed + .5))); + QueueLine("M106 P{0} S{1}".FormatWith(fanIndex, (int)(fanSpeed[fanIndex] + .5))); + } + else + { + QueueLine("M106 S{0}".FormatWith((int)(fanSpeed[fanIndex] + .5))); } } } @@ -1265,7 +1283,7 @@ Make sure that your printer is turned on. Some printers will appear to be connec forceImmediateWrites = true; ReleaseMotors(); TurnOffBedAndExtruders(TurnOff.Now); - FanSpeed0To255 = 0; + forceImmediateWrites = false; CommunicationState = CommunicationStates.Disconnecting; @@ -1282,7 +1300,6 @@ Make sure that your printer is turned on. Some printers will appear to be connec { // Need to reset UI - even if manual disconnect TurnOffBedAndExtruders(TurnOff.Now); - FanSpeed0To255 = 0; } CommunicationState = CommunicationStates.Disconnected; @@ -1312,12 +1329,14 @@ Make sure that your printer is turned on. Some printers will appear to be connec public void FanOffWasWritenToPrinter(string line) { - fanSpeed = 0; + fanSpeed[0] = 0; OnFanSpeedSet(null); } public void FanSpeedWasWritenToPrinter(string line) { + var fanIndex = 0.0; + GCodeFile.GetFirstNumberAfter("P", "line", ref fanIndex); string[] splitOnS = line.Split('S'); if (splitOnS.Length != 2) { @@ -1331,9 +1350,9 @@ Make sure that your printer is turned on. Some printers will appear to be connec try { int fanSpeedBeingSet = int.Parse(fanSpeedString); - if (FanSpeed0To255 != fanSpeedBeingSet) + if (GetFanSpeed0To255((int)fanIndex) != fanSpeedBeingSet) { - fanSpeed = fanSpeedBeingSet; + SetFanSpeed0To255((int)fanIndex, fanSpeedBeingSet); OnFanSpeedSet(null); } } @@ -2646,6 +2665,7 @@ Make sure that your printer is turned on. Some printers will appear to be connec CommunicationState = CommunicationStates.Connected; // never leave the extruder and the bed hot ReleaseMotors(); + TurnOffPartCoolingFan(); TurnOffBedAndExtruders(TurnOff.AfterDelay); this.PrintWasCanceled = false; // and finally notify anyone that wants to know @@ -2664,6 +2684,7 @@ Make sure that your printer is turned on. Some printers will appear to be connec ReleaseMotors(); if (SecondsPrinted < GCodeMemoryFile.LeaveHeatersOnTime) { + TurnOffPartCoolingFan(); // The user may still be sitting at the machine, leave it heated for a period of time TurnOffBedAndExtruders(TurnOff.AfterDelay); } @@ -2751,9 +2772,26 @@ Make sure that your printer is turned on. Some printers will appear to be connec public PrintTask ActivePrintTask { get; set; } + public void TurnOffPartCoolingFan() + { + // turn off all the part cooling fans + if (Printer.Settings.GetValue(SettingsKey.has_fan_per_extruder)) + { + for (int i = 0; i < this.ExtruderCount; i++) + { + SetFanSpeed0To255(i, 0); + } + } + else + { + SetFanSpeed0To255(0, 0); + } + } public void TurnOffBedAndExtruders(TurnOff turnOffTime) { + TurnOffPartCoolingFan(); + if (turnOffTime == TurnOff.Now) { for (int i = 0; i < this.ExtruderCount; i++) diff --git a/MatterControlLib/PrinterControls/ControlWidgets/FanControlsRow.cs b/MatterControlLib/PrinterControls/ControlWidgets/FanControlsRow.cs index 038b51b5f..66b4b21fe 100644 --- a/MatterControlLib/PrinterControls/ControlWidgets/FanControlsRow.cs +++ b/MatterControlLib/PrinterControls/ControlWidgets/FanControlsRow.cs @@ -42,12 +42,15 @@ namespace MatterHackers.MatterControl.PrinterControls private RoundedToggleSwitch toggleSwitch; private PrinterConfig printer; + private int fanIndex; - public FanControlsRow(PrinterConfig printer, ThemeConfig theme) - : base ("Part Cooling Fan".Localize(), null, theme) + public FanControlsRow(int fanIndex, string fanName, PrinterConfig printer, ThemeConfig theme) + : base (fanName, null, theme) { this.printer = printer; + this.fanIndex = fanIndex; + var timeSinceLastManualSend = new Stopwatch(); var container = new FlowLayoutWidget(); @@ -56,7 +59,7 @@ namespace MatterHackers.MatterControl.PrinterControls fanSpeedDisplay = new MHNumberEdit(0, theme, minValue: 0, maxValue: 100, pixelWidth: 30) { - Value = printer.Connection.FanSpeed0To255 * 100 / 255, + Value = printer.Connection.GetFanSpeed0To255(fanIndex) * 100 / 255, VAnchor = VAnchor.Center | VAnchor.Fit, Margin = new BorderDouble(right: 2), }; @@ -67,7 +70,7 @@ namespace MatterHackers.MatterControl.PrinterControls || timeSinceLastManualSend.ElapsedMilliseconds > 500) { timeSinceLastManualSend.Restart(); - printer.Connection.FanSpeed0To255 = (int)(fanSpeedDisplay.Value * 255 / 100 + .5); + printer.Connection.SetFanSpeed0To255(fanIndex, (int)(fanSpeedDisplay.Value * 255 / 100 + .5)); } }; container.AddChild(fanSpeedDisplay); @@ -93,11 +96,11 @@ namespace MatterHackers.MatterControl.PrinterControls timeSinceLastManualSend.Restart(); if (toggleSwitch.Checked) { - printer.Connection.FanSpeed0To255 = 255; + printer.Connection.SetFanSpeed0To255(fanIndex, 255); } else { - printer.Connection.FanSpeed0To255 = 0; + printer.Connection.SetFanSpeed0To255(fanIndex, 0); } } }; @@ -118,7 +121,7 @@ namespace MatterHackers.MatterControl.PrinterControls private void Connection_FanSpeedSet(object s, EventArgs e) { - if ((int)printer.Connection.FanSpeed0To255 > 0) + if ((int)printer.Connection.GetFanSpeed0To255(fanIndex) > 0) { toggleSwitch.Checked = true; } @@ -127,7 +130,7 @@ namespace MatterHackers.MatterControl.PrinterControls toggleSwitch.Checked = false; } - fanSpeedDisplay.Value = printer.Connection.FanSpeed0To255 * 100 / 255; + fanSpeedDisplay.Value = printer.Connection.GetFanSpeed0To255(fanIndex) * 100 / 255; } } } \ No newline at end of file diff --git a/MatterControlLib/PrinterControls/ControlWidgets/TemperatureControls.cs b/MatterControlLib/PrinterControls/ControlWidgets/TemperatureControls.cs index c0e8185e2..0560cb923 100644 --- a/MatterControlLib/PrinterControls/ControlWidgets/TemperatureControls.cs +++ b/MatterControlLib/PrinterControls/ControlWidgets/TemperatureControls.cs @@ -103,6 +103,7 @@ namespace MatterHackers.MatterControl.PrinterControls { printer.Connection.SetTargetHotendTemperature(extruderIndex, printer.Settings.Helpers.ExtruderTargetTemperature(extruderIndex)); } + printer.Connection.TurnOffBedAndExtruders(TurnOff.AfterDelay); }; @@ -116,7 +117,17 @@ namespace MatterHackers.MatterControl.PrinterControls printer.Connection.TurnOffBedAndExtruders(TurnOff.Now); }; - this.AddChild(new FanControlsRow(printer, theme)); + if (printer.Settings.GetValue(SettingsKey.has_fan_per_extruder)) + { + for (int i = 0; i < printer.Settings.GetValue(SettingsKey.extruder_count); i++) + { + this.AddChild(new FanControlsRow(i, $"Part Cooling Fan {i}".Localize(), printer, theme)); + } + } + else // just add one + { + this.AddChild(new FanControlsRow(0, "Part Cooling Fan".Localize(), printer, theme)); + } // Register listeners printer.Connection.CommunicationStateChanged += Printer_StatusChanged; diff --git a/StaticData/SliceSettings/Layouts.txt b/StaticData/SliceSettings/Layouts.txt index 40446d325..5345b7a77 100644 --- a/StaticData/SliceSettings/Layouts.txt +++ b/StaticData/SliceSettings/Layouts.txt @@ -199,6 +199,7 @@ Printer Hardware firmware_type has_fan + has_fan_per_extruder has_hardware_leveling has_heated_bed has_sd_card_reader diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 9371fc13d..a8b5a00f8 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 9371fc13d7e56ded89f67453578996a2dd79936d +Subproject commit a8b5a00f82ce5f3718f630d6648a5f99fd0c1aa1