From 59dfcbe14622c20aaa7d5b131eece9f4c8db6887 Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Thu, 7 Mar 2013 21:28:45 +1300 Subject: altosdroid: Import initial versions of XML and Java for Tab content * Includes TabsAdapter class borrowed from Support Library sample code * New "GoNoGoLights" class for dealing with the red/green/gray LEDs * extra required strings in strings.xml * Couple of support functions in AltosDroid.java * rudimentary Maps tab - does nothing at present. Signed-off-by: Mike Beattie --- .../src/org/altusmetrum/AltosDroid/TabLanded.java | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java (limited to 'altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java') diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java new file mode 100644 index 00000000..a95e9145 --- /dev/null +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java @@ -0,0 +1,83 @@ +/* + * Copyright © 2013 Mike Beattie + * + * 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; version 2 of the License. + * + * 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.altusmetrum.AltosDroid; + +import org.altusmetrum.altoslib_1.AltosState; + +import android.app.Activity; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +public class TabLanded extends Fragment implements AltosDroidTab { + AltosDroid mAltosDroid; + + private TextView mBearingView; + private TextView mDistanceView; + private TextView mLatitudeView; + private TextView mLongitudeView; + private TextView mMaxHeightView; + private TextView mMaxSpeedView; + private TextView mMaxAccelView; + + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + mAltosDroid = (AltosDroid) activity; + mAltosDroid.registerTab(this); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View v = inflater.inflate(R.layout.tab_landed, container, false); + + mBearingView = (TextView) v.findViewById(R.id.bearing_value); + mDistanceView = (TextView) v.findViewById(R.id.distance_value); + mLatitudeView = (TextView) v.findViewById(R.id.lat_value); + mLongitudeView = (TextView) v.findViewById(R.id.lon_value); + mMaxHeightView = (TextView) v.findViewById(R.id.max_height_value); + mMaxSpeedView = (TextView) v.findViewById(R.id.max_speed_value); + mMaxAccelView = (TextView) v.findViewById(R.id.max_accel_value); + + return v; + } + + @Override + public void onDestroy() { + super.onDestroy(); + mAltosDroid.unregisterTab(this); + mAltosDroid = null; + } + + public void update_ui(AltosState state) { + if (state.from_pad != null) { + mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing)); + mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance)); + } + mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); + mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + mMaxHeightView.setText(String.format("%6.0f m", state.max_height)); + mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration)); + mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed())); + } + +} -- cgit v1.2.3 From 9212ce268f3a4a9f3f019f23f6eef8b57207d340 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 12 Apr 2013 00:19:24 -0700 Subject: altosdroid: Compute course from android device to rocket, display it Signed-off-by: Keith Packard --- .../src/org/altusmetrum/AltosDroid/AltosDroid.java | 28 ++++++++++++++++++++- .../org/altusmetrum/AltosDroid/AltosDroidTab.java | 4 +-- .../src/org/altusmetrum/AltosDroid/TabAscent.java | 4 +-- .../src/org/altusmetrum/AltosDroid/TabDescent.java | 23 ++++++++++------- .../src/org/altusmetrum/AltosDroid/TabLanded.java | 10 ++++---- .../src/org/altusmetrum/AltosDroid/TabMap.java | 2 +- .../src/org/altusmetrum/AltosDroid/TabPad.java | 2 +- .../altusmetrum/AltosDroid/TelemetryReader.java | 8 +++--- .../altusmetrum/AltosDroid/TelemetryService.java | 29 ++++++++++++++-------- 9 files changed, 73 insertions(+), 37 deletions(-) (limited to 'altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java') diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index c9ce46a0..b1d080db 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -47,6 +47,7 @@ import android.widget.TabHost; import android.widget.TextView; import android.widget.Toast; import android.app.AlertDialog; +import android.location.Location; import org.altusmetrum.altoslib_1.*; @@ -59,6 +60,8 @@ public class AltosDroid extends FragmentActivity { public static final int MSG_STATE_CHANGE = 1; public static final int MSG_TELEMETRY = 2; public static final int MSG_UPDATE_AGE = 3; + public static final int MSG_LOCATION = 4; + public static final int MSG_CRC_ERROR = 5; // Intent request codes private static final int REQUEST_CONNECT_DEVICE = 1; @@ -87,6 +90,7 @@ public class AltosDroid extends FragmentActivity { // Timer and Saved flight state for Age calculation private Timer timer = new Timer(); AltosState saved_state; + Location saved_location; // Service private boolean mIsBound = false; @@ -137,6 +141,10 @@ public class AltosDroid extends FragmentActivity { case MSG_TELEMETRY: ad.update_ui((AltosState) msg.obj); break; + case MSG_LOCATION: + ad.set_location((Location) msg.obj); + break; + case MSG_CRC_ERROR: case MSG_UPDATE_AGE: if (ad.saved_state != null) { ad.mAgeView.setText(String.format("%d", (System.currentTimeMillis() - ad.saved_state.report_time + 500) / 1000)); @@ -196,6 +204,13 @@ public class AltosDroid extends FragmentActivity { mTabs.remove(mTab); } + void set_location(Location location) { + saved_location = location; + if (saved_state != null) { + update_ui(saved_state); + } + } + void update_ui(AltosState state) { if (saved_state != null) { if (saved_state.state != state.state) { @@ -215,6 +230,17 @@ public class AltosDroid extends FragmentActivity { } saved_state = state; + AltosGreatCircle from_receiver = null; + + if (saved_location != null && state.gps != null && state.gps.locked) { + from_receiver = new AltosGreatCircle(saved_location.getLatitude(), + saved_location.getLongitude(), + saved_location.getAltitude(), + state.gps.lat, + state.gps.lon, + state.gps.alt); + } + mCallsignView.setText(state.data.callsign); mSerialView.setText(String.format("%d", state.data.serial)); mFlightView.setText(String.format("%d", state.data.flight)); @@ -222,7 +248,7 @@ public class AltosDroid extends FragmentActivity { mRSSIView.setText(String.format("%d", state.data.rssi)); for (AltosDroidTab mTab : mTabs) - mTab.update_ui(state); + mTab.update_ui(state, from_receiver); mAltosVoice.tell(state); } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java index 68bbe593..2b5cdae7 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java @@ -17,8 +17,8 @@ package org.altusmetrum.AltosDroid; -import org.altusmetrum.altoslib_1.AltosState; +import org.altusmetrum.altoslib_1.*; public interface AltosDroidTab { - public void update_ui(AltosState state); + public void update_ui(AltosState state, AltosGreatCircle from_receiver); } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java index bda6b1fd..ce677c57 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java @@ -17,7 +17,7 @@ package org.altusmetrum.AltosDroid; -import org.altusmetrum.altoslib_1.AltosState; +import org.altusmetrum.altoslib_1.*; import android.app.Activity; import android.os.Bundle; @@ -84,7 +84,7 @@ public class TabAscent extends Fragment implements AltosDroidTab { mAltosDroid = null; } - public void update_ui(AltosState state) { + public void update_ui(AltosState state, AltosGreatCircle from_receiver) { mHeightView.setText(String.format("%6.0f m", state.height)); mMaxHeightView.setText(String.format("%6.0f m", state.max_height)); mSpeedView.setText(String.format("%6.0f m/s", state.speed())); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java index 3805b7e7..b0c6539c 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java @@ -17,8 +17,7 @@ package org.altusmetrum.AltosDroid; -import org.altusmetrum.altoslib_1.AltosGreatCircle; -import org.altusmetrum.altoslib_1.AltosState; +import org.altusmetrum.altoslib_1.*; import android.app.Activity; import android.os.Bundle; @@ -89,16 +88,22 @@ public class TabDescent extends Fragment implements AltosDroidTab { mAltosDroid = null; } - public void update_ui(AltosState state) { + public void update_ui(AltosState state, AltosGreatCircle from_receiver) { mSpeedView.setText(String.format("%6.0f m/s", state.speed())); mHeightView.setText(String.format("%6.0f m", state.height)); - mElevationView.setText(String.format("%3.0f°", state.elevation)); - mRangeView.setText(String.format("%6.0f m", state.range)); - if (state.from_pad != null) { - mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing)); - mCompassView.setText(state.from_pad.bearing_words(AltosGreatCircle.BEARING_LONG)); + if (from_receiver != null) { + mElevationView.setText(String.format("%3.0f°", from_receiver.elevation)); + mRangeView.setText(String.format("%6.0f m", from_receiver.range)); + mBearingView.setText(String.format("%3.0f°", from_receiver.bearing)); + mCompassView.setText(from_receiver.bearing_words(AltosGreatCircle.BEARING_LONG)); + mDistanceView.setText(String.format("%6.0f m", from_receiver.distance)); + } else { + mElevationView.setText(""); + mRangeView.setText(""); + mBearingView.setText(""); + mCompassView.setText(""); + mDistanceView.setText(""); } - mDistanceView.setText(String.format("%6.0f m", state.range)); mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java index a95e9145..93a42334 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java @@ -17,7 +17,7 @@ package org.altusmetrum.AltosDroid; -import org.altusmetrum.altoslib_1.AltosState; +import org.altusmetrum.altoslib_1.*; import android.app.Activity; import android.os.Bundle; @@ -68,10 +68,10 @@ public class TabLanded extends Fragment implements AltosDroidTab { mAltosDroid = null; } - public void update_ui(AltosState state) { - if (state.from_pad != null) { - mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing)); - mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance)); + public void update_ui(AltosState state, AltosGreatCircle from_receiver) { + if (from_receiver != null) { + mBearingView.setText(String.format("%3.0f°", from_receiver.bearing)); + mDistanceView.setText(String.format("%6.0f m", from_receiver.distance)); } mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java index 8fc8f592..607ded46 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java @@ -139,7 +139,7 @@ public class TabMap extends Fragment implements AltosDroidTab { } } - public void update_ui(AltosState state) { + public void update_ui(AltosState state, AltosGreatCircle from_receiver) { if (state.from_pad != null) { mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance)); mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing)); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java index 41776c10..6906324d 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java @@ -100,7 +100,7 @@ public class TabPad extends Fragment implements AltosDroidTab { mAltosDroid = null; } - public void update_ui(AltosState state) { + public void update_ui(AltosState state, AltosGreatCircle from_receiver) { mBatteryVoltageView.setText(String.format("%4.2f V", state.battery)); mBatteryLights.set(state.battery > 3.7); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java index fb07442e..716ec589 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java @@ -36,7 +36,6 @@ public class TelemetryReader extends Thread { Handler handler; - TelemetryService service; AltosLink link; AltosRecord previous; @@ -69,12 +68,12 @@ public class TelemetryReader extends Thread { if (record == null) break; state = new AltosState(record, state); - service.sendTelemetry(state); + handler.obtainMessage(TelemetryService.MSG_TELEMETRY, state).sendToTarget(); } catch (ParseException pp) { Log.e(TAG, String.format("Parse error: %d \"%s\"", pp.getErrorOffset(), pp.getMessage())); } catch (AltosCRCException ce) { ++crc_errors; - service.sendCrcErrors(crc_errors); + handler.obtainMessage(TelemetryService.MSG_CRC_ERROR, new Integer(crc_errors)).sendToTarget(); } } } catch (InterruptedException ee) { @@ -84,8 +83,7 @@ public class TelemetryReader extends Thread { } } - public TelemetryReader (TelemetryService in_service, AltosLink in_link, Handler in_handler) { - service = in_service; + public TelemetryReader (AltosLink in_link, Handler in_handler) { link = in_link; handler = in_handler; diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java index e6854585..0ddfdfc3 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java @@ -45,10 +45,10 @@ import android.location.LocationListener; import org.altusmetrum.altoslib_1.*; class AltosLocationListener implements LocationListener { - TelemetryService service; + Handler handler; public void onLocationChanged(Location location) { - service.sendLocation(location); + handler.obtainMessage(TelemetryService.MSG_LOCATION, location).sendToTarget(); } public void onStatusChanged(String provider, int status, Bundle extras) { @@ -60,8 +60,8 @@ class AltosLocationListener implements LocationListener { public void onProviderDisabled(String provider) { } - public AltosLocationListener(TelemetryService service) { - this.service = service; + public AltosLocationListener(Handler handler) { + this.handler = handler; } } @@ -169,8 +169,20 @@ public class TelemetryService extends Service { } break; case MSG_TELEMETRY: + // forward telemetry messages + s.last_state = (AltosState) msg.obj; s.sendMessageToClients(Message.obtain(null, AltosDroid.MSG_TELEMETRY, msg.obj)); break; + case MSG_LOCATION: + // forward location messages + s.last_location = (Location) msg.obj; + s.sendMessageToClients(Message.obtain(null, AltosDroid.MSG_LOCATION, msg.obj)); + break; + case MSG_CRC_ERROR: + // forward crc error messages + s.last_crc_errors = (Integer) msg.obj; + s.sendMessageToClients(Message.obtain(null, AltosDroid.MSG_CRC_ERROR, msg.obj)); + break; case MSG_SETFREQUENCY: if (s.state == STATE_CONNECTED) { try { @@ -187,18 +199,13 @@ public class TelemetryService extends Service { } public void sendTelemetry(AltosState state) { - last_state = state; - mHandler.obtainMessage(MSG_TELEMETRY, state).sendToTarget(); } public void sendLocation(Location location) { - last_location = location; mHandler.obtainMessage(MSG_LOCATION, location).sendToTarget(); } public void sendCrcErrors(int crc_errors) { - last_crc_errors = crc_errors; - mHandler.obtainMessage(MSG_CRC_ERROR, new Integer(crc_errors)).sendToTarget(); } private void sendMessageToClients(Message m) { @@ -278,7 +285,7 @@ public class TelemetryService extends Service { setState(STATE_CONNECTED); - mTelemetryReader = new TelemetryReader(this, mAltosBluetooth, mHandler); + mTelemetryReader = new TelemetryReader(mAltosBluetooth, mHandler); mTelemetryReader.start(); mTelemetryLogger = new TelemetryLogger(this, mAltosBluetooth); @@ -308,7 +315,7 @@ public class TelemetryService extends Service { timer.scheduleAtFixedRate(new TimerTask(){ public void run() {onTimerTick();}}, 10000L, 10000L); // Listen for GPS and Network position updates - locationListener = new AltosLocationListener(this); + locationListener = new AltosLocationListener(mHandler); LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); -- cgit v1.2.3 From 1ec6fb3b9cec0f864d6e65d0cc6b4dd42edd3e16 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 12 Apr 2013 01:00:36 -0700 Subject: altosdroid: Check state.gps != null before using it Avoid crashing. Signed-off-by: Keith Packard --- .../src/org/altusmetrum/AltosDroid/AltosDroid.java | 7 +++-- .../org/altusmetrum/AltosDroid/AltosDroidTab.java | 3 ++- .../src/org/altusmetrum/AltosDroid/TabAscent.java | 9 ++++--- .../src/org/altusmetrum/AltosDroid/TabDescent.java | 9 ++++--- .../src/org/altusmetrum/AltosDroid/TabLanded.java | 9 ++++--- .../src/org/altusmetrum/AltosDroid/TabMap.java | 31 +++++++++++++++++----- .../src/org/altusmetrum/AltosDroid/TabPad.java | 31 +++++++++++++--------- 7 files changed, 68 insertions(+), 31 deletions(-) (limited to 'altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java') diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index b1d080db..cf4227ca 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -233,9 +233,12 @@ public class AltosDroid extends FragmentActivity { AltosGreatCircle from_receiver = null; if (saved_location != null && state.gps != null && state.gps.locked) { + double altitude = 0; + if (saved_location.hasAltitude()) + altitude = saved_location.getAltitude(); from_receiver = new AltosGreatCircle(saved_location.getLatitude(), saved_location.getLongitude(), - saved_location.getAltitude(), + altitude, state.gps.lat, state.gps.lon, state.gps.alt); @@ -248,7 +251,7 @@ public class AltosDroid extends FragmentActivity { mRSSIView.setText(String.format("%d", state.data.rssi)); for (AltosDroidTab mTab : mTabs) - mTab.update_ui(state, from_receiver); + mTab.update_ui(state, from_receiver, saved_location); mAltosVoice.tell(state); } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java index 2b5cdae7..6ebb47f7 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java @@ -18,7 +18,8 @@ package org.altusmetrum.AltosDroid; import org.altusmetrum.altoslib_1.*; +import android.location.Location; public interface AltosDroidTab { - public void update_ui(AltosState state, AltosGreatCircle from_receiver); + public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver); } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java index ce677c57..de3bc3d2 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java @@ -27,6 +27,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import android.location.Location; public class TabAscent extends Fragment implements AltosDroidTab { AltosDroid mAltosDroid; @@ -84,7 +85,7 @@ public class TabAscent extends Fragment implements AltosDroidTab { mAltosDroid = null; } - public void update_ui(AltosState state, AltosGreatCircle from_receiver) { + public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) { mHeightView.setText(String.format("%6.0f m", state.height)); mMaxHeightView.setText(String.format("%6.0f m", state.max_height)); mSpeedView.setText(String.format("%6.0f m/s", state.speed())); @@ -92,8 +93,10 @@ public class TabAscent extends Fragment implements AltosDroidTab { mAccelView.setText(String.format("%6.0f m/s²", state.acceleration)); mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration)); - mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); - mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + if (state.gps != null) { + mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); + mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + } mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense)); mApogeeLights.set(state.drogue_sense > 3.2); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java index b0c6539c..698e89fc 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java @@ -27,6 +27,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import android.location.Location; public class TabDescent extends Fragment implements AltosDroidTab { AltosDroid mAltosDroid; @@ -88,7 +89,7 @@ public class TabDescent extends Fragment implements AltosDroidTab { mAltosDroid = null; } - public void update_ui(AltosState state, AltosGreatCircle from_receiver) { + public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) { mSpeedView.setText(String.format("%6.0f m/s", state.speed())); mHeightView.setText(String.format("%6.0f m", state.height)); if (from_receiver != null) { @@ -104,8 +105,10 @@ public class TabDescent extends Fragment implements AltosDroidTab { mCompassView.setText(""); mDistanceView.setText(""); } - mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); - mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + if (state.gps != null) { + mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); + mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + } mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense)); mApogeeLights.set(state.drogue_sense > 3.2); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java index 93a42334..c346dc99 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java @@ -26,6 +26,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import android.location.Location; public class TabLanded extends Fragment implements AltosDroidTab { AltosDroid mAltosDroid; @@ -68,13 +69,15 @@ public class TabLanded extends Fragment implements AltosDroidTab { mAltosDroid = null; } - public void update_ui(AltosState state, AltosGreatCircle from_receiver) { + public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) { if (from_receiver != null) { mBearingView.setText(String.format("%3.0f°", from_receiver.bearing)); mDistanceView.setText(String.format("%6.0f m", from_receiver.distance)); } - mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); - mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + if (state.gps != null) { + mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); + mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + } mMaxHeightView.setText(String.format("%6.0f m", state.max_height)); mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration)); mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed())); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java index 607ded46..371fd9c1 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java @@ -40,6 +40,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import android.location.Location; public class TabMap extends Fragment implements AltosDroidTab { AltosDroid mAltosDroid; @@ -50,6 +51,7 @@ public class TabMap extends Fragment implements AltosDroidTab { private Marker mRocketMarker; private Marker mPadMarker; + private Marker mReceiverMarker; private Polyline mPolyline; private TextView mDistanceView; @@ -128,6 +130,12 @@ public class TabMap extends Fragment implements AltosDroidTab { .visible(false) ); + mReceiverMarker = mMap.addMarker( + new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.pad)) + .position(new LatLng(0,0)) + .visible(false) + ); + mPolyline = mMap.addPolyline( new PolylineOptions().add(new LatLng(0,0), new LatLng(0,0)) .width(3) @@ -139,25 +147,34 @@ public class TabMap extends Fragment implements AltosDroidTab { } } - public void update_ui(AltosState state, AltosGreatCircle from_receiver) { + public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) { if (state.from_pad != null) { mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance)); mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing)); } - mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); - mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + if (state.gps != null) { + mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); + mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + } if (mapLoaded) { - mRocketMarker.setPosition(new LatLng(state.gps.lat, state.gps.lon)); - mRocketMarker.setVisible(true); + if (state.gps != null) { + mRocketMarker.setPosition(new LatLng(state.gps.lat, state.gps.lon)); + mRocketMarker.setVisible(true); - mPolyline.setPoints(Arrays.asList(new LatLng(state.pad_lat, state.pad_lon), new LatLng(state.gps.lat, state.gps.lon))); - mPolyline.setVisible(true); + mPolyline.setPoints(Arrays.asList(new LatLng(state.pad_lat, state.pad_lon), new LatLng(state.gps.lat, state.gps.lon))); + mPolyline.setVisible(true); + } if (state.state == AltosLib.ao_flight_pad) { mPadMarker.setPosition(new LatLng(state.pad_lat, state.pad_lon)); mPadMarker.setVisible(true); } + + if (receiver != null) { + mReceiverMarker.setPosition(new LatLng(receiver.getLatitude(), receiver.getLongitude())); + mReceiverMarker.setVisible(true); + } } } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java index 6906324d..5070ec0b 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java @@ -27,6 +27,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import android.location.Location; public class TabPad extends Fragment implements AltosDroidTab { AltosDroid mAltosDroid; @@ -100,7 +101,7 @@ public class TabPad extends Fragment implements AltosDroidTab { mAltosDroid = null; } - public void update_ui(AltosState state, AltosGreatCircle from_receiver) { + public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) { mBatteryVoltageView.setText(String.format("%4.2f V", state.battery)); mBatteryLights.set(state.battery > 3.7); @@ -122,18 +123,24 @@ public class TabPad extends Fragment implements AltosDroidTab { } mDataLoggingLights.set(state.data.flight != 0); - mGPSLockedView.setText(String.format("%4d sats", state.gps.nsat)); - mGPSLockedLights.set(state.gps.locked && state.gps.nsat >= 4); - - if (state.gps_ready) - mGPSReadyView.setText("Ready"); - else - mGPSReadyView.setText(String.format("Waiting %d", state.gps_waiting)); - mGPSReadyLights.set(state.gps_ready); + if (state.gps != null) { + mGPSLockedView.setText(String.format("%4d sats", state.gps.nsat)); + mGPSLockedLights.set(state.gps.locked && state.gps.nsat >= 4); + if (state.gps_ready) + mGPSReadyView.setText("Ready"); + else + mGPSReadyView.setText(String.format("Waiting %d", state.gps_waiting)); + mGPSReadyLights.set(state.gps_ready); + } - mPadLatitudeView.setText(AltosDroid.pos(state.pad_lat, "N", "S")); - mPadLongitudeView.setText(AltosDroid.pos(state.pad_lon, "W", "E")); - mPadAltitudeView.setText(String.format("%4.0f m", state.pad_alt)); + if (receiver != null) { + double altitude = 0; + if (receiver.hasAltitude()) + altitude = receiver.getAltitude(); + mPadLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S")); + mPadLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "W", "E")); + mPadAltitudeView.setText(String.format("%4.0f m", altitude)); + } } } -- cgit v1.2.3 From 3cd8ff18a7546c1e251747ba26240cb130003ef1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 13 Apr 2013 12:13:18 -0700 Subject: altosdroid: Update UI even if no telem has been received. Center map. This allows the receiver location to be displayed even when telemetry is not. Center the map on the first valid location, either receiver or rocket. Update center if a significantly more precise location is received. Signed-off-by: Keith Packard --- altosdroid/res/layout/tab_landed.xml | 58 +++++++++++++++++--- .../src/org/altusmetrum/AltosDroid/AltosDroid.java | 23 ++++---- .../src/org/altusmetrum/AltosDroid/TabAscent.java | 34 ++++++------ .../src/org/altusmetrum/AltosDroid/TabDescent.java | 50 ++++++++--------- .../src/org/altusmetrum/AltosDroid/TabLanded.java | 32 +++++++---- .../src/org/altusmetrum/AltosDroid/TabMap.java | 62 ++++++++++++++-------- .../src/org/altusmetrum/AltosDroid/TabPad.java | 60 +++++++++++---------- 7 files changed, 199 insertions(+), 120 deletions(-) (limited to 'altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java') diff --git a/altosdroid/res/layout/tab_landed.xml b/altosdroid/res/layout/tab_landed.xml index 9008700f..f27baa9e 100644 --- a/altosdroid/res/layout/tab_landed.xml +++ b/altosdroid/res/layout/tab_landed.xml @@ -67,17 +67,17 @@ android:paddingTop="5dp" > + android:text="@string/target_latitude_label" /> @@ -88,17 +88,59 @@ android:paddingTop="5dp" > + android:text="@string/target_longitude_label" /> + + + + + + + + + + + + + + diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index 93af2fdc..5ce6f810 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -205,13 +205,11 @@ public class AltosDroid extends FragmentActivity { void set_location(Location location) { saved_location = location; - if (saved_state != null) { - update_ui(saved_state); - } + update_ui(saved_state); } void update_ui(AltosState state) { - if (saved_state != null) { + if (state != null && saved_state != null) { if (saved_state.state != state.state) { String currentTab = mTabHost.getCurrentTabTag(); switch (state.state) { @@ -231,7 +229,7 @@ public class AltosDroid extends FragmentActivity { AltosGreatCircle from_receiver = null; - if (saved_location != null && state.gps != null && state.gps.locked) { + if (state != null && saved_location != null && state.gps != null && state.gps.locked) { double altitude = 0; if (saved_location.hasAltitude()) altitude = saved_location.getAltitude(); @@ -243,16 +241,19 @@ public class AltosDroid extends FragmentActivity { state.gps.alt); } - mCallsignView.setText(state.data.callsign); - mSerialView.setText(String.format("%d", state.data.serial)); - mFlightView.setText(String.format("%d", state.data.flight)); - mStateView.setText(state.data.state()); - mRSSIView.setText(String.format("%d", state.data.rssi)); + if (state != null) { + mCallsignView.setText(state.data.callsign); + mSerialView.setText(String.format("%d", state.data.serial)); + mFlightView.setText(String.format("%d", state.data.flight)); + mStateView.setText(state.data.state()); + mRSSIView.setText(String.format("%d", state.data.rssi)); + } for (AltosDroidTab mTab : mTabs) mTab.update_ui(state, from_receiver, saved_location); - mAltosVoice.tell(state); + if (state != null) + mAltosVoice.tell(state); } private void onTimerTick() { diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java index de3bc3d2..23d2e97c 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java @@ -86,22 +86,24 @@ public class TabAscent extends Fragment implements AltosDroidTab { } public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) { - mHeightView.setText(String.format("%6.0f m", state.height)); - mMaxHeightView.setText(String.format("%6.0f m", state.max_height)); - mSpeedView.setText(String.format("%6.0f m/s", state.speed())); - mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed())); - mAccelView.setText(String.format("%6.0f m/s²", state.acceleration)); - mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration)); - - if (state.gps != null) { - mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); - mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + if (state != null) { + mHeightView.setText(String.format("%6.0f m", state.height)); + mMaxHeightView.setText(String.format("%6.0f m", state.max_height)); + mSpeedView.setText(String.format("%6.0f m/s", state.speed())); + mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed())); + mAccelView.setText(String.format("%6.0f m/s²", state.acceleration)); + mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration)); + + if (state.gps != null) { + mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); + mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + } + + mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense)); + mApogeeLights.set(state.drogue_sense > 3.2); + + mMainVoltageView.setText(String.format("%4.2f V", state.main_sense)); + mMainLights.set(state.main_sense > 3.2); } - - mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense)); - mApogeeLights.set(state.drogue_sense > 3.2); - - mMainVoltageView.setText(String.format("%4.2f V", state.main_sense)); - mMainLights.set(state.main_sense > 3.2); } } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java index 698e89fc..49774a30 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java @@ -90,31 +90,33 @@ public class TabDescent extends Fragment implements AltosDroidTab { } public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) { - mSpeedView.setText(String.format("%6.0f m/s", state.speed())); - mHeightView.setText(String.format("%6.0f m", state.height)); - if (from_receiver != null) { - mElevationView.setText(String.format("%3.0f°", from_receiver.elevation)); - mRangeView.setText(String.format("%6.0f m", from_receiver.range)); - mBearingView.setText(String.format("%3.0f°", from_receiver.bearing)); - mCompassView.setText(from_receiver.bearing_words(AltosGreatCircle.BEARING_LONG)); - mDistanceView.setText(String.format("%6.0f m", from_receiver.distance)); - } else { - mElevationView.setText(""); - mRangeView.setText(""); - mBearingView.setText(""); - mCompassView.setText(""); - mDistanceView.setText(""); + if (state != null) { + mSpeedView.setText(String.format("%6.0f m/s", state.speed())); + mHeightView.setText(String.format("%6.0f m", state.height)); + if (from_receiver != null) { + mElevationView.setText(String.format("%3.0f°", from_receiver.elevation)); + mRangeView.setText(String.format("%6.0f m", from_receiver.range)); + mBearingView.setText(String.format("%3.0f°", from_receiver.bearing)); + mCompassView.setText(from_receiver.bearing_words(AltosGreatCircle.BEARING_LONG)); + mDistanceView.setText(String.format("%6.0f m", from_receiver.distance)); + } else { + mElevationView.setText(""); + mRangeView.setText(""); + mBearingView.setText(""); + mCompassView.setText(""); + mDistanceView.setText(""); + } + if (state.gps != null) { + mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); + mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + } + + mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense)); + mApogeeLights.set(state.drogue_sense > 3.2); + + mMainVoltageView.setText(String.format("%4.2f V", state.main_sense)); + mMainLights.set(state.main_sense > 3.2); } - if (state.gps != null) { - mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); - mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); - } - - mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense)); - mApogeeLights.set(state.drogue_sense > 3.2); - - mMainVoltageView.setText(String.format("%4.2f V", state.main_sense)); - mMainLights.set(state.main_sense > 3.2); } } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java index c346dc99..f42b46b5 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java @@ -33,8 +33,10 @@ public class TabLanded extends Fragment implements AltosDroidTab { private TextView mBearingView; private TextView mDistanceView; - private TextView mLatitudeView; - private TextView mLongitudeView; + private TextView mTargetLatitudeView; + private TextView mTargetLongitudeView; + private TextView mReceiverLatitudeView; + private TextView mReceiverLongitudeView; private TextView mMaxHeightView; private TextView mMaxSpeedView; private TextView mMaxAccelView; @@ -53,8 +55,10 @@ public class TabLanded extends Fragment implements AltosDroidTab { mBearingView = (TextView) v.findViewById(R.id.bearing_value); mDistanceView = (TextView) v.findViewById(R.id.distance_value); - mLatitudeView = (TextView) v.findViewById(R.id.lat_value); - mLongitudeView = (TextView) v.findViewById(R.id.lon_value); + mTargetLatitudeView = (TextView) v.findViewById(R.id.target_lat_value); + mTargetLongitudeView = (TextView) v.findViewById(R.id.target_lon_value); + mReceiverLatitudeView = (TextView) v.findViewById(R.id.receiver_lat_value); + mReceiverLongitudeView = (TextView) v.findViewById(R.id.receiver_lon_value); mMaxHeightView = (TextView) v.findViewById(R.id.max_height_value); mMaxSpeedView = (TextView) v.findViewById(R.id.max_speed_value); mMaxAccelView = (TextView) v.findViewById(R.id.max_accel_value); @@ -74,13 +78,21 @@ public class TabLanded extends Fragment implements AltosDroidTab { mBearingView.setText(String.format("%3.0f°", from_receiver.bearing)); mDistanceView.setText(String.format("%6.0f m", from_receiver.distance)); } - if (state.gps != null) { - mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); - mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + if (state != null && state.gps != null) { + mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); + mTargetLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + } + + if (receiver != null) { + mReceiverLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S")); + mReceiverLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "W", "E")); + } + + if (state != null) { + mMaxHeightView.setText(String.format("%6.0f m", state.max_height)); + mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration)); + mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed())); } - mMaxHeightView.setText(String.format("%6.0f m", state.max_height)); - mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration)); - mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed())); } } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java index 29696dbf..66669ad0 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java @@ -60,6 +60,8 @@ public class TabMap extends Fragment implements AltosDroidTab { private TextView mReceiverLatitudeView; private TextView mReceiverLongitudeView; + private double mapAccuracy = -1; + @Override public void onAttach(Activity activity) { super.onAttach(activity); @@ -118,7 +120,6 @@ public class TabMap extends Fragment implements AltosDroidTab { mMap.setMyLocationEnabled(true); mMap.getUiSettings().setTiltGesturesEnabled(false); mMap.getUiSettings().setZoomControlsEnabled(false); - mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40.8,-104.7),8)); mRocketMarker = mMap.addMarker( // From: http://mapicons.nicolasmollet.com/markers/industry/military/missile-2/ @@ -144,35 +145,52 @@ public class TabMap extends Fragment implements AltosDroidTab { } } - public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) { - if (state.from_pad != null) { - mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance)); - mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing)); + private void center(double lat, double lon, double accuracy) { + if (mapAccuracy < 0 || accuracy < mapAccuracy/10) { + mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lon),14)); + mapAccuracy = accuracy; } - if (state.gps != null) { - mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); - mTargetLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + } + public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) { + if (state != null) { + if (state.from_pad != null) { + mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance)); + mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing)); + } + if (mapLoaded) { + if (state.gps != null) { + mRocketMarker.setPosition(new LatLng(state.gps.lat, state.gps.lon)); + mRocketMarker.setVisible(true); + + mPolyline.setPoints(Arrays.asList(new LatLng(state.pad_lat, state.pad_lon), new LatLng(state.gps.lat, state.gps.lon))); + mPolyline.setVisible(true); + } + + if (state.state == AltosLib.ao_flight_pad) { + mPadMarker.setPosition(new LatLng(state.pad_lat, state.pad_lon)); + mPadMarker.setVisible(true); + } + } + if (state.gps != null) { + mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); + mTargetLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + if (state.gps.locked && state.gps.nsat >= 4) + center (state.gps.lat, state.gps.lon, 10); + } } if (receiver != null) { + double accuracy; + + if (receiver.hasAccuracy()) + accuracy = receiver.getAccuracy(); + else + accuracy = 1000; mReceiverLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S")); mReceiverLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "W", "E")); + center (receiver.getLatitude(), receiver.getLongitude(), accuracy); } - if (mapLoaded) { - if (state.gps != null) { - mRocketMarker.setPosition(new LatLng(state.gps.lat, state.gps.lon)); - mRocketMarker.setVisible(true); - - mPolyline.setPoints(Arrays.asList(new LatLng(state.pad_lat, state.pad_lon), new LatLng(state.gps.lat, state.gps.lon))); - mPolyline.setVisible(true); - } - - if (state.state == AltosLib.ao_flight_pad) { - mPadMarker.setPosition(new LatLng(state.pad_lat, state.pad_lon)); - mPadMarker.setVisible(true); - } - } } } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java index 5070ec0b..3c168e37 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java @@ -102,35 +102,37 @@ public class TabPad extends Fragment implements AltosDroidTab { } public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) { - mBatteryVoltageView.setText(String.format("%4.2f V", state.battery)); - mBatteryLights.set(state.battery > 3.7); - - mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense)); - mApogeeLights.set(state.drogue_sense > 3.2); - - mMainVoltageView.setText(String.format("%4.2f V", state.main_sense)); - mMainLights.set(state.main_sense > 3.2); - - if (state.data.flight != 0) { - if (state.data.state <= AltosLib.ao_flight_pad) - mDataLoggingView.setText("Ready to record"); - else if (state.data.state < AltosLib.ao_flight_landed) - mDataLoggingView.setText("Recording data"); - else - mDataLoggingView.setText("Recorded data"); - } else { - mDataLoggingView.setText("Storage full"); - } - mDataLoggingLights.set(state.data.flight != 0); - - if (state.gps != null) { - mGPSLockedView.setText(String.format("%4d sats", state.gps.nsat)); - mGPSLockedLights.set(state.gps.locked && state.gps.nsat >= 4); - if (state.gps_ready) - mGPSReadyView.setText("Ready"); - else - mGPSReadyView.setText(String.format("Waiting %d", state.gps_waiting)); - mGPSReadyLights.set(state.gps_ready); + if (state != null) { + mBatteryVoltageView.setText(String.format("%4.2f V", state.battery)); + mBatteryLights.set(state.battery > 3.7); + + mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense)); + mApogeeLights.set(state.drogue_sense > 3.2); + + mMainVoltageView.setText(String.format("%4.2f V", state.main_sense)); + mMainLights.set(state.main_sense > 3.2); + + if (state.data.flight != 0) { + if (state.data.state <= AltosLib.ao_flight_pad) + mDataLoggingView.setText("Ready to record"); + else if (state.data.state < AltosLib.ao_flight_landed) + mDataLoggingView.setText("Recording data"); + else + mDataLoggingView.setText("Recorded data"); + } else { + mDataLoggingView.setText("Storage full"); + } + mDataLoggingLights.set(state.data.flight != 0); + + if (state.gps != null) { + mGPSLockedView.setText(String.format("%4d sats", state.gps.nsat)); + mGPSLockedLights.set(state.gps.locked && state.gps.nsat >= 4); + if (state.gps_ready) + mGPSReadyView.setText("Ready"); + else + mGPSReadyView.setText(String.format("Waiting %d", state.gps_waiting)); + mGPSReadyLights.set(state.gps_ready); + } } if (receiver != null) { -- cgit v1.2.3