/** * stop sending file commands to the robot. * * @todo add an e-stop command? */ public void Halt() { running = false; paused = false; linesProcessed = 0; previewPane.setLinesProcessed(0); previewPane.setRunning(running); UpdateMenuBar(); }
// Take the next line from the file and send it to the robot, if permitted. public void SendFileCommand() { if (running == false || paused == true || fileOpened == false || portConfirmed == false || linesProcessed >= linesTotal) return; String line; do { // are there any more commands? line = gcode.get((int) linesProcessed++).trim(); previewPane.setLinesProcessed(linesProcessed); statusBar.SetProgress(linesProcessed, linesTotal); // loop until we find a line that gets sent to the robot, at which point we'll // pause for the robot to respond. Also stop at end of file. } while (ProcessLine(line) && linesProcessed < linesTotal); if (linesProcessed == linesTotal) { // end of file Halt(); } }
// The user has done something. respond to it. public void actionPerformed(ActionEvent e) { Object subject = e.getSource(); if (subject == buttonZoomIn) { previewPane.ZoomIn(); return; } if (subject == buttonZoomOut) { previewPane.ZoomOut(); return; } if (subject == buttonOpenFile) { OpenFileDialog(); return; } if (subject == buttonStart) { if (fileOpened) { paused = false; running = true; UpdateMenuBar(); linesProcessed = 0; previewPane.setRunning(running); previewPane.setLinesProcessed(linesProcessed); statusBar.Start(); SendFileCommand(); } return; } if (subject == buttonPause) { if (running) { if (paused == true) { buttonPause.setText("Pause"); paused = false; // @TODO: if the robot is not ready to unpause, this might fail and the program would // appear to hang. SendFileCommand(); } else { buttonPause.setText("Unpause"); paused = true; } } return; } if (subject == buttonDrive) { Drive(); return; } if (subject == buttonHalt) { Halt(); return; } if (subject == buttonRescan) { ListSerialPorts(); UpdateMenuBar(); return; } if (subject == buttonConfig) { UpdateConfig(); return; } if (subject == buttonJogMotors) { JogMotors(); return; } if (subject == buttonAbout) { JOptionPane.showMessageDialog( null, "Created by Dan Royer ([email protected]).\n\n" + "Find out more at http://www.marginallyclever.com/\n" + "Get the latest version and read the documentation online @ http://github.com/i-make-robots/DrawBot/"); return; } if (subject == buttonCheckForUpdate) { CheckForUpdate(); return; } if (subject == buttonExit) { System.exit(0); // @TODO: be more graceful? return; } int i; for (i = 0; i < 10; ++i) { if (subject == buttonRecent[i]) { OpenFileOnDemand(recentFiles[i]); return; } } for (i = 0; i < portsDetected.length; ++i) { if (subject == buttonPorts[i]) { OpenPort(portsDetected[i]); return; } } }