public override void PageIsBecomingActive() { bedStartingTemp = printer.Connection.ActualBedTemperature; runningInterval = UiThread.SetInterval(ShowTempChangeProgress, 1); if (bedTargetTemp > 0) { // start heating the bed and show our progress printer.Connection.TargetBedTemperature = bedTargetTemp; } if (hotEndTargetTemp > 0) { // start heating the hot end and show our progress printer.Connection.SetTargetHotendTemperature(0, hotEndTargetTemp); } NextButton.Enabled = false; // if we are trying to go to a temp of 0 than just move on to next window if (bedTargetTemp == 0 && hotEndTargetTemp == 0) { // advance to the next page UiThread.RunOnIdle(() => NextButton.InvokeClick()); } base.PageIsBecomingActive(); }
public void TopWindowKeyDown(object s, KeyEventArgs keyEvent) { switch (keyEvent.KeyCode) { case Keys.Up: ZPlusControl_Click(null, null); NextButton.Enabled = true; break; case Keys.Down: ZMinusControl_Click(null, null); NextButton.Enabled = true; break; case Keys.Right: if (NextButton.Enabled) { UiThread.RunOnIdle(() => NextButton.InvokeClick()); } break; } OnKeyDown(keyEvent); }
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; // move on to the next page of the wizard UiThread.RunOnIdle(() => NextButton.InvokeClick()); } } else // did not find endstop yet { nozzleCurrentPosition.Z -= moveDelta; state = State.WaitingForEndstopStatusOk; } } break; case State.WaitingForEndstopStatusOk: // found the ok of the M119 command // move down more if (printer.Connection.CurrentDestination.Z < printer.Settings.GetValue <double>(SettingsKey.conductive_probe_min_z)) { // we have gone down too far // 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; } } }
private void ShowTempChangeProgress() { int progressBarIndex = 0; for (int i = 0; i < targetHotendTemps.Length; i++) { if (targetHotendTemps[i] > 0) { hotEndProgressBars[progressBarIndex].Visible = true; double targetTemp = printer.Connection.GetTargetHotendTemperature(i); double actualTemp = printer.Connection.GetActualHotendTemperature(i); double totalDelta = targetTemp; double currentDelta = actualTemp; double ratioDone = hotEndDoneTexts[progressBarIndex].Visible ? 1 : totalDelta != 0 ? (currentDelta / totalDelta) : 1; hotEndProgressBars[progressBarIndex].RatioComplete = Math.Min(Math.Max(0, ratioDone), 1); hotEndProgressBarTexts[progressBarIndex].Text = $"{actualTemp:0} / {targetTemp:0}"; // if we are within 1 degree of our target if (Math.Abs(targetTemp - actualTemp) < 2 && hotEndDoneTexts[progressBarIndex].Visible == false) { hotEndDoneTexts[progressBarIndex].Visible = true; NextButton.Enabled = true; } progressBarIndex++; } } if (bedTargetTemp > 0) { bedProgressBar.Visible = true; double targetTemp = printer.Connection.TargetBedTemperature; double actualTemp = printer.Connection.ActualBedTemperature; double totalDelta = targetTemp - bedStartingTemp; double currentDelta = actualTemp - bedStartingTemp; double ratioDone = bedDoneText.Visible ? 1 : totalDelta != 0 ? (currentDelta / totalDelta) : 1; bedProgressBar.RatioComplete = Math.Min(Math.Max(0, ratioDone), 1); bedProgressBarText.Text = $"{actualTemp:0} / {targetTemp:0}"; // if we are within 1 degree of our target if (Math.Abs(targetTemp - actualTemp) < 2 && bedDoneText.Visible == false) { bedDoneText.Visible = true; NextButton.Enabled = true; } } if ((bedTargetTemp == 0 || bedDoneText.Visible) && (targetHotendTemps.All(i => i == 0) || hotEndDoneTexts.All(i => i.Visible)) && !HasBeenClosed) { // advance to the next page UiThread.RunOnIdle(() => NextButton.InvokeClick()); } }
private void GetZProbeHeight(object sender, string line) { if (line != null) { double sampleRead = double.MinValue; if (line.StartsWith("Bed")) // marlin G30 return code (looks like: 'Bed Position X:20 Y:32 Z:.01') { probePositions[probePositionsBeingEditedIndex].Position.X = probeStartPosition.X; probePositions[probePositionsBeingEditedIndex].Position.Y = probeStartPosition.Y; GCodeFile.GetFirstNumberAfter("Z:", line, ref sampleRead); } else if (line.StartsWith("Z:")) // smoothie G30 return code (looks like: 'Z:10.01') { probePositions[probePositionsBeingEditedIndex].Position.X = probeStartPosition.X; probePositions[probePositionsBeingEditedIndex].Position.Y = probeStartPosition.Y; // smoothie returns the position relative to the start position double reportedProbeZ = 0; GCodeFile.GetFirstNumberAfter("Z:", line, ref reportedProbeZ); sampleRead = probeStartPosition.Z - reportedProbeZ; } if (sampleRead != double.MinValue) { samples.Add(sampleRead); int numberOfSamples = printer.Settings.GetValue <int>(SettingsKey.z_probe_samples); if (samples.Count == numberOfSamples) { samples.Sort(); if (samples.Count > 3) { // drop the high and low values samples.RemoveAt(0); samples.RemoveAt(samples.Count - 1); } probePositions[probePositionsBeingEditedIndex].Position.Z = Math.Round(samples.Average(), 2); UiThread.RunOnIdle(() => NextButton.InvokeClick()); } else if (!this.HasBeenClosed) { // add the next request for probe printer.Connection.QueueLine("G30"); // raise the probe after each sample printer.Connection.MoveAbsolute(adjustedProbePosition, feedRates.X); } } } }
private void Connection_DetailedPrintingStateChanged(object sender, EventArgs e) { if (printer.Connection.DetailedPrintingState == DetailedPrintingState.HomingAxis && !homingAxisObserved) { homingAxisObserved = true; } if (homingAxisObserved && printer.Connection.DetailedPrintingState != DetailedPrintingState.HomingAxis) { NextButton.Enabled = true; UiThread.RunOnIdle(() => NextButton.InvokeClick()); } }
private void FinishedProbe(object sender, string line) { if (line != null) { if (line.Contains("endstops hit")) { printer.Connection.LineReceived -= FinishedProbe; int zStringPos = line.LastIndexOf("Z:"); string zProbeHeight = line.Substring(zStringPos + 2); probePosition.position = new Vector3(probeStartPosition.X, probeStartPosition.Y, double.Parse(zProbeHeight)); printer.Connection.MoveAbsolute(probeStartPosition, printer.Settings.Helpers.ManualMovementSpeeds().Z); printer.Connection.ReadPosition(); UiThread.RunOnIdle(() => NextButton.InvokeClick()); } } }
public override void OnLoad(EventArgs args) { // hook our parent so we can turn off the bed when we are done with leveling this.DialogWindow.Closed += WizardWindow_Closed; bedStartingTemp = printer.Connection.ActualBedTemperature; runningInterval = UiThread.SetInterval(ShowTempChangeProgress, 1); if (bedTargetTemp > 0) { // start heating the bed and show our progress printer.Connection.TargetBedTemperature = bedTargetTemp; } for (int i = 0; i < targetHotendTemps.Length; i++) { if (targetHotendTemps[i] > 0) { // start heating the hot end and show our progress printer.Connection.SetTargetHotendTemperature(i, targetHotendTemps[i]); } } NextButton.Enabled = false; // if we are trying to go to a temp of 0 than just move on to next window if (bedTargetTemp == 0 && targetHotendTemps.All(i => i == 0)) { // advance to the next page UiThread.RunOnIdle(() => NextButton.InvokeClick()); } base.OnLoad(args); }