X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FTelemetryService.java;fp=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FTelemetryService.java;h=926109e2b27642d0ec538daa0113354d350a49f4;hp=1834d55b2eb1fa4bb3280803b5fbc1a283b06f21;hb=f49fd5d2be68de97ebe65fa4f6484746e91dd677;hpb=ea89feedd4185a5f583fa8ddf33a2ec0906e0dc0 diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java index 1834d55b..926109e2 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java @@ -57,6 +57,7 @@ public class TelemetryService extends Service { static final int MSG_SETBAUD = 11; static final int MSG_DISCONNECT = 12; static final int MSG_DELETE_SERIAL = 13; + static final int MSG_BLUETOOTH_ENABLED = 14; // Unique Identification Number for the Notification. // We use it on Notification start, and to cancel it. @@ -86,6 +87,8 @@ public class TelemetryService extends Service { @Override public void handleMessage(Message msg) { + DeviceAddress address; + TelemetryService s = service.get(); AltosDroidLink bt = null; if (s == null) @@ -101,7 +104,7 @@ public class TelemetryService extends Service { break; case MSG_CONNECT: AltosDebug.debug("Connect command received"); - DeviceAddress address = (DeviceAddress) msg.obj; + address = (DeviceAddress) msg.obj; AltosDroidPreferences.set_active_device(address); s.start_altos_bluetooth(address, false); break; @@ -203,6 +206,12 @@ public class TelemetryService extends Service { s.telemetry_state.crc_errors = (Integer) msg.obj; s.send_to_clients(); break; + case MSG_BLUETOOTH_ENABLED: + AltosDebug.debug("TelemetryService notes that BT is now enabled"); + address = AltosDroidPreferences.active_device(); + if (address != null && !address.address.startsWith("USB")) + s.start_altos_bluetooth(address, false); + break; default: super.handleMessage(msg); } @@ -348,10 +357,14 @@ public class TelemetryService extends Service { } private void start_altos_bluetooth(DeviceAddress address, boolean pause) { - // Get the BLuetoothDevice object - BluetoothDevice device = bluetooth_adapter.getRemoteDevice(address.address); + if (bluetooth_adapter == null || !bluetooth_adapter.isEnabled()) + return; disconnect(false); + + // Get the BluetoothDevice object + BluetoothDevice device = bluetooth_adapter.getRemoteDevice(address.address); + this.address = address; AltosDebug.debug("start_altos_bluetooth(): Connecting to %s (%s)", device.getName(), device.getAddress()); altos_link = new AltosBluetooth(device, handler, pause); @@ -441,11 +454,6 @@ public class TelemetryService extends Service { // Get local Bluetooth adapter bluetooth_adapter = BluetoothAdapter.getDefaultAdapter(); - // If the adapter is null, then Bluetooth is not supported - if (bluetooth_adapter == null) { - Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); - } - telemetry_state = new TelemetryState(); // Create a reference to the NotificationManager so that we can update our notifcation text later