Put in per extruder fan controls

This commit is contained in:
LarsBrubaker 2020-05-05 09:26:09 -07:00
parent 1752aa8473
commit 37e6f3bd44
9 changed files with 89 additions and 24 deletions

View file

@ -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,

View file

@ -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);

View file

@ -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(),

View file

@ -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");

View file

@ -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<bool>(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<bool>(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++)

View file

@ -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;
}
}
}

View file

@ -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<bool>(SettingsKey.has_fan_per_extruder))
{
for (int i = 0; i < printer.Settings.GetValue<int>(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;

View file

@ -199,6 +199,7 @@ Printer
Hardware
firmware_type
has_fan
has_fan_per_extruder
has_hardware_leveling
has_heated_bed
has_sd_card_reader

@ -1 +1 @@
Subproject commit 9371fc13d7e56ded89f67453578996a2dd79936d
Subproject commit a8b5a00f82ce5f3718f630d6648a5f99fd0c1aa1