public static List <string> ProcessWriteRegEx(string lineToWrite, PrintHostConfig printer) { var linesToWrite = new List <string>(); linesToWrite.Add(lineToWrite); var addedLines = new List <string>(); for (int i = 0; i < linesToWrite.Count; i++) { foreach (var item in printer.Settings.Helpers.WriteLineReplacements) { var splitReplacement = item.Replacement.Split(','); if (splitReplacement.Length > 0) { if (item.Regex.IsMatch(lineToWrite)) { // replace on the first replacement group only var replacedString = item.Regex.Replace(lineToWrite, splitReplacement[0]); linesToWrite[i] = replacedString; // add in the other replacement groups for (int j = 1; j < splitReplacement.Length; j++) { addedLines.Add(splitReplacement[j]); } break; } } } } linesToWrite.AddRange(addedLines); return(linesToWrite); }
public PrinterConfig(PrinterSettings settings) { this.Settings = settings; this.Bed = new BedConfig(ApplicationController.Instance.Library.PlatingHistory, this); this.ViewState = new PrinterViewState(); this.printerShim = new PrintHostConfig() { Settings = settings }; this.Connection = new PrinterConnection(printerShim); printerShim.Connection = this.Connection; this.TerminalLog = new TerminalLog(this.Connection); // Register listeners this.Connection.TemporarilyHoldingTemp += ApplicationController.Instance.Connection_TemporarilyHoldingTemp; this.Connection.PrintFinished += ApplicationController.Instance.Connection_PrintFinished; this.Connection.PrintCanceled += ApplicationController.Instance.Connection_PrintCanceled; this.Connection.ErrorReported += ApplicationController.Instance.Connection_ErrorReported; this.Connection.CommunicationStateChanged += Connection_CommunicationStateChanged; this.Connection.DetailedPrintingStateChanged += Connection_CommunicationStateChanged; this.Connection.PrintFinished += Connection_PrintFinished; // Initialize bed settings this.ReloadBedSettings(); this.Bed.InvalidateBedMesh(); this.Settings.SettingChanged += Printer_SettingChanged; }
public void MaxLengthStreamTests() { string[] lines = new string[] { "G1 X0 Y0 Z0 E0 F500", "M105", "G1 X18 Y0 Z0 F2500", "G28", "G1 X0 Y0 Z0 E0 F500", }; // We should go back to the above code when possible. It requires making pause part and move while paused part of the stream. // All communication should go through stream to minimize the difference between printing and controlling while not printing (all printing in essence). string[] expected = new string[] { "G1 X0 Y0 Z0 E0 F500", "M105", "G1 X6 F2500", "G1 X12", "G1 X18", "G28", "G1 X0 Y0 Z0 E0 F500", }; PrintHostConfig printer = null; MaxLengthStream maxLengthStream = new MaxLengthStream(printer, new TestGCodeStream(printer, lines), 6); ValidateStreamResponse(expected, maxLengthStream); }
public static List <Vector2> ParseLevelingSamplePoints(PrintHostConfig printer) { var pointsToProbe = new List <Vector2>(); var samples = printer.Settings.GetValue(SettingsKey.leveling_sample_points).Replace("\r", "").Replace("\n", "").Trim(); double xPos = double.NegativeInfinity; foreach (var coord in samples.Split(',')) { if (double.TryParse(coord, out double result)) { if (xPos == double.NegativeInfinity) { // this is the first coord it is an x position xPos = result; } else // we have an x { pointsToProbe.Add(new Vector2(xPos, result)); xPos = double.NegativeInfinity; } } } return(pointsToProbe); }
public GCodeStream(PrintHostConfig printer) { this.printer = printer; if (printer != null) { useG0ForMovement = printer.Settings.GetValue <bool>(SettingsKey.g0); } }
public PrintLevelingWizard(PrinterConfig printer) : base(printer) { this.printerShim = ApplicationController.Instance.Shim(printer); this.Title = "Print Leveling".Localize(); hasHardwareLeveling = printer.Settings.GetValue <bool>(SettingsKey.has_hardware_leveling); }
public static Vector2 ProbeOffsetSamplePosition(PrintHostConfig printer) { if (printer.Settings.GetValue <LevelingSystem>(SettingsKey.print_leveling_solution) == LevelingSystem.ProbeCustom) { return(printer.Settings.GetValue <Vector2>(SettingsKey.probe_offset_sample_point)); } return(printer.Settings.GetValue <Vector2>(SettingsKey.print_center)); }
public SoftwareEndstopsStream(PrintHostConfig printer, GCodeStream internalStream) : base(printer, internalStream) { CalculateBounds(); printer.Settings.SettingChanged += Settings_SettingChanged; printer.Connection.HomingPositionChanged += Connection_HomingPositionChanged; // Register to listen for position after home and update Bounds based on the axis homed and position info. }
public BabyStepsStream(PrintHostConfig printer, GCodeStream internalStream) : base(printer, internalStream) { printer.Settings.SettingChanged += Printer_SettingChanged; extruderIndex = printer.Connection.ActiveExtruderIndex; BabbyStepOffset = new Vector3(0, 0, printer.Settings.GetValue <double>(SettingsKey.baby_step_z_offset)); ReadExtruderOffsets(); }
public ToolChangeStream(PrintHostConfig printer, GCodeStream internalStream, QueuedCommandsStream queuedCommandsStream, IGCodeLineReader gcodeLineReader) : base(printer, internalStream) { this.gcodeLineReader = gcodeLineReader; if (gcodeLineReader != null) { this.gCodeMemoryFile = gcodeLineReader.GCodeFile as GCodeMemoryFile; } this.queuedCommandsStream = queuedCommandsStream; extruderCount = printer.Settings.GetValue <int>(SettingsKey.extruder_count); activeTool = printer.Connection.ActiveExtruderIndex; }
public PrintRecoveryStream(GCodeSwitcher internalStream, PrintHostConfig printer, double percentDone) : base(printer) { this.internalStream = internalStream; this.percentDone = percentDone; recoverFeedRate = printer.Settings.GetValue <double>(SettingsKey.recover_first_layer_speed); if (recoverFeedRate == 0) { recoverFeedRate = 10; } recoverFeedRate *= 60; queuedCommands = new QueuedCommandsStream(printer, null); }
public void FeedRateRatioChangesFeedRate() { string line; Assert.AreEqual(1, (int)FeedRateMultiplierStream.FeedRateRatio, "FeedRateRatio should default to 1"); PrintHostConfig printer = null; var gcodeStream = new FeedRateMultiplierStream(printer, new TestGCodeStream(printer, new string[] { "G1 X10 F1000", "G1 Y5 F1000" })); line = gcodeStream.ReadLine(); Assert.AreEqual("G1 X10 F1000", line, "FeedRate should remain unchanged when FeedRateRatio is 1.0"); FeedRateMultiplierStream.FeedRateRatio = 2; line = gcodeStream.ReadLine(); Assert.AreEqual("G1 Y5 F2000", line, "FeedRate should scale from F1000 to F2000 when FeedRateRatio is 2x"); }
public GCodeSwitcher(Stream gcodeStream, PrintHostConfig printer, int startLine = 0) : base(printer) { var settings = this.printer.Settings; var maxAcceleration = settings.GetValue <double>(SettingsKey.max_acceleration); var maxVelocity = settings.GetValue <double>(SettingsKey.max_velocity); var jerkVelocity = settings.GetValue <double>(SettingsKey.jerk_velocity); var multiplier = settings.GetValue <double>(SettingsKey.print_time_estimate_multiplier) / 100.0; var fileStreaming = GCodeFile.Load(gcodeStream, new Vector4(maxAcceleration, maxAcceleration, maxAcceleration, maxAcceleration), new Vector4(maxVelocity, maxVelocity, maxVelocity, maxVelocity), new Vector4(jerkVelocity, jerkVelocity, jerkVelocity, jerkVelocity), new Vector4(multiplier, multiplier, multiplier, multiplier), CancellationToken.None); this.GCodeFile = fileStreaming; LineIndex = startLine; }
public void ExtrusionRatioChangesExtrusionAmount() { string line; Assert.AreEqual(1, (int)ExtrusionMultiplierStream.ExtrusionRatio, "ExtrusionRatio should default to 1"); PrintHostConfig printer = null; var gcodeStream = new ExtrusionMultiplierStream(printer, new TestGCodeStream(printer, new string[] { "G1 E10", "G1 E0 ; Move back to 0", "G1 E12" })); line = gcodeStream.ReadLine(); // Move back to E0 gcodeStream.ReadLine(); Assert.AreEqual("G1 E10", line, "ExtrusionMultiplier should remain unchanged when FeedRateRatio is 1.0"); ExtrusionMultiplierStream.ExtrusionRatio = 2; line = gcodeStream.ReadLine(); Assert.AreEqual("G1 E24", line, "ExtrusionMultiplier should scale from E12 to E24 when ExtrusionRatio is 2x"); }
public PauseHandlingStream(PrintHostConfig printer, GCodeStream internalStream) : base(printer, internalStream) { // if we have a runout sensor, register to listen for lines to check it if (printer.Settings.GetValue <bool>(SettingsKey.filament_runout_sensor)) { printer.Connection.LineReceived += (s, line) => { if (line != null) { if (line.Contains("ros_")) { if (line.Contains("TRIGGERED")) { readOutOfFilament = true; } } if (line.Contains("pos_")) { double sensorDistance = 0; double stepperDistance = 0; if (GCodeFile.GetFirstNumberAfter("SENSOR:", line, ref sensorDistance)) { if (sensorDistance < -1 || sensorDistance > 1) { printer.Connection.FilamentPositionSensorDetected = true; } if (printer.Connection.FilamentPositionSensorDetected) { GCodeFile.GetFirstNumberAfter("STEPPER:", line, ref stepperDistance); var stepperDelta = Math.Abs(stepperDistance - positionSensorData.LastStepperDistance); // if we think we should have move the filament by more than 1mm if (stepperDelta > 1) { var sensorDelta = Math.Abs(sensorDistance - positionSensorData.LastSensorDistance); // check if the sensor data is within a tolerance of the stepper data var deltaRatio = sensorDelta / stepperDelta; if (deltaRatio < .5 || deltaRatio > 2) { // we have a reportable discrepancy set a runout state positionSensorData.ExtrusionDiscrepency++; if (positionSensorData.ExtrusionDiscrepency > 2) { readOutOfFilament = true; positionSensorData.ExtrusionDiscrepency = 0; } } else { positionSensorData.ExtrusionDiscrepency = 0; } // and record this position positionSensorData.LastSensorDistance = sensorDistance; positionSensorData.LastStepperDistance = stepperDistance; } } } } } }; } }
public LevelingPlan(PrintHostConfig printer) { this.printer = printer; }
public SendProgressStream(GCodeStream internalStream, PrintHostConfig printer) : base(printer, internalStream) { }
private PrinterConfig() { this.printerShim = new PrintHostConfig(); this.Connection = new PrinterConnection(this.printerShim); }
public RequestTemperaturesStream(PrintHostConfig printer, GCodeStream internalStream) : base(printer, internalStream) { nextReadTimeMs = UiThread.CurrentTimerMs + 1000; }
public ToolSpeedMultiplierStream(PrintHostConfig printer, GCodeStream internalStream) : base(printer, internalStream) { t0Multiplier = printer.Settings.GetValue <double>(SettingsKey.t1_extrusion_move_speed_multiplier); printer.Settings.SettingChanged += Settings_SettingChanged; }
public GCodeFileStream(GCodeFile fileStreaming, PrintHostConfig printer, int startLine = 0) : base(printer) { this.GCodeFile = fileStreaming; printerCommandQueueLineIndex = startLine; }
public NotPrintingStream(PrintHostConfig printer) : base(printer) { }
public QueuedCommandsStream(PrintHostConfig printer, GCodeStream internalStream) : base(printer, internalStream) { }
public static bool NeedsToBeRun(PrintHostConfig printer) { PrintLevelingData levelingData = printer.Settings.Helpers.PrintLevelingData; var required = printer.Settings.GetValue <bool>(SettingsKey.print_leveling_required_to_print); if (required && levelingData == null) { // need but don't have data return(true); } if (printer.Settings.GetValue <bool>(SettingsKey.has_hardware_leveling)) { // If printer has hardware leveling, software leveling is disabled return(false); } var enabled = printer.Settings.GetValue <bool>(SettingsKey.print_leveling_enabled); // check if leveling is turned on 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 levelingData.SampledPositions group x by x into g let count = g.Count() orderby count descending select new { Value = g.Key, Count = count }; foreach (var x in positionCounts) { if (x.Count > 1) { return(true); } } // check that the solution last measured is the currently selected solution if (printer.Settings.GetValue <LevelingSystem>(SettingsKey.print_leveling_solution) != levelingData.LevelingSystem) { return(true); } // check that the bed temperature at probe time was close enough to the current print bed temp double requiredLevelingTemp = printer.Settings.GetValue <bool>(SettingsKey.has_heated_bed) ? printer.Settings.GetValue <double>(SettingsKey.bed_temperature) : 0; // check that the number of points sampled is correct for the solution switch (levelingData.LevelingSystem) { case LevelingSystem.Probe3Points: if (levelingData.SampledPositions.Count != 3) // different criteria for what is not initialized { return(true); } break; case LevelingSystem.Probe7PointRadial: if (levelingData.SampledPositions.Count != 7) // different criteria for what is not initialized { return(true); } break; case LevelingSystem.Probe13PointRadial: if (levelingData.SampledPositions.Count != 13) // different criteria for what is not initialized { return(true); } break; case LevelingSystem.Probe100PointRadial: if (levelingData.SampledPositions.Count != 100) // different criteria for what is not initialized { return(true); } break; case LevelingSystem.Probe3x3Mesh: if (levelingData.SampledPositions.Count != 9) // different criteria for what is not initialized { return(true); } break; case LevelingSystem.Probe5x5Mesh: if (levelingData.SampledPositions.Count != 25) // different criteria for what is not initialized { return(true); } break; case LevelingSystem.Probe10x10Mesh: if (levelingData.SampledPositions.Count != 100) // different criteria for what is not initialized { return(true); } break; case LevelingSystem.ProbeCustom: if (levelingData.SampledPositions.Count != LevelWizardCustom.ParseLevelingSamplePoints(printer).Count) { return(true); } break; default: throw new NotImplementedException(); } return(false); }
public ProcessWriteRegexStream(PrintHostConfig printer, GCodeStream internalStream, QueuedCommandsStream queueStream) : base(printer, internalStream) { this.queueStream = queueStream; }
public GCodeStreamProxy(PrintHostConfig printer, GCodeStream internalStream) : base(printer) { this.internalStream = internalStream; }
public MaxLengthStream(PrintHostConfig printer, GCodeStream internalStream, double maxSegmentLength) : base(printer, internalStream) { this.MaxSegmentLength = maxSegmentLength; }
public RemoveNOPsStream(PrintHostConfig printer, GCodeStream internalStream) : base(printer, internalStream) { }
public LevelWizardMesh(PrintHostConfig printer, int width, int height) : base(printer) { this.gridWidth = width; this.gridHeight = height; }
public PrintLevelingStream(PrintHostConfig printer, GCodeStream internalStream) : base(printer, internalStream) { // always reset this when we construct AllowLeveling = true; }