mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
AndroidGCS: Check in the stubs for a logging activity which will eventually
move into the service and this will become the control interface.
This commit is contained in:
parent
51765f4033
commit
0274c8c860
@ -26,9 +26,11 @@
|
||||
<activity android:name="PFD" android:label="PFD" />
|
||||
<activity android:name="Controller" android:label="@string/controller_name" />
|
||||
<activity android:name="Preferences" android:label="@string/preference_title" />
|
||||
<activity android:name="UAVLocation" android:label="@string/location_name"/>
|
||||
<activity android:name="UAVLocation" android:label="@string/location_name" />
|
||||
<activity android:name="ObjectEditor" android:label="ObjectEditor"
|
||||
android:theme="@android:style/Theme.Dialog" />
|
||||
<activity android:name="Logger" android:label="Logger"
|
||||
android:theme="@android:style/Theme.Dialog" />
|
||||
|
||||
<receiver android:name="TelemetryWidget">
|
||||
<intent-filter>
|
||||
|
7
androidgcs/res/layout/logger.xml
Normal file
7
androidgcs/res/layout/logger.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
|
||||
</ListView>
|
@ -41,6 +41,13 @@ public class HomePage extends ObjectManagerActivity {
|
||||
}
|
||||
});
|
||||
|
||||
Button logger = (Button) findViewById(R.id.launch_logger);
|
||||
logger.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View arg0) {
|
||||
startActivity(new Intent(HomePage.this, Logger.class));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
37
androidgcs/src/org/openpilot/androidgcs/Logger.java
Normal file
37
androidgcs/src/org/openpilot/androidgcs/Logger.java
Normal file
@ -0,0 +1,37 @@
|
||||
package org.openpilot.androidgcs;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.openpilot.uavtalk.UAVObject;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class Logger extends ObjectManagerActivity {
|
||||
|
||||
final String TAG = "Logger";
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
void onOPConnected() {
|
||||
Log.d(TAG, "onOPConnected()");
|
||||
|
||||
List<List<UAVObject>> allObjects = objMngr.getObjects();
|
||||
registerObjectUpdates(allObjects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever any objects subscribed to via registerObjects
|
||||
*/
|
||||
@Override
|
||||
protected void objectUpdated(UAVObject obj) {
|
||||
Log.d(TAG,"Updated: " + obj.toString());
|
||||
}
|
||||
}
|
@ -1,7 +1,13 @@
|
||||
package org.openpilot.androidgcs;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
import org.openpilot.androidgcs.OPTelemetryService.LocalBinder;
|
||||
import org.openpilot.androidgcs.OPTelemetryService.TelemTask;
|
||||
import org.openpilot.uavtalk.UAVObject;
|
||||
import org.openpilot.uavtalk.UAVObjectManager;
|
||||
|
||||
import android.app.Activity;
|
||||
@ -12,6 +18,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
@ -24,11 +31,15 @@ public abstract class ObjectManagerActivity extends Activity {
|
||||
private static int LOGLEVEL = 0;
|
||||
// private static boolean WARN = LOGLEVEL > 1;
|
||||
private static boolean DEBUG = LOGLEVEL > 0;
|
||||
|
||||
|
||||
//! Object manager, populated by parent for the children to use
|
||||
UAVObjectManager objMngr;
|
||||
boolean mBound = false;
|
||||
boolean mConnected = false;
|
||||
LocalBinder binder;
|
||||
//! Indicates if the activity is bound to the service
|
||||
boolean mBound = false;
|
||||
//! Indicates if telemetry is connected
|
||||
boolean mConnected = false;
|
||||
//! The binder to access the telemetry task, and thus the object manager
|
||||
LocalBinder binder;
|
||||
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@ -42,7 +53,6 @@ public abstract class ObjectManagerActivity extends Activity {
|
||||
Log.d(TAG, "Received intent");
|
||||
TelemTask task;
|
||||
if(intent.getAction().compareTo(OPTelemetryService.INTENT_ACTION_CONNECTED) == 0) {
|
||||
|
||||
if(binder == null)
|
||||
return;
|
||||
if((task = binder.getTelemTask(0)) == null)
|
||||
@ -67,10 +77,57 @@ public abstract class ObjectManagerActivity extends Activity {
|
||||
registerReceiver(connectedReceiver, filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever any objects subscribed to via registerObjects
|
||||
*/
|
||||
protected void objectUpdated(UAVObject obj) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A message handler and a custom Observer to use it which calls
|
||||
* objectUpdated with the right object type
|
||||
*/
|
||||
final Handler uavobjHandler = new Handler();
|
||||
private class UpdatedObserver implements Observer {
|
||||
UAVObject obj;
|
||||
UpdatedObserver(UAVObject obj) { this.obj = obj; };
|
||||
public void update(Observable observable, Object data) {
|
||||
uavobjHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() { objectUpdated(obj); }
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Register an activity to receive updates from this object
|
||||
*
|
||||
* the objectUpdated() method will be called in the original UI thread
|
||||
*/
|
||||
protected void registerObjectUpdates(UAVObject object) {
|
||||
object.addUpdatedObserver(new UpdatedObserver(object));
|
||||
}
|
||||
protected void registerObjectUpdates(List<List<UAVObject>> objects) {
|
||||
ListIterator<List<UAVObject>> li = objects.listIterator();
|
||||
while(li.hasNext()) {
|
||||
ListIterator<UAVObject> li2 = li.next().listIterator();
|
||||
while(li2.hasNext())
|
||||
registerObjectUpdates(li2.next());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when either the telemetry establishes a connection or
|
||||
* if it already has on creation of this activity
|
||||
*/
|
||||
void onOPConnected() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when telemetry drops the connection
|
||||
*/
|
||||
void onOPDisconnected() {
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user