mirror of https://github.com/noisymime/Arduino.git
Adding interface for serial communication from PC to Arduino board.
This commit is contained in:
parent
f6f4fe59c5
commit
77ecc6476c
|
@ -1399,6 +1399,7 @@ public class Editor extends JFrame
|
||||||
buttons.activate(EditorButtons.SERIAL);
|
buttons.activate(EditorButtons.SERIAL);
|
||||||
serialPort = new Serial(true);
|
serialPort = new Serial(true);
|
||||||
debugging = true;
|
debugging = true;
|
||||||
|
status.serial("Serial message:");
|
||||||
} else {
|
} else {
|
||||||
doStop();
|
doStop();
|
||||||
}
|
}
|
||||||
|
@ -1421,6 +1422,7 @@ public class Editor extends JFrame
|
||||||
public void doStop() {
|
public void doStop() {
|
||||||
//if (runtime != null) runtime.stop();
|
//if (runtime != null) runtime.stop();
|
||||||
if (debugging) {
|
if (debugging) {
|
||||||
|
status.unserial();
|
||||||
serialPort.dispose();
|
serialPort.dispose();
|
||||||
debugging = false;
|
debugging = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,13 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
static final int ERR = 1;
|
static final int ERR = 1;
|
||||||
static final int PROMPT = 2;
|
static final int PROMPT = 2;
|
||||||
static final int EDIT = 3;
|
static final int EDIT = 3;
|
||||||
|
static final int SERIAL = 4;
|
||||||
|
|
||||||
static final int YES = 1;
|
static final int YES = 1;
|
||||||
static final int NO = 2;
|
static final int NO = 2;
|
||||||
static final int CANCEL = 3;
|
static final int CANCEL = 3;
|
||||||
static final int OK = 4;
|
static final int OK = 4;
|
||||||
|
static final int SEND = 5;
|
||||||
|
|
||||||
static final String NO_MESSAGE = "";
|
static final String NO_MESSAGE = "";
|
||||||
|
|
||||||
|
@ -64,6 +66,7 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
JButton noButton;
|
JButton noButton;
|
||||||
JButton cancelButton;
|
JButton cancelButton;
|
||||||
JButton okButton;
|
JButton okButton;
|
||||||
|
JButton sendButton;
|
||||||
JTextField editField;
|
JTextField editField;
|
||||||
|
|
||||||
//Thread promptThread;
|
//Thread promptThread;
|
||||||
|
@ -75,7 +78,7 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
empty();
|
empty();
|
||||||
|
|
||||||
if (bgcolor == null) {
|
if (bgcolor == null) {
|
||||||
bgcolor = new Color[4];
|
bgcolor = new Color[5];
|
||||||
// Arduino 0003 switched to a blue color scheme to visually distinguish
|
// Arduino 0003 switched to a blue color scheme to visually distinguish
|
||||||
// itself from Processing. Because the image files for certain interface
|
// itself from Processing. Because the image files for certain interface
|
||||||
// elements (e.g. buttons and tabs) are distributed with the application
|
// elements (e.g. buttons and tabs) are distributed with the application
|
||||||
|
@ -88,16 +91,18 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
// however, it obviates the need to provide for version-specific
|
// however, it obviates the need to provide for version-specific
|
||||||
// preferences.
|
// preferences.
|
||||||
//bgcolor[0] = Preferences.getColor("status.notice.bgcolor");
|
//bgcolor[0] = Preferences.getColor("status.notice.bgcolor");
|
||||||
bgcolor[0] = new Color(0x54, 0x91, 0x9e);
|
bgcolor[0] = new Color(0x54, 0x91, 0x9e);
|
||||||
bgcolor[1] = Preferences.getColor("status.error.bgcolor");
|
bgcolor[1] = Preferences.getColor("status.error.bgcolor");
|
||||||
bgcolor[2] = Preferences.getColor("status.prompt.bgcolor");
|
bgcolor[2] = Preferences.getColor("status.prompt.bgcolor");
|
||||||
bgcolor[3] = Preferences.getColor("status.prompt.bgcolor");
|
bgcolor[3] = Preferences.getColor("status.prompt.bgcolor");
|
||||||
|
bgcolor[4] = new Color(0x54, 0x91, 0x9e);
|
||||||
|
|
||||||
fgcolor = new Color[4];
|
fgcolor = new Color[5];
|
||||||
fgcolor[0] = Preferences.getColor("status.notice.fgcolor");
|
fgcolor[0] = Preferences.getColor("status.notice.fgcolor");
|
||||||
fgcolor[1] = Preferences.getColor("status.error.fgcolor");
|
fgcolor[1] = Preferences.getColor("status.error.fgcolor");
|
||||||
fgcolor[2] = Preferences.getColor("status.prompt.fgcolor");
|
fgcolor[2] = Preferences.getColor("status.prompt.fgcolor");
|
||||||
fgcolor[3] = Preferences.getColor("status.prompt.fgcolor");
|
fgcolor[3] = Preferences.getColor("status.prompt.fgcolor");
|
||||||
|
fgcolor[4] = Preferences.getColor("status.notice.fgcolor");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +179,26 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
empty();
|
empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void serial(String message)
|
||||||
|
{
|
||||||
|
mode = SERIAL;
|
||||||
|
this.message = message;
|
||||||
|
|
||||||
|
sendButton.setVisible(true);
|
||||||
|
editField.setVisible(true);
|
||||||
|
editField.setText("");
|
||||||
|
editField.requestFocus();
|
||||||
|
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unserial()
|
||||||
|
{
|
||||||
|
sendButton.setVisible(false);
|
||||||
|
editField.setVisible(false);
|
||||||
|
empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public void update() {
|
public void update() {
|
||||||
|
@ -249,6 +274,7 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
noButton = new JButton(Preferences.PROMPT_NO);
|
noButton = new JButton(Preferences.PROMPT_NO);
|
||||||
cancelButton = new JButton(Preferences.PROMPT_CANCEL);
|
cancelButton = new JButton(Preferences.PROMPT_CANCEL);
|
||||||
okButton = new JButton(Preferences.PROMPT_OK);
|
okButton = new JButton(Preferences.PROMPT_OK);
|
||||||
|
sendButton = new JButton(Preferences.PROMPT_SEND);
|
||||||
|
|
||||||
// !@#(* aqua ui #($*(( that turtle-neck wearing #(** (#$@)(
|
// !@#(* aqua ui #($*(( that turtle-neck wearing #(** (#$@)(
|
||||||
// os9 seems to work if bg of component is set, but x still a bastard
|
// os9 seems to work if bg of component is set, but x still a bastard
|
||||||
|
@ -257,6 +283,7 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
noButton.setBackground(bgcolor[PROMPT]);
|
noButton.setBackground(bgcolor[PROMPT]);
|
||||||
cancelButton.setBackground(bgcolor[PROMPT]);
|
cancelButton.setBackground(bgcolor[PROMPT]);
|
||||||
okButton.setBackground(bgcolor[PROMPT]);
|
okButton.setBackground(bgcolor[PROMPT]);
|
||||||
|
sendButton.setBackground(bgcolor[SERIAL]);
|
||||||
}
|
}
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
|
|
||||||
|
@ -264,16 +291,19 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
noButton.addActionListener(this);
|
noButton.addActionListener(this);
|
||||||
cancelButton.addActionListener(this);
|
cancelButton.addActionListener(this);
|
||||||
okButton.addActionListener(this);
|
okButton.addActionListener(this);
|
||||||
|
sendButton.addActionListener(this);
|
||||||
|
|
||||||
add(yesButton);
|
add(yesButton);
|
||||||
add(noButton);
|
add(noButton);
|
||||||
add(cancelButton);
|
add(cancelButton);
|
||||||
add(okButton);
|
add(okButton);
|
||||||
|
add(sendButton);
|
||||||
|
|
||||||
yesButton.setVisible(false);
|
yesButton.setVisible(false);
|
||||||
noButton.setVisible(false);
|
noButton.setVisible(false);
|
||||||
cancelButton.setVisible(false);
|
cancelButton.setVisible(false);
|
||||||
okButton.setVisible(false);
|
okButton.setVisible(false);
|
||||||
|
sendButton.setVisible(false);
|
||||||
|
|
||||||
editField = new JTextField();
|
editField = new JTextField();
|
||||||
editField.addActionListener(this);
|
editField.addActionListener(this);
|
||||||
|
@ -297,76 +327,85 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
// KeyEvent.VK_SPACE);
|
// KeyEvent.VK_SPACE);
|
||||||
int c = event.getKeyChar();
|
int c = event.getKeyChar();
|
||||||
|
|
||||||
if (c == KeyEvent.VK_ENTER) { // accept the input
|
if (mode == EDIT) {
|
||||||
String answer = editField.getText();
|
if (c == KeyEvent.VK_ENTER) { // accept the input
|
||||||
editor.sketch.nameCode(answer);
|
String answer = editField.getText();
|
||||||
unedit();
|
editor.sketch.nameCode(answer);
|
||||||
event.consume();
|
unedit();
|
||||||
|
|
||||||
// easier to test the affirmative case than the negative
|
|
||||||
} else if ((c == KeyEvent.VK_BACK_SPACE) ||
|
|
||||||
(c == KeyEvent.VK_DELETE) ||
|
|
||||||
(c == KeyEvent.VK_RIGHT) ||
|
|
||||||
(c == KeyEvent.VK_LEFT) ||
|
|
||||||
(c == KeyEvent.VK_UP) ||
|
|
||||||
(c == KeyEvent.VK_DOWN) ||
|
|
||||||
(c == KeyEvent.VK_HOME) ||
|
|
||||||
(c == KeyEvent.VK_END) ||
|
|
||||||
(c == KeyEvent.VK_SHIFT)) {
|
|
||||||
//System.out.println("nothing to see here");
|
|
||||||
//noop();
|
|
||||||
|
|
||||||
} else if (c == KeyEvent.VK_ESCAPE) {
|
|
||||||
unedit();
|
|
||||||
editor.buttons.clear();
|
|
||||||
event.consume();
|
|
||||||
|
|
||||||
} else if (c == KeyEvent.VK_SPACE) {
|
|
||||||
//System.out.println("got a space");
|
|
||||||
// if a space, insert an underscore
|
|
||||||
//editField.insert("_", editField.getCaretPosition());
|
|
||||||
/* tried to play nice and see where it got me
|
|
||||||
editField.dispatchEvent(new KeyEvent(editField,
|
|
||||||
KeyEvent.KEY_PRESSED,
|
|
||||||
System.currentTimeMillis(),
|
|
||||||
0, 45, '_'));
|
|
||||||
*/
|
|
||||||
//System.out.println("start/end = " +
|
|
||||||
// editField.getSelectionStart() + " " +
|
|
||||||
// editField.getSelectionEnd());
|
|
||||||
String t = editField.getText();
|
|
||||||
//int p = editField.getCaretPosition();
|
|
||||||
//editField.setText(t.substring(0, p) + "_" + t.substring(p));
|
|
||||||
//editField.setCaretPosition(p+1);
|
|
||||||
int start = editField.getSelectionStart();
|
|
||||||
int end = editField.getSelectionEnd();
|
|
||||||
editField.setText(t.substring(0, start) + "_" +
|
|
||||||
t.substring(end));
|
|
||||||
editField.setCaretPosition(start+1);
|
|
||||||
//System.out.println("consuming event");
|
|
||||||
event.consume();
|
|
||||||
|
|
||||||
} else if ((c == '_') || (c == '.') || // allow .pde and .java
|
|
||||||
((c >= 'A') && (c <= 'Z')) ||
|
|
||||||
((c >= 'a') && (c <= 'z'))) {
|
|
||||||
// everything fine, catches upper and lower
|
|
||||||
//noop();
|
|
||||||
|
|
||||||
} else if ((c >= '0') && (c <= '9')) {
|
|
||||||
// getCaretPosition == 0 means that it's the first char
|
|
||||||
// and the field is empty.
|
|
||||||
// getSelectionStart means that it *will be* the first
|
|
||||||
// char, because the selection is about to be replaced
|
|
||||||
// with whatever is typed.
|
|
||||||
if ((editField.getCaretPosition() == 0) ||
|
|
||||||
(editField.getSelectionStart() == 0)) {
|
|
||||||
// number not allowed as first digit
|
|
||||||
//System.out.println("bad number bad");
|
|
||||||
event.consume();
|
event.consume();
|
||||||
|
|
||||||
|
// easier to test the affirmative case than the negative
|
||||||
|
} else if ((c == KeyEvent.VK_BACK_SPACE) ||
|
||||||
|
(c == KeyEvent.VK_DELETE) ||
|
||||||
|
(c == KeyEvent.VK_RIGHT) ||
|
||||||
|
(c == KeyEvent.VK_LEFT) ||
|
||||||
|
(c == KeyEvent.VK_UP) ||
|
||||||
|
(c == KeyEvent.VK_DOWN) ||
|
||||||
|
(c == KeyEvent.VK_HOME) ||
|
||||||
|
(c == KeyEvent.VK_END) ||
|
||||||
|
(c == KeyEvent.VK_SHIFT)) {
|
||||||
|
//System.out.println("nothing to see here");
|
||||||
|
//noop();
|
||||||
|
|
||||||
|
} else if (c == KeyEvent.VK_ESCAPE) {
|
||||||
|
unedit();
|
||||||
|
editor.buttons.clear();
|
||||||
|
event.consume();
|
||||||
|
|
||||||
|
} else if (c == KeyEvent.VK_SPACE) {
|
||||||
|
//System.out.println("got a space");
|
||||||
|
// if a space, insert an underscore
|
||||||
|
//editField.insert("_", editField.getCaretPosition());
|
||||||
|
/* tried to play nice and see where it got me
|
||||||
|
editField.dispatchEvent(new KeyEvent(editField,
|
||||||
|
KeyEvent.KEY_PRESSED,
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
0, 45, '_'));
|
||||||
|
*/
|
||||||
|
//System.out.println("start/end = " +
|
||||||
|
// editField.getSelectionStart() + " " +
|
||||||
|
// editField.getSelectionEnd());
|
||||||
|
String t = editField.getText();
|
||||||
|
//int p = editField.getCaretPosition();
|
||||||
|
//editField.setText(t.substring(0, p) + "_" + t.substring(p));
|
||||||
|
//editField.setCaretPosition(p+1);
|
||||||
|
int start = editField.getSelectionStart();
|
||||||
|
int end = editField.getSelectionEnd();
|
||||||
|
editField.setText(t.substring(0, start) + "_" +
|
||||||
|
t.substring(end));
|
||||||
|
editField.setCaretPosition(start+1);
|
||||||
|
//System.out.println("consuming event");
|
||||||
|
event.consume();
|
||||||
|
|
||||||
|
} else if ((c == '_') || (c == '.') || // allow .pde and .java
|
||||||
|
((c >= 'A') && (c <= 'Z')) ||
|
||||||
|
((c >= 'a') && (c <= 'z'))) {
|
||||||
|
// everything fine, catches upper and lower
|
||||||
|
//noop();
|
||||||
|
|
||||||
|
} else if ((c >= '0') && (c <= '9')) {
|
||||||
|
// getCaretPosition == 0 means that it's the first char
|
||||||
|
// and the field is empty.
|
||||||
|
// getSelectionStart means that it *will be* the first
|
||||||
|
// char, because the selection is about to be replaced
|
||||||
|
// with whatever is typed.
|
||||||
|
if ((editField.getCaretPosition() == 0) ||
|
||||||
|
(editField.getSelectionStart() == 0)) {
|
||||||
|
// number not allowed as first digit
|
||||||
|
//System.out.println("bad number bad");
|
||||||
|
event.consume();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
event.consume();
|
||||||
|
//System.out.println("code is " + code + " char = " + c);
|
||||||
|
}
|
||||||
|
} else { // mode != EDIT (i.e. mode == SERIAL)
|
||||||
|
if (c == KeyEvent.VK_ENTER) { // accept the input
|
||||||
|
String answer = editField.getText();
|
||||||
|
editor.serialPort.write(answer + "\n");
|
||||||
|
event.consume();
|
||||||
|
editField.setText("");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
event.consume();
|
|
||||||
//System.out.println("code is " + code + " char = " + c);
|
|
||||||
}
|
}
|
||||||
//System.out.println("code is " + code + " char = " + c);
|
//System.out.println("code is " + code + " char = " + c);
|
||||||
}
|
}
|
||||||
|
@ -390,11 +429,13 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
cancelButton.setLocation(cancelLeft, top);
|
cancelButton.setLocation(cancelLeft, top);
|
||||||
editField.setLocation(yesLeft - Preferences.BUTTON_WIDTH, top);
|
editField.setLocation(yesLeft - Preferences.BUTTON_WIDTH, top);
|
||||||
okButton.setLocation(noLeft, top);
|
okButton.setLocation(noLeft, top);
|
||||||
|
sendButton.setLocation(cancelLeft, top);
|
||||||
|
|
||||||
yesButton.setSize( Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
|
yesButton.setSize( Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
|
||||||
noButton.setSize( Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
|
noButton.setSize( Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
|
||||||
cancelButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
|
cancelButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
|
||||||
okButton.setSize( Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
|
okButton.setSize( Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
|
||||||
|
sendButton.setSize( Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
|
||||||
editField.setSize( 2*Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
|
editField.setSize( 2*Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,6 +478,9 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
//editor.handleSaveAs2(answer);
|
//editor.handleSaveAs2(answer);
|
||||||
editor.sketch.nameCode(answer);
|
editor.sketch.nameCode(answer);
|
||||||
unedit();
|
unedit();
|
||||||
|
} else if (e.getSource() == sendButton) {
|
||||||
|
editor.serialPort.write(editField.getText());
|
||||||
|
editField.setText("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,7 @@ public class Preferences {
|
||||||
static final String PROMPT_NO = "No";
|
static final String PROMPT_NO = "No";
|
||||||
static final String PROMPT_CANCEL = "Cancel";
|
static final String PROMPT_CANCEL = "Cancel";
|
||||||
static final String PROMPT_OK = "OK";
|
static final String PROMPT_OK = "OK";
|
||||||
|
static final String PROMPT_SEND = "Send";
|
||||||
static final String PROMPT_BROWSE = "Browse";
|
static final String PROMPT_BROWSE = "Browse";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue