Wait for Save to conclude before exiting

Wait for start of G34 before looking for 'ok'
This commit is contained in:
Lars Brubaker 2022-04-04 16:26:28 -07:00
parent 5b438d20c7
commit 6e12c4c4f3
10 changed files with 137 additions and 123 deletions

View file

@ -729,7 +729,7 @@ namespace MatterHackers.MatterControl
} }
}); });
this.EditContext?.Save(this.Scene); await this.EditContext?.Save(this.Scene);
} }
} }

View file

@ -120,7 +120,7 @@ namespace MatterHackers.MatterControl
} }
} }
public void Save(IObject3D scene) public async Task Save(IObject3D scene)
{ {
if (!this.FreezeGCode) if (!this.FreezeGCode)
{ {
@ -134,7 +134,7 @@ namespace MatterHackers.MatterControl
using (new SelectionMaintainer(interactiveScene)) using (new SelectionMaintainer(interactiveScene))
{ {
// Call save on the provider // Call save on the provider
this.ContentStore?.Save(this.SourceItem, scene); await this.ContentStore?.Save(this.SourceItem, scene);
} }
interactiveScene.MarkSavePoint(); interactiveScene.MarkSavePoint();
@ -142,7 +142,7 @@ namespace MatterHackers.MatterControl
else else
{ {
// Call save on the provider // Call save on the provider
this.ContentStore?.Save(this.SourceItem, scene); await this.ContentStore?.Save(this.SourceItem, scene);
} }
} }
} }

View file

@ -29,8 +29,6 @@ either expressed or implied, of the FreeBSD Project.
using MatterHackers.Agg.UI; using MatterHackers.Agg.UI;
using MatterHackers.Localizations; using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration;
using System; using System;
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
@ -38,6 +36,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public class AligningZAxisPageInstructions : WizardPage public class AligningZAxisPageInstructions : WizardPage
{ {
private bool calibrationComplete; private bool calibrationComplete;
private bool g32HasBeenSent;
public AligningZAxisPageInstructions(ISetupWizard setupWizard, string instructionsText) public AligningZAxisPageInstructions(ISetupWizard setupWizard, string instructionsText)
: base(setupWizard, "Aligning Z Axis".Localize(), instructionsText) : base(setupWizard, "Aligning Z Axis".Localize(), instructionsText)
@ -50,12 +49,15 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
// Unregister listeners // Unregister listeners
printer.Connection.LineReceived -= Connection_LineRecieved; printer.Connection.LineReceived -= Connection_LineRecieved;
printer.Connection.LineSent -= Connection_LineSent;
base.OnClosed(e); base.OnClosed(e);
} }
public override void OnLoad(EventArgs args) public override void OnLoad(EventArgs args)
{ {
printer.Connection.LineSent += Connection_LineSent;
// Send the G34 Z Stepper Auto Align (https://reprap.org/wiki/G-code#G34:_Z_Stepper_Auto-Align) // Send the G34 Z Stepper Auto Align (https://reprap.org/wiki/G-code#G34:_Z_Stepper_Auto-Align)
// 7 iterations .1 accuracy for early exit // 7 iterations .1 accuracy for early exit
printer.Connection.QueueLine("G34 I7 T.1"); printer.Connection.QueueLine("G34 I7 T.1");
@ -79,7 +81,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private void Connection_LineRecieved(object sender, string reciviedString) private void Connection_LineRecieved(object sender, string reciviedString)
{ {
if (reciviedString == "ok") if (g32HasBeenSent && reciviedString == "ok")
{ {
calibrationComplete = true; calibrationComplete = true;
printer.Connection.LineReceived -= Connection_LineRecieved; printer.Connection.LineReceived -= Connection_LineRecieved;
@ -91,5 +93,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
UiThread.RunOnIdle(() => NextButton.InvokeClick()); UiThread.RunOnIdle(() => NextButton.InvokeClick());
} }
} }
private void Connection_LineSent(object sender, string sentString)
{
if (sentString.Contains("G34"))
{
g32HasBeenSent = true;
printer.Connection.LineSent -= Connection_LineSent;
}
}
} }
} }

