altosdroid: Move pause before reopening bluetooth into connec thread
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / AltosBluetooth.java
index e68b1885175c6bcb76641437359025c3196c6ea4..d506ff59cc4702e2d2fa8561330af5289edb2b8e 100644 (file)
@@ -41,19 +41,19 @@ public class AltosBluetooth extends AltosDroidLink {
 
        private ConnectThread    connect_thread = null;
 
-       private BluetoothAdapter adapter;
+       private BluetoothDevice  device;
        private BluetoothSocket  socket;
        private InputStream      input;
        private OutputStream     output;
+       private boolean          pause;
 
        // Constructor
-       public AltosBluetooth(BluetoothDevice device, Handler handler) {
+       public AltosBluetooth(BluetoothDevice device, Handler handler, boolean pause) {
                super(handler);
-//             set_debug(D);
-               adapter = BluetoothAdapter.getDefaultAdapter();
+               this.device = device;
                this.handler = handler;
+               this.pause = pause;
 
-               create_socket(device);
                connect_thread = new ConnectThread();
                connect_thread.start();
        }
@@ -64,6 +64,7 @@ public class AltosBluetooth extends AltosDroidLink {
                        return;
                }
 
+               AltosDebug.check_ui("connected\n");
                try {
                        synchronized(this) {
                                if (socket != null) {
@@ -141,9 +142,17 @@ public class AltosBluetooth extends AltosDroidLink {
                        if (D) Log.d(TAG, "ConnectThread: BEGIN");
                        setName("ConnectThread");
 
+                       if (pause) {
+                               try {
+                                       Thread.sleep(4000);
+                               } catch (InterruptedException e) {
+                               }
+                       }
+
+                       create_socket(device);
                        // Always cancel discovery because it will slow down a connection
                        try {
-                               adapter.cancelDiscovery();
+                               BluetoothAdapter.getDefaultAdapter().cancelDiscovery();
                        } catch (Exception e) {
                                if (D) Log.d(TAG, String.format("cancelDiscovery exception %s", e.toString()));
                        }