Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 693498f

Browse files
committed
Handle suspend/resume if serial port disappears
Similar to minicom behaviour. Automatically reopens the port only if it takes the same name (could be improved based on vid/pid)
1 parent e7d85d8 commit 693498f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎app/src/processing/app/AbstractMonitor.java‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package processing.app;
22

33
import cc.arduino.packages.BoardPort;
4+
import cc.arduino.packages.DiscoveryManager;
45
import processing.app.legacy.PApplet;
56

67
import javax.swing.*;
@@ -9,6 +10,7 @@
910
import java.awt.event.ActionListener;
1011
import java.awt.event.WindowAdapter;
1112
import java.awt.event.WindowEvent;
13+
import java.util.List;
1214

1315
@SuppressWarnings("serial")
1416
public abstract class AbstractMonitor extends JFrame implements ActionListener {
@@ -17,6 +19,7 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
1719

1820
private StringBuffer updateBuffer;
1921
private Timer updateTimer;
22+
private Timer portExistsTimer;
2023

2124
private BoardPort boardPort;
2225

@@ -73,6 +76,26 @@ public void actionPerformed(ActionEvent event) {
7376
updateTimer = new Timer(33, this); // redraw serial monitor at 30 Hz
7477
updateTimer.start();
7578

79+
ActionListener portExists = new ActionListener() {
80+
@Override
81+
public void actionPerformed(ActionEvent ae) {
82+
try {
83+
if (!Base.getDiscoveryManager().discovery().contains(boardPort)) {
84+
if (!closed) {
85+
suspend();
86+
}
87+
} else {
88+
if (closed) {
89+
resume(boardPort);
90+
}
91+
}
92+
} catch (Exception e) {}
93+
}
94+
};
95+
96+
portExistsTimer = new Timer(1000, portExists); // check if the port is still there every second
97+
portExistsTimer.start();
98+
7699
closed = false;
77100
}
78101

@@ -92,6 +115,11 @@ public void suspend() throws Exception {
92115
close();
93116
}
94117

118+
public void dispose() {
119+
super.dispose();
120+
portExistsTimer.stop();
121+
}
122+
95123
public void resume(BoardPort boardPort) throws Exception {
96124
setBoardPort(boardPort);
97125

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /