1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

AndroidGCS: Add copyright header of the other files

This commit is contained in:
James Cotton 2012-08-08 09:22:09 -05:00
parent dc6b3af707
commit 07074ef41e
19 changed files with 832 additions and 335 deletions

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file AttitudeView.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A view for UAV attitude.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import android.content.Context;
@ -14,75 +37,75 @@ public class AttitudeView extends View {
initAttitudeView();
}
public AttitudeView(Context context, AttributeSet ats, int defaultStyle) {
public AttitudeView(Context context, AttributeSet ats, int defaultStyle) {
super(context, ats, defaultStyle);
initAttitudeView();
}
public AttitudeView(Context context, AttributeSet ats) {
public AttitudeView(Context context, AttributeSet ats) {
super(context, ats);
initAttitudeView();
}
protected void initAttitudeView() {
protected void initAttitudeView() {
setFocusable(true);
circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
circlePaint.setColor(R.color.background_color);
circlePaint.setStrokeWidth(1);
circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
circlePaint.setColor(getResources().getColor(R.color.background_color));
circlePaint.setStrokeWidth(1);
circlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
Resources r = this.getResources();
textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
Resources r = this.getResources();
textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint.setColor(r.getColor(R.color.text_color));
markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
markerPaint.setColor(r.getColor(R.color.marker_color));
markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
markerPaint.setColor(r.getColor(R.color.marker_color));
}
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int measuredWidth = measure(widthMeasureSpec);
int measuredWidth = measure(widthMeasureSpec);
int measuredHeight = measure(heightMeasureSpec);
int d = Math.min(measuredWidth, measuredHeight);
int d = Math.min(measuredWidth, measuredHeight);
setMeasuredDimension(d/2, d/2);
}
private int measure(int measureSpec) {
private int measure(int measureSpec) {
int result = 0;
// Decode the measurement specifications.
// Decode the measurement specifications.
int specMode = MeasureSpec.getMode(measureSpec);
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
if (specMode == MeasureSpec.UNSPECIFIED) { // Return a default size of 200 if no bounds are specified.
if (specMode == MeasureSpec.UNSPECIFIED) { // Return a default size of 200 if no bounds are specified.
result = 200;
} else {
// As you want to fill the available space
// always return the full available bounds.
} else {
// As you want to fill the available space
// always return the full available bounds.
result = specSize;
}
return result;
}
private double roll;
public void setRoll(double roll) {
public void setRoll(double roll) {
this.roll = roll;
}
}
private double pitch;
public void setPitch(double d) {
public void setPitch(double d) {
this.pitch = d;
}
}
// Drawing related code
private Paint markerPaint;
private Paint textPaint;
private Paint circlePaint;
private Paint markerPaint;
private Paint textPaint;
private Paint circlePaint;
@Override
protected void onDraw(Canvas canvas) {
int px = getMeasuredWidth() / 2;
int px = getMeasuredWidth() / 2;
int py = getMeasuredHeight() /2 ;
int radius = Math.min(px, py);
canvas.drawLine(px,py, (int) (px+radius * Math.cos(roll)), (int) (py + radius * Math.sin(roll)), markerPaint);
canvas.drawLine(px,py, (int) (px+radius * Math.cos(roll)), (int) (py + radius * Math.sin(roll)), markerPaint);
canvas.drawLine(px,py, (int) (px+radius * Math.cos(pitch)), (int) (py + radius * Math.sin(pitch)), markerPaint);
}

View File

@ -1,12 +1,38 @@
/**
******************************************************************************
* @file BluetoothDevicePreference.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A dialog in the preferences options that shows the paired BT
* devices.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import android.bluetooth.*;
import java.util.Set;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.preference.ListPreference;
import android.util.AttributeSet;
import java.util.Set;
public class BluetoothDevicePreference extends ListPreference {
public BluetoothDevicePreference(Context context, AttributeSet attrs) {

View File

@ -1,3 +1,27 @@
/**
******************************************************************************
* @file BluetoothUAVTalk.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Telemetry over bluetooth.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import java.io.IOException;
@ -24,19 +48,19 @@ import android.util.Log;
public static int LOGLEVEL = 2;
public static boolean WARN = LOGLEVEL > 1;
public static boolean DEBUG = LOGLEVEL > 0;
// Temporarily define fixed device name
private String device_name = "RN42-222D";
private final static UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
private BluetoothAdapter mBluetoothAdapter;
private BluetoothSocket socket;
private BluetoothDevice device;
private UAVTalk uavTalk;
private boolean connected;
private boolean connected;
public BluetoothUAVTalk(Context caller) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(caller);
device_name = prefs.getString("bluetooth_mac","");
@ -44,52 +68,52 @@ import android.util.Log;
connected = false;
device = null;
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
Log.e(TAG, "Device does not support Bluetooth");
return;
}
if (!mBluetoothAdapter.isEnabled()) {
// Enable bluetooth if it isn't already
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
caller.sendOrderedBroadcast(enableBtIntent, "android.permission.BLUETOOTH_ADMIN", new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.e(TAG,"Received " + context + intent);
Log.e(TAG,"Received " + context + intent);
//TODO: some logic here to see if it worked
queryDevices();
}
}
}, null, Activity.RESULT_OK, null, null);
} else {
queryDevices();
}
}
}
public boolean connect(UAVObjectManager objMngr) {
if( getConnected() )
if( getConnected() )
return true;
if( !getFoundDevice() )
return false;
return false;
if( !openTelemetryBluetooth(objMngr) )
return false;
return true;
return true;
}
public boolean getConnected() {
return connected;
}
public boolean getFoundDevice() {
return (device != null);
}
public UAVTalk getUavtalk() {
return uavTalk;
}
private void queryDevices() {
Log.d(TAG, "Searching for devices");
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
@ -107,7 +131,7 @@ import android.util.Log;
}
}
}
}
private boolean openTelemetryBluetooth(UAVObjectManager objMngr) {
@ -119,11 +143,11 @@ import android.util.Log;
} catch (IOException e) {
Log.e(TAG,"Unable to create Rfcomm socket");
return false;
//e.printStackTrace();
//e.printStackTrace();
}
mBluetoothAdapter.cancelDiscovery();
try {
socket.connect();
}
@ -138,7 +162,7 @@ import android.util.Log;
}
connected = true;
try {
uavTalk = new UAVTalk(socket.getInputStream(), socket.getOutputStream(), objMngr);
} catch (IOException e) {
@ -147,7 +171,7 @@ import android.util.Log;
//e.printStackTrace();
return false;
}
return true;
}

View File

@ -1,3 +1,27 @@
/**
******************************************************************************
* @file CompassView.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A view of the compass heading.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import android.content.Context;
@ -14,104 +38,104 @@ public class CompassView extends View {
initCompassView();
}
public CompassView(Context context, AttributeSet ats, int defaultStyle) {
public CompassView(Context context, AttributeSet ats, int defaultStyle) {
super(context, ats, defaultStyle);
initCompassView();
}
public CompassView(Context context, AttributeSet ats) {
public CompassView(Context context, AttributeSet ats) {
super(context, ats);
initCompassView();
}
protected void initCompassView() {
protected void initCompassView() {
setFocusable(true);
circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
circlePaint.setColor(R.color.background_color);
circlePaint.setStrokeWidth(1);
circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
circlePaint.setColor(getResources().getColor(R.color.background_color));
circlePaint.setStrokeWidth(1);
circlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
Resources r = this.getResources();
northString = r.getString(R.string.cardinal_north);
eastString = r.getString(R.string.cardinal_east);
southString = r.getString(R.string.cardinal_south);
Resources r = this.getResources();
northString = r.getString(R.string.cardinal_north);
eastString = r.getString(R.string.cardinal_east);
southString = r.getString(R.string.cardinal_south);
westString = r.getString(R.string.cardinal_west);
textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint.setColor(r.getColor(R.color.text_color));
textHeight = (int)textPaint.measureText("yY");
markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
markerPaint.setColor(r.getColor(R.color.marker_color));
markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
markerPaint.setColor(r.getColor(R.color.marker_color));
}
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int measuredWidth = measure(widthMeasureSpec);
int measuredWidth = measure(widthMeasureSpec);
int measuredHeight = measure(heightMeasureSpec);
int d = Math.min(measuredWidth, measuredHeight);
int d = Math.min(measuredWidth, measuredHeight);
setMeasuredDimension(d/2, d/2);
}
private int measure(int measureSpec) {
private int measure(int measureSpec) {
int result = 0;
// Decode the measurement specifications.
// Decode the measurement specifications.
int specMode = MeasureSpec.getMode(measureSpec);
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
if (specMode == MeasureSpec.UNSPECIFIED) { // Return a default size of 200 if no bounds are specified.
if (specMode == MeasureSpec.UNSPECIFIED) { // Return a default size of 200 if no bounds are specified.
result = 200;
} else {
// As you want to fill the available space
// always return the full available bounds.
} else {
// As you want to fill the available space
// always return the full available bounds.
result = specSize;
}
return result;
}
private double bearing;
public void setBearing(double bearing) {
public void setBearing(double bearing) {
this.bearing = bearing;
}
}
// Drawing related code
private Paint markerPaint;
private Paint textPaint;
private Paint circlePaint;
private String northString;
private String eastString;
private String southString;
private String westString;
private Paint markerPaint;
private Paint textPaint;
private Paint circlePaint;
private String northString;
private String eastString;
private String southString;
private String westString;
private int textHeight;
@Override
protected void onDraw(Canvas canvas) {
int px = getMeasuredWidth() / 2;
int px = getMeasuredWidth() / 2;
int py = getMeasuredHeight() /2 ;
int radius = Math.min(px, py);
// Draw the background
// Draw the background
canvas.drawCircle(px, py, radius, circlePaint);
// Rotate our perspective so that the ÔtopÕ is
// facing the current bearing.
canvas.save();
// Rotate our perspective so that the ÔtopÕ is
// facing the current bearing.
canvas.save();
canvas.rotate((float) -bearing, px, py);
int textWidth = (int)textPaint.measureText("W");
int cardinalX = px-textWidth/2;
int textWidth = (int)textPaint.measureText("W");
int cardinalX = px-textWidth/2;
int cardinalY = py-radius+textHeight;
// Draw the marker every 15 degrees and text every 45.
// Draw the marker every 15 degrees and text every 45.
for (int i = 0; i < 24; i++) {
// Draw a marker.
// Draw a marker.
canvas.drawLine(px, py-radius, px, py-radius+10, markerPaint);
canvas.save();
canvas.save();
canvas.translate(0, textHeight);
// Draw the cardinal points
// Draw the cardinal points
if (i % 6 == 0) {
String dirString = null;
switch (i) {
case 0 : {
dirString = northString;
int arrowY = 2*textHeight;
dirString = northString;
int arrowY = 2*textHeight;
canvas.drawLine(px, arrowY, px-5, 3*textHeight, markerPaint);
canvas.drawLine(px, arrowY, px+5, 3*textHeight, markerPaint);
break;
@ -122,18 +146,18 @@ public class CompassView extends View {
}
canvas.drawText(dirString, cardinalX, cardinalY, textPaint);
}
else if (i % 3 == 0) {
// Draw the text every alternate 45deg
String angle = String.valueOf(i*15);
else if (i % 3 == 0) {
// Draw the text every alternate 45deg
String angle = String.valueOf(i*15);
float angleTextWidth = textPaint.measureText(angle);
int angleTextX = (int)(px-angleTextWidth/2);
int angleTextY = py-radius+textHeight;
int angleTextX = (int)(px-angleTextWidth/2);
int angleTextY = py-radius+textHeight;
canvas.drawText(angle, angleTextX, angleTextY, textPaint);
}
canvas.restore();
canvas.rotate(15, px, py);
}
canvas.restore();
canvas.restore();
}
}

View File

@ -1,3 +1,28 @@
/**
******************************************************************************
* @file Controller.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Allows controlling the UAV over telemetry. This activity
* pushes the appropriate settings to the remote device for it to
* listen to the GCSReceiver.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import java.util.Observable;
@ -9,16 +34,16 @@ import org.openpilot.uavtalk.UAVDataObject;
import org.openpilot.uavtalk.UAVObject;
import org.openpilot.uavtalk.UAVObjectField;
import com.MobileAnarchy.Android.Widgets.Joystick.DualJoystickView;
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener;
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickView;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import com.MobileAnarchy.Android.Widgets.Joystick.DualJoystickView;
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener;
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickView;
public class Controller extends ObjectManagerActivity {
private final String TAG = "Controller";
@ -29,18 +54,18 @@ public class Controller extends ObjectManagerActivity {
private final int PITCH_CHANNEL = 2;
private final int YAW_CHANNEL = 3;
private final int FLIGHTMODE_CHANNEL = 4;
private final int CHANNEL_MIN = 1000;
private final int CHANNEL_MAX = 2000;
private final int CHANNEL_NEUTRAL = 1500;
private final int CHANNEL_NEUTRAL_THROTTLE = 1100;
private double throttle = 0.1, roll = 0.1, pitch = -0.1, yaw = 0;
private boolean updated;
private boolean leftJoystickHeld, rightJoystickHeld;
Timer sendTimer = new Timer();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
@ -63,7 +88,7 @@ public class Controller extends ObjectManagerActivity {
}
}
};
@Override
void onOPConnected() {
super.onOPConnected();
@ -74,43 +99,48 @@ public class Controller extends ObjectManagerActivity {
manualControl.addUpdatedObserver(updatedObserver);
}
UAVDataObject manualControlSettings = (UAVDataObject) objMngr.getObject("ManualControlSettings");
if(manualControlSettings != null) {
Log.d(TAG, "Requested settings update");
manualControlSettings.addUpdatedObserver(updatedObserver);
manualControlSettings.updateRequested();
}
}
final double MOVEMENT_RANGE = 50.0;
DualJoystickView joystick = (DualJoystickView) findViewById(R.id.dualjoystickView);
joystick.setMovementConstraint(JoystickView.CONSTRAIN_BOX);
joystick.setMovementRange((int)MOVEMENT_RANGE, (int)MOVEMENT_RANGE);
// Hardcode a Mode 1 listener for now
joystick.setOnJostickMovedListener(new JoystickMovedListener() {
@Override
public void OnMoved(int pan, int tilt) {
pitch = (double) tilt / MOVEMENT_RANGE;
yaw = (double) pan / MOVEMENT_RANGE;
pitch = tilt / MOVEMENT_RANGE;
yaw = pan / MOVEMENT_RANGE;
leftJoystickHeld = true;
}
@Override
public void OnReleased() { leftJoystickHeld = false; throttle = -1; updated = true; }
@Override
public void OnReturnedToCenter() { }
}, new JoystickMovedListener() {
@Override
public void OnMoved(int pan, int tilt) {
throttle = (double) (-tilt + (MOVEMENT_RANGE -5)) / (MOVEMENT_RANGE - 5);
throttle = (-tilt + (MOVEMENT_RANGE -5)) / (MOVEMENT_RANGE - 5);
throttle *= 0.5;
if (throttle < 0)
throttle = -1;
roll = (double) pan / MOVEMENT_RANGE;
roll = pan / MOVEMENT_RANGE;
rightJoystickHeld = true;
}
@Override
public void OnReleased() { rightJoystickHeld = false; throttle = -1; updated = true; }
@Override
public void OnReturnedToCenter() { }
}) ;
TimerTask controllerTask = new TimerTask() {
@Override
public void run() {
uavobjHandler.post(new Runnable() {
@Override
@ -152,17 +182,19 @@ public class Controller extends ObjectManagerActivity {
* 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 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);
}
}
};
/**
@ -174,33 +206,33 @@ public class Controller extends ObjectManagerActivity {
if (manualView != null && manualControl != null)
manualView.setText(manualControl.toStringData());
}
/**
* Active GCS receiver mode
*/
private void activateGcsReceiver() {
UAVObject manualControlSettings = objMngr.getObject("ManualControlSettings");
if (manualControlSettings == null) {
Toast.makeText(this, "Failed to get manual control settings", Toast.LENGTH_SHORT).show();
return;
}
UAVObjectField channelGroups = manualControlSettings.getField("ChannelGroups");
UAVObjectField channelNumber = manualControlSettings.getField("ChannelNumber");
UAVObjectField channelMax = manualControlSettings.getField("ChannelMax");
UAVObjectField channelNeutral = manualControlSettings.getField("ChannelNeutral");
UAVObjectField channelMin = manualControlSettings.getField("ChannelMin");
if (channelGroups == null || channelMax == null || channelNeutral == null ||
if (channelGroups == null || channelMax == null || channelNeutral == null ||
channelMin == null || channelNumber == null) {
Toast.makeText(this, "Manual control settings not formatted correctly", Toast.LENGTH_SHORT).show();
return;
}
/* Configure the manual control module how the GCS controller expects
* This order MUST correspond to the enumeration order of ChannelNumber in
* This order MUST correspond to the enumeration order of ChannelNumber in
* ManualControlSettings.
*/
*/
int channels[] = { THROTTLE_CHANNEL, ROLL_CHANNEL, PITCH_CHANNEL, YAW_CHANNEL, FLIGHTMODE_CHANNEL };
for (int i = 0; i < channels.length; i++) {
channelGroups.setValue("GCS", channels[i]);
@ -216,23 +248,23 @@ public class Controller extends ObjectManagerActivity {
break;
}
}
// Send settings to the UAV
manualControlSettings.updated();
}
/**
* Scale the channels to the output range the flight controller expects
*/
private float scaleChannel(double in, double neutral) {
private float scaleChannel(double in, double neutral) {
// Check bounds
if (in > 1)
if (in > 1)
in = 1;
if (in < -1)
in = -1;
if (in >= 0)
return (float) (neutral + (CHANNEL_MAX - neutral) * in);
return (float) (neutral + (neutral - CHANNEL_MIN) * in);

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file HomePage.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Main launch page for the Android GCS actitivies
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import android.content.Intent;
@ -10,48 +33,54 @@ public class HomePage extends ObjectManagerActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gcs_home);
super.onCreate(savedInstanceState);
setContentView(R.layout.gcs_home);
Button objectBrowser = (Button) findViewById(R.id.launch_object_browser);
objectBrowser.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(HomePage.this, ObjectBrowser.class));
}
startActivity(new Intent(HomePage.this, ObjectBrowser.class));
}
});
Button pfd = (Button) findViewById(R.id.launch_pfd);
pfd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(HomePage.this, PFD.class));
}
startActivity(new Intent(HomePage.this, PFD.class));
}
});
Button location = (Button) findViewById(R.id.launch_location);
location.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(HomePage.this, UAVLocation.class));
}
startActivity(new Intent(HomePage.this, UAVLocation.class));
}
});
Button controller = (Button) findViewById(R.id.launch_controller);
controller.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(HomePage.this, Controller.class));
}
startActivity(new Intent(HomePage.this, Controller.class));
}
});
Button logger = (Button) findViewById(R.id.launch_logger);
logger.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(HomePage.this, Logger.class));
startActivity(new Intent(HomePage.this, Logger.class));
}
});
Button alarms = (Button) findViewById(R.id.launch_alarms);
alarms.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(HomePage.this, SystemAlarmActivity.class));
startActivity(new Intent(HomePage.this, SystemAlarmActivity.class));
}
});
}

