Skip to content

Commit 87400d9

Browse files
committed
Keep Serial Monitor open during upload
Keep Serial Monitor open during upload and don't break existing functions.
1 parent f9ec8a4 commit 87400d9

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

app/src/processing/app/AbstractMonitor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
4141
protected JScrollPane scrollPane;
4242
protected JTextField textField;
4343
protected JButton sendButton;
44+
4445
protected JCheckBox autoscrollBox;
4546
protected JComboBox lineEndings;
4647
protected JComboBox serialRates;
@@ -228,6 +229,9 @@ public String getAuthorizationKey() {
228229

229230
public abstract void close() throws Exception;
230231

232+
public abstract void openSerial() throws Exception;
233+
public abstract void closeSerial() throws Exception;
234+
231235
public synchronized void addToUpdateBuffer(char buff[], int n) {
232236
updateBuffer.append(buff, 0, n);
233237
}

app/src/processing/app/Editor.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,11 +2422,12 @@ synchronized public void handleExport(final boolean usingProgrammer) {
24222422
// DAM: in Arduino, this is upload
24232423
class DefaultExportHandler implements Runnable {
24242424
public void run() {
2425+
boolean serialMonitorWasOpen = false;
24252426

24262427
try {
24272428
if (serialMonitor != null) {
2428-
serialMonitor.close();
2429-
serialMonitor.setVisible(false);
2429+
serialMonitor.closeSerial();
2430+
serialMonitorWasOpen=true;
24302431
}
24312432

24322433
uploading = true;
@@ -2458,17 +2459,28 @@ public void run() {
24582459
uploading = false;
24592460
//toolbar.clear();
24602461
toolbar.deactivate(EditorToolbar.EXPORT);
2462+
2463+
try {
2464+
if ( (serialMonitor != null) && (serialMonitorWasOpen) ){
2465+
serialMonitor.openSerial();
2466+
}
2467+
} catch (Exception e) {
2468+
// we are in deep trouble....
2469+
e.printStackTrace();
2470+
}
2471+
24612472
}
24622473
}
24632474

24642475
// DAM: in Arduino, this is upload (with verbose output)
24652476
class DefaultExportAppHandler implements Runnable {
24662477
public void run() {
2478+
boolean serialMonitorWasOpen = false;
24672479

24682480
try {
24692481
if (serialMonitor != null) {
2470-
serialMonitor.close();
2471-
serialMonitor.setVisible(false);
2482+
serialMonitor.closeSerial();
2483+
serialMonitorWasOpen=true;
24722484
}
24732485

24742486
uploading = true;
@@ -2500,6 +2512,15 @@ public void run() {
25002512
uploading = false;
25012513
//toolbar.clear();
25022514
toolbar.deactivate(EditorToolbar.EXPORT);
2515+
2516+
try {
2517+
if ( (serialMonitor != null) && (serialMonitorWasOpen) ){
2518+
serialMonitor.openSerial();
2519+
}
2520+
} catch (Exception e) {
2521+
// uh, deep trouble....
2522+
e.printStackTrace();
2523+
}
25032524
}
25042525
}
25052526

app/src/processing/app/SerialMonitor.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void actionPerformed(ActionEvent e) {
6565
textField.setText("");
6666
}
6767
});
68+
6869
}
6970

7071
private void send(String s) {
@@ -88,7 +89,7 @@ private void send(String s) {
8889
}
8990
}
9091

91-
public void open() throws Exception {
92+
public void openSerial() throws Exception {
9293
if (serial != null) return;
9394

9495
serial = new Serial(port, serialRate) {
@@ -98,8 +99,8 @@ protected void message(char buff[], int n) {
9899
}
99100
};
100101
}
101-
102-
public void close() throws Exception {
102+
103+
public void closeSerial() throws Exception {
103104
if (serial != null) {
104105
int[] location = getPlacement();
105106
String locationStr = PApplet.join(PApplet.str(location), ",");
@@ -110,4 +111,12 @@ public void close() throws Exception {
110111
}
111112
}
112113

114+
public void open() throws Exception {
115+
openSerial();
116+
}
117+
118+
public void close() throws Exception {
119+
closeSerial();
120+
}
121+
113122
}

0 commit comments

Comments
 (0)