mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-21 11:54:15 +01:00
AndroidGCS: Respond to the virtual pad movements and stop transmitting updates
when they are released.
This commit is contained in:
parent
8b26696e77
commit
87f6700d74
@ -497,8 +497,9 @@ public class JoystickView extends View {
|
|||||||
public void run() {
|
public void run() {
|
||||||
touchX += intervalsX;
|
touchX += intervalsX;
|
||||||
touchY += intervalsY;
|
touchY += intervalsY;
|
||||||
|
|
||||||
reportOnMoved();
|
// No longer reportOnMoved() in this method because we only
|
||||||
|
// want to receive inputs from the user
|
||||||
invalidate();
|
invalidate();
|
||||||
|
|
||||||
if (moveListener != null && j == numberOfFrames - 1) {
|
if (moveListener != null && j == numberOfFrames - 1) {
|
||||||
|
@ -10,6 +10,7 @@ import org.openpilot.uavtalk.UAVObject;
|
|||||||
import org.openpilot.uavtalk.UAVObjectField;
|
import org.openpilot.uavtalk.UAVObjectField;
|
||||||
|
|
||||||
import com.MobileAnarchy.Android.Widgets.Joystick.DualJoystickView;
|
import com.MobileAnarchy.Android.Widgets.Joystick.DualJoystickView;
|
||||||
|
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -20,6 +21,8 @@ import android.widget.Toast;
|
|||||||
public class Controller extends ObjectManagerActivity {
|
public class Controller extends ObjectManagerActivity {
|
||||||
private final String TAG = "Controller";
|
private final String TAG = "Controller";
|
||||||
|
|
||||||
|
private final boolean DEBUG = false;
|
||||||
|
|
||||||
private final int THROTTLE_CHANNEL = 0;
|
private final int THROTTLE_CHANNEL = 0;
|
||||||
private final int ROLL_CHANNEL = 1;
|
private final int ROLL_CHANNEL = 1;
|
||||||
private final int PITCH_CHANNEL = 2;
|
private final int PITCH_CHANNEL = 2;
|
||||||
@ -33,6 +36,7 @@ public class Controller extends ObjectManagerActivity {
|
|||||||
|
|
||||||
private double throttle = 0.1, roll = 0.1, pitch = -0.1, yaw = 0;
|
private double throttle = 0.1, roll = 0.1, pitch = -0.1, yaw = 0;
|
||||||
private boolean updated;
|
private boolean updated;
|
||||||
|
private boolean leftJoystickHeld, rightJoystickHeld;
|
||||||
|
|
||||||
Timer sendTimer = new Timer();
|
Timer sendTimer = new Timer();
|
||||||
|
|
||||||
@ -59,32 +63,58 @@ public class Controller extends ObjectManagerActivity {
|
|||||||
|
|
||||||
activateGcsReceiver();
|
activateGcsReceiver();
|
||||||
|
|
||||||
|
DualJoystickView joystick = (DualJoystickView) findViewById(R.id.dualjoystickView);
|
||||||
|
|
||||||
|
// Hardcode a Mode 1 listener for now
|
||||||
|
joystick.setOnJostickMovedListener(new JoystickMovedListener() {
|
||||||
|
public void OnMoved(int pan, int tilt) {
|
||||||
|
pitch = -(double) tilt / 10.0;
|
||||||
|
yaw = (double) pan / 10.0;
|
||||||
|
updated = true;
|
||||||
|
leftJoystickHeld = true;
|
||||||
|
}
|
||||||
|
public void OnReleased() { leftJoystickHeld = false; }
|
||||||
|
@Override
|
||||||
|
public void OnReturnedToCenter() { }
|
||||||
|
}, new JoystickMovedListener() {
|
||||||
|
public void OnMoved(int pan, int tilt) {
|
||||||
|
throttle = (double) (tilt + 10) / 20.0;
|
||||||
|
roll = (double) pan / 10.0;
|
||||||
|
updated = true;
|
||||||
|
rightJoystickHeld = true;
|
||||||
|
}
|
||||||
|
public void OnReleased() { rightJoystickHeld = false; }
|
||||||
|
@Override
|
||||||
|
public void OnReturnedToCenter() { }
|
||||||
|
}) ;
|
||||||
TimerTask controllerTask = new TimerTask() {
|
TimerTask controllerTask = new TimerTask() {
|
||||||
public void run() {
|
public void run() {
|
||||||
uavobjHandler.post(new Runnable() {
|
uavobjHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
UAVObject gcsReceiver = objMngr.getObject("GCSReceiver");
|
if (leftJoystickHeld && rightJoystickHeld) {
|
||||||
if (gcsReceiver == null) {
|
UAVObject gcsReceiver = objMngr.getObject("GCSReceiver");
|
||||||
Log.e(TAG, "No GCS Receiver object found");
|
if (gcsReceiver == null) {
|
||||||
return;
|
Log.e(TAG, "No GCS Receiver object found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UAVObjectField channels = gcsReceiver.getField("Channel");
|
||||||
|
if(channels == null) {
|
||||||
|
Log.e(TAG, "GCS Receiver object ill formatted");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
channels.setValue(scaleChannel(throttle, CHANNEL_NEUTRAL_THROTTLE), THROTTLE_CHANNEL);
|
||||||
|
channels.setValue(scaleChannel(roll, CHANNEL_NEUTRAL), ROLL_CHANNEL);
|
||||||
|
channels.setValue(scaleChannel(pitch, CHANNEL_NEUTRAL), PITCH_CHANNEL);
|
||||||
|
channels.setValue(scaleChannel(yaw, CHANNEL_NEUTRAL), YAW_CHANNEL);
|
||||||
|
channels.setValue(scaleChannel(0, CHANNEL_NEUTRAL), FLIGHTMODE_CHANNEL);
|
||||||
|
|
||||||
|
gcsReceiver.updated();
|
||||||
|
|
||||||
|
if (DEBUG) Log.d(TAG, "Send update" + gcsReceiver.toStringData());
|
||||||
}
|
}
|
||||||
|
|
||||||
UAVObjectField channels = gcsReceiver.getField("Channel");
|
|
||||||
if(channels == null) {
|
|
||||||
Log.e(TAG, "GCS Receiver object ill formatted");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
channels.setValue(scaleChannel(throttle, CHANNEL_NEUTRAL_THROTTLE), THROTTLE_CHANNEL);
|
|
||||||
channels.setValue(scaleChannel(roll, CHANNEL_NEUTRAL), ROLL_CHANNEL);
|
|
||||||
channels.setValue(scaleChannel(pitch, CHANNEL_NEUTRAL), PITCH_CHANNEL);
|
|
||||||
channels.setValue(scaleChannel(yaw, CHANNEL_NEUTRAL), YAW_CHANNEL);
|
|
||||||
channels.setValue(scaleChannel(0, CHANNEL_NEUTRAL), FLIGHTMODE_CHANNEL);
|
|
||||||
|
|
||||||
gcsReceiver.updated();
|
|
||||||
|
|
||||||
Log.d(TAG, "Send update");
|
|
||||||
updated = false;
|
updated = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user