View file

@ -27,131 +27,127 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project. either expressed or implied, of the FreeBSD Project.
*/ */
using System;
using System.Collections.Generic;
using System.Linq;
using MatterControl.Printing;
using MatterHackers.Agg.UI; using MatterHackers.Agg.UI;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.VectorMath; using MatterHackers.VectorMath;
using System;
using System.Collections.Generic;
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{ {
public class ConductiveProbeFeedback : WizardPage public class ConductiveProbeFeedback : WizardPage
{ {
private readonly List<PrintLevelingWizard.ProbePosition> probePositions; private readonly List<PrintLevelingWizard.ProbePosition> probePositions;
private Vector3 nozzleCurrentPosition; private Vector3 feedRates;
private double moveDelta = .5;
private Vector3 nozzleCurrentPosition;
public ConductiveProbeFeedback(ISetupWizard setupWizard, Vector3 nozzleStartPosition, string headerText, string details, List<PrintLevelingWizard.ProbePosition> probePositions) private State state = State.WaitingForEndstopStatusStart;
: base(setupWizard, headerText, details)
{
this.nozzleCurrentPosition = nozzleStartPosition;
this.probePositions = probePositions;
var spacer = new GuiWidget(15, 15); public ConductiveProbeFeedback(ISetupWizard setupWizard, Vector3 nozzleStartPosition, string headerText, string details, List<PrintLevelingWizard.ProbePosition> probePositions)
contentRow.AddChild(spacer); : base(setupWizard, headerText, details)
{
this.nozzleCurrentPosition = nozzleStartPosition;
this.probePositions = probePositions;
feedRates = printer.Settings.Helpers.ManualMovementSpeeds(); var spacer = new GuiWidget(15, 15);
} contentRow.AddChild(spacer);
double moveDelta = .5; feedRates = printer.Settings.Helpers.ManualMovementSpeeds();
}
enum State private enum State
{ {
WaitingForEndstopStatusStart, WaitingForEndstopStatusStart,
WaitingForEndstopStatusOk, WaitingForEndstopStatusOk,
} }
State state = State.WaitingForEndstopStatusStart; public bool MovedBelowMinZ { get; private set; }
private Vector3 feedRates;
public bool MovedBelowMinZ { get; private set; } public override void OnClosed(EventArgs e)
{
printer.Connection.LineReceived -= PrinterLineRecieved;
base.OnClosed(e);
}
private void PrinterLineRecieved(object sender, string line) public override void OnLoad(EventArgs args)
{ {
// looking for 'conductive: TRIGGERED' in an M119 command // always make sure we don't have print leveling turned on
if (line != null) printer.Connection.AllowLeveling = false;
{
switch (state)
{
case State.WaitingForEndstopStatusStart:
if (line.StartsWith("conductive:"))
{
if (line.Contains("TRIGGERED"))
{
if (moveDelta > .02)
{
nozzleCurrentPosition.Z += moveDelta * 3;
moveDelta *= .5;
state = State.WaitingForEndstopStatusOk;
}
else
{
probePositions[0].Position = nozzleCurrentPosition;
// move on to the next page of the wizard NextButton.Enabled = false;
UiThread.RunOnIdle(() => NextButton.InvokeClick());
}
}
else // did not find endstop yet
{
nozzleCurrentPosition.Z -= moveDelta;
state = State.WaitingForEndstopStatusOk;
}
}
break;
case State.WaitingForEndstopStatusOk: // do a last minute check that the printer is ready to do this action
// found the ok of the M119 command if (printer.Connection.IsConnected
// move down more && !(printer.Connection.Printing
if (printer.Connection.CurrentDestination.Z < printer.Settings.GetValue<double>(SettingsKey.conductive_probe_min_z)) || printer.Connection.Paused))
{ {
// we have gone down too far printer.Connection.LineReceived += PrinterLineRecieved;
// abort with error printer.Connection.MoveAbsolute(nozzleCurrentPosition, feedRates.X);
this.MovedBelowMinZ = true; printer.Connection.QueueLine("G4 P1");
// move on to the next page of the wizard printer.Connection.QueueLine("M119");
UiThread.RunOnIdle(() => NextButton.InvokeClick()); }
}
else if (line.StartsWith("ok"))
{
state = State.WaitingForEndstopStatusStart;
// send the next set of commands
printer.Connection.MoveAbsolute(nozzleCurrentPosition, feedRates.X);
printer.Connection.QueueLine("G4 P1");
printer.Connection.QueueLine("M119");
}
break;
}
}
}
public override void OnLoad(EventArgs args) base.OnLoad(args);
{ }
// always make sure we don't have print leveling turned on
printer.Connection.AllowLeveling = false;
NextButton.Enabled = false; private void PrinterLineRecieved(object sender, string line)
{
// looking for 'conductive: TRIGGERED' in an M119 command
if (line != null)
{
switch (state)
{
case State.WaitingForEndstopStatusStart:
if (line.StartsWith("conductive:"))
{
if (line.Contains("TRIGGERED"))
{
if (moveDelta > .02)
{
nozzleCurrentPosition.Z += moveDelta * 3;
moveDelta *= .5;
state = State.WaitingForEndstopStatusOk;
}
else
{
probePositions[0].Position = nozzleCurrentPosition;
// do a last minute check that the printer is ready to do this action // move on to the next page of the wizard
if (printer.Connection.IsConnected UiThread.RunOnIdle(() => NextButton.InvokeClick());
&& !(printer.Connection.Printing }
|| printer.Connection.Paused)) }
{ else // did not find endstop yet
printer.Connection.LineReceived += PrinterLineRecieved; {
printer.Connection.MoveAbsolute(nozzleCurrentPosition, feedRates.X); nozzleCurrentPosition.Z -= moveDelta;
printer.Connection.QueueLine("G4 P1"); state = State.WaitingForEndstopStatusOk;
printer.Connection.QueueLine("M119"); }
} }
break;
base.OnLoad(args); case State.WaitingForEndstopStatusOk:
} // found the ok of the M119 command
// move down more
public override void OnClosed(EventArgs e) if (printer.Connection.CurrentDestination.Z < printer.Settings.GetValue<double>(SettingsKey.conductive_probe_min_z))
{ {
printer.Connection.LineReceived -= PrinterLineRecieved; // we have gone down too far
base.OnClosed(e); // abort with error
} this.MovedBelowMinZ = true;
} // move on to the next page of the wizard
UiThread.RunOnIdle(() => NextButton.InvokeClick());
}
else if (line.StartsWith("ok"))
{
state = State.WaitingForEndstopStatusStart;
// send the next set of commands
printer.Connection.MoveAbsolute(nozzleCurrentPosition, feedRates.X);
printer.Connection.QueueLine("G4 P1");
printer.Connection.QueueLine("M119");
}
break;
}
}
}
}
} }

