Merge remote-tracking branch 'mjb/freq_menu'
authorKeith Packard <keithp@keithp.com>
Sat, 1 Sep 2012 03:24:16 +0000 (22:24 -0500)
committerKeith Packard <keithp@keithp.com>
Sat, 1 Sep 2012 03:24:16 +0000 (22:24 -0500)
altosdroid/res/menu/option_menu.xml
altosdroid/res/values/strings.xml
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java
altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java
altoslib/AltosConfigData.java
ao-tools/ao-send-telem/ao-send-telem.c

index 6946e298cdc5a3881d8ccec764898bf67e4435ad..d7ba8305766c3106bb6cc656a65885ce2200d77a 100644 (file)
@@ -17,4 +17,7 @@
     <item android:id="@+id/connect_scan"
           android:icon="@android:drawable/ic_menu_search"
           android:title="@string/connect_device" />
+    <item android:id="@+id/select_freq"
+          android:icon="@android:drawable/ic_menu_preferences"
+          android:title="@string/select_freq" />
 </menu>
index f803840607bc9cd8a15fd8614c5d87658981c690..1b28284a33b4911dedb77e6b7deaaa5d2f65e0e6 100644 (file)
@@ -25,6 +25,7 @@
 
     <!-- Options Menu -->
     <string name="connect_device">Connect a device</string>
+    <string name="select_freq">Select radio frequency</string>
 
     <!--  DeviceListActivity -->
     <string name="scanning">scanning for devices…</string>
index 20904d2b0845f6de6723144bfb6bf2dca3ac23b9..006896842a338fc2b2b330c85de4d12c48241eed 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2012 Mike Beattie <mike@ethernal.org>
+ * Copyright Â© 2012 Mike Beattie <mike@ethernal.org>
  *
  * 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
@@ -26,6 +26,7 @@ import android.content.Intent;
 import android.content.Context;
 import android.content.ComponentName;
 import android.content.ServiceConnection;
+import android.content.DialogInterface;
 import android.os.IBinder;
 import android.os.Bundle;
 import android.os.Handler;
@@ -40,6 +41,7 @@ import android.view.MenuItem;
 import android.view.Window;
 import android.widget.TextView;
 import android.widget.Toast;
+import android.app.AlertDialog;
 
 import org.altusmetrum.AltosLib.*;
 
@@ -188,12 +190,12 @@ public class AltosDroid extends Activity {
                if (!state.ascent)
                        speed = state.baro_speed;
                mSpeedView.setText(String.format("%6.0f m/s", speed));
-               mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
+               mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
                mRangeView.setText(String.format("%6.0f m", state.range));
                mHeightView.setText(String.format("%6.0f m", state.height));
-               mElevationView.setText(String.format("%3.0f°", state.elevation));
+               mElevationView.setText(String.format("%3.0f°", state.elevation));
                if (state.from_pad != null)
-                       mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
+                       mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
                mLatitudeView.setText(pos(state.gps.lat, "N", "S"));
                mLongitudeView.setText(pos(state.gps.lon, "W", "E"));
 
@@ -208,7 +210,7 @@ public class AltosDroid extends Activity {
                }
                int deg = (int) Math.floor(p);
                double min = (p - Math.floor(p)) * 60.0;
-               return String.format("%d° %9.6f\" %s", deg, min, h);
+               return String.format("%d° %9.6f\" %s", deg, min, h);
        }
 
        @Override
@@ -352,6 +354,20 @@ public class AltosDroid extends Activity {
                return true;
        }
 
+       void setFrequency(double freq) {
+               try {
+                       mService.send(Message.obtain(null, TelemetryService.MSG_SETFREQUENCY, freq));
+               } catch (RemoteException e) {
+               }
+       }
+
+       void setFrequency(String freq) {
+               try {
+                       setFrequency (Double.parseDouble(freq.substring(11, 17)));
+               } catch (NumberFormatException e) {
+               }
+       }
+
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
                Intent serverIntent = null;
@@ -361,6 +377,33 @@ public class AltosDroid extends Activity {
                        serverIntent = new Intent(this, DeviceListActivity.class);
                        startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
                        return true;
+               case R.id.select_freq:
+                       // Set the TBT radio frequency
+
+                       final String[] frequencies = {
+                               "Channel 0 (434.550MHz)",
+                               "Channel 1 (434.650MHz)",
+                               "Channel 2 (434.750MHz)",
+                               "Channel 3 (434.850MHz)",
+                               "Channel 4 (434.950MHz)",
+                               "Channel 5 (435.050MHz)",
+                               "Channel 6 (435.150MHz)",
+                               "Channel 7 (435.250MHz)",
+                               "Channel 8 (435.350MHz)",
+                               "Channel 9 (435.450MHz)"
+                       };
+
+                       AlertDialog.Builder builder = new AlertDialog.Builder(this);
+                       builder.setTitle("Pick a frequency");
+                       builder.setItems(frequencies,
+                                        new DialogInterface.OnClickListener() {
+                                                public void onClick(DialogInterface dialog, int item) {
+                                                        setFrequency(frequencies[item]);
+                                                }
+                                        });
+                       AlertDialog alert = builder.create();
+                       alert.show();
+                       return true;
                }
                return false;
        }
index ffe96946772a114f92c770c1cfb768b09200244a..6a1f1c5aee73bcad5b5e58af21632e59d45ee371 100644 (file)
@@ -52,6 +52,7 @@ public class TelemetryService extends Service {
        static final int MSG_CONNECT_FAILED    = 5;
        static final int MSG_DISCONNECTED      = 6;
        static final int MSG_TELEMETRY         = 7;
+       static final int MSG_SETFREQUENCY      = 8;
 
        public static final int STATE_NONE       = 0;
        public static final int STATE_READY      = 1;
@@ -126,6 +127,15 @@ public class TelemetryService extends Service {
                        case MSG_TELEMETRY:
                                s.sendMessageToClients(Message.obtain(null, AltosDroid.MSG_TELEMETRY, msg.obj));
                                break;
+                       case MSG_SETFREQUENCY:
+                               if (s.state == STATE_CONNECTED) {
+                                       try {
+                                               s.mAltosBluetooth.set_radio_frequency((Double) msg.obj);
+                                       } catch (InterruptedException e) {
+                                       } catch (TimeoutException e) {
+                                       }
+                               }
+                               break;
                        default:
                                super.handleMessage(msg);
                        }
index ecc2d0aa5f0210eea02972320b7f863dbd3c3e8f..c143036c1a9e13ecc05837631ebb66d7b42a2966 100644 (file)
@@ -170,6 +170,7 @@ public class AltosConfigData implements Iterable<String> {
                        try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {}
                        try { version = get_string(line,"software-version"); } catch (Exception e) {}
                        try { product = get_string(line,"product"); } catch (Exception e) {}
+                       try { manufacturer = get_string(line,"manufacturer"); } catch (Exception e) {}
 
                        try { get_int(line, "flight"); stored_flight++; }  catch (Exception e) {}
                        try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {}
index c6cc51a160227f7e3c9d7620f432fb388043a6db..db061377807bf2c9624874ef07de249f0c5c3ad9 100644 (file)
@@ -199,7 +199,7 @@ main (int argc, char **argv)
                exit (1);
 
        cc_usb_printf(cc, "m 0\n");
-       cc_usb_printf(cc, "F %d\n", freq);
+       cc_usb_printf(cc, "F %d\n", freq);
        for (i = optind; i < argc; i++) {
                file = fopen(argv[i], "r");
                if (!file) {