diff --git a/pom.xml b/pom.xml
index 7ff0841..f592f5b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
info.istlab.IoTP
IoTP
jar
- 0.32
+ 0.33
IoTP
http://maven.apache.org
diff --git a/src/main/java/info/istlab/IoTP/Editor.java b/src/main/java/info/istlab/IoTP/Editor.java
index 3df323d..9dc910b 100644
--- a/src/main/java/info/istlab/IoTP/Editor.java
+++ b/src/main/java/info/istlab/IoTP/Editor.java
@@ -93,7 +93,7 @@
saveB = new JButton("Save");
saveB.addActionListener(this);
saveB.setEnabled(false);
- saveB.setToolTipText("保存");
+ saveB.setToolTipText("保存 (CTRL+S)");
// ファイルの拡張子によって、きりかえる
if (file.getName().endsWith(".ino")) {
@@ -123,7 +123,7 @@
} else if (textArea.getSyntaxEditingStyle() == SyntaxConstants.SYNTAX_STYLE_C) {
// compileB = new JButton("Compile");
execB = new JButton("Upload");
- execB.setToolTipText("コンパイルと書き込み");
+ execB.setToolTipText("コンパイルと書き込み (CTRL+U)");
// compileB.addActionListener(this);
execB.addActionListener(this);
// topP.add(compileB);
@@ -151,6 +151,8 @@
// topP.add(comlineOption);
}
fixIndentB = new JButton("インデント調整");
+ fixIndentB.setToolTipText("ソースコードの自動フォーマット (CTRL+F or CTRL+T)");
+
topP.add(fixIndentB);
fixIndentB.addActionListener(e -> fixIndent());
getContentPane().add(topP, BorderLayout.NORTH);
@@ -254,10 +256,14 @@
if (e.getKeyCode() == 83) { // Save
save();
}
+ if (e.getKeyCode() == 85) { // Upload
+ save();
+ new ScriptRunner("Upload", file.getName()).startstop();
+ }
if (e.getKeyCode() == 87) { // W (Close)
setVisible(false);
}
- if (e.getKeyCode() == 70) { // F (format)
+ if (e.getKeyCode() == 70 || e.getKeyCode() == 84) { // F (format:70) or T(84)
fixIndent();
}
}
diff --git a/src/main/java/info/istlab/IoTP/JTAConsole.java b/src/main/java/info/istlab/IoTP/JTAConsole.java
index a324c17..262a94c 100644
--- a/src/main/java/info/istlab/IoTP/JTAConsole.java
+++ b/src/main/java/info/istlab/IoTP/JTAConsole.java
@@ -319,6 +319,10 @@
}
}
+ public void closeWin() {
+ frame.dispose();
+ }
+
// public void setMainSrcByFileName(String absolutePath) {
// File f = new File(absolutePath);
// mainSrc = Editor.loadFile(f);
diff --git a/src/main/java/info/istlab/IoTP/Launcher.java b/src/main/java/info/istlab/IoTP/Launcher.java
index aa42f36..a643438 100644
--- a/src/main/java/info/istlab/IoTP/Launcher.java
+++ b/src/main/java/info/istlab/IoTP/Launcher.java
@@ -26,12 +26,13 @@
public class Launcher extends JFrame implements MouseInputListener, KeyListener, Runnable {
public static Launcher theapp;
- public static String version = "0.32";
+ public static String version = "0.33";
static int reboot_msec = 2000;
// JPanel mainP;
File root;
JTree tree;
Hashtable file2editor;
+ SerialChecker serialChecker;
public static ArrayList allProcs = new ArrayList();
@@ -152,6 +153,9 @@
// getContentPane().add(mainP, BorderLayout.WEST);
setSize(310, 600);
setLocation(SerialWindow.leftOfScreen(getSize()));
+
+ serialChecker = new SerialChecker(this);
+
}
public void renameOrDeleteNWPFolder() {
@@ -353,4 +357,9 @@
System.exit(0);
}
+ public void updateTitle(String string) {
+ setTitle("IoTP Launcher v" + version + " "+string);
+ }
+
+
}
diff --git a/src/main/java/info/istlab/IoTP/ScriptRunner.java b/src/main/java/info/istlab/IoTP/ScriptRunner.java
index e48018e..7f76250 100644
--- a/src/main/java/info/istlab/IoTP/ScriptRunner.java
+++ b/src/main/java/info/istlab/IoTP/ScriptRunner.java
@@ -54,18 +54,24 @@
comlist.add(App.serialName);
} else {
comlist.add("bash");
+ // comlist.add("-l");
comlist.add(scriptfile);
if (srcfile != null && srcfile.length() > 0)
comlist.add(srcfile);
}
- // シリアルコンソールを閉じる
- if (App.serialName != null) {
- SerialWindow swin = SerialWindow.hash.get(App.serialName);
+ // シリアルコンソールをすべて閉じる
+ for(String key : SerialWindow.hash.keySet()){
+ SerialWindow swin = SerialWindow.hash.get(key);
if (swin != null) {
- swin.closeSerialPort();
+ swin.closeSerialPort(null);
}
}
+ // 既存のコンソールをすべて閉じる
+ while (!JTAConsole.winStack.isEmpty()){
+ JTAConsole jcon = JTAConsole.winStack.pop();
+ jcon.closeWin();
+ }
}
@Override
@@ -111,6 +117,7 @@
thread = null;
// runB.setText("Run");
if (scriptfile_base.startsWith("Upload")){
+ SerialWindow.disposeAll();
SerialWindow.invoke(false); // no serial connectionsのとき、メッセージ表示しない
}
if (App.isWindows) {
diff --git a/src/main/java/info/istlab/IoTP/SerialChecker.java b/src/main/java/info/istlab/IoTP/SerialChecker.java
new file mode 100644
index 0000000..2083d0e
--- /dev/null
+++ b/src/main/java/info/istlab/IoTP/SerialChecker.java
@@ -0,0 +1,61 @@
+package info.istlab.IoTP;
+
+import com.fazecast.jSerialComm.SerialPort;
+
+public class SerialChecker implements Runnable {
+
+ Launcher launcher;
+ Thread thread;
+ String last_connections;
+
+ public SerialChecker(Launcher _launcher) {
+ launcher = _launcher;
+ last_connections = "";
+ thread = new Thread(this);
+ thread.start();
+
+ }
+
+ @Override
+ public void run() {
+ while (thread != null) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ update_menu();
+ }
+ }
+
+ void update_menu() {
+ SerialPort[] ports = SerialPort.getCommPorts();
+ StringBuffer sb = new StringBuffer();
+ for (SerialPort sp : ports) {
+ String name = sp.getSystemPortName();
+ if (name.startsWith("cu.usbserial") || name.startsWith("COM")) {
+ sb.append(name+" ");
+ }
+ }
+
+ // check if state changed
+ if (!last_connections.equals(sb.toString())) {
+ System.out.println("Serial state changed");
+ System.out.println(sb.toString());
+ launcher.updateTitle(sb.toString());
+
+ if (last_connections.length() > sb.length()){
+ SerialWindow.closeAll("切断されました");
+ } else {
+ String key = sb.toString().trim();
+ if (SerialWindow.hash.get(key)!= null){
+ SerialWindow.hash.get(key).reconnect();
+ }
+ }
+ }
+
+ last_connections = sb.toString();
+
+ }
+
+}
diff --git a/src/main/java/info/istlab/IoTP/SerialWindow.java b/src/main/java/info/istlab/IoTP/SerialWindow.java
index 003f244..8fb74a0 100644
--- a/src/main/java/info/istlab/IoTP/SerialWindow.java
+++ b/src/main/java/info/istlab/IoTP/SerialWindow.java
@@ -51,6 +51,7 @@
if (splist_valid.size()==1){
SerialPort sp = splist_valid.get(0);
App.serialName = sp.getSystemPortName();
+
} else if (splist_valid.size()==0){
if (popup_if_zero) JOptionPane.showMessageDialog(Launcher.theapp, "No available serial ports.");
} else {
@@ -70,7 +71,6 @@
if (splist_valid.size()==1){
SerialPort sp = splist_valid.get(0);
SerialWindow sw = new SerialWindow(sp);
- hash.put(sp.getSystemPortName(), sw);
} else if (splist_valid.size()==0){
JOptionPane.showMessageDialog(Launcher.theapp, "No available serial ports.");
} else {
@@ -89,6 +89,7 @@
System.out.println("Unable to open the port.");
return;
}
+ hash.put(sp.getSystemPortName(), this);
jtf = new JTextField("(ここをクリックして、入力して、Enterを押すと、シリアル送信します)");
jtf.setForeground(Color.GRAY);
@@ -130,10 +131,17 @@
//フォーカスをあえて外す
jta.requestFocus();
}
+ /**
+ * 再接続
+ */
+ public void reconnect() {
+ sp.openPort();
+ jta.setBackground(Color.white);
+ }
@Override
public int getListeningEvents() {
- return SerialPort.LISTENING_EVENT_DATA_AVAILABLE;
+ return SerialPort.LISTENING_EVENT_DATA_AVAILABLE | SerialPort.LISTENING_EVENT_PORT_DISCONNECTED;
}
@Override
@@ -148,18 +156,22 @@
int bytesToRead = sp.bytesAvailable();
if (bytesToRead == -1) {
System.out.println("-1 means port is closed.");
- closeSerialPort();
+ closeSerialPort("切断されました");
return;
}
byte[] newData = new byte[bytesToRead];
sp.readBytes(newData, bytesToRead);
String s = new String(newData, "UTF8");
appendToJTA(s);
+ } else if (evt == SerialPort.LISTENING_EVENT_PORT_DISCONNECTED){
+ System.out.println("Port disconnected.");
+ // System.out.println(event.toString());
+ SerialWindow.closeAll("切断されました");
}
} catch (Exception ex) {
System.err.println(ex.getMessage());
- closeSerialPort();
+ closeSerialPort("切断されました");
}
}
@@ -167,7 +179,7 @@
if (jta == null)
return;
if (s.contains("waiting for download")) {
- closeSerialPort(); //切断のみ。再接続はしない
+ closeSerialPort(null); //切断のみ。再接続はしない
}
jta.append(s);
int len = jta.getDocument().getLength();
@@ -175,12 +187,14 @@
jta.setCaretPosition(len);
}
- void closeSerialPort() {
+ void closeSerialPort(String mes) {
if (sp != null) {
if (sp.isOpen()) {
System.out.println("close Serial Port");
sp.closePort();
jta.setBackground(Color.lightGray);
+ if (mes == null) appendToJTA("Uploadに備えて、切断しました。");
+ else appendToJTA(mes);
// thread = new Thread(this);
// thread.start();
}
@@ -246,12 +260,12 @@
@Override
public void windowClosing(WindowEvent e) {
- closeSerialPort();
+ closeSerialPort(null);
}
@Override
public void windowClosed(WindowEvent e) {
- closeSerialPort();
+ closeSerialPort(null);
}
@Override
@@ -269,4 +283,24 @@
@Override
public void windowDeactivated(WindowEvent e) {
}
+
+ public static void disposeAll() {
+ for(String key : SerialWindow.hash.keySet()){
+ SerialWindow swin = SerialWindow.hash.get(key);
+ if (swin != null) {
+ swin.dispose();
+ }
+ }
+ SerialWindow.hash.clear();
+ }
+ public static void closeAll(String mes) {
+ for(String key : SerialWindow.hash.keySet()){
+ SerialWindow swin = SerialWindow.hash.get(key);
+ if (swin != null) {
+ if (mes == null) mes = "Uploadに備え、切断しました";
+ swin.closeSerialPort(mes);
+ }
+ }
+ }
+
}