Merge pull request #3138 from larsbrubaker/design_tools

Fixed bug with delayed heat turning off even after it has been set to on
This commit is contained in:
Lars Brubaker 2018-04-05 14:58:49 -07:00 committed by GitHub
commit 6b62a22b4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 107 deletions

View file

@ -196,10 +196,10 @@ namespace MatterHackers.MatterControl
{
UiThread.RunOnIdle(() =>
{
if(!string.IsNullOrEmpty(OemSettings.Instance.AffiliateCode)
if (!string.IsNullOrEmpty(OemSettings.Instance.AffiliateCode)
&& targetUri.Contains("matterhackers.com"))
{
if(targetUri.Contains("?"))
if (targetUri.Contains("?"))
{
targetUri += $"&aff={OemSettings.Instance.AffiliateCode}";
}
@ -241,7 +241,7 @@ namespace MatterHackers.MatterControl
internal void QueueForGeneration(Func<Task> func)
{
lock(thumbsLock)
lock (thumbsLock)
{
if (thumbnailGenerator == null)
{
@ -258,7 +258,7 @@ namespace MatterHackers.MatterControl
{
Thread.CurrentThread.Name = $"ThumbnailGeneration";
while(!this.ApplicationExiting)
while (!this.ApplicationExiting)
{
Thread.Sleep(100);
@ -298,8 +298,8 @@ namespace MatterHackers.MatterControl
thumbnailGenerator = null;
}
public static Func<PrinterInfo,string, Task<PrinterSettings>> GetPrinterProfileAsync;
public static Func<string, IProgress<ProgressStatus>,Task> SyncPrinterProfiles;
public static Func<PrinterInfo, string, Task<PrinterSettings>> GetPrinterProfileAsync;
public static Func<string, IProgress<ProgressStatus>, Task> SyncPrinterProfiles;
public static Func<Task<OemProfileDictionary>> GetPublicProfileList;
public static Func<string, Task<PrinterSettings>> DownloadPublicProfileAsync;
@ -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
@ -780,15 +757,11 @@ namespace MatterHackers.MatterControl
printerConnection.TurnOffBedAndExtruders(TurnOff.Now);
}
if(cancellationToken.IsCancellationRequested)
if (cancellationToken.IsCancellationRequested)
{
printerConnection.ContinuWaitingToTurnOffHeaters = false;
}
printerConnection.BedTemperatureSet.UnregisterEvent(heatChanged, ref unregisterEvent);
printerConnection.HotendTemperatureSet.UnregisterEvent(heatChanged, ref unregisterEvent);
printerConnection.CommunicationStateChanged.UnregisterEvent(stateChanged, ref unregisterEvent);
return Task.CompletedTask;
});
}
@ -816,12 +789,9 @@ namespace MatterHackers.MatterControl
{
// run the print leveling wizard if we need to for this printer
var printer = ApplicationController.Instance.ActivePrinters.Where(p => p.Connection == s).FirstOrDefault();
if (printer != null
&& (printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print)
|| printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled)))
if (printer != null)
{
PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();
if (levelingData?.HasBeenRunAndEnabled(printer) != true)
if (PrintLevelingData.NeedsToBeRun(printer))
{
UiThread.RunOnIdle(() => LevelWizardBase.ShowPrintLevelWizard(printer));
}
@ -1450,8 +1420,7 @@ namespace MatterHackers.MatterControl
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.print_leveling_required_to_print)
|| ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.print_leveling_enabled))
{
PrintLevelingData levelingData = ActiveSliceSettings.Instance.Helpers.GetPrintLevelingData();
if (levelingData?.HasBeenRunAndEnabled(printer) != true)
if (PrintLevelingData.NeedsToBeRun(printer))
{
LevelWizardBase.ShowPrintLevelWizard(printer);
return;

View file

@ -25,16 +25,32 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
}
public bool HasBeenRunAndEnabled(PrinterConfig printer)
public static bool NeedsToBeRun(PrinterConfig printer)
{
PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();
var required = printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print);
if (required && levelingData == null)
{
// need but don't have data
return true;
}
var enabled = ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.print_leveling_enabled);
// check if leveling is turned on
if(!ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.print_leveling_enabled))
if (required && !enabled)
{
// need but not turned on
return true;
}
if(!required && !enabled)
{
return false;
}
// check that there are no duplicate points
var positionCounts = from x in SampledPositions
var positionCounts = from x in levelingData.SampledPositions
group x by x into g
let count = g.Count()
orderby count descending
@ -44,14 +60,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
if(x.Count > 1)
{
return false;
return true;
}
}
// check that the solution last measured is the currently selected solution
if(printer.Settings.GetValue<LevelingSystem>(SettingsKey.print_leveling_solution) != LevelingSystem)
if(printer.Settings.GetValue<LevelingSystem>(SettingsKey.print_leveling_solution) != levelingData.LevelingSystem)
{
return false;
return true;
}
// check that the bed temperature at probe time was close enough to the current print bed temp
@ -60,47 +76,46 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
: 0;
// check that it is within 10 degrees
if(Math.Abs(reqiredLevlingTemp - BedTemperature) > 10)
if(Math.Abs(reqiredLevlingTemp - levelingData.BedTemperature) > 10)
{
return false;
return true;
}
// check that the number of poins sampled is correct for the solution
switch (LevelingSystem)
switch (levelingData.LevelingSystem)
{
case LevelingSystem.Probe3Points:
if (SampledPositions.Count != 3) // different criteria for what is not initialized
if (levelingData.SampledPositions.Count != 3) // different criteria for what is not initialized
{
return false;
return true;
}
break;
case LevelingSystem.Probe7PointRadial:
if (SampledPositions.Count != 7) // different criteria for what is not initialized
if (levelingData.SampledPositions.Count != 7) // different criteria for what is not initialized
{
return false;
return true;
}
break;
case LevelingSystem.Probe13PointRadial:
if (SampledPositions.Count != 13) // different criteria for what is not initialized
if (levelingData.SampledPositions.Count != 13) // different criteria for what is not initialized
{
return false;
return true;
}
break;
case LevelingSystem.Probe3x3Mesh:
if (SampledPositions.Count != 9) // different criteria for what is not initialized
if (levelingData.SampledPositions.Count != 9) // different criteria for what is not initialized
{
return false;
return true;
}
break;
case LevelingSystem.Probe5x5Mesh:
if (SampledPositions.Count != 25) // different criteria for what is not initialized
if (levelingData.SampledPositions.Count != 25) // different criteria for what is not initialized
{
return false;
return true;
}
break;
@ -108,7 +123,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
throw new NotImplementedException();
}
return true;
return false;
}
public bool SamplesAreSame(List<Vector3> sampledPositions)

View file

@ -90,7 +90,10 @@ 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
|| stringEvent.Data == SettingsKey.print_leveling_enabled
|| stringEvent.Data == SettingsKey.print_leveling_required_to_print))
{
SetButtonStates();
}
@ -107,59 +110,45 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
protected void SetButtonStates()
{
PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();
// If we don't have leveling data and we need it
bool showSetupButton = PrintLevelingData.NeedsToBeRun(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);
}