Skip to content

Commit ffa8720

Browse files
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.
1 parent b40f54a commit ffa8720

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

app/src/processing/app/AbstractTextMonitor.java

-5
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,9 @@ protected void onEnableWindow(boolean enable) {
190190
textArea.setBackground(new Color(238, 238, 238));
191191
}
192192
textArea.invalidate();
193-
clearButton.setEnabled(enable);
194193
scrollPane.setEnabled(enable);
195194
textField.setEnabled(enable);
196195
sendButton.setEnabled(enable);
197-
autoscrollBox.setEnabled(enable);
198-
addTimeStampBox.setEnabled(enable);
199-
lineEndings.setEnabled(enable);
200-
serialRates.setEnabled(enable);
201196
}
202197

203198
public void onSendCommand(ActionListener listener) {

app/src/processing/app/SerialMonitor.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ public SerialMonitor(BoardPort port) {
4848
String rateString = wholeString.substring(0, wholeString.indexOf(' '));
4949
serialRate = Integer.parseInt(rateString);
5050
PreferencesData.set("serial.debug_rate", rateString);
51-
try {
52-
close();
53-
Thread.sleep(100); // Wait for serial port to properly close
54-
open();
55-
} catch (InterruptedException e) {
56-
// noop
57-
} catch (Exception e) {
58-
System.err.println(e);
51+
if (serial != null) {
52+
try {
53+
close();
54+
Thread.sleep(100); // Wait for serial port to properly close
55+
open();
56+
} catch (InterruptedException e) {
57+
// noop
58+
} catch (Exception e) {
59+
System.err.println(e);
60+
}
5961
}
6062
});
6163

app/src/processing/app/SerialPlotter.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,14 @@ public SerialPlotter(BoardPort port) {
242242
String rateString = wholeString.substring(0, wholeString.indexOf(' '));
243243
serialRate = Integer.parseInt(rateString);
244244
PreferencesData.set("serial.debug_rate", rateString);
245-
try {
246-
close();
247-
Thread.sleep(100); // Wait for serial port to properly close
248-
open();
249-
} catch (Exception e) {
250-
// ignore
245+
if (serial != null) {
246+
try {
247+
close();
248+
Thread.sleep(100); // Wait for serial port to properly close
249+
open();
250+
} catch (Exception e) {
251+
// ignore
252+
}
251253
}
252254
});
253255

@@ -379,10 +381,8 @@ public void appyPreferences() {
379381
}
380382

381383
protected void onEnableWindow(boolean enable) {
382-
serialRates.setEnabled(enable);
383384
textField.setEnabled(enable);
384385
sendButton.setEnabled(enable);
385-
lineEndings.setEnabled(enable);
386386
}
387387

388388
private void onSerialRateChange(ActionListener listener) {

0 commit comments

Comments
 (0)