altosdroid: Add input thread for reading from TBT
authorMike Beattie <mike@ethernal.org>
Sun, 26 Aug 2012 03:21:36 +0000 (15:21 +1200)
committerMike Beattie <mike@ethernal.org>
Sun, 26 Aug 2012 03:21:36 +0000 (15:21 +1200)
Signed-off-by: Mike Beattie <mike@ethernal.org>
altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java

index 32140b3cbb513b656e476fbbfdef15607f4262b3..4c3f979d7c386df38e3260f864ba0bf23124b64c 100644 (file)
@@ -37,6 +37,7 @@ public class AltosBluetooth extends AltosLink {
        private static final boolean D = true;
 
        private ConnectThread    connect_thread = null;
+       private Thread           input_thread   = null;
 
        private BluetoothAdapter adapter;
        private BluetoothDevice  device;
@@ -51,6 +52,9 @@ public class AltosBluetooth extends AltosLink {
 
                connect_thread = new ConnectThread(device);
                connect_thread.start();
+
+               input_thread = new Thread(this);
+               input_thread.start();
        }
 
        private class ConnectThread extends Thread {
@@ -155,6 +159,13 @@ public class AltosBluetooth extends AltosLink {
                                connect_thread.cancel();
                                connect_thread = null;
                        }
+                       if (input_thread != null) {
+                               try {
+                                       input_thread.interrupt();
+                                       input_thread.join();
+                               } catch (Exception e) {}
+                               input_thread = null;
+                       }
                }
        }