View file

@ -28,15 +28,16 @@ either expressed or implied, of the FreeBSD Project.
*/ */
using System; using System;
using System.Threading.Tasks;
using MatterHackers.DataConverters3D; using MatterHackers.DataConverters3D;
namespace MatterHackers.MatterControl.Library namespace MatterHackers.MatterControl.Library
{ {
public class DynamicContentStore : IContentStore public class DynamicContentStore : IContentStore
{ {
private Action<ILibraryItem, IObject3D> saveAction; private Func<ILibraryItem, IObject3D, Task> saveAction;
public DynamicContentStore(Action<ILibraryItem, IObject3D> saveAction) public DynamicContentStore(Func<ILibraryItem, IObject3D, Task> saveAction)
{ {
this.saveAction = saveAction; this.saveAction = saveAction;
} }
@ -45,9 +46,9 @@ namespace MatterHackers.MatterControl.Library
{ {
} }
public void Save(ILibraryItem item, IObject3D content) public Task Save(ILibraryItem item, IObject3D content)
{ {
saveAction.Invoke(item, content); return saveAction.Invoke(item, content);
} }
} }
} }

View file

@ -29,11 +29,12 @@ either expressed or implied, of the FreeBSD Project.
using MatterHackers.DataConverters3D; using MatterHackers.DataConverters3D;
using System; using System;
using System.Threading.Tasks;
namespace MatterHackers.MatterControl.Library namespace MatterHackers.MatterControl.Library
{ {
public interface IContentStore : IDisposable public interface IContentStore : IDisposable
{ {
void Save(ILibraryItem item, IObject3D content); Task Save(ILibraryItem item, IObject3D content);
} }
} }

