From 21d176f161b90f18f236ef887cef9676d712eee3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 21 Apr 2016 21:12:40 -0400 Subject: Update java library version numbers Prepare for 1.6.3 release. Signed-off-by: Keith Packard --- altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java') diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java index 92a7ecfa..6edc20c7 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java @@ -43,7 +43,7 @@ import android.location.LocationManager; import android.location.LocationListener; import android.location.Criteria; -import org.altusmetrum.altoslib_9.*; +import org.altusmetrum.altoslib_10.*; public class TelemetryService extends Service implements LocationListener { -- cgit v1.2.3 From 57c1320962ad08d52e89d39bd5852f8d228dd872 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 21 Apr 2016 22:37:35 -0400 Subject: altosdroid: Can only use message once And here I thought re-using the message was clever. That generates a nice exception and crashes the program. Signed-off-by: Keith Packard --- altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java') diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java index 6edc20c7..63592e29 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java @@ -248,7 +248,7 @@ public class TelemetryService extends Service implements LocationListener { /* On connect, send the current state to the new client */ - send_to_client(client, message()); + send_to_client(client); /* If we've got an address from a previous session, then * go ahead and try to reconnect to the device @@ -275,7 +275,8 @@ public class TelemetryService extends Service implements LocationListener { } } - private void send_to_client(Messenger client, Message m) { + private void send_to_client(Messenger client) { + Message m = message(); try { client.send(m); } catch (RemoteException e) { @@ -285,9 +286,8 @@ public class TelemetryService extends Service implements LocationListener { } private void send_to_clients() { - Message m = message(); for (Messenger client : clients) - send_to_client(client, m); + send_to_client(client); } private void disconnect(boolean notify) { -- cgit v1.2.3 From 39af826ce9032e339929eb7917b1d29c87d03f69 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 22 Apr 2016 17:32:10 -0400 Subject: altosdroid: Track device location in app, not telemetry service This means we get location even if there isn't a telemetry device connected, making it possible to walk to old device locations Signed-off-by: Keith Packard --- .../src/org/altusmetrum/AltosDroid/AltosDroid.java | 46 ++++++++++++++++++++-- .../altusmetrum/AltosDroid/TelemetryService.java | 30 +------------- .../org/altusmetrum/AltosDroid/TelemetryState.java | 2 - 3 files changed, 43 insertions(+), 35 deletions(-) (limited to 'altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java') diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index f317f31d..85513325 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -45,13 +45,15 @@ import android.view.*; import android.widget.*; import android.app.AlertDialog; import android.location.Location; +import android.location.LocationManager; +import android.location.LocationListener; import android.hardware.usb.*; import android.graphics.*; import android.graphics.drawable.*; import org.altusmetrum.altoslib_10.*; -public class AltosDroid extends FragmentActivity implements AltosUnitsListener { +public class AltosDroid extends FragmentActivity implements AltosUnitsListener, LocationListener { // Actions sent to the telemetry server at startup time @@ -98,6 +100,8 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { private double frequency; private int telemetry_rate; + public Location location = null; + // Tabs TabHost mTabHost; AltosViewPager mViewPager; @@ -314,7 +318,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { state = newest_state; } - update_ui(telemetry_state, state, telemetry_state.location); + update_ui(telemetry_state, state); start_timer(); } @@ -379,7 +383,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { } } - void update_ui(TelemetryState telem_state, AltosState state, Location location) { + void update_ui(TelemetryState telem_state, AltosState state) { int prev_state = AltosLib.ao_flight_invalid; @@ -679,12 +683,26 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { public void onResume() { super.onResume(); AltosDebug.debug("+ ON RESUME +"); + + // Listen for GPS and Network position updates + LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this); + + location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + + AltosDebug.debug("Resume, location is %f,%f\n", + location.getLatitude(), + location.getLongitude()); + + update_ui(telemetry_state, saved_state); } @Override public void onPause() { super.onPause(); AltosDebug.debug("- ON PAUSE -"); + // Stop listening for location updates + ((LocationManager) getSystemService(Context.LOCATION_SERVICE)).removeUpdates(this); } @Override @@ -1015,7 +1033,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { } static String direction(AltosGreatCircle from_receiver, - Location receiver) { + Location receiver) { if (from_receiver == null) return null; @@ -1044,4 +1062,24 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { else return String.format("right %d°", iheading); } + + public void onLocationChanged(Location location) { + this.location = location; + AltosDebug.debug("Location changed to %f,%f", + location.getLatitude(), + location.getLongitude()); + update_ui(telemetry_state, saved_state); + } + + public void onStatusChanged(String provider, int status, Bundle extras) { + AltosDebug.debug("Location status now %d\n", status); + } + + public void onProviderEnabled(String provider) { + AltosDebug.debug("Location provider enabled %s\n", provider); + } + + public void onProviderDisabled(String provider) { + AltosDebug.debug("Location provider disabled %s\n", provider); + } } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java index 63592e29..1834d55b 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java @@ -38,14 +38,11 @@ import android.os.Messenger; import android.os.RemoteException; import android.os.Looper; import android.widget.Toast; -import android.location.Location; -import android.location.LocationManager; -import android.location.LocationListener; import android.location.Criteria; import org.altusmetrum.altoslib_10.*; -public class TelemetryService extends Service implements LocationListener { +public class TelemetryService extends Service { static final int MSG_REGISTER_CLIENT = 1; static final int MSG_UNREGISTER_CLIENT = 2; @@ -484,11 +481,6 @@ public class TelemetryService extends Service implements LocationListener { telemetry_state.states.put(serial, saved_state.state); } } - - // Listen for GPS and Network position updates - LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); - - locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this); } @Override @@ -535,9 +527,6 @@ public class TelemetryService extends Service implements LocationListener { @Override public void onDestroy() { - // Stop listening for location updates - ((LocationManager) getSystemService(Context.LOCATION_SERVICE)).removeUpdates(this); - // Stop the bluetooth Comms threads disconnect(true); @@ -552,21 +541,4 @@ public class TelemetryService extends Service implements LocationListener { public IBinder onBind(Intent intent) { return messenger.getBinder(); } - - - public void onLocationChanged(Location location) { - telemetry_state.location = location; - AltosDebug.debug("location changed"); - send_to_clients(); - } - - public void onStatusChanged(String provider, int status, Bundle extras) { - } - - public void onProviderEnabled(String provider) { - } - - public void onProviderDisabled(String provider) { - } - } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryState.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryState.java index ec9f4798..d3ccf0a9 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryState.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryState.java @@ -30,7 +30,6 @@ public class TelemetryState { int connect; DeviceAddress address; AltosConfigData config; - Location location; int crc_errors; double receiver_battery; double frequency; @@ -44,7 +43,6 @@ public class TelemetryState { connect = CONNECT_NONE; config = null; states = new HashMap(); - location = null; crc_errors = 0; receiver_battery = AltosLib.MISSING; frequency = AltosPreferences.frequency(0); -- cgit v1.2.3 From f49fd5d2be68de97ebe65fa4f6484746e91dd677 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 22 Apr 2016 18:53:32 -0400 Subject: altosdroid: Run even without Bluetooth This lets us view old state information on USB-only devices, or when the bluetooth device can't be enabled. Signed-off-by: Keith Packard --- .../src/org/altusmetrum/AltosDroid/AltosDroid.java | 41 ++++++++++------------ .../altusmetrum/AltosDroid/TelemetryService.java | 24 ++++++++----- 2 files changed, 35 insertions(+), 30 deletions(-) (limited to 'altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java') diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index 85513325..4f1dcb1a 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -564,22 +564,15 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, mAgeOldColor = getResources().getColor(R.color.old_color); } - private boolean ensureBluetooth() { + private void ensureBluetooth() { // Get local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); - // If the adapter is null, then Bluetooth is not supported - if (mBluetoothAdapter == null) { - Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); - return false; - } - - if (!mBluetoothAdapter.isEnabled()) { + /* if there is a BT adapter and it isn't turned on, then turn it on */ + if (mBluetoothAdapter != null && !mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, AltosDroid.REQUEST_ENABLE_BT); } - - return true; } private boolean check_usb() { @@ -645,9 +638,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, return; } AltosDebug.debug("Starting by looking for bluetooth devices"); - if (ensureBluetooth()) - return; - finish(); + ensureBluetooth(); } } @@ -738,12 +729,11 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, if (resultCode == Activity.RESULT_OK) { // Bluetooth is now enabled, so set up a chat session //setupChat(); + AltosDebug.debug("BT enabled"); + bluetoothEnabled(data); } else { // User did not enable Bluetooth or an error occured - AltosDebug.error("BT not enabled"); - stopService(new Intent(AltosDroid.this, TelemetryService.class)); - Toast.makeText(this, R.string.bt_not_enabled, Toast.LENGTH_SHORT).show(); - finish(); + AltosDebug.debug("BT not enabled"); } break; case REQUEST_MAP_TYPE: @@ -767,6 +757,14 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, } } + private void bluetoothEnabled(Intent data) { + try { + mService.send(Message.obtain(null, TelemetryService.MSG_BLUETOOTH_ENABLED, null)); + } catch (RemoteException e) { + AltosDebug.debug("send BT enabled message failed"); + } + } + private void connectDevice(Intent data) { // Attempt to connect to the device try { @@ -907,11 +905,10 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, Intent serverIntent = null; switch (item.getItemId()) { case R.id.connect_scan: - if (ensureBluetooth()) { - // Launch the DeviceListActivity to see devices and do scan - serverIntent = new Intent(this, DeviceListActivity.class); - startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE); - } + ensureBluetooth(); + // Launch the DeviceListActivity to see devices and do scan + serverIntent = new Intent(this, DeviceListActivity.class); + startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE); return true; case R.id.disconnect: /* Disconnect the device diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java index 1834d55b..926109e2 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java @@ -57,6 +57,7 @@ public class TelemetryService extends Service { static final int MSG_SETBAUD = 11; static final int MSG_DISCONNECT = 12; static final int MSG_DELETE_SERIAL = 13; + static final int MSG_BLUETOOTH_ENABLED = 14; // Unique Identification Number for the Notification. // We use it on Notification start, and to cancel it. @@ -86,6 +87,8 @@ public class TelemetryService extends Service { @Override public void handleMessage(Message msg) { + DeviceAddress address; + TelemetryService s = service.get(); AltosDroidLink bt = null; if (s == null) @@ -101,7 +104,7 @@ public class TelemetryService extends Service { break; case MSG_CONNECT: AltosDebug.debug("Connect command received"); - DeviceAddress address = (DeviceAddress) msg.obj; + address = (DeviceAddress) msg.obj; AltosDroidPreferences.set_active_device(address); s.start_altos_bluetooth(address, false); break; @@ -203,6 +206,12 @@ public class TelemetryService extends Service { s.telemetry_state.crc_errors = (Integer) msg.obj; s.send_to_clients(); break; + case MSG_BLUETOOTH_ENABLED: + AltosDebug.debug("TelemetryService notes that BT is now enabled"); + address = AltosDroidPreferences.active_device(); + if (address != null && !address.address.startsWith("USB")) + s.start_altos_bluetooth(address, false); + break; default: super.handleMessage(msg); } @@ -348,10 +357,14 @@ public class TelemetryService extends Service { } private void start_altos_bluetooth(DeviceAddress address, boolean pause) { - // Get the BLuetoothDevice object - BluetoothDevice device = bluetooth_adapter.getRemoteDevice(address.address); + if (bluetooth_adapter == null || !bluetooth_adapter.isEnabled()) + return; disconnect(false); + + // Get the BluetoothDevice object + BluetoothDevice device = bluetooth_adapter.getRemoteDevice(address.address); + this.address = address; AltosDebug.debug("start_altos_bluetooth(): Connecting to %s (%s)", device.getName(), device.getAddress()); altos_link = new AltosBluetooth(device, handler, pause); @@ -441,11 +454,6 @@ public class TelemetryService extends Service { // Get local Bluetooth adapter bluetooth_adapter = BluetoothAdapter.getDefaultAdapter(); - // If the adapter is null, then Bluetooth is not supported - if (bluetooth_adapter == null) { - Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); - } - telemetry_state = new TelemetryState(); // Create a reference to the NotificationManager so that we can update our notifcation text later -- cgit v1.2.3 From 204ae5142702044eb8ad2697a55028e904067958 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 25 Apr 2016 23:12:34 -0400 Subject: altosdroid: Add idle mode monitoring, reboot. Start igniters This adds three idle mode operations -- monitor idle, reboot flight computer and test igniters. The igniter test isn't quite wired up. Signed-off-by: Keith Packard --- altosdroid/AndroidManifest.xml.in | 12 +- altosdroid/Makefile.am | 2 +- altosdroid/res/layout/device_list.xml | 24 +- altosdroid/res/layout/idle_mode.xml | 54 ++++ altosdroid/res/layout/igniter_status.xml | 38 +++ altosdroid/res/layout/igniters.xml | 48 ++++ altosdroid/res/menu/option_menu.xml | 3 + altosdroid/res/values/strings.xml | 15 + .../src/org/altusmetrum/AltosDroid/AltosDroid.java | 80 +++++- .../org/altusmetrum/AltosDroid/AltosDroidLink.java | 3 +- .../altusmetrum/AltosDroid/IdleModeActivity.java | 130 +++++++++ .../altusmetrum/AltosDroid/IgniterActivity.java | 303 +++++++++++++++++++++ .../altusmetrum/AltosDroid/TelemetryService.java | 178 +++++++++++- altoslib/AltosIdleMonitor.java | 18 +- altoslib/AltosIgnite.java | 15 +- altoslib/AltosLink.java | 16 +- 16 files changed, 888 insertions(+), 51 deletions(-) create mode 100644 altosdroid/res/layout/idle_mode.xml create mode 100644 altosdroid/res/layout/igniter_status.xml create mode 100644 altosdroid/res/layout/igniters.xml create mode 100644 altosdroid/src/org/altusmetrum/AltosDroid/IdleModeActivity.java create mode 100644 altosdroid/src/org/altusmetrum/AltosDroid/IgniterActivity.java (limited to 'altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java') diff --git a/altosdroid/AndroidManifest.xml.in b/altosdroid/AndroidManifest.xml.in index 24035796..15b04445 100644 --- a/altosdroid/AndroidManifest.xml.in +++ b/altosdroid/AndroidManifest.xml.in @@ -39,7 +39,7 @@ - + + + + + - + + + + +