Fixed bug with delayed heat turning off even after it has been set to on

Made the print setup button have much better state logic
Move all turn off heat logic to printer connection
This commit is contained in:
Lars Brubaker 2018-04-05 12:44:51 -07:00
parent dd6294e32d
commit 2c5208a845
3 changed files with 52 additions and 71 deletions

View file

@ -735,34 +735,11 @@ namespace MatterHackers.MatterControl
PrinterConnection.HeatTurningOffSoon.RegisterEvent((s, e) =>
{
var printerConnection = ApplicationController.Instance.ActivePrinter.Connection;
bool anyHeatersAreOn = false;
for (int i=0; i<printerConnection.ExtruderCount; i++)
{
anyHeatersAreOn |= printerConnection.GetTargetHotendTemperature(i) != 0;
}
anyHeatersAreOn |= printerConnection.TargetBedTemperature != 0;
if (anyHeatersAreOn)
if (printerConnection.AnyHeatIsOn)
{
Tasks.Execute("Disable Heaters".Localize(), (reporter, cancellationToken) =>
{
EventHandler heatChanged = (s2, e2) =>
{
printerConnection.ContinuWaitingToTurnOffHeaters = false;
};
EventHandler stateChanged = (s2, e2) =>
{
if (printerConnection.CommunicationState == CommunicationStates.PreparingToPrint
|| printerConnection.PrinterIsPrinting)
{
printerConnection.ContinuWaitingToTurnOffHeaters = false;
};
};
printerConnection.BedTemperatureSet.RegisterEvent(heatChanged, ref unregisterEvent);
printerConnection.HotendTemperatureSet.RegisterEvent(heatChanged, ref unregisterEvent);
printerConnection.CommunicationStateChanged.RegisterEvent(stateChanged, ref unregisterEvent);
var progressStatus = new ProgressStatus();
while (printerConnection.SecondsUntilTurnOffHeaters > 0
@ -785,10 +762,6 @@ namespace MatterHackers.MatterControl
printerConnection.ContinuWaitingToTurnOffHeaters = false;
}
printerConnection.BedTemperatureSet.UnregisterEvent(heatChanged, ref unregisterEvent);
printerConnection.HotendTemperatureSet.UnregisterEvent(heatChanged, ref unregisterEvent);
printerConnection.CommunicationStateChanged.UnregisterEvent(stateChanged, ref unregisterEvent);
return Task.CompletedTask;
});
}

View file

@ -90,7 +90,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
if (e is StringEventArgs stringEvent
&& (stringEvent.Data == SettingsKey.z_probe_z_offset
|| stringEvent.Data == SettingsKey.print_leveling_data
|| stringEvent.Data == SettingsKey.print_leveling_solution))
|| stringEvent.Data == SettingsKey.print_leveling_solution
|| stringEvent.Data == SettingsKey.bed_temperature))
{
SetButtonStates();
}
@ -109,57 +110,47 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();
// If we don't have leveling data and we need it
bool showSetupButton = printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print) && levelingData != null;
// or we have leveling data but it needs to be recalculated
showSetupButton |= levelingData != null && !levelingData.HasBeenRunAndEnabled(printer);
switch (printer.Connection.CommunicationState)
{
case CommunicationStates.FinishedPrint:
case CommunicationStates.Connected:
if (levelingData != null && printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print)
&& !levelingData.HasBeenRunAndEnabled(printer))
if(showSetupButton)
{
SetChildVisible(finishSetupButton, true);
finishSetupButton.Visible = true;
finishSetupButton.Enabled = true;
startPrintButton.Visible = false;
}
else
{
SetChildVisible(startPrintButton, true);
startPrintButton.Visible = true;
startPrintButton.Enabled = true;
finishSetupButton.Visible = false;
}
break;
case CommunicationStates.PrintingFromSd:
case CommunicationStates.Printing:
case CommunicationStates.Paused:
break;
case CommunicationStates.FinishedPrint:
SetChildVisible(startPrintButton, true);
break;
default:
if (levelingData != null && printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print)
&& !levelingData.HasBeenRunAndEnabled(printer))
if (showSetupButton)
{
SetChildVisible(finishSetupButton, false);
finishSetupButton.Visible = true;
finishSetupButton.Enabled = false;
startPrintButton.Visible = false;
}
else
{
SetChildVisible(startPrintButton, false);
startPrintButton.Visible = true;
startPrintButton.Enabled = false;
finishSetupButton.Visible = false;
}
break;
}
}
private void SetChildVisible(GuiWidget visibleChild, bool enabled)
{
foreach (var child in Children)
{
if (child == visibleChild)
{
child.Visible = true;
child.Enabled = enabled;
}
else
{
child.Visible = false;
}
}
}
}
}

View file

@ -744,6 +744,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
get => _targetBedTemperature;
set
{
ContinuWaitingToTurnOffHeaters = false;
if (_targetBedTemperature != value)
{
_targetBedTemperature = value;
@ -1845,6 +1846,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
if (targetHotendTemperature[hotendIndex0Based] != temperature
|| forceSend)
{
ContinuWaitingToTurnOffHeaters = false;
targetHotendTemperature[hotendIndex0Based] = temperature;
OnHotendTemperatureSet(new TemperatureEventArgs(hotendIndex0Based, temperature));
if (this.IsConnected)
@ -2421,6 +2423,25 @@ namespace MatterHackers.MatterControl.PrinterCommunication
public int TurnOffHeatDelay { get; set; } = 60;
public bool AnyHeatIsOn
{
get
{
bool anyHeatIsOn = false;
// check if any temps are set
for (int i = 0; i < this.ExtruderCount; i++)
{
if (GetTargetHotendTemperature(i) > 0)
{
anyHeatIsOn = true;
break;
}
}
anyHeatIsOn |= TargetBedTemperature > 0;
return anyHeatIsOn;
}
}
public void TurnOffBedAndExtruders(TurnOff turnOffTime)
{
if (turnOffTime == TurnOff.Now)
@ -2446,21 +2467,17 @@ namespace MatterHackers.MatterControl.PrinterCommunication
while (TimeHaveBeenWaitingToTurnOffHeaters.Elapsed.TotalSeconds < TurnOffHeatDelay
&& ContinuWaitingToTurnOffHeaters)
{
bool anyHeatIsOn = false;
// check if any temps are set
for (int i = 0; i < this.ExtruderCount; i++)
{
if(GetTargetHotendTemperature(i) > 0)
{
anyHeatIsOn = true;
break;
}
}
anyHeatIsOn |= TargetBedTemperature > 0;
if(!anyHeatIsOn)
if (CommunicationState == CommunicationStates.PreparingToPrint
|| PrinterIsPrinting)
{
ContinuWaitingToTurnOffHeaters = false;
}
if (!AnyHeatIsOn)
{
ContinuWaitingToTurnOffHeaters = false;
}
SecondsUntilTurnOffHeaters = ContinuWaitingToTurnOffHeaters ? Math.Max(0, TurnOffHeatDelay - TimeHaveBeenWaitingToTurnOffHeaters.Elapsed.TotalSeconds) : 0;
Thread.Sleep(100);
}