diff --git a/app/src/processing/app/AbstractMonitor.java b/app/src/processing/app/AbstractMonitor.java index 146a8c25e20..7834e96e7ae 100644 --- a/app/src/processing/app/AbstractMonitor.java +++ b/app/src/processing/app/AbstractMonitor.java @@ -41,6 +41,7 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener { protected JScrollPane scrollPane; protected JTextField textField; protected JButton sendButton; + protected JButton resetButton; protected JCheckBox autoscrollBox; protected JComboBox lineEndings; protected JComboBox serialRates; @@ -101,10 +102,12 @@ public void actionPerformed(ActionEvent event) { textField = new JTextField(40); sendButton = new JButton(_("Send")); + resetButton = new JButton(_("Send Reset")); upperPane.add(textField); upperPane.add(Box.createRigidArea(new Dimension(4, 0))); upperPane.add(sendButton); + upperPane.add(resetButton); getContentPane().add(upperPane, BorderLayout.NORTH); @@ -188,6 +191,10 @@ public void onSendCommand(ActionListener listener) { sendButton.addActionListener(listener); } + public void onResetCommand(ActionListener listener) { + resetButton.addActionListener(listener); + } + protected void setPlacement(int[] location) { setBounds(location[0], location[1], location[2], location[3]); } @@ -228,6 +235,9 @@ public String getAuthorizationKey() { public abstract void close() throws Exception; + public abstract void openSerial() throws Exception; + public abstract void closeSerial() throws Exception; + public synchronized void addToUpdateBuffer(char buff[], int n) { updateBuffer.append(buff, 0, n); } diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 1450878fd92..9869f09b6ab 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -2422,11 +2422,12 @@ synchronized public void handleExport(final boolean usingProgrammer) { // DAM: in Arduino, this is upload class DefaultExportHandler implements Runnable { public void run() { + boolean serialMonitorWasOpen = false; try { if (serialMonitor != null) { - serialMonitor.close(); - serialMonitor.setVisible(false); + serialMonitor.closeSerial(); + serialMonitorWasOpen=true; } uploading = true; @@ -2458,17 +2459,28 @@ public void run() { uploading = false; //toolbar.clear(); toolbar.deactivate(EditorToolbar.EXPORT); + + try { + if ( (serialMonitor != null) && (serialMonitorWasOpen) ){ + serialMonitor.openSerial(); + } + } catch (Exception e) { + // we are in deep trouble.... + e.printStackTrace(); + } + } } // DAM: in Arduino, this is upload (with verbose output) class DefaultExportAppHandler implements Runnable { public void run() { + boolean serialMonitorWasOpen = false; try { if (serialMonitor != null) { - serialMonitor.close(); - serialMonitor.setVisible(false); + serialMonitor.closeSerial(); + serialMonitorWasOpen=true; } uploading = true; @@ -2500,6 +2512,15 @@ public void run() { uploading = false; //toolbar.clear(); toolbar.deactivate(EditorToolbar.EXPORT); + + try { + if ( (serialMonitor != null) && (serialMonitorWasOpen) ){ + serialMonitor.openSerial(); + } + } catch (Exception e) { + // uh, deep trouble.... + e.printStackTrace(); + } } } diff --git a/app/src/processing/app/NetworkMonitor.java b/app/src/processing/app/NetworkMonitor.java index 850481ef76e..18927ef4394 100644 --- a/app/src/processing/app/NetworkMonitor.java +++ b/app/src/processing/app/NetworkMonitor.java @@ -121,6 +121,13 @@ public void run() { }); } } + + @Override + public void openSerial() throws Exception {} + + @Override + public void closeSerial() throws Exception {} + @Override public synchronized void message(String s) { diff --git a/app/src/processing/app/SerialMonitor.java b/app/src/processing/app/SerialMonitor.java index 122e3323d75..102ba7175e7 100644 --- a/app/src/processing/app/SerialMonitor.java +++ b/app/src/processing/app/SerialMonitor.java @@ -27,6 +27,7 @@ import static processing.app.I18n._; + @SuppressWarnings("serial") public class SerialMonitor extends AbstractMonitor { @@ -64,6 +65,18 @@ public void actionPerformed(ActionEvent e) { send(textField.getText()); textField.setText(""); } + }); + + onResetCommand(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + serial.setDTR(true); + Thread.sleep(207); // Pfffffff. + serial.setDTR(false); + } catch (Exception se) { + se.printStackTrace(); // we are in deep trouble if this happens.... + } + } }); } @@ -88,7 +101,7 @@ private void send(String s) { } } - public void open() throws Exception { + public void openSerial() throws Exception { if (serial != null) return; serial = new Serial(port, serialRate) { @@ -98,8 +111,8 @@ protected void message(char buff[], int n) { } }; } - - public void close() throws Exception { + + public void closeSerial() throws Exception { if (serial != null) { int[] location = getPlacement(); String locationStr = PApplet.join(PApplet.str(location), ","); @@ -110,4 +123,12 @@ public void close() throws Exception { } } + public void open() throws Exception { + openSerial(); + } + + public void close() throws Exception { + closeSerial(); + } + } diff --git a/arduino-core/src/processing/app/Serial.java b/arduino-core/src/processing/app/Serial.java index 53d0601ae7b..65f339f2dd1 100644 --- a/arduino-core/src/processing/app/Serial.java +++ b/arduino-core/src/processing/app/Serial.java @@ -121,7 +121,7 @@ public Serial(String iname, int irate, char iparity, int idatabits, float istopb try { port = new SerialPort(iname); port.openPort(); - port.setParams(rate, databits, stopbits, parity, true, true); + port.setParams(rate, databits, stopbits, parity, true, false); port.addEventListener(this); } catch (Exception e) { throw new SerialException(I18n.format(_("Error opening serial port ''{0}''."), iname), e);