1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

Make port and bluetooth adapter be listed in the preferences. Using the BT

adapter not working yet.
This commit is contained in:
James Cotton 2012-08-04 03:18:26 -05:00
parent 45f4ae0701
commit 20b585383d
4 changed files with 29 additions and 10 deletions

View File

@ -11,5 +11,13 @@
android:summary="Enter a TCP/IP address here"
android:defaultValue="192.168.0.1" android:title="IP address:"
android:key="ip_address" />
<EditTextPreference android:name="port"
android:summary="Enter a TCP/IP port here"
android:defaultValue="9001" android:title="Port:"
android:key="port" />
<org.openpilot.androidgcs.BluetoothDevicePreference android:name="bt_adapter"
android:key="bluetooth_mac"
android:title="Bluetooth Device"
android:dialogTitle="Choose Bluetooth Device" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -7,6 +7,7 @@ import java.util.UUID;
import org.openpilot.uavtalk.UAVObjectManager;
import org.openpilot.uavtalk.UAVTalk;
import android.annotation.TargetApi;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@ -14,16 +15,18 @@ import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
public class BluetoothUAVTalk {
@TargetApi(10) public class BluetoothUAVTalk {
private final String TAG = "BluetoothUAVTalk";
public static int LOGLEVEL = 2;
public static boolean WARN = LOGLEVEL > 1;
public static boolean DEBUG = LOGLEVEL > 0;
// Temporarily define fixed device name
public final static String DEVICE_NAME = "RN42-222D";
private String device_name = "RN42-222D";
private final static UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
private BluetoothAdapter mBluetoothAdapter;
@ -32,8 +35,12 @@ public class BluetoothUAVTalk {
private UAVTalk uavTalk;
private boolean connected;
public BluetoothUAVTalk(Context caller, String deviceName) {
if (DEBUG) Log.d(TAG, "Trying to open UAVTalk with " + deviceName);
public BluetoothUAVTalk(Context caller) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(caller);
device_name = prefs.getString("bluetooth_mac","");
if (DEBUG) Log.d(TAG, "Trying to open UAVTalk with " + device_name);
connected = false;
device = null;
@ -93,7 +100,7 @@ public class BluetoothUAVTalk {
// Add the name and address to an array adapter to show in a ListView
//mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
Log.d(TAG, "Paired device: " + device.getName());
if(device.getName().compareTo(DEVICE_NAME) == 0) {
if(device.getName().compareTo(device_name) == 0) {
this.device = device;
return;
}

View File

@ -277,7 +277,7 @@ public class OPTelemetryService extends Service {
Looper.prepare();
BluetoothUAVTalk bt = new BluetoothUAVTalk(OPTelemetryService.this, BluetoothUAVTalk.DEVICE_NAME);
BluetoothUAVTalk bt = new BluetoothUAVTalk(OPTelemetryService.this);
for( int i = 0; i < 10; i++ ) {
if (DEBUG) Log.d(TAG, "Attempting Bluetooth Connection");

View File

@ -20,7 +20,7 @@ public class TcpUAVTalk {
// Temporarily define fixed device name
private String ip_address = "1";
public final static int PORT = 9001;
private int port = 9001;
private UAVTalk uavTalk;
private boolean connected;
@ -28,8 +28,12 @@ public class TcpUAVTalk {
public TcpUAVTalk(Context caller) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(caller);
ip_address = prefs.getString("ip_address","127.0.0.1");
try {
port = Integer.decode(prefs.getString("port", ""));
} catch (NumberFormatException e) {
}
if (DEBUG) Log.d(TAG, "Trying to open UAVTalk with " + ip_address);
if (DEBUG) Log.d(TAG, "Trying to open UAVTalk with " + ip_address);
connected = false;
}
@ -52,7 +56,7 @@ public class TcpUAVTalk {
private boolean openTelemetryTcp(UAVObjectManager objMngr) {
Log.d(TAG, "Opening connection to " + ip_address + " at address " + PORT);
Log.d(TAG, "Opening connection to " + ip_address + " at address " + port);
InetAddress serverAddr = null;
try {
@ -65,7 +69,7 @@ public class TcpUAVTalk {
Socket socket = null;
try {
socket = new Socket(serverAddr,PORT);
socket = new Socket(serverAddr,port);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();