X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FAltosBluetooth.java;h=4c3f979d7c386df38e3260f864ba0bf23124b64c;hb=fb8cd14cca61ca59b95c23e71505607b4509d4ed;hp=4c1f09a285587a0f78b7168b9a6318705c1bdd1d;hpb=d184638be79dafd6fb43df21040eb52402f54ea5;p=fw%2Faltos diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java index 4c1f09a2..4c3f979d 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java @@ -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; @@ -44,6 +45,18 @@ public class AltosBluetooth extends AltosLink { private InputStream input; private OutputStream output; + // Constructor + public AltosBluetooth(BluetoothDevice in_device) { + adapter = BluetoothAdapter.getDefaultAdapter(); + + + connect_thread = new ConnectThread(device); + connect_thread.start(); + + input_thread = new Thread(this); + input_thread.start(); + } + private class ConnectThread extends Thread { private final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); @@ -146,27 +159,21 @@ 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; + } } } - public void flush_output() { - super.flush_output(); - /* any local work needed to flush bluetooth? */ - } - public boolean can_cancel_reply() { - return false; - } - public boolean show_reply_timeout() { - return true; - } - - public void hide_reply_timeout() { - } + //public void flush_output() { super.flush_output(); } - public AltosBluetooth(BluetoothDevice device) { - adapter = BluetoothAdapter.getDefaultAdapter(); - connect_thread = new ConnectThread(device, true); - connect_thread.start(); - } -} \ No newline at end of file + public boolean can_cancel_reply() { return false; } + public boolean show_reply_timeout() { return true; } + public void hide_reply_timeout() { } + +}