altosdroid: Add telemetry rate support
authorKeith Packard <keithp@keithp.com>
Mon, 18 Aug 2014 03:46:48 +0000 (20:46 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 18 Aug 2014 03:46:48 +0000 (20:46 -0700)
Provides a menu to select the receiver telemetry bit rate

Signed-off-by: Keith Packard <keithp@keithp.com>
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

index d7ba8305766c3106bb6cc656a65885ce2200d77a..ee9d475f88029931288eab3a5b370df2390fba71 100644 (file)
@@ -20,4 +20,7 @@
     <item android:id="@+id/select_freq"
           android:icon="@android:drawable/ic_menu_preferences"
           android:title="@string/select_freq" />
+    <item android:id="@+id/select_rate"
+          android:icon="@android:drawable/ic_menu_preferences"
+          android:title="@string/select_rate" />
 </menu>
index 90da617b2ffe9af6e29e49e5f476ebe600415a79..ce335b76be47e9751ec108d3c1af60018e09716f 100644 (file)
@@ -28,6 +28,7 @@
        <!-- Options Menu -->
        <string name="connect_device">Connect a device</string>
        <string name="select_freq">Select radio frequency</string>
+       <string name="select_rate">Select data rate</string>
 
        <!-- DeviceListActivity -->
        <string name="scanning">scanning for devices…</string>
index 1b49ba953de7450f4ce6cf60f6a0f458a62c8d5f..563ccd5a69749398e4b7f3bd3764f1475269eb39 100644 (file)
@@ -476,6 +476,33 @@ public class AltosDroid extends FragmentActivity {
                }
        }
 
+       void setBaud(int baud) {
+               try {
+                       mService.send(Message.obtain(null, TelemetryService.MSG_SETBAUD, baud));
+               } catch (RemoteException e) {
+               }
+       }
+
+       void setBaud(String baud) {
+               try {
+                       int     value = Integer.parseInt(baud);
+                       int     rate = AltosLib.ao_telemetry_rate_38400;
+                       switch (value) {
+                       case 2400:
+                               rate = AltosLib.ao_telemetry_rate_2400;
+                               break;
+                       case 9600:
+                               rate = AltosLib.ao_telemetry_rate_9600;
+                               break;
+                       case 38400:
+                               rate = AltosLib.ao_telemetry_rate_38400;
+                               break;
+                       }
+                       setBaud(rate);
+               } catch (NumberFormatException e) {
+               }
+       }
+
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
                Intent serverIntent = null;
@@ -501,16 +528,36 @@ public class AltosDroid extends FragmentActivity {
                                "Channel 9 (435.450MHz)"
                        };
 
-                       AlertDialog.Builder builder = new AlertDialog.Builder(this);
-                       builder.setTitle("Pick a frequency");
-                       builder.setItems(frequencies,
+                       AlertDialog.Builder builder_freq = new AlertDialog.Builder(this);
+                       builder_freq.setTitle("Pick a frequency");
+                       builder_freq.setItems(frequencies,
                                         new DialogInterface.OnClickListener() {
                                                 public void onClick(DialogInterface dialog, int item) {
                                                         setFrequency(frequencies[item]);
                                                 }
                                         });
-                       AlertDialog alert = builder.create();
-                       alert.show();
+                       AlertDialog alert_freq = builder_freq.create();
+                       alert_freq.show();
+                       return true;
+               case R.id.select_rate:
+                       // Set the TBT baud rate
+
+                       final String[] rates = {
+                               "38400",
+                               "9600",
+                               "2400",
+                       };
+
+                       AlertDialog.Builder builder_rate = new AlertDialog.Builder(this);
+                       builder_rate.setTitle("Pick a baud rate");
+                       builder_rate.setItems(rates,
+                                        new DialogInterface.OnClickListener() {
+                                                public void onClick(DialogInterface dialog, int item) {
+                                                        setBaud(rates[item]);
+                                                }
+                                        });
+                       AlertDialog alert_rate = builder_rate.create();
+                       alert_rate.show();
                        return true;
                }
                return false;
index f06ed213984a2413e65febb35ab96f93a1ff3b10..4ec353e30e88ff2d298b8bea8cb7005607061699 100644 (file)
@@ -61,6 +61,7 @@ public class TelemetryService extends Service implements LocationListener {
        static final int MSG_TELEMETRY         = 7;
        static final int MSG_SETFREQUENCY      = 8;
        static final int MSG_CRC_ERROR         = 9;
+       static final int MSG_SETBAUD           = 10;
 
        public static final int STATE_NONE       = 0;
        public static final int STATE_READY      = 1;
@@ -162,6 +163,11 @@ public class TelemetryService extends Service implements LocationListener {
                                        }
                                }
                                break;
+                       case MSG_SETBAUD:
+                               if (s.state == STATE_CONNECTED) {
+                                       s.mAltosBluetooth.set_telemetry_rate((Integer) msg.obj);
+                               }
+                               break;
                        default:
                                super.handleMessage(msg);
                        }