altosui: check for closed serial device before reading
[fw/altos] / ao-tools / altosui / AltosSerial.java
index b016c1d65fbecfe0463c0e97933148cf10c2d55b..96e8b61f599d2329678dbe547b3edc3eb3389f11 100644 (file)
@@ -51,6 +51,8 @@ public class AltosSerial implements Runnable {
 
                try {
                        for (;;) {
+                               if (altos == null)
+                                       break;
                                c = libaltos.altos_getchar(altos, 0);
                                if (Thread.interrupted())
                                        break;
@@ -119,7 +121,8 @@ public class AltosSerial implements Runnable {
        }
 
        public void putc(char c) {
-               libaltos.altos_putchar(altos, c);
+               if (altos != null)
+                       libaltos.altos_putchar(altos, c);
        }
 
        public void print(String data) {
@@ -138,6 +141,17 @@ public class AltosSerial implements Runnable {
                        throw new FileNotFoundException(device.getPath());
                input_thread = new Thread(this);
                input_thread.start();
+               print("\nE 0\n");
+               try {
+                       Thread.sleep(200);
+               } catch (InterruptedException e) {
+               }
+               flush();
+       }
+
+       public void set_channel(int channel) {
+               if (altos != null)
+                       printf("m 0\nc r %d\nm 1\n", channel);
        }
 
        public AltosSerial() {