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
|
||||||
|
@ -92,12 +95,14 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
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,6 +327,7 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
// KeyEvent.VK_SPACE);
|
// KeyEvent.VK_SPACE);
|
||||||
int c = event.getKeyChar();
|
int c = event.getKeyChar();
|
||||||
|
|
||||||
|
if (mode == EDIT) {
|
||||||
if (c == KeyEvent.VK_ENTER) { // accept the input
|
if (c == KeyEvent.VK_ENTER) { // accept the input
|
||||||
String answer = editField.getText();
|
String answer = editField.getText();
|
||||||
editor.sketch.nameCode(answer);
|
editor.sketch.nameCode(answer);
|
||||||
|
@ -368,6 +399,14 @@ public class EditorStatus extends JPanel implements ActionListener {
|
||||||
event.consume();
|
event.consume();
|
||||||
//System.out.println("code is " + code + " char = " + c);
|
//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("");
|
||||||
|
}
|
||||||
|
}
|
||||||
//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