View File

@ -1,3 +1,27 @@
/**
******************************************************************************
* @file Logger.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Controller for logging data as well as interface for getting that
* data on and off the tablet.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import java.io.File;
@ -16,17 +40,17 @@ import android.widget.TextView;
public class Logger extends ObjectManagerActivity {
final String TAG = "Logger";
final boolean VERBOSE = false;
final boolean DEBUG = true;
private File file;
private boolean logging;
private FileOutputStream fileStream;
private UAVTalk uavTalk;
private int writtenBytes;
private int writtenObjects;
@ -36,15 +60,15 @@ public class Logger extends ObjectManagerActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.logger);
}
private void onStartLogging() {
File root = Environment.getExternalStorageDirectory();
Date d = new Date();
String date = (new SimpleDateFormat("yyyyMMdd_hhmmss")).format(d);
String fileName = "/logs/logs_" + date + ".opl";
file = new File(root, fileName);
if (DEBUG) Log.d(TAG, "Trying for file: " + file.getAbsolutePath());
try {
@ -60,10 +84,10 @@ public class Logger extends ObjectManagerActivity {
} catch (IOException e) {
Log.e(TAG, "Could not write file " + e.getMessage());
}
// TODO: if logging succeeded then retrieve all settings
}
private void onStopLogging() {
if (DEBUG) Log.d(TAG, "Stop logging");
logging = false;
@ -74,11 +98,11 @@ public class Logger extends ObjectManagerActivity {
e.printStackTrace();
}
}
@Override
void onOPConnected() {
super.onOPConnected();
if (DEBUG) Log.d(TAG, "onOPConnected()");
onStartLogging();
registerObjectUpdates(objMngr.getObjects());
@ -104,7 +128,7 @@ public class Logger extends ObjectManagerActivity {
onStartLogging();
}
/**
* Called whenever any objects subscribed to via registerObjects
* Called whenever any objects subscribed to via registerObjects
*/
@Override
protected void objectUpdated(UAVObject obj) {
@ -126,18 +150,18 @@ public class Logger extends ObjectManagerActivity {
fileStream.write((byte)(size & 0x0000ff0000000000l) >> 40);
fileStream.write((byte)(size & 0x00ff000000000000l) >> 48);
fileStream.write((byte)(size & 0xff00000000000000l) >> 56);
uavTalk.sendObject(obj, false, false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
writtenBytes += obj.getNumBytes();
writtenObjects ++;
((TextView) findViewById(R.id.logger_number_of_bytes)).setText(Integer.valueOf(writtenBytes).toString());
((TextView) findViewById(R.id.logger_number_of_objects)).setText(Integer.valueOf(writtenObjects).toString());
((TextView) findViewById(R.id.logger_number_of_objects)).setText(Integer.valueOf(writtenObjects).toString());
}
}
}

