telegps: Support variable telemetry rate
authorKeith Packard <keithp@keithp.com>
Sat, 5 Jul 2014 07:16:57 +0000 (00:16 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 5 Jul 2014 07:38:10 +0000 (00:38 -0700)
Add combo box to monitoring window and device configuration.

Signed-off-by: Keith Packard <keithp@keithp.com>
telegps/TeleGPS.java
telegps/TeleGPSConfigUI.java

index 7e5ff42aa86c0696445c719da12e2745980dac06..d4b7bacf47b0575829a6d9f5ca93125dbe405e43 100644 (file)
@@ -60,6 +60,8 @@ public class TeleGPS
        JMenu                   device_menu;
        AltosUIFreqList         frequencies;
        ActionListener          frequency_listener;
+       AltosUIRateList         rates;
+       ActionListener          rate_listener;
 
        Container               bag;
 
@@ -184,6 +186,7 @@ public class TeleGPS
 
                telegps_status.disable_receive();
                disable_frequency_menu();
+               disable_rate_menu();
        }
 
        void connect(AltosDevice device) {
@@ -364,6 +367,40 @@ public class TeleGPS
 
        }
 
+       void enable_rate_menu(int serial, final AltosFlightReader reader) {
+
+               if (rate_listener != null)
+                       disable_rate_menu();
+
+               rate_listener = new ActionListener() {
+                               public void actionPerformed(ActionEvent e) {
+                                       int rate = rates.rate();
+                                       try {
+                                               System.out.printf("set rate %d\n", rate);
+                                               reader.set_telemetry_rate(rate);
+                                       } catch (TimeoutException te) {
+                                       } catch (InterruptedException ie) {
+                                       }
+                                       reader.save_telemetry_rate();
+                               }
+                       };
+
+               rates.addActionListener(rate_listener);
+               rates.set_product("Monitor");
+               rates.set_serial(serial);
+               rates.set_rate(AltosUIPreferences.telemetry_rate(serial));
+               rates.setEnabled(reader.supports_telemetry_rate(AltosLib.ao_telemetry_rate_2400));
+       }
+
+       void disable_rate_menu() {
+               if (rate_listener != null) {
+                       rates.removeActionListener(rate_listener);
+                       rates.setEnabled(false);
+                       rate_listener = null;
+               }
+
+       }
+
        public void set_reader(AltosFlightReader reader, AltosDevice device) {
                status_update = new TeleGPSStatusUpdate(telegps_status);
 
@@ -374,8 +411,10 @@ public class TeleGPS
                thread = new TeleGPSDisplayThread(this, voice(), this, reader);
                thread.start();
 
-               if (device != null)
+               if (device != null) {
                        enable_frequency_menu(device.getSerial(), reader);
+                       enable_rate_menu(device.getSerial(), reader);
+               }
        }
 
        static int      number_of_windows;
@@ -467,6 +506,16 @@ public class TeleGPS
                c.gridwidth = 1;
                bag.add(frequencies, c);
 
+               rates = new AltosUIRateList();
+               rates.setEnabled(false);
+               c.gridx = 1;
+               c.gridy = 0;
+               c.fill = GridBagConstraints.NONE;
+               c.anchor = GridBagConstraints.WEST;
+               c.weightx = 0;
+               c.gridwidth = 1;
+               bag.add(rates, c);
+
                displays = new LinkedList<AltosFlightDisplay>();
 
                int serial = -1;
index e5ac6d7ed4db9a3a22da6f3746af519130a4c014..2bd1d2dfc243c0f56d3dda96a8debef09937a6c6 100644 (file)
@@ -37,6 +37,7 @@ public class TeleGPSConfigUI
        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;
@@ -53,6 +54,7 @@ public class TeleGPSConfigUI
        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;
@@ -147,6 +149,13 @@ public class TeleGPSConfigUI
                        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");
@@ -326,6 +335,31 @@ public class TeleGPSConfigUI
                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;
@@ -703,6 +737,14 @@ public class TeleGPSConfigUI
                        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);