/* GcodePostProcessor.pde (C) 2018 lingib https://www.instructables.com/ Last update 6 March 2018 -------- ABOUT -------- This code requires "Processing 3" from . The program inserts the special gcode sequences that are required when GRBL is modified to control a Z-axis servo. (GRBL is an ardino program for controlling the stepping motors on three-axis machines such as 3D-printers and milling-machines. See for more details.) Copy the contents of this file into a "Processing 3" sketch and save as "GcodePostProcessor" (without the quotes). Click the run arrow then follow the on-screen instructions. Absolute and relative addressing may be used when entering the source "filename". When using relative addressing precede each DOS path symbol (\) with an escape character (\). Examples: "filename" means the file is inside the Processing folder. ".\\filename" also means the file is inside the Processing folder. "..\\filename" means the file is one level up. "..\\folder1\\filename means file is in folder1 which is one level up. ---------- COPYRIGHT ---------- This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License. If not, see . */ // --------------------------------------------------- // DEFINITIONS // --------------------------------------------------- // ----- PrintWriter PrintWriter Output; //create an "Output" port for PrintWriter // ----- source file String Input_filename; //source filename String Output_filename; //output filename /* The routine for creating the "Output_filename" is located within the keyPressed() routine */ // ----- commands String[] Command_array; //array of g-code commands String Command_line = ""; //holds one line of g-code int Number_commands; //number of g-code commands // ----- user interface String Message = ""; //used for on-screen instructions String Keyboard = ""; //keyboard buffer // ----- flags boolean Pen_up = true; boolean Pen_down_S90 = false; boolean Input_filename_valid = false; boolean Suppress_output_flag =false; // --------------------------------------------------- // SETUP // --------------------------------------------------- void setup() { // ----- create draw window size(400, 300); //message window dimensions textSize(18); //set text characters to 18 textAlign(CENTER); //center the text background(#EEEEEE); //light gray background fill(0); //black text // ----- get input filename /* The keyPressed() routine intercepts your keypresses and performs this task */ if (!Input_filename_valid) { Message = "This program inserts GRBL compatible servo commands into gcode files.\r\n\r\nThe cursor does not blink.\r\n\r\nClick this box to start."; text(Message, 25, 55, 360, 200); // Text wraps within text box } } // --------------------------------------------------- // DRAW (main loop) // --------------------------------------------------- void draw() { // ----- check for mouse click if (mousePressed) { delay(100); //debounce delay background(#EEEEEE); textAlign(CENTER); text("Enter the \"source\" filename", width/2, height/4); } if (Input_filename_valid) { // ----- process the file contents for (int i=0; i