diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index 9cf4719a4..be91dcdbc 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -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 { - 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; }); } diff --git a/PartPreviewWindow/View3D/PrinterBar/PauseResumeButton.cs b/PartPreviewWindow/View3D/PrinterBar/PauseResumeButton.cs index 1e10e1d53..65d4cd35c 100644 --- a/PartPreviewWindow/View3D/PrinterBar/PauseResumeButton.cs +++ b/PartPreviewWindow/View3D/PrinterBar/PauseResumeButton.cs @@ -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(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(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(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; - } - } - } } } \ No newline at end of file diff --git a/PrinterCommunication/PrinterConnection.cs b/PrinterCommunication/PrinterConnection.cs index 08b0de272..0173f9473 100644 --- a/PrinterCommunication/PrinterConnection.cs +++ b/PrinterCommunication/PrinterConnection.cs @@ -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); }