altosui: Support telemetry data rates
authorKeith Packard <keithp@keithp.com>
Sat, 5 Jul 2014 06:41:16 +0000 (23:41 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 5 Jul 2014 07:38:10 +0000 (00:38 -0700)
Add combo box to flight UI and flight hardware configuration UIs
Add telemetry rate to the TD/TBT config dialog

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosConfigTD.java
altosui/AltosConfigTDUI.java
altosui/AltosConfigUI.java
altosui/AltosFlightUI.java
altosuilib/AltosUIRateList.java [new file with mode: 0644]
altosuilib/Makefile.am

index 2976657c356be2743c356c1bb2b8956f0bd5da4d..397ed3db05b5e38a343353528e5a43dc8e784a85 100644 (file)
@@ -62,6 +62,7 @@ public class AltosConfigTD implements ActionListener {
        int_ref         radio_calibration;
        int_ref         radio_setting;
        int_ref         radio_frequency;
+       int_ref         telemetry_rate;
        string_ref      config_version;
        string_ref      version;
        string_ref      product;
@@ -105,6 +106,7 @@ public class AltosConfigTD implements ActionListener {
                config_ui.set_version(version.get());
                config_ui.set_radio_frequency(frequency());
                config_ui.set_radio_calibration(radio_calibration.get());
+               config_ui.set_telemetry_rate(telemetry_rate.get());
                config_ui.set_clean();
                if (!made_visible) {
                        made_visible = true;
@@ -140,6 +142,7 @@ public class AltosConfigTD implements ActionListener {
                        get_int(line, "Radio cal:", radio_calibration);
                        get_int(line, "Frequency:", radio_frequency);
                        get_int(line, "Radio setting:", radio_setting);
+                       get_int(line, "Telemetry rate:", telemetry_rate);
                        get_string(line,"software-version", version);
                        get_string(line,"product", product);
                }
@@ -151,6 +154,7 @@ public class AltosConfigTD implements ActionListener {
                radio_setting.set(0);
                radio_frequency.set(0);
                radio_calibration.set(1186611);
+               telemetry_rate.set(Altos.ao_telemetry_rate_38400);
                config_version.set("0.0");
                version.set("unknown");
                product.set("unknown");
@@ -178,6 +182,19 @@ public class AltosConfigTD implements ActionListener {
                }
        }
 
+       synchronized int telemetry_rate() {
+               System.out.printf("telemetry_rate: %d\n", telemetry_rate.get());
+               return telemetry_rate.get();
+       }
+
+       synchronized void set_telemetry_rate(int new_telemetry_rate){
+               int     rate = telemetry_rate.get();
+
+               System.out.printf("set_telemetry_rate %d\n", new_telemetry_rate);
+               if (rate >= 0)
+                       telemetry_rate.set(new_telemetry_rate);
+       }
+
        final static int        serial_mode_read = 0;
        final static int        serial_mode_save = 1;
        final static int        serial_mode_reboot = 2;
@@ -218,6 +235,7 @@ public class AltosConfigTD implements ActionListener {
                         * available firmware version might place on the actual frequency
                         */
                        config.set_frequency(AltosPreferences.frequency(serial.get()));
+                       config.set_telemetry_rate(AltosPreferences.telemetry_rate(serial.get()));
                        config.process_line("all finished");
                }
 
@@ -226,6 +244,8 @@ public class AltosConfigTD implements ActionListener {
                        if (frequency != 0)
                                AltosPreferences.set_frequency(serial.get(),
                                                               frequency);
+                       AltosPreferences.set_telemetry_rate(serial.get(),
+                                                           telemetry_rate());
                }
 
                public void run () {
@@ -279,6 +299,8 @@ public class AltosConfigTD implements ActionListener {
        void save_data() {
                double  freq = config_ui.radio_frequency();
                set_frequency(freq);
+               int telemetry_rate = config_ui.telemetry_rate();
+               set_telemetry_rate(telemetry_rate);
                run_serial_thread(serial_mode_save);
        }
 
@@ -311,6 +333,7 @@ public class AltosConfigTD implements ActionListener {
                radio_setting = new int_ref(0);
                radio_frequency = new int_ref(0);
                radio_calibration = new int_ref(1186611);
+               telemetry_rate = new int_ref(AltosLib.ao_telemetry_rate_38400);
                config_version = new string_ref("0.0");
                version = new string_ref("unknown");
                product = new string_ref("unknown");
@@ -340,4 +363,4 @@ public class AltosConfigTD implements ActionListener {
                        }
                }
        }
-}
\ No newline at end of file
+}
index 947d78ee1815adf8ef8c9e2ffcf81a408a68224f..b677ad2388de472cbe0d4bae76279d7cccb8e435 100644 (file)
@@ -37,6 +37,7 @@ public class AltosConfigTDUI
        JLabel          frequency_label;
        JLabel          radio_calibration_label;
        JLabel          radio_frequency_label;
+       JLabel          rate_label;
 
        public boolean          dirty;
 
@@ -46,6 +47,7 @@ public class AltosConfigTDUI
        JLabel          serial_value;
        AltosUIFreqList radio_frequency_value;
        JLabel          radio_calibration_value;
+       AltosUIRateList rate_value;
 
        JButton         save;
        JButton         reset;
@@ -192,6 +194,28 @@ public class AltosConfigTDUI
                radio_calibration_value = new JLabel(String.format("%d", 1186611));
                pane.add(radio_calibration_value, c);
 
+               /* Telemetry Rate */
+               c = new GridBagConstraints();
+               c.gridx = 0; c.gridy = 7;
+               c.gridwidth = 4;
+               c.fill = GridBagConstraints.NONE;
+               c.anchor = GridBagConstraints.LINE_START;
+               c.insets = il;
+               c.ipady = 5;
+               rate_label = new JLabel("Telemetry Rate:");
+               pane.add(rate_label, c);
+
+               c = new GridBagConstraints();
+               c.gridx = 4; c.gridy = 7;
+               c.gridwidth = 4;
+               c.fill = GridBagConstraints.HORIZONTAL;
+               c.weightx = 1;
+               c.anchor = GridBagConstraints.LINE_START;
+               c.insets = ir;
+               c.ipady = 5;
+               rate_value = new AltosUIRateList();
+               pane.add(rate_value, c);
+
                /* Buttons */
                c = new GridBagConstraints();
                c.gridx = 0; c.gridy = 12;
@@ -339,6 +363,14 @@ public class AltosConfigTDUI
                radio_calibration_value.setText(String.format("%d", calibration));
        }
 
+       public int telemetry_rate() {
+               return rate_value.getSelectedIndex();
+       }
+
+       public void set_telemetry_rate(int rate) {
+               rate_value.setSelectedIndex(rate);
+       }
+
        public void set_clean() {
                dirty = false;
        }
index 91c37fd530f5d19c6259c8e5866c525325051511..e3a1a24fe2f46dcebef5171006d8d805b36c0c55 100644 (file)
@@ -40,6 +40,7 @@ public class AltosConfigUI
        JLabel                  radio_calibration_label;
        JLabel                  radio_frequency_label;
        JLabel                  radio_enable_label;
+       JLabel                  rate_label;
        JLabel                  aprs_interval_label;
        JLabel                  aprs_ssid_label;
        JLabel                  flight_log_max_label;
@@ -62,6 +63,7 @@ public class AltosConfigUI
        AltosUIFreqList         radio_frequency_value;
        JTextField              radio_calibration_value;
        JRadioButton            radio_enable_value;
+       AltosUIRateList         rate_value;
        JComboBox<String>       aprs_interval_value;
        JComboBox<Integer>      aprs_ssid_value;
        JComboBox<String>       flight_log_max_value;
@@ -200,6 +202,13 @@ public class AltosConfigUI
                        radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
        }
 
+       void set_rate_tool_tip() {
+               if (rate_value.isEnabled())
+                       rate_value.setToolTipText("Select telemetry baud rate");
+               else
+                       rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
+       }
+
        void set_aprs_interval_tool_tip() {
                if (aprs_interval_value.isEnabled())
                        aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
@@ -490,6 +499,31 @@ public class AltosConfigUI
                set_radio_enable_tool_tip();
                row++;
 
+               /* Telemetry Rate */
+               c = new GridBagConstraints();
+               c.gridx = 0; c.gridy = row;
+               c.gridwidth = 4;
+               c.fill = GridBagConstraints.NONE;
+               c.anchor = GridBagConstraints.LINE_START;
+               c.insets = il;
+               c.ipady = 5;
+               rate_label = new JLabel("Telemetry baud rate:");
+               pane.add(radio_enable_label, c);
+
+               c = new GridBagConstraints();
+               c.gridx = 4; c.gridy = row;
+               c.gridwidth = 4;
+               c.fill = GridBagConstraints.HORIZONTAL;
+               c.weightx = 1;
+               c.anchor = GridBagConstraints.LINE_START;
+               c.insets = ir;
+               c.ipady = 5;
+               rate_value = new AltosUIRateList();
+               rate_value.addItemListener(this);
+               pane.add(rate_value, c);
+               set_rate_tool_tip();
+               row++;
+
                /* APRS interval */
                c = new GridBagConstraints();
                c.gridx = 0; c.gridy = row;
@@ -1009,6 +1043,14 @@ public class AltosConfigUI
                        return -1;
        }
 
+       public void set_telemetry_rate(int new_rate) {
+               rate_value.set_rate(new_rate);
+       }
+
+       public int telemetry_rate() {
+               return rate_value.rate();
+       }
+
        public void set_callsign(String new_callsign) {
                callsign_value.setVisible(new_callsign != null);
                callsign_value.setText(new_callsign);
index 5db0ee92864641e273e5ee80c31828ccb195d627..6af345ea909068c09fdf1cb887badd0e7532b540 100644 (file)
@@ -171,6 +171,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
 
        Container               bag;
        AltosUIFreqList         frequencies;
+       AltosUIRateList         rates;
        AltosUITelemetryList    telemetries;
        JLabel                  telemetry;
 
@@ -217,27 +218,40 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
                        c.anchor = GridBagConstraints.WEST;
                        bag.add (frequencies, c);
 
+                       // Telemetry rate list
+                       rates = new AltosUIRateList(AltosUIPreferences.telemetry_rate(serial));
+                       rates.addActionListener(new ActionListener() {
+                                       public void actionPerformed(ActionEvent e) {
+                                               int rate = rates.rate();
+                                               try {
+                                                       reader.set_telemetry_rate(rate);
+                                               } catch (TimeoutException te) {
+                                               } catch (InterruptedException ie) {
+                                               }
+                                               reader.save_telemetry_rate();
+                                       }
+                               });
+                       rates.setEnabled(reader.supports_telemetry_rate(AltosLib.ao_telemetry_rate_2400));
+                       c.gridx = 1;
+                       c.gridy = 0;
+                       c.weightx = 0;
+                       c.weighty = 0;
+                       c.insets = new Insets(3, 3, 3, 3);
+                       c.fill = GridBagConstraints.NONE;
+                       c.anchor = GridBagConstraints.WEST;
+                       bag.add (rates, c);
+
                        // Telemetry format list
                        if (reader.supports_telemetry(Altos.ao_telemetry_standard)) {
-                               telemetries = new JComboBox<String>();
-                               for (int i = 1; i <= Altos.ao_telemetry_max; i++)
-                                       telemetries.addItem(Altos.telemetry_name(i));
-                               int telemetry = AltosPreferences.telemetry(serial);
-                               if (telemetry <= Altos.ao_telemetry_off ||
-                                   telemetry > Altos.ao_telemetry_max)
-                                       telemetry = Altos.ao_telemetry_standard;
-                               telemetries.setSelectedIndex(telemetry - 1);
-                               telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
-                               telemetries.setPreferredSize(null);
-                               telemetries.revalidate();
+                               telemetries = new AltosUITelemetryList(serial);
                                telemetries.addActionListener(new ActionListener() {
                                                public void actionPerformed(ActionEvent e) {
-                                                       int telemetry = telemetries.getSelectedIndex() + 1;
+                                                       int telemetry = telemetries.get_selected();
                                                        reader.set_telemetry(telemetry);
                                                        reader.save_telemetry();
                                                }
                                        });
-                               c.gridx = 1;
+                               c.gridx = 2;
                                c.gridy = 0;
                                c.weightx = 0;
                                c.weighty = 0;
@@ -256,7 +270,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
                                        version = "Telemetry: None";
 
                                telemetry = new JLabel(version);
-                               c.gridx = 1;
+                               c.gridx = 2;
                                c.gridy = 0;
                                c.weightx = 0;
                                c.weighty = 0;
@@ -274,9 +288,8 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
                c.gridy = 1;
                c.fill = GridBagConstraints.HORIZONTAL;
                c.weightx = 1;
-               c.gridwidth = 2;
+               c.gridwidth = 3;
                bag.add(flightStatus, c);
-               c.gridwidth = 1;
 
                /* The rest of the window uses a tabbed pane to
                 * show one of the alternate data views
@@ -315,7 +328,6 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
                c.fill = GridBagConstraints.BOTH;
                c.weightx = 1;
                c.weighty = 1;
-               c.gridwidth = 2;
                bag.add(pane, c);
 
                setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
diff --git a/altosuilib/AltosUIRateList.java b/altosuilib/AltosUIRateList.java
new file mode 100644 (file)
index 0000000..2e0c65a
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * 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.altosuilib_3;
+
+import javax.swing.*;
+import org.altusmetrum.altoslib_5.*;
+
+public class AltosUIRateList extends JComboBox<String> {
+
+       String  product;
+       int     serial;
+
+       public void set_rate(int new_rate) {
+               int i;
+
+               if (new_rate < 0) {
+                       setVisible(false);
+                       return;
+               }
+
+               setSelectedIndex(new_rate);
+       }
+
+       public void set_product(String new_product) {
+               product = new_product;
+       }
+
+       public void set_serial(int new_serial) {
+               serial = new_serial;
+       }
+
+       public int rate() {
+               return getSelectedIndex();
+       }
+
+       public AltosUIRateList () {
+               super();
+               for (int i = 0; i < AltosLib.ao_telemetry_rate_values.length; i++)
+                       addItem(String.format("%d baud", AltosLib.ao_telemetry_rate_values[i]));
+               setMaximumRowCount(getItemCount());
+               setEditable(false);
+               product = "Unknown";
+               serial = 0;
+       }
+
+       public AltosUIRateList(int in_rate) {
+               this();
+               set_rate(in_rate);
+       }
+}
index 40e6dda52ac80e28738a544e95bd8f291dd08bd5..21ccd131ef42418cf81cb2d366f7216da08c0567 100644 (file)
@@ -83,6 +83,7 @@ altosuilib_JAVA = \
        AltosUIVoltageIndicator.java \
        AltosUIFreqList.java \
        AltosUITelemetryList.java \
+       AltosUIRateList.java \
        OSXAdapter.java
 
 JAR=altosuilib_$(ALTOSUILIB_VERSION).jar