mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +01:00
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)
This commit is contained in:
parent
e7d85d8b6d
commit
693498fb76
@ -1,6 +1,7 @@
|
||||
package processing.app;
|
||||
|
||||
import cc.arduino.packages.BoardPort;
|
||||
import cc.arduino.packages.DiscoveryManager;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
import javax.swing.*;
|
||||
@ -9,6 +10,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
@ -17,6 +19,7 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
|
||||
private StringBuffer updateBuffer;
|
||||
private Timer updateTimer;
|
||||
private Timer portExistsTimer;
|
||||
|
||||
private BoardPort boardPort;
|
||||
|
||||
@ -73,6 +76,26 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
updateTimer = new Timer(33, this); // redraw serial monitor at 30 Hz
|
||||
updateTimer.start();
|
||||
|
||||
ActionListener portExists = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
try {
|
||||
if (!Base.getDiscoveryManager().discovery().contains(boardPort)) {
|
||||
if (!closed) {
|
||||
suspend();
|
||||
}
|
||||
} else {
|
||||
if (closed) {
|
||||
resume(boardPort);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
};
|
||||
|
||||
portExistsTimer = new Timer(1000, portExists); // check if the port is still there every second
|
||||
portExistsTimer.start();
|
||||
|
||||
closed = false;
|
||||
}
|
||||
|
||||
@ -92,6 +115,11 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
close();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
portExistsTimer.stop();
|
||||
}
|
||||
|
||||
public void resume(BoardPort boardPort) throws Exception {
|
||||
setBoardPort(boardPort);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user