Make automattic heat shutoff have a two minute delay
This commit is contained in:
Lars Brubaker 2018-01-30 14:48:53 -08:00
parent e7f16bc5b8
commit ee49004e43
4 changed files with 85 additions and 19 deletions

View file

@ -615,6 +615,63 @@ namespace MatterHackers.MatterControl
}
}, ref unregisterEvents);
PrinterConnection.DoDelayedTurnOffHeat.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)
{
bool continueWaiting = true;
Tasks.Execute((reporter, cancellationToken) =>
{
EventHandler cancel = (s2, e2) => { continueWaiting = false; };
printerConnection.BedTemperatureSet.RegisterEvent(cancel, ref unregisterEvent);
printerConnection.HotendTemperatureSet.RegisterEvent(cancel, ref unregisterEvent);
EventHandler stateChanged = (s2, e2) =>
{
if (printerConnection.CommunicationState == CommunicationStates.PreparingToPrint)
{
continueWaiting = false;
};
};
printerConnection.CommunicationStateChanged.RegisterEvent(stateChanged, ref unregisterEvent);
Stopwatch time = Stopwatch.StartNew();
var progressStatus = new ProgressStatus();
int secondsToWait = 60;
while (time.Elapsed.TotalSeconds < secondsToWait
&& !cancellationToken.IsCancellationRequested
&& continueWaiting)
{
reporter.Report(progressStatus);
progressStatus.Status = "Turn Off Heat in".Localize() + " " + (60 - time.Elapsed.TotalSeconds).ToString("0");
Thread.Sleep(100);
}
if (!cancellationToken.IsCancellationRequested
&& continueWaiting)
{
printerConnection.TurnOffBedAndExtruders(true);
}
printerConnection.BedTemperatureSet.UnregisterEvent(cancel, ref unregisterEvent);
printerConnection.HotendTemperatureSet.UnregisterEvent(cancel, ref unregisterEvent);
printerConnection.CommunicationStateChanged.UnregisterEvent(stateChanged, ref unregisterEvent);
return Task.CompletedTask;
});
}
}, ref unregisterEvents);
PrinterConnection.ErrorReported.RegisterEvent((s, e) =>
{
var foundStringEventArgs = e as FoundStringEventArgs;

View file

@ -35,7 +35,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public class Translate : Object3D
{
public Translate()
{ }
{
}
public Translate(IObject3D item, double x = 0, double y = 0, double z = 0)
: this(item, new Vector3(x, y, z))

View file

@ -75,6 +75,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
/// </summary>
public class PrinterConnection
{
public static RootedObjectEventHandler DoDelayedTurnOffHeat = new RootedObjectEventHandler();
public static RootedObjectEventHandler ErrorReported = new RootedObjectEventHandler();
public static RootedObjectEventHandler AnyCommunicationStateChanged = new RootedObjectEventHandler();
@ -210,7 +211,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
private bool stopTryingToConnect = false;
private double targetBedTemperature;
private double _targetBedTemperature;
private double[] targetHotendTemperature = new double[MAX_EXTRUDERS];
@ -421,7 +422,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
case CommunicationStates.Disconnected:
if (communicationPossible)
{
TurnOffBedAndExtruders();
TurnOffBedAndExtruders(true);
for (int hotendIndex = 0; hotendIndex < MAX_EXTRUDERS; hotendIndex++)
{
actualHotendTemperature[hotendIndex] = 0;
@ -765,17 +766,17 @@ namespace MatterHackers.MatterControl.PrinterCommunication
{
get
{
return targetBedTemperature;
return _targetBedTemperature;
}
set
{
if (targetBedTemperature != value)
if (_targetBedTemperature != value)
{
targetBedTemperature = value;
_targetBedTemperature = value;
OnBedTemperatureSet(new TemperatureEventArgs(0, TargetBedTemperature));
if (PrinterIsConnected)
{
QueueLine("M140 S{0}".FormatWith(targetBedTemperature));
QueueLine("M140 S{0}".FormatWith(_targetBedTemperature));
}
}
}
@ -835,7 +836,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
if (TargetBedTemperature != tempBeingSet)
{
// we set the private variable so that we don't get the callbacks called and get in a loop of setting the temp
targetBedTemperature = tempBeingSet;
_targetBedTemperature = tempBeingSet;
OnBedTemperatureSet(new TemperatureEventArgs(0, TargetBedTemperature));
}
}
@ -970,7 +971,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
CreateStreamProcessors(null, false);
TurnOffBedAndExtruders(); // make sure our ui and the printer agree and that the printer is in a known state (not heating).
TurnOffBedAndExtruders(true); // make sure our ui and the printer agree and that the printer is in a known state (not heating).
haveReportedError = false;
QueueLine(this.ConnectGCode);
@ -1056,7 +1057,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
// the motors and heaters (a good idea and something for the future).
forceImmediateWrites = true;
ReleaseMotors();
TurnOffBedAndExtruders();
TurnOffBedAndExtruders(true);
FanSpeed0To255 = 0;
forceImmediateWrites = false;
@ -1073,7 +1074,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
else
{
//Need to reset UI - even if manual disconnect
TurnOffBedAndExtruders();
TurnOffBedAndExtruders(true);
FanSpeed0To255 = 0;
}
OnEnabledChanged(null);
@ -2086,7 +2087,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
this.PrintJobName = null;
// never leave the extruder and the bed hot
TurnOffBedAndExtruders();
TurnOffBedAndExtruders(false);
ReleaseMotors();
}
@ -2422,7 +2423,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
CommunicationState = CommunicationStates.Connected;
// never leave the extruder and the bed hot
ReleaseMotors();
TurnOffBedAndExtruders();
TurnOffBedAndExtruders(false);
this.PrintWasCanceled = false;
}
else if (communicationState == CommunicationStates.Printing)// we finished printing normally
@ -2436,19 +2437,26 @@ namespace MatterHackers.MatterControl.PrinterCommunication
// never leave the extruder and the bed hot
ReleaseMotors();
TurnOffBedAndExtruders();
TurnOffBedAndExtruders(false);
}
}
}
}
private void TurnOffBedAndExtruders()
public void TurnOffBedAndExtruders(bool now)
{
for (int i = 0; i < this.ExtruderCount; i++)
if (now)
{
SetTargetHotendTemperature(i, 0, true);
for (int i = 0; i < this.ExtruderCount; i++)
{
SetTargetHotendTemperature(i, 0, true);
}
TargetBedTemperature = 0;
}
else
{
DoDelayedTurnOffHeat.CallEvents(this, null);
}
TargetBedTemperature = 0;
}
// this is to make it misbehave, chaos monkey, bad checksum

@ -1 +1 @@
Subproject commit bf84635332c1fa7aaad095bc3ce3be7f5f866793
Subproject commit 695626d55e91b06a5bccb6098bca1cafe9201568