mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Update display to show connected icon
This commit is contained in:
parent
bd0a599e96
commit
77910a93ab
Binary file not shown.
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 47 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 47 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 47 KiB |
@ -8,4 +8,6 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
<TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
|
||||
<ToggleButton android:text="ToggleButton" android:id="@+id/toggleButton1" android:layout_width="wrap_content" android:layout_height="wrap_content"></ToggleButton>
|
||||
</LinearLayout>
|
||||
|
@ -1,6 +1,8 @@
|
||||
package org.openpilot.androidgcs;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -10,11 +12,15 @@ import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
import org.openpilot.androidgcs.*;
|
||||
import org.openpilot.uavtalk.Telemetry;
|
||||
import org.openpilot.uavtalk.TelemetryMonitor;
|
||||
import org.openpilot.uavtalk.UAVObject;
|
||||
import org.openpilot.uavtalk.UAVObjectManager;
|
||||
import org.openpilot.uavtalk.UAVTalk;
|
||||
import org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize;
|
||||
@ -26,9 +32,35 @@ public class ObjectBrowser extends Activity {
|
||||
private final int REQUEST_ENABLE_BT = 0;
|
||||
private UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
|
||||
BluetoothAdapter mBluetoothAdapter;
|
||||
BluetoothSocket socket;
|
||||
boolean connected;
|
||||
UAVObjectManager objMngr;
|
||||
UAVTalk uavTalk;
|
||||
|
||||
final Handler uavobjHandler = new Handler();
|
||||
final Runnable updateText = new Runnable() {
|
||||
public void run() {
|
||||
ToggleButton button = (ToggleButton) findViewById(R.id.toggleButton1);
|
||||
button.setChecked(!connected);
|
||||
|
||||
Log.d(TAG,"HERE" + connected);
|
||||
|
||||
TextView text = (TextView) findViewById(R.id.textView1);
|
||||
|
||||
UAVObject obj1 = objMngr.getObject("SystemStats");
|
||||
UAVObject obj2 = objMngr.getObject("AttitudeRaw");
|
||||
UAVObject obj3 = objMngr.getObject("AttitudeActual");
|
||||
UAVObject obj4 = objMngr.getObject("SystemAlarms");
|
||||
|
||||
if(obj1 == null || obj2 == null || obj3 == null || obj4 == null)
|
||||
return;
|
||||
|
||||
Log.d(TAG,"And here");
|
||||
text.setText(obj1.toString() + "\n" + obj2.toString() + "\n" + obj3.toString() + "\n" + obj4.toString() );
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@ -37,10 +69,15 @@ public class ObjectBrowser extends Activity {
|
||||
|
||||
Log.d(TAG, "Launching Object Browser");
|
||||
|
||||
connected = false;
|
||||
|
||||
objMngr = new UAVObjectManager();
|
||||
UAVObjectsInitialize.register(objMngr);
|
||||
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (mBluetoothAdapter == null) {
|
||||
// Device does not support Bluetooth
|
||||
Log.d(TAG, "Device does not support Bluetooth");
|
||||
Log.e(TAG, "Device does not support Bluetooth");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -50,16 +87,49 @@ public class ObjectBrowser extends Activity {
|
||||
} else {
|
||||
queryDevices();
|
||||
}
|
||||
|
||||
|
||||
UAVObject obj = objMngr.getObject("SystemStats");
|
||||
if(obj != null)
|
||||
obj.addUpdatedObserver(new Observer() {
|
||||
public void update(Observable observable, Object data) {
|
||||
uavobjHandler.post(updateText);
|
||||
}
|
||||
});
|
||||
obj = objMngr.getObject("AttitudeRaw");
|
||||
if(obj != null)
|
||||
obj.addUpdatedObserver(new Observer() {
|
||||
public void update(Observable observable, Object data) {
|
||||
uavobjHandler.post(updateText);
|
||||
}
|
||||
});
|
||||
obj = objMngr.getObject("AttitudeActual");
|
||||
if(obj != null)
|
||||
obj.addUpdatedObserver(new Observer() {
|
||||
public void update(Observable observable, Object data) {
|
||||
uavobjHandler.post(updateText);
|
||||
}
|
||||
});
|
||||
obj = objMngr.getObject("SystemAlarms");
|
||||
if(obj != null)
|
||||
obj.addUpdatedObserver(new Observer() {
|
||||
public void update(Observable observable, Object data) {
|
||||
uavobjHandler.post(updateText);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if(requestCode == REQUEST_ENABLE_BT && resultCode == RESULT_OK) {
|
||||
Log.d(TAG, "Bluetooth started succesfully");
|
||||
//Log.d(TAG, "Bluetooth started succesfully");
|
||||
queryDevices();
|
||||
}
|
||||
if(requestCode == REQUEST_ENABLE_BT && resultCode != RESULT_OK)
|
||||
Log.d(TAG, "Bluetooth could not be started");
|
||||
if(requestCode == REQUEST_ENABLE_BT && resultCode != RESULT_OK) {
|
||||
//Log.d(TAG, "Bluetooth could not be started");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -84,12 +154,13 @@ public class ObjectBrowser extends Activity {
|
||||
|
||||
private void openTelmetryBluetooth(BluetoothDevice device) {
|
||||
Log.d(TAG, "Opening conncetion to " + device.getName());
|
||||
BluetoothSocket socket = null;
|
||||
socket = null;
|
||||
connected = false;
|
||||
try {
|
||||
socket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG,"Unable to create Rfcomm socket");
|
||||
e.printStackTrace();
|
||||
//e.printStackTrace();
|
||||
}
|
||||
|
||||
mBluetoothAdapter.cancelDiscovery();
|
||||
@ -102,20 +173,19 @@ public class ObjectBrowser extends Activity {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e2) {
|
||||
Log.e(TAG, "unable to close() socket during connection failure", e2);
|
||||
//Log.e(TAG, "unable to close() socket during connection failure", e2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
objMngr = new UAVObjectManager();
|
||||
UAVObjectsInitialize.register(objMngr);
|
||||
connected = true;
|
||||
|
||||
try {
|
||||
uavTalk = new UAVTalk(socket.getInputStream(), socket.getOutputStream(), objMngr);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG,"Error starting UAVTalk");
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
//e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user