mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
Allow the serial monitor to stay opened during upload, disabling it
This commit is contained in:
parent
94b16a550e
commit
f48df59b8a
@ -44,6 +44,8 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
|||||||
protected JCheckBox autoscrollBox;
|
protected JCheckBox autoscrollBox;
|
||||||
protected JComboBox lineEndings;
|
protected JComboBox lineEndings;
|
||||||
protected JComboBox serialRates;
|
protected JComboBox serialRates;
|
||||||
|
private boolean monitorEnabled;
|
||||||
|
private boolean closed;
|
||||||
|
|
||||||
private Timer updateTimer;
|
private Timer updateTimer;
|
||||||
private StringBuffer updateBuffer;
|
private StringBuffer updateBuffer;
|
||||||
@ -54,6 +56,7 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
|||||||
addWindowListener(new WindowAdapter() {
|
addWindowListener(new WindowAdapter() {
|
||||||
public void windowClosing(WindowEvent event) {
|
public void windowClosing(WindowEvent event) {
|
||||||
try {
|
try {
|
||||||
|
closed = true;
|
||||||
close();
|
close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore
|
// ignore
|
||||||
@ -177,6 +180,53 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
|||||||
updateBuffer = new StringBuffer(1048576);
|
updateBuffer = new StringBuffer(1048576);
|
||||||
updateTimer = new Timer(33, this); // redraw serial monitor at 30 Hz
|
updateTimer = new Timer(33, this); // redraw serial monitor at 30 Hz
|
||||||
updateTimer.start();
|
updateTimer.start();
|
||||||
|
|
||||||
|
monitorEnabled = true;
|
||||||
|
closed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableWindow(boolean enable)
|
||||||
|
{
|
||||||
|
textArea.setEnabled(enable);
|
||||||
|
scrollPane.setEnabled(enable);
|
||||||
|
textField.setEnabled(enable);
|
||||||
|
sendButton.setEnabled(enable);
|
||||||
|
autoscrollBox.setEnabled(enable);
|
||||||
|
lineEndings.setEnabled(enable);
|
||||||
|
serialRates.setEnabled(enable);
|
||||||
|
|
||||||
|
monitorEnabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Puts the window in suspend state, closing the serial port
|
||||||
|
// to allow other entity (the programmer) to use it
|
||||||
|
public void suspend()
|
||||||
|
{
|
||||||
|
enableWindow(false);
|
||||||
|
|
||||||
|
try {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
//throw new SerialException("Failed closing the port");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resume() throws SerialException
|
||||||
|
{
|
||||||
|
// Enable the window
|
||||||
|
enableWindow(true);
|
||||||
|
|
||||||
|
// If the window is visible, try to open the serial port
|
||||||
|
if (isVisible())
|
||||||
|
try {
|
||||||
|
open();
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
throw new SerialException("Failed opening the port");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSerialRateChange(ActionListener listener) {
|
public void onSerialRateChange(ActionListener listener) {
|
||||||
@ -224,6 +274,10 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isClosed() {
|
||||||
|
return closed;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void open() throws Exception;
|
public abstract void open() throws Exception;
|
||||||
|
|
||||||
public abstract void close() throws Exception;
|
public abstract void close() throws Exception;
|
||||||
|
@ -2517,8 +2517,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (serialMonitor != null) {
|
if (serialMonitor != null) {
|
||||||
serialMonitor.close();
|
serialMonitor.suspend();
|
||||||
serialMonitor.setVisible(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uploading = true;
|
uploading = true;
|
||||||
@ -2550,7 +2549,17 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
uploading = false;
|
uploading = false;
|
||||||
//toolbar.clear();
|
//toolbar.clear();
|
||||||
toolbar.deactivate(EditorToolbar.EXPORT);
|
toolbar.deactivate(EditorToolbar.EXPORT);
|
||||||
}
|
|
||||||
|
// Return the serial monitor window to its initial state
|
||||||
|
try {
|
||||||
|
if (serialMonitor != null)
|
||||||
|
serialMonitor.resume();
|
||||||
|
}
|
||||||
|
catch (SerialException e) {
|
||||||
|
statusError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DAM: in Arduino, this is upload (with verbose output)
|
// DAM: in Arduino, this is upload (with verbose output)
|
||||||
@ -2559,8 +2568,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (serialMonitor != null) {
|
if (serialMonitor != null) {
|
||||||
serialMonitor.close();
|
serialMonitor.suspend();
|
||||||
serialMonitor.setVisible(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uploading = true;
|
uploading = true;
|
||||||
@ -2592,6 +2600,16 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
uploading = false;
|
uploading = false;
|
||||||
//toolbar.clear();
|
//toolbar.clear();
|
||||||
toolbar.deactivate(EditorToolbar.EXPORT);
|
toolbar.deactivate(EditorToolbar.EXPORT);
|
||||||
|
|
||||||
|
if (serialMonitor != null) {
|
||||||
|
try {
|
||||||
|
if (serialMonitor != null)
|
||||||
|
serialMonitor.resume();
|
||||||
|
}
|
||||||
|
catch (SerialException e) {
|
||||||
|
statusError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2631,14 +2649,23 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
|
|
||||||
|
|
||||||
public void handleSerial() {
|
public void handleSerial() {
|
||||||
if (uploading) return;
|
|
||||||
|
|
||||||
if (serialMonitor != null) {
|
if (serialMonitor != null) {
|
||||||
try {
|
// The serial monitor already exists
|
||||||
serialMonitor.close();
|
|
||||||
serialMonitor.setVisible(false);
|
if (serialMonitor.isClosed()) {
|
||||||
} catch (Exception e) {
|
// If it's closed, clear the refrence to the existing
|
||||||
// noop
|
// monitor and create a new one
|
||||||
|
serialMonitor = null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// If it's not closed, give it the focus
|
||||||
|
try {
|
||||||
|
serialMonitor.toFront();
|
||||||
|
serialMonitor.requestFocus();
|
||||||
|
return;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// noop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2652,6 +2679,11 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
serialMonitor = new MonitorFactory().newMonitor(port);
|
serialMonitor = new MonitorFactory().newMonitor(port);
|
||||||
serialMonitor.setIconImage(getIconImage());
|
serialMonitor.setIconImage(getIconImage());
|
||||||
|
|
||||||
|
// If currently uploading, disable the monitor (it will be later
|
||||||
|
// enabled when done uploading)
|
||||||
|
if (uploading)
|
||||||
|
serialMonitor.suspend();
|
||||||
|
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
do {
|
do {
|
||||||
if (serialMonitor.requiresAuthorization() && !PreferencesData.has(serialMonitor.getAuthorizationKey())) {
|
if (serialMonitor.requiresAuthorization() && !PreferencesData.has(serialMonitor.getAuthorizationKey())) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user