mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-06 21:54:15 +01:00
AndroidGCS: Class to facilitate selecting a bluetooth device in the preferences
pane
This commit is contained in:
parent
76ef6292de
commit
ab5c3128c2
@ -0,0 +1,33 @@
|
|||||||
|
package org.openpilot.androidgcs;
|
||||||
|
|
||||||
|
import android.bluetooth.*;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.preference.ListPreference;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class BluetoothDevicePreference extends ListPreference {
|
||||||
|
|
||||||
|
public BluetoothDevicePreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
|
||||||
|
BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
Set<BluetoothDevice> pairedDevices = bta.getBondedDevices();
|
||||||
|
CharSequence[] entries = new CharSequence[pairedDevices.size()];
|
||||||
|
CharSequence[] entryValues = new CharSequence[pairedDevices.size()];
|
||||||
|
int i = 0;
|
||||||
|
for (BluetoothDevice dev : pairedDevices) {
|
||||||
|
entries[i] = dev.getName();
|
||||||
|
entryValues[i] = dev.getAddress();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
setEntries(entries);
|
||||||
|
setEntryValues(entryValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BluetoothDevicePreference(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -99,8 +99,9 @@ import android.util.Log;
|
|||||||
for (BluetoothDevice device : pairedDevices) {
|
for (BluetoothDevice device : pairedDevices) {
|
||||||
// Add the name and address to an array adapter to show in a ListView
|
// Add the name and address to an array adapter to show in a ListView
|
||||||
//mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
|
//mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
|
||||||
Log.d(TAG, "Paired device: " + device.getName());
|
Log.d(TAG, "Paired device: " + device.getAddress() + " compared to " + device_name);
|
||||||
if(device.getName().compareTo(device_name) == 0) {
|
if(device.getAddress().compareTo(device_name) == 0) {
|
||||||
|
Log.d(TAG, "Found device: " + device.getName());
|
||||||
this.device = device;
|
this.device = device;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -110,7 +111,7 @@ import android.util.Log;
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean openTelemetryBluetooth(UAVObjectManager objMngr) {
|
private boolean openTelemetryBluetooth(UAVObjectManager objMngr) {
|
||||||
Log.d(TAG, "Opening conncetion to " + device.getName());
|
Log.d(TAG, "Opening connection to " + device.getName());
|
||||||
socket = null;
|
socket = null;
|
||||||
connected = false;
|
connected = false;
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user