private void InjectPauseGCode(string codeToInject) { codeToInject = GCodeProcessing.ReplaceMacroValues(codeToInject); codeToInject = codeToInject.Replace("\\n", "\n"); string[] lines = codeToInject.Split('\n'); for (int i = 0; i < lines.Length; i++) { string[] splitOnSemicolon = lines[i].Split(';'); string trimedLine = splitOnSemicolon[0].Trim().ToUpper(); if (trimedLine != "") { this.Add(trimedLine); } } }
public override string ReadLine() { string lineToSend = null; { // lock queue lock (locker) { if (commandQueue.Count > 0) { lineToSend = commandQueue[0]; lineToSend = GCodeProcessing.ReplaceMacroValues(lineToSend); commandQueue.RemoveAt(0); } } if (lineToSend == null) { lineToSend = base.ReadLine(); } } return(lineToSend); }
protected void SendCommandToPrinter(string command) { command = GCodeProcessing.ReplaceMacroValues(command); PrinterConnectionAndCommunication.Instance.SendLineToPrinterNow(command); }
public override string ReadLine() { string lineToSend = null; if (waitingForUserInput) { lineToSend = ""; Thread.Sleep(100); if (timeHaveBeenWaiting.IsRunning && timeHaveBeenWaiting.Elapsed.TotalSeconds > maxTimeToWaitForOk) { if (commandsToRepeat.Count > 0) { // We timed out without the user responding. Cancel the operation. Reset(); } else { // everything normal continue after time waited Continue(); } } if (maxTimeToWaitForOk > 0 && timeHaveBeenWaiting.Elapsed.TotalSeconds < maxTimeToWaitForOk && commandsToRepeat.Count > 0) { lineToSend = commandsToRepeat[repeatCommandIndex % commandsToRepeat.Count]; repeatCommandIndex++; } } else { // lock queue lock (locker) { if (commandQueue.Count > 0) { lineToSend = commandQueue[0]; lineToSend = GCodeProcessing.ReplaceMacroValues(lineToSend); commandQueue.RemoveAt(0); } } if (lineToSend != null) { if (lineToSend.StartsWith(MacroPrefix) && lineToSend.TrimEnd().EndsWith(")")) { if (!runningMacro) { runningMacro = true; int extruderCount = ActiveSliceSettings.Instance.GetValue <int>(SettingsKey.extruder_count); for (int i = 0; i < extruderCount; i++) { startingExtruderTemps.Add(PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(i)); } if (ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.has_heated_bed)) { startingBedTemp = PrinterConnectionAndCommunication.Instance.TargetBedTemperature; } } int parensAfterCommand = lineToSend.IndexOf('(', MacroPrefix.Length); string command = ""; if (parensAfterCommand > 0) { command = lineToSend.Substring(MacroPrefix.Length, parensAfterCommand - MacroPrefix.Length); } RunningMacroPage.MacroCommandData macroData = new RunningMacroPage.MacroCommandData(); string value = ""; if (TryGetAfterString(lineToSend, "title", out value)) { macroData.title = value; } if (TryGetAfterString(lineToSend, "expire", out value)) { double.TryParse(value, out macroData.expireTime); maxTimeToWaitForOk = macroData.expireTime; } if (TryGetAfterString(lineToSend, "count_down", out value)) { double.TryParse(value, out macroData.countDown); } if (TryGetAfterString(lineToSend, "image", out value)) { macroData.image = LoadImageAsset(value); } if (TryGetAfterString(lineToSend, "wait_ok", out value)) { macroData.waitOk = value == "true"; } if (TryGetAfterString(lineToSend, "repeat_gcode", out value)) { foreach (string line in value.Split('|')) { commandsToRepeat.Add(line); } } switch (command) { case "choose_material": waitingForUserInput = true; macroData.showMaterialSelector = true; macroData.waitOk = true; UiThread.RunOnIdle(() => RunningMacroPage.Show(macroData)); break; case "close": runningMacro = false; UiThread.RunOnIdle(() => WizardWindow.Close("Macro")); break; case "ding": MatterControlApplication.Instance.PlaySound("timer-done.wav"); break; case "show_message": waitingForUserInput = macroData.waitOk | macroData.expireTime > 0; UiThread.RunOnIdle(() => RunningMacroPage.Show(macroData)); break; default: // Don't know the command. Print to terminal log? break; } } } else { lineToSend = base.ReadLine(); } } return(lineToSend); }
private void TestMacroReplacement(string inputText, string outputControl) { string outputTest = GCodeProcessing.ReplaceMacroValues(inputText); Assert.IsTrue(outputTest == outputControl); }