1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-05 21:52:10 +01:00

AndroidGCS: Update the controller gadget to the newer style updates

This commit is contained in:
James Cotton 2012-08-10 16:16:39 -05:00
parent 9985910969
commit cab661e94b

View File

@ -35,7 +35,6 @@ import org.openpilot.uavtalk.UAVObject;
import org.openpilot.uavtalk.UAVObjectField; import org.openpilot.uavtalk.UAVObjectField;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.util.Log; import android.util.Log;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -72,8 +71,6 @@ public class Controller extends ObjectManagerActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.controller); setContentView(R.layout.controller);
TextView manualView = (TextView) findViewById(R.id.manualControlValues); TextView manualView = (TextView) findViewById(R.id.manualControlValues);
if(manualView != null)
manualView.setText("Hello");
} }
Observer settingsUpdated = new Observer() { Observer settingsUpdated = new Observer() {
@ -93,19 +90,16 @@ public class Controller extends ObjectManagerActivity {
void onOPConnected() { void onOPConnected() {
super.onOPConnected(); super.onOPConnected();
Log.d(TAG, "onOPConnected()");
// Subscribe to updates from ManualControlCommand and show the values for crude feedback // Subscribe to updates from ManualControlCommand and show the values for crude feedback
UAVDataObject manualControl = (UAVDataObject) objMngr.getObject("ManualControlCommand"); UAVDataObject manualControl = (UAVDataObject) objMngr.getObject("ManualControlCommand");
if(manualControl != null) { registerObjectUpdates(manualControl);
manualControl.addUpdatedObserver(updatedObserver);
}
// Request a one time update before configuring for GCS control mode
UAVDataObject manualControlSettings = (UAVDataObject) objMngr.getObject("ManualControlSettings"); UAVDataObject manualSettings = (UAVDataObject) objMngr.getObject("ManualControlSettings");
if(manualControlSettings != null) { manualSettings.addUpdatedObserver(settingsUpdated);
Log.d(TAG, "Requested settings update"); manualSettings.updateRequested();
manualControlSettings.addUpdatedObserver(updatedObserver);
manualControlSettings.updateRequested();
}
final double MOVEMENT_RANGE = 50.0; final double MOVEMENT_RANGE = 50.0;
DualJoystickView joystick = (DualJoystickView) findViewById(R.id.dualjoystickView); DualJoystickView joystick = (DualJoystickView) findViewById(R.id.dualjoystickView);
@ -138,7 +132,9 @@ public class Controller extends ObjectManagerActivity {
public void OnReleased() { rightJoystickHeld = false; throttle = -1; updated = true; } public void OnReleased() { rightJoystickHeld = false; throttle = -1; updated = true; }
@Override @Override
public void OnReturnedToCenter() { } public void OnReturnedToCenter() { }
}) ; });
//! This timer task actually periodically sends updates to the UAV
TimerTask controllerTask = new TimerTask() { TimerTask controllerTask = new TimerTask() {
@Override @Override
public void run() { public void run() {
@ -175,36 +171,19 @@ public class Controller extends ObjectManagerActivity {
}); });
} }
}; };
sendTimer.schedule(controllerTask, 500, 100); sendTimer.schedule(controllerTask, 500, 10);
} }
/**
* The callbacks from the UAVOs must run in the correct thread to update the
* UI. This is what using a runnable does.
*/
final Handler uavobjHandler = new Handler();
final Runnable updateText = new Runnable() {
@Override
public void run() {
updateManualControl();
}
};
private final Observer updatedObserver = new Observer() {
@Override
public void update(Observable observable, Object data) {
uavobjHandler.post(updateText);
}
};
/** /**
* Show the string description of manual control command * Show the string description of manual control command
*/ */
private void updateManualControl() { @Override
UAVDataObject manualControl = (UAVDataObject) objMngr.getObject("ManualControlCommand"); protected void objectUpdated(UAVObject obj) {
TextView manualView = (TextView) findViewById(R.id.manualControlValues); if (obj.getName().compareTo("ManualControlCommand") == 0) {
if (manualView != null && manualControl != null) TextView manualView = (TextView) findViewById(R.id.manualControlValues);
manualView.setText(manualControl.toStringData()); if (manualView != null)
manualView.setText(obj.toStringData());
}
} }
/** /**