View File

@ -1,3 +1,29 @@
/**
******************************************************************************
* @file OPTelemetryService.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Provides UAVTalk telemetry over multiple physical links. The
* details of each of these are in their respective connection
* classes. This mostly creates those threads based on the selected
* preferences.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import java.io.IOException;
@ -67,7 +93,7 @@ public class OPTelemetryService extends Service {
case MSG_START:
stopSelf(msg.arg2);
break;
case MSG_CONNECT:
case MSG_CONNECT:
terminate = false;
int connection_type;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(OPTelemetryService.this);
@ -111,7 +137,7 @@ public class OPTelemetryService extends Service {
Intent intent = new Intent();
intent.setAction(INTENT_ACTION_DISCONNECTED);
sendBroadcast(intent,null);
stopSelf();
break;
@ -131,14 +157,14 @@ public class OPTelemetryService extends Service {
*/
public void startup() {
Toast.makeText(getApplicationContext(), "Telemetry service starting", Toast.LENGTH_SHORT).show();
thread = new HandlerThread("TelemetryServiceHandler", Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
// Get the HandlerThread's Looper and use it for our Handler
// Get the HandlerThread's Looper and use it for our Handler
mServiceLooper = thread.getLooper();
mServiceHandler = new ServiceHandler(mServiceLooper);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(OPTelemetryService.this);
if(prefs.getBoolean("autoconnect", false)) {
Message msg = mServiceHandler.obtainMessage();
@ -148,7 +174,7 @@ public class OPTelemetryService extends Service {
}
}
@Override
public void onCreate() {
startup();
@ -157,19 +183,19 @@ public class OPTelemetryService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Currently only using as bound service
// If we get killed, after returning from here, restart
return START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
public void onDestroy() {
Toast.makeText(this, "Telemetry service done", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Telemetry service done", Toast.LENGTH_SHORT).show();
}
public class LocalBinder extends Binder {
@ -206,9 +232,10 @@ public class OPTelemetryService extends Service {
public UAVObjectManager getObjectManager();
};
// Fake class for testing, simply emits periodic updates on
// Fake class for testing, simply emits periodic updates on
private class FakeTelemetryThread extends Thread implements TelemTask {
private UAVObjectManager objMngr;
private final UAVObjectManager objMngr;
@Override
public UAVObjectManager getObjectManager() { return objMngr; };
FakeTelemetryThread() {
@ -216,6 +243,7 @@ public class OPTelemetryService extends Service {
UAVObjectsInitialize.register(objMngr);
}
@Override
public void run() {
System.out.println("Running fake thread");
@ -229,22 +257,22 @@ public class OPTelemetryService extends Service {
UAVDataObject homeLocation = (UAVDataObject) objMngr.getObject("HomeLocation");
UAVDataObject positionActual = (UAVDataObject) objMngr.getObject("PositionActual");
UAVDataObject systemAlarms = (UAVDataObject) objMngr.getObject("SystemAlarms");
systemAlarms.getField("Alarm").setValue("Warning",0);
systemAlarms.getField("Alarm").setValue("OK",1);
systemAlarms.getField("Alarm").setValue("Critical",2);
systemAlarms.getField("Alarm").setValue("Error",3);
systemAlarms.updated();
homeLocation.getField("Latitude").setDouble(379420315);
homeLocation.getField("Longitude").setDouble(-88330078);
homeLocation.getField("Be").setDouble(26702.78710938,0);
homeLocation.getField("Be").setDouble(-1468.33605957,1);
homeLocation.getField("Be").setDouble(34181.78515625,2);
double roll = 0;
double pitch = 0;
double pitch = 0;
double yaw = 0;
double north = 0;
double east = 0;
@ -257,7 +285,7 @@ public class OPTelemetryService extends Service {
roll = (roll + 10) % 180;
pitch = (pitch + 10) % 180;
yaw = (yaw + 10) % 360;
systemStats.updated();
attitudeActual.updated();
positionActual.updated();
@ -269,13 +297,14 @@ public class OPTelemetryService extends Service {
}
}
}
private class BTTelemetryThread extends Thread implements TelemTask {
private class BTTelemetryThread extends Thread implements TelemTask {
private UAVObjectManager objMngr;
private final UAVObjectManager objMngr;
private UAVTalk uavTalk;
private Telemetry tel;
private TelemetryMonitor mon;
@Override
public UAVObjectManager getObjectManager() { return objMngr; };
BTTelemetryThread() {
@ -283,10 +312,11 @@ public class OPTelemetryService extends Service {
UAVObjectsInitialize.register(objMngr);
}
public void run() {
@Override
public void run() {
if (DEBUG) Log.d(TAG, "Telemetry Thread started");
Looper.prepare();
Looper.prepare();
BluetoothUAVTalk bt = new BluetoothUAVTalk(OPTelemetryService.this);
for( int i = 0; i < 10; i++ ) {
@ -318,14 +348,15 @@ public class OPTelemetryService extends Service {
tel = new Telemetry(uavTalk, objMngr);
mon = new TelemetryMonitor(objMngr,tel);
mon.addObserver(new Observer() {
@Override
public void update(Observable arg0, Object arg1) {
System.out.println("Mon updated. Connected: " + mon.getConnected() + " objects updated: " + mon.getObjectsUpdated());
if(mon.getConnected() /*&& mon.getObjectsUpdated()*/) {
Intent intent = new Intent();
intent.setAction(INTENT_ACTION_CONNECTED);
sendBroadcast(intent,null);
sendBroadcast(intent,null);
}
}
}
});
@ -345,13 +376,14 @@ public class OPTelemetryService extends Service {
};
private class TcpTelemetryThread extends Thread implements TelemTask {
private class TcpTelemetryThread extends Thread implements TelemTask {
private UAVObjectManager objMngr;
private final UAVObjectManager objMngr;
private UAVTalk uavTalk;
private Telemetry tel;
private TelemetryMonitor mon;
@Override
public UAVObjectManager getObjectManager() { return objMngr; };
TcpTelemetryThread() {
@ -359,7 +391,8 @@ public class OPTelemetryService extends Service {
UAVObjectsInitialize.register(objMngr);
}
public void run() {
@Override
public void run() {
if (DEBUG) Log.d(TAG, "Telemetry Thread started");
Looper.prepare();
@ -371,7 +404,7 @@ public class OPTelemetryService extends Service {
tcp.connect(objMngr);
if( tcp.getConnected() )
break;
try {
@ -394,6 +427,7 @@ public class OPTelemetryService extends Service {
tel = new Telemetry(uavTalk, objMngr);
mon = new TelemetryMonitor(objMngr,tel);
mon.addObserver(new Observer() {
@Override
public void update(Observable arg0, Object arg1) {
System.out.println("Mon updated. Connected: " + mon.getConnected() + " objects updated: " + mon.getObjectsUpdated());
if(mon.getConnected() /*&& mon.getObjectsUpdated()*/) {
@ -401,7 +435,7 @@ public class OPTelemetryService extends Service {
intent.setAction(INTENT_ACTION_CONNECTED);
sendBroadcast(intent,null);
}
}
}
});
@ -417,16 +451,16 @@ public class OPTelemetryService extends Service {
}
}
Looper.myLooper().quit();
// Shut down all the attached
mon.stopMonitor();
mon = null;
tel.stopTelemetry();
tel = null;
// Finally close the stream if it is still open
tcp.disconnect();
if (DEBUG) Log.d(TAG, "UAVTalk stream disconnected");
toastMessage("TCP Thread finished");
}

View File

@ -1,3 +1,27 @@
/**
******************************************************************************
* @file ObjectBrowser.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A simple object browser for UAVOs that allows viewing, editing,
* loading and saving.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import java.util.ArrayList;
@ -6,6 +30,9 @@ import java.util.ListIterator;
import java.util.Observable;
import java.util.Observer;
import org.openpilot.uavtalk.UAVDataObject;
import org.openpilot.uavtalk.UAVObject;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
@ -16,6 +43,7 @@ import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
@ -23,10 +51,6 @@ import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import org.openpilot.uavtalk.UAVDataObject;
import org.openpilot.uavtalk.UAVObject;
public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPreferenceChangeListener {
@ -36,24 +60,26 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
SharedPreferences prefs;
ArrayAdapter<UAVDataObject> adapter;
List<UAVDataObject> allObjects;
final Handler uavobjHandler = new Handler();
final Handler uavobjHandler = new Handler();
final Runnable updateText = new Runnable() {
@Override
public void run() {
updateObject();
}
};
private final Observer updatedObserver = new Observer() {
@Override
public void update(Observable observable, Object data) {
uavobjHandler.post(updateText);
}
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.object_browser);
setContentView(R.layout.object_browser);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(this);
super.onCreate(savedInstanceState);
@ -63,7 +89,7 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
void onOPConnected() {
super.onOPConnected();
Log.d(TAG, "onOPConnected()");
OnCheckedChangeListener checkListener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
@ -71,10 +97,10 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
updateList();
}
};
((CheckBox) findViewById(R.id.dataCheck)).setOnCheckedChangeListener(checkListener);
((CheckBox) findViewById(R.id.settingsCheck)).setOnCheckedChangeListener(checkListener);
((Button) findViewById(R.id.editButton)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -87,7 +113,7 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
}
}
});
((Button) findViewById(R.id.object_load_button)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -100,7 +126,7 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
objPer.getField("ObjectID").setValue(allObjects.get(selected_index).getObjID());
objPer.getField("InstanceID").setValue(0);
objPer.updated();
allObjects.get(selected_index).updateRequested();
}
}
@ -137,6 +163,7 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
objects.setAdapter(adapter);
objects.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
@ -149,9 +176,9 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
updateObject();
}
});
}
private void updateObject() {
//adapter.notifyDataSetChanged();
TextView text = (TextView) findViewById(R.id.object_information);
@ -161,6 +188,7 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
Log.d(TAG,"Update called but invalid index: " + selected_index);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
// TODO Auto-generated method stub

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file ObjectEditor.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A popup dialog for editing the contents of a UAVO.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import java.util.List;
@ -17,7 +40,7 @@ import android.widget.Toast;
public class ObjectEditor extends ObjectManagerActivity {
static final String TAG = "ObjectEditor";
static final String TAG = "ObjectEditor";
String objectName;
long objectID;
long instID;
@ -58,6 +81,7 @@ public class ObjectEditor extends ObjectManagerActivity {
});
}
@Override
public void onOPConnected() {
UAVObject obj = objMngr.getObject(objectID, instID);
if (obj == null) {
@ -86,15 +110,15 @@ public class ObjectEditor extends ObjectManagerActivity {
Toast.makeText(this, "Save failed", Toast.LENGTH_LONG).show();
return;
}
long thisId = objectID < 0 ? ((Long) 0x100000000l) + objectID : objectID;
long thisId = objectID < 0 ? 0x100000000l + objectID : objectID;
objPer.getField("Operation").setValue("Save");
objPer.getField("Selection").setValue("SingleObject");
Log.d(TAG,"Saving with object id: " + objectID + " swapped to " + thisId);
objPer.getField("ObjectID").setValue(thisId);
objPer.getField("InstanceID").setValue(instID);
objPer.updated();
Toast.makeText(this, "Save succeeded", Toast.LENGTH_LONG).show();
}
@ -125,7 +149,7 @@ public class ObjectEditor extends ObjectManagerActivity {
default:
String val = ((EditText) editView.fields.get(field_idx)).getText().toString();
Double num = Double.parseDouble(val);
Log.e(TAG, "Updating field: " + field.getName() + " value: " + num);
field.setValue(num, i);
break;

View File

@ -1,3 +1,32 @@
/**
******************************************************************************
* @file ObjectManagerActivity.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Base object for all activies that use the UAVObjectManager.
* This class takes care of binding to the service and getting the
* object manager as well as setting up callbacks to the objects of
* interest that run on the UI thread.
* Implements a new Android lifecycle: onOPConnected() / onOPDisconnected()
* which indicates when a valid telemetry is established as well as a
* valid object manager handle.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import java.util.List;

View File

@ -1,3 +1,29 @@
/**
******************************************************************************
* @file ObjectManagerFragment.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Base class for all fragments that use the UAVObjectManager. This
* supports all the extensions the ObjectManagerActivity does, namely
* access to the UAVObjectManager and callbacks in the UI thread for
* object updates.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import org.openpilot.uavtalk.UAVObject;
@ -9,12 +35,12 @@ import android.os.Bundle;
import android.util.Log;
public class ObjectManagerFragment extends Fragment {
private static final String TAG = ObjectManagerFragment.class.getSimpleName();
private static int LOGLEVEL = 1;
// private static boolean WARN = LOGLEVEL > 1;
private static boolean DEBUG = LOGLEVEL > 0;
UAVObjectManager objMngr;
/** Called when the activity is first created. */
@ -25,15 +51,16 @@ public class ObjectManagerFragment extends Fragment {
// For an activity this registers against the telemetry service intents. Fragments must be notified by their
// parent activity
}
/**
* Attach to the parent activity so it can notify us when the connection
* changed
*/
public void onAttach(Activity activity) {
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (DEBUG) Log.d(TAG,"onAttach");
ObjectManagerActivity castActivity = null;
try {
castActivity = (ObjectManagerActivity)activity;
@ -44,25 +71,25 @@ public class ObjectManagerFragment extends Fragment {
}
castActivity.addOnConnectionListenerFragment(this);
}
// The below methods should all be called by the parent activity at the appropriate times
protected void onOPConnected(UAVObjectManager objMngr) {
this.objMngr = objMngr;
if (DEBUG) Log.d(TAG,"onOPConnected");
}
protected void onOPDisconnected() {
objMngr = null;
if (DEBUG) Log.d(TAG,"onOPDisconnected");
}
/**
* Called whenever any objects subscribed to via registerObjects
* Called whenever any objects subscribed to via registerObjects
*/
protected void objectUpdated(UAVObject obj) {
}
}
/**
* Register on the activities object monitor handler so that updates
@ -72,5 +99,5 @@ public class ObjectManagerFragment extends Fragment {
protected void registerObjectUpdates(UAVObject object) {
((ObjectManagerActivity) getActivity()).registerObjectUpdates(object, this);
}
}

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file PFD.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Shows the PFD activity.
* @see The GNU Public License (GPL) Version 3
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import org.openpilot.uavtalk.UAVObject;
@ -15,6 +38,7 @@ public class PFD extends ObjectManagerActivity {
/**
* Update the UI whenever the attitude is updated
*/
@Override
protected void objectUpdated(UAVObject obj) {
// Throttle the UI redraws. Eventually this should maybe come from a periodic task
if ((System.currentTimeMillis() - lastUpdateMs) < MIN_UPDATE_PERIOD)
@ -22,7 +46,7 @@ public class PFD extends ObjectManagerActivity {
if (obj.getName().compareTo("AttitudeActual") != 0)
return;
lastUpdateMs = System.currentTimeMillis();
lastUpdateMs = System.currentTimeMillis();
heading = obj.getField("Yaw").getDouble();
pitch = obj.getField("Pitch").getDouble();
@ -42,7 +66,7 @@ public class PFD extends ObjectManagerActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pfd);
}
}
@Override
void onOPConnected() {
@ -52,5 +76,5 @@ public class PFD extends ObjectManagerActivity {
UAVObject obj = objMngr.getObject("AttitudeActual");
if (obj != null)
registerObjectUpdates(obj);
}
}
}

View File

@ -1,3 +1,27 @@
/**
******************************************************************************
* @file Preferences.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Displays the preferences dialog.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import android.os.Bundle;

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file SystemAlarmActivity.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief An activity that displays the SystemAlarmsFragment.
* @see The GNU Public License (GPL) Version 3
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import android.os.Bundle;

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file SystemAlarmsFragment.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A fragment that will connect to the SystemAlarms and visualize them.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import java.util.List;
@ -14,28 +37,30 @@ import android.view.ViewGroup;
import android.widget.TextView;
public class SystemAlarmsFragment extends ObjectManagerFragment {
private static final String TAG = SystemAlarmsFragment.class.getSimpleName();
//@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.system_alarms_fragment, container, false);
}
public void onOPConnected(UAVObjectManager objMngr) {
@Override
public void onOPConnected(UAVObjectManager objMngr) {
super.onOPConnected(objMngr);
Log.d(TAG,"On connected");
UAVObject obj = objMngr.getObject("SystemAlarms");
if (obj != null)
registerObjectUpdates(obj);
objectUpdated(obj);
}
/**
* Called whenever any objects subscribed to via registerObjects
* Called whenever any objects subscribed to via registerObjects
*/
@Override
protected void objectUpdated(UAVObject obj) {
@ -46,7 +71,7 @@ public class SystemAlarmsFragment extends ObjectManagerFragment {
List<String> names = a.getElementNames();
String contents = new String();
List <String> options = a.getOptions();
// Rank the alarms by order of severity, skip uninitialized
for (int j = options.size() - 1; j > 0; j--) {
for (int i = 0; i < names.size(); i++) {
@ -57,6 +82,6 @@ public class SystemAlarmsFragment extends ObjectManagerFragment {
alarms.setText(contents);
}
}
}

View File

@ -1,9 +1,33 @@
/**
******************************************************************************
* @file TcpUAVTalk.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief UAVTalk over TCP.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import org.openpilot.uavtalk.UAVObjectManager;
import org.openpilot.uavtalk.UAVTalk;
@ -17,17 +41,17 @@ public class TcpUAVTalk {
public static int LOGLEVEL = 2;
public static boolean WARN = LOGLEVEL > 1;
public static boolean DEBUG = LOGLEVEL > 0;
// Temporarily define fixed device name
private String ip_address = "1";
private int port = 9001;
private UAVTalk uavTalk;
private boolean connected;
private boolean connected;
private Socket socket;
/**
* Construct a TcpUAVTalk object attached to the OPTelemetryService. Gets the
* Construct a TcpUAVTalk object attached to the OPTelemetryService. Gets the
* connection settings from the preferences.
*/
public TcpUAVTalk(Context caller) {
@ -41,21 +65,21 @@ public class TcpUAVTalk {
if (DEBUG) Log.d(TAG, "Trying to open UAVTalk with " + ip_address);
connected = false;
connected = false;
}
/**
* Connect a TCP object to an object manager. Returns true if already
* connected, otherwise returns true if managed a successful socket.
*/
public boolean connect(UAVObjectManager objMngr) {
if( getConnected() )
if( getConnected() )
return true;
if( !openTelemetryTcp(objMngr) )
return false;
return true;
return true;
}
public void disconnect() {
try {
socket.close();
@ -69,18 +93,18 @@ public class TcpUAVTalk {
public boolean getConnected() {
return connected;
}
public UAVTalk getUavtalk() {
return uavTalk;
}
/**
* Opens a TCP socket to the address determined on construction. If successful
* creates a UAVTalk stream connection this socket to the passed in object manager
*/
private boolean openTelemetryTcp(UAVObjectManager objMngr) {
Log.d(TAG, "Opening connection to " + ip_address + " at address " + port);
InetAddress serverAddr = null;
try {
serverAddr = InetAddress.getByName(ip_address);
@ -98,7 +122,7 @@ public class TcpUAVTalk {
}
connected = true;
try {
uavTalk = new UAVTalk(socket.getInputStream(), socket.getOutputStream(), objMngr);
} catch (IOException e) {
@ -107,7 +131,7 @@ public class TcpUAVTalk {
//e.printStackTrace();
return false;
}
return true;
}

View File

@ -1,3 +1,25 @@
/**
******************************************************************************
* @file TelemetryWidget.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A widget that shows the status of telemetry.
* @see The GNU Public License (GPL) Version 3
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import android.appwidget.AppWidgetManager;
@ -8,7 +30,7 @@ import android.content.Intent;
import android.widget.RemoteViews;
public class TelemetryWidget extends AppWidgetProvider {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(OPTelemetryService.INTENT_ACTION_CONNECTED)) {
@ -16,11 +38,11 @@ public class TelemetryWidget extends AppWidgetProvider {
}
if(intent.getAction().equals(OPTelemetryService.INTENT_ACTION_DISCONNECTED)) {
changeStatus(context, false);
}
}
super.onReceive(context, intent);
}
public void changeStatus(Context context, boolean status) {
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.telemetry_widget);
updateViews.setTextViewText(R.id.telemetryWidgetStatus, "Connection status: " + status);
@ -30,6 +52,7 @@ public class TelemetryWidget extends AppWidgetProvider {
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
@ -44,6 +67,6 @@ public class TelemetryWidget extends AppWidgetProvider {
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file UAVLocation.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Display the UAV location on google maps
* @see The GNU Public License (GPL) Version 3
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.androidgcs;
import java.util.List;
@ -10,14 +33,6 @@ import org.openpilot.uavtalk.UAVDataObject;
import org.openpilot.uavtalk.UAVObject;
import org.openpilot.uavtalk.UAVObjectManager;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
import com.google.android.maps.MyLocationOverlay;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@ -36,14 +51,22 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class UAVLocation extends MapActivity
{
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
public class UAVLocation extends MapActivity
{
private final String TAG = "UAVLocation";
private static int LOGLEVEL = 0;
// private static boolean WARN = LOGLEVEL > 1;
private static boolean DEBUG = LOGLEVEL > 0;
private MapView mapView;
private MapView mapView;
private MapController mapController;
UAVObjectManager objMngr;
@ -55,28 +78,28 @@ public class UAVLocation extends MapActivity
GeoPoint uavLocation;
@Override public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.map_layout);
super.onCreate(icicle);
setContentView(R.layout.map_layout);
mapView = (MapView)findViewById(R.id.map_view);
mapController = mapView.getController();
mapView.displayZoomControls(true);
Double lat = 37.422006*1E6;
Double lng = -122.084095*1E6;
Double lat = 37.422006*1E6;
Double lng = -122.084095*1E6;
homeLocation = new GeoPoint(lat.intValue(), lng.intValue());
uavLocation = homeLocation;
mapController.setCenter(homeLocation);
mapController.setCenter(homeLocation);
mapController.setZoom(18);
List<Overlay> overlays = mapView.getOverlays();
UAVOverlay myOverlay = new UAVOverlay();
overlays.add(myOverlay);
UAVOverlay myOverlay = new UAVOverlay();
overlays.add(myOverlay);
MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
myLocationOverlay.enableMyLocation();
myLocationOverlay.enableCompass();
overlays.add(myLocationOverlay);
mapView.postInvalidate();
// ObjectManager related stuff (can't inherit standard class)
@ -86,7 +109,7 @@ public class UAVLocation extends MapActivity
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)
@ -101,9 +124,9 @@ public class UAVLocation extends MapActivity
onOPDisconnected();
Log.d(TAG, "Disonnected()");
}
}
}
};
IntentFilter filter = new IntentFilter();
filter.addCategory(OPTelemetryService.INTENT_CATEGORY_GCS);
filter.addAction(OPTelemetryService.INTENT_ACTION_CONNECTED);
@ -111,103 +134,108 @@ public class UAVLocation extends MapActivity
registerReceiver(connectedReceiver, filter);
}
//@Override
//@Override
@Override
protected boolean isRouteDisplayed() {
// IMPORTANT: This method must return true if your Activity // is displaying driving directions. Otherwise return false.
// IMPORTANT: This method must return true if your Activity // is displaying driving directions. Otherwise return false.
return false;
}
public class UAVOverlay extends Overlay {
Bitmap homeSymbol = BitmapFactory.decodeResource(getResources(), R.drawable.ic_home);
Bitmap uavSymbol = BitmapFactory.decodeResource(getResources(), R.drawable.ic_uav);
@Override
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
Projection projection = mapView.getProjection();
if (shadow == false) {
Point myPoint = new Point();
Point myPoint = new Point();
projection.toPixels(uavLocation, myPoint);
//// Draw UAV
// Create and setup your paint brush
Paint paint = new Paint();
paint.setARGB(250, 255, 0, 0);
paint.setAntiAlias(true);
// Create and setup your paint brush
Paint paint = new Paint();
paint.setARGB(250, 255, 0, 0);
paint.setAntiAlias(true);
paint.setFakeBoldText(true);
// Draw on the canvas
canvas.drawBitmap(uavSymbol, myPoint.x - uavSymbol.getWidth() / 2,
// Draw on the canvas
canvas.drawBitmap(uavSymbol, myPoint.x - uavSymbol.getWidth() / 2,
myPoint.y - uavSymbol.getHeight() / 2, paint);
canvas.drawText("UAV", myPoint.x+uavSymbol.getWidth() / 2, myPoint.y, paint);
canvas.drawText("UAV", myPoint.x+uavSymbol.getWidth() / 2, myPoint.y, paint);
//// Draw Home
myPoint = new Point();
projection.toPixels(homeLocation, myPoint);
// Create and setup your paint brush
paint.setARGB(250, 0, 0, 0);
paint.setAntiAlias(true);
// Create and setup your paint brush
paint.setARGB(250, 0, 0, 0);
paint.setAntiAlias(true);
paint.setFakeBoldText(true);
canvas.drawBitmap(homeSymbol, myPoint.x - homeSymbol.getWidth() / 2,
myPoint.y - homeSymbol.getHeight() / 2, paint);
canvas.drawText("Home", myPoint.x+homeSymbol.getWidth(), myPoint.y, paint);
}
canvas.drawBitmap(homeSymbol, myPoint.x - homeSymbol.getWidth() / 2,
myPoint.y - homeSymbol.getHeight() / 2, paint);
canvas.drawText("Home", myPoint.x+homeSymbol.getWidth(), myPoint.y, paint);
}
}
@Override
public boolean onTap(GeoPoint point, MapView mapView1) {
// Return true if screen tap is handled by this overlay
return false;
return false;
}
}
void onOPConnected() {
UAVObject obj = objMngr.getObject("HomeLocation");
if(obj != null)
obj.addUpdatedObserver(new Observer() {
@Override
public void update(Observable observable, Object data) {
UAVDataObject obj = (UAVDataObject) data;
Double lat = obj.getField("Latitude").getDouble() / 10;
Double lon = obj.getField("Longitude").getDouble() / 10;
homeLocation = new GeoPoint(lat.intValue(), lon.intValue());
runOnUiThread(new Runnable() {
@Override
public void run() {
mapController.setCenter(homeLocation);
}
mapController.setCenter(homeLocation);
}
});
System.out.println("HomeLocation: " + homeLocation.toString());
}
}
});
obj.updateRequested();
obj = objMngr.getObject("PositionActual");
if(obj != null)
obj.addUpdatedObserver(new Observer() {
@Override
public void update(Observable observable, Object data) {
uavLocation = getUavLocation();
runOnUiThread(new Runnable() {
@Override
public void run() {
mapView.invalidate();
}
});
}
}
});
}
private GeoPoint getUavLocation() {
UAVObject pos = (UAVObject) objMngr.getObject("PositionActual");
UAVObject pos = objMngr.getObject("PositionActual");
if (pos == null)
return new GeoPoint(0,0);
UAVObject home = (UAVObject) objMngr.getObject("HomeLocation");
if (home == null)
UAVObject home = objMngr.getObject("HomeLocation");
if (home == null)
return new GeoPoint(0,0);
double lat, lon, alt;
lat = home.getField("Latitude").getDouble() / 10.0e6;
lon = home.getField("Longitude").getDouble() / 10.0e6;
@ -217,23 +245,23 @@ public class UAVLocation extends MapActivity
double T0, T1;
T0 = alt+6.378137E6;
T1 = Math.cos(lat * Math.PI / 180.0)*(alt+6.378137E6);
// Get the NED coordinates
double NED0, NED1;
NED0 = pos.getField("North").getDouble();
NED1 = pos.getField("East").getDouble();
// Compute the LLA coordinates
lat = lat + (NED0 / T0) * 180.0 / Math.PI;
lon = lon + (NED1 / T1) * 180.0 / Math.PI;
return new GeoPoint((int) (lat * 1e6), (int) (lon * 1e6));
}
void onOPDisconnected() {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
@ -265,15 +293,16 @@ public class UAVLocation extends MapActivity
Intent intent = new Intent(this, OPTelemetryService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
public void onBind() {
}
/** Defines callbacks for service binding, passed to bindService() */
private ServiceConnection mConnection = new ServiceConnection() {
private final ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName arg0, IBinder service) {
// We've bound to LocalService, cast the IBinder and attempt to open a connection
// We've bound to LocalService, cast the IBinder and attempt to open a connection
if (DEBUG) Log.d(TAG,"Service bound");
mBound = true;
binder = (LocalBinder) service;
@ -285,10 +314,11 @@ public class UAVLocation extends MapActivity
mConnected = true;
onOPConnected();
}
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
mBound = false;
binder = null;