<item android:id="@+id/connect_scan"
android:icon="@android:drawable/ic_menu_search"
android:title="@string/connect_device" />
+ <item android:id="@+id/disconnect"
+ android:icon="@android:drawable/ic_notification_clear_all"
+ android:title="@string/disconnect_device" />
<item android:id="@+id/quit"
android:icon="@android:drawable/ic_menu_close_clear_cancel"
android:title="@string/quit" />
<!-- Options Menu -->
<string name="connect_device">Connect a device</string>
+ <string name="disconnect_device">Disconnect device</string>
<string name="quit">Quit</string>
<string name="select_freq">Select radio frequency</string>
<string name="select_rate">Select data rate</string>
}
}
+ private void disconnectDevice() {
+ try {
+ mService.send(Message.obtain(null, TelemetryService.MSG_DISCONNECT, null));
+ } catch (RemoteException e) {
+ }
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
serverIntent = new Intent(this, DeviceListActivity.class);
startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
return true;
+ case R.id.disconnect:
+ /* Disconnect the bluetooth device
+ */
+ disconnectDevice();
+ return true;
case R.id.quit:
Log.d(TAG, "R.id.quit");
- stopService(new Intent(AltosDroid.this, TelemetryService.class));
+ disconnectDevice();
finish();
return true;
case R.id.select_freq:
static final int MSG_SETFREQUENCY = 8;
static final int MSG_CRC_ERROR = 9;
static final int MSG_SETBAUD = 10;
+ static final int MSG_DISCONNECT = 11;
// Unique Identification Number for the Notification.
// We use it on Notification start, and to cancel it.
AltosDroidPreferences.set_active_device(address);
s.start_altos_bluetooth(address);
break;
+ case MSG_DISCONNECT:
+ if (D) Log.d(TAG, "Disconnect command received");
+ s.address = null;
+ s.stop_altos_bluetooth(true);
+ break;
case MSG_SETFREQUENCY:
if (D) Log.d(TAG, "MSG_SETFREQUENCY");
s.telemetry_state.frequency = (Double) msg.obj;
}
break;
case MSG_CONNECT_FAILED:
- if (s.address != null && !s.clients.isEmpty()) {
+ if (s.address != null) {
if (D) Log.d(TAG, "Connection failed... retrying");
s.start_altos_bluetooth(s.address);
} else {
break;
case MSG_DISCONNECTED:
Log.d(TAG, "MSG_DISCONNECTED");
- if (s.address != null && !s.clients.isEmpty()) {
+ if (s.address != null) {
if (D) Log.d(TAG, "Connection lost... retrying");
s.start_altos_bluetooth(s.address);
} else {