MCPcopy
hub / github.com/arduino/Arduino / SerialMonitor

Method SerialMonitor

app/src/processing/app/SerialMonitor.java:41–101  ·  view source on GitHub ↗
(BoardPort port)

Source from the content-addressed store, hash-verified

39 new CommandHistory(COMMAND_HISTORY_SIZE);
40
41 public SerialMonitor(BoardPort port) {
42 super(port);
43
44 serialRate = PreferencesData.getInteger("serial.debug_rate");
45 serialRates.setSelectedItem(serialRate + " " + tr("baud"));
46 onSerialRateChange((ActionEvent event) -> {
47 String wholeString = (String) serialRates.getSelectedItem();
48 String rateString = wholeString.substring(0, wholeString.indexOf(' '));
49 serialRate = Integer.parseInt(rateString);
50 PreferencesData.set("serial.debug_rate", rateString);
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 }
61 }
62 });
63
64 onSendCommand((ActionEvent event) -> {
65 String command = textField.getText();
66 send(command);
67 commandHistory.addCommand(command);
68 textField.setText("");
69 });
70
71 onClearCommand((ActionEvent event) -> textArea.setText(""));
72
73 // Add key listener to UP, DOWN, ESC keys for command history traversal.
74 textField.addKeyListener(new KeyAdapter() {
75 @Override
76 public void keyPressed(KeyEvent e) {
77 switch (e.getKeyCode()) {
78
79 // Select previous command.
80 case KeyEvent.VK_UP:
81 if (commandHistory.hasPreviousCommand()) {
82 textField.setText(
83 commandHistory.getPreviousCommand(textField.getText()));
84 }
85 break;
86
87 // Select next command.
88 case KeyEvent.VK_DOWN:
89 if (commandHistory.hasNextCommand()) {
90 textField.setText(commandHistory.getNextCommand());
91 }
92 break;
93
94 // Reset history location, restoring the last unexecuted command.
95 case KeyEvent.VK_ESCAPE:
96 textField.setText(commandHistory.resetHistoryLocation());
97 break;
98 }

Callers

nothing calls this directly

Calls 15

getIntegerMethod · 0.95
setMethod · 0.95
closeMethod · 0.95
openMethod · 0.95
sendMethod · 0.95
trMethod · 0.80
parseIntMethod · 0.80
sleepMethod · 0.80
addCommandMethod · 0.80
onClearCommandMethod · 0.80
addKeyListenerMethod · 0.80
getTextMethod · 0.65

Tested by

no test coverage detected