Skip to content

Allow the serial monitor to stay opened during upload, disabling it (1.5.x) #2180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions app/src/processing/app/AbstractMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ public abstract class AbstractMonitor extends JFrame implements MessageConsumer
protected JCheckBox autoscrollBox;
protected JComboBox lineEndings;
protected JComboBox serialRates;
private boolean monitorEnabled;
private boolean closed;

public AbstractMonitor(String title) {
super(title);

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
try {
closed = true;
close();
} catch (Exception e) {
// ignore
Expand Down Expand Up @@ -148,6 +151,53 @@ public void actionPerformed(ActionEvent event) {
}
}
}

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) {
Expand Down Expand Up @@ -195,6 +245,10 @@ public String getAuthorizationKey() {
return null;
}

public boolean isClosed() {
return closed;
}

public abstract void open() throws Exception;

public abstract void close() throws Exception;
Expand Down
56 changes: 44 additions & 12 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2388,8 +2388,7 @@ public void run() {

try {
if (serialMonitor != null) {
serialMonitor.close();
serialMonitor.setVisible(false);
serialMonitor.suspend();
}

uploading = true;
Expand Down Expand Up @@ -2421,7 +2420,17 @@ public void run() {
uploading = false;
//toolbar.clear();
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)
Expand All @@ -2430,8 +2439,7 @@ public void run() {

try {
if (serialMonitor != null) {
serialMonitor.close();
serialMonitor.setVisible(false);
serialMonitor.suspend();
}

uploading = true;
Expand Down Expand Up @@ -2463,6 +2471,16 @@ public void run() {
uploading = false;
//toolbar.clear();
toolbar.deactivate(EditorToolbar.EXPORT);

if (serialMonitor != null) {
try {
if (serialMonitor != null)
serialMonitor.resume();
}
catch (SerialException e) {
statusError(e);
}
}
}
}

Expand Down Expand Up @@ -2502,14 +2520,23 @@ protected boolean handleExportCheckModified() {


public void handleSerial() {
if (uploading) return;

if (serialMonitor != null) {
try {
serialMonitor.close();
serialMonitor.setVisible(false);
} catch (Exception e) {
// noop
// The serial monitor already exists

if (serialMonitor.isClosed()) {
// If it's closed, clear the refrence to the existing
// 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
}
}
}

Expand All @@ -2523,6 +2550,11 @@ public void handleSerial() {
serialMonitor = new UploaderAndMonitorFactory().newMonitor(port, base);
serialMonitor.setIconImage(getIconImage());

// If currently uploading, disable the monitor (it will be later
// enabled when done uploading)
if (uploading)
serialMonitor.suspend();

boolean success = false;
do {
if (serialMonitor.requiresAuthorization() && !Preferences.has(serialMonitor.getAuthorizationKey())) {
Expand Down