1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-01 21:52:12 +01:00

Allow config changes and clear in disabled serial monitor and plotter

When the serial device disconnects, the serial monitor and plotter are
disabled. Previously, the window would be completely disabled. Now, the
configuration controls (autoscroll, add timestamp, baudrate, line
endings) can still be changed while the window is disconnected. These
settings will not take effect immediately, but will be used when the
port is next opened.

Also, the clear output button can now also be used when the port is
disconnected, which makes it easy to get a clean start when reconnecting
the serial port.
This commit is contained in:
Matthijs Kooijman 2020-03-05 10:38:35 +01:00
parent b40f54af06
commit ffa8720114
3 changed files with 18 additions and 21 deletions

View File

@ -190,14 +190,9 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
textArea.setBackground(new Color(238, 238, 238)); textArea.setBackground(new Color(238, 238, 238));
} }
textArea.invalidate(); textArea.invalidate();
clearButton.setEnabled(enable);
scrollPane.setEnabled(enable); scrollPane.setEnabled(enable);
textField.setEnabled(enable); textField.setEnabled(enable);
sendButton.setEnabled(enable); sendButton.setEnabled(enable);
autoscrollBox.setEnabled(enable);
addTimeStampBox.setEnabled(enable);
lineEndings.setEnabled(enable);
serialRates.setEnabled(enable);
} }
public void onSendCommand(ActionListener listener) { public void onSendCommand(ActionListener listener) {

View File

@ -48,14 +48,16 @@ public class SerialMonitor extends AbstractTextMonitor {
String rateString = wholeString.substring(0, wholeString.indexOf(' ')); String rateString = wholeString.substring(0, wholeString.indexOf(' '));
serialRate = Integer.parseInt(rateString); serialRate = Integer.parseInt(rateString);
PreferencesData.set("serial.debug_rate", rateString); PreferencesData.set("serial.debug_rate", rateString);
try { if (serial != null) {
close(); try {
Thread.sleep(100); // Wait for serial port to properly close close();
open(); Thread.sleep(100); // Wait for serial port to properly close
} catch (InterruptedException e) { open();
// noop } catch (InterruptedException e) {
} catch (Exception e) { // noop
System.err.println(e); } catch (Exception e) {
System.err.println(e);
}
} }
}); });

View File

@ -242,12 +242,14 @@ public class SerialPlotter extends AbstractMonitor {
String rateString = wholeString.substring(0, wholeString.indexOf(' ')); String rateString = wholeString.substring(0, wholeString.indexOf(' '));
serialRate = Integer.parseInt(rateString); serialRate = Integer.parseInt(rateString);
PreferencesData.set("serial.debug_rate", rateString); PreferencesData.set("serial.debug_rate", rateString);
try { if (serial != null) {
close(); try {
Thread.sleep(100); // Wait for serial port to properly close close();
open(); Thread.sleep(100); // Wait for serial port to properly close
} catch (Exception e) { open();
// ignore } catch (Exception e) {
// ignore
}
} }
}); });
@ -379,10 +381,8 @@ public class SerialPlotter extends AbstractMonitor {
} }
protected void onEnableWindow(boolean enable) { protected void onEnableWindow(boolean enable) {
serialRates.setEnabled(enable);
textField.setEnabled(enable); textField.setEnabled(enable);
sendButton.setEnabled(enable); sendButton.setEnabled(enable);
lineEndings.setEnabled(enable);
} }
private void onSerialRateChange(ActionListener listener) { private void onSerialRateChange(ActionListener listener) {