View file

@ -82,7 +82,7 @@ namespace MatterHackers.MatterControl.Library
} }
} }
public override void Save(ILibraryItem item, IObject3D content) public override async Task Save(ILibraryItem item, IObject3D content)
{ {
if (item is FileSystemFileItem fileItem) if (item is FileSystemFileItem fileItem)
{ {
@ -96,7 +96,7 @@ namespace MatterHackers.MatterControl.Library
} }
else else
{ {
ApplicationController.Instance.Tasks.Execute( await ApplicationController.Instance.Tasks.Execute(
"Saving Changes".Localize(), "Saving Changes".Localize(),
null, null,
async (reporter, cancellationTokenSource) => async (reporter, cancellationTokenSource) =>

View file

@ -190,7 +190,7 @@ namespace MatterHackers.MatterControl.Library
this.ReloadContent(); this.ReloadContent();
} }
public override void Save(ILibraryItem item, IObject3D content) public override Task Save(ILibraryItem item, IObject3D content)
{ {
if (item is FileSystemFileItem fileItem) if (item is FileSystemFileItem fileItem)
{ {
@ -200,6 +200,8 @@ namespace MatterHackers.MatterControl.Library
this.OnItemContentChanged(new LibraryItemChangedEventArgs(fileItem)); this.OnItemContentChanged(new LibraryItemChangedEventArgs(fileItem));
} }
return null;
} }
public override void SetThumbnail(ILibraryItem item, int width, int height, ImageBuffer imageBuffer) public override void SetThumbnail(ILibraryItem item, int width, int height, ImageBuffer imageBuffer)

View file

@ -31,6 +31,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using MatterHackers.Agg.Image; using MatterHackers.Agg.Image;
using MatterHackers.DataConverters3D; using MatterHackers.DataConverters3D;
@ -49,7 +50,7 @@ namespace MatterHackers.MatterControl.Library
public abstract void Remove(IEnumerable<ILibraryItem> items); public abstract void Remove(IEnumerable<ILibraryItem> items);
public abstract void Save(ILibraryItem item, IObject3D content); public abstract Task Save(ILibraryItem item, IObject3D content);
public virtual void Move(IEnumerable<ILibraryItem> items, ILibraryWritableContainer sourceContainer) public virtual void Move(IEnumerable<ILibraryItem> items, ILibraryWritableContainer sourceContainer)
{ {

View file

@ -534,13 +534,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
editorPanel.AddChild(editorWidget); editorPanel.AddChild(editorWidget);
} }
public void Save(ILibraryItem item, IObject3D content) public Task Save(ILibraryItem item, IObject3D content)
{ {
this.item.Parent.Children.Modify(children => this.item.Parent.Children.Modify(children =>
{ {
children.Remove(this.item); children.Remove(this.item);
children.Add(content); children.Add(content);
}); });
return null;
} }
public override void OnClosed(EventArgs e) public override void OnClosed(EventArgs e)