altosui: Support gps receiver setting
authorKeith Packard <keithp@keithp.com>
Wed, 3 Jan 2024 20:31:54 +0000 (12:31 -0800)
committerKeith Packard <keithp@keithp.com>
Fri, 19 Apr 2024 21:19:34 +0000 (14:19 -0700)
Create a combo box listing the available receiver models and allow the
user to select which one to use, including the builtin one.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosConfigData.java
altoslib/AltosConfigValues.java
altoslib/AltosLib.java
altosui/AltosConfigFCUI.java
telegps/TeleGPSConfigUI.java

index 005ef57156a4da31eb7187ce43df9167446a696b..6b980be6b641dd784e06c020d07a743eea036b0c 100644 (file)
@@ -88,6 +88,9 @@ public class AltosConfigData {
 
        public int              report_feet;
 
+       /* HAS_GPS_MOSAIC */
+       public int              gps_receiver;
+
        /* Storage info replies */
        public int      storage_size;
        public int      storage_erase_unit;
@@ -331,6 +334,8 @@ public class AltosConfigData {
 
                report_feet = AltosLib.MISSING;
 
+               gps_receiver = AltosLib.MISSING;
+
                tracker_motion = AltosLib.MISSING;
                tracker_interval = AltosLib.MISSING;
 
@@ -526,6 +531,8 @@ public class AltosConfigData {
 
                try { report_feet = get_int(line, "Report in feet:"); } catch (Exception e) {}
 
+               try { gps_receiver = get_int(line, "GPS receiver:"); } catch (Exception e) {}
+
                /* HAS_TRACKER */
                try {
                        int[] values = get_values(line, "Tracker setting:");
@@ -777,6 +784,9 @@ public class AltosConfigData {
                if (report_feet != AltosLib.MISSING)
                        report_feet = source.report_feet();
 
+               if (gps_receiver != AltosLib.MISSING)
+                       gps_receiver = source.gps_receiver();
+
                /* HAS_TRACKER */
                if (tracker_motion != AltosLib.MISSING)
                        tracker_motion = source.tracker_motion();
@@ -834,6 +844,7 @@ public class AltosConfigData {
                dest.set_beep(beep);
                dest.set_radio_10mw(radio_10mw);
                dest.set_report_feet(report_feet);
+               dest.set_gps_receiver(gps_receiver);
                dest.set_tracker_motion(tracker_motion);
                dest.set_tracker_interval(tracker_interval);
        }
@@ -957,10 +968,13 @@ public class AltosConfigData {
                if (radio_10mw != AltosLib.MISSING)
                        link.printf("c p %d\n", radio_10mw);
 
-               /* HAS_RADIO_10MW */
                if (report_feet != AltosLib.MISSING)
                        link.printf("c u %d\n", report_feet);
 
+               /* HAS_GPS_MOSAIC */
+               if (gps_receiver != AltosLib.MISSING)
+                       link.printf("c g %d\n", gps_receiver);
+
                /* HAS_TRACKER */
                if (tracker_motion != AltosLib.MISSING && tracker_interval != AltosLib.MISSING)
                        link.printf("c t %d %d\n", tracker_motion, tracker_interval);
index 6823e0f99c9b1dc24f122dacd695af99aa60a68e..1de180d30ae3485303e6f705ee4aeb68ea6a10bb 100644 (file)
@@ -128,5 +128,9 @@ public interface AltosConfigValues {
 
        public abstract int report_feet() throws AltosConfigDataException;
 
-       public abstract void set_report_feet(int radio_10mw);
+       public abstract void set_report_feet(int report_feet);
+
+       public abstract int gps_receiver() throws AltosConfigDataException;
+
+       public abstract void set_gps_receiver(int gps_receiver);
 }
index 82b5881ae49dc4389328460a859cada80acbfbe1..fbbfd63c3e7cc7f207ace6907b83ea0e73e4d16a 100644 (file)
@@ -140,6 +140,13 @@ public class AltosLib {
        public final static int product_basestation = 0x10000 + 1;
        public final static int product_altimeter = 0x10000 + 2;
 
+       public final static int gps_builtin = 0;
+       public final static int gps_mosaic = 1;
+
+       public final static String[] gps_receiver_names = {
+               "Builtin", "Mosaic-X5"
+       };
+
        private static class Product {
                final String    name;
                final int       product;
index a238c7df0827ad5d1ce69d82f86c02bfd3db0606..3e5bede5169718a291533600d878fe50589a86fc 100644 (file)
@@ -44,6 +44,7 @@ public class AltosConfigFCUI
        JLabel                  radio_enable_label;
        JLabel                  radio_10mw_label;
        JLabel                  report_feet_label;
+       JLabel                  gps_receiver_label;
        JLabel                  rate_label;
        JLabel                  aprs_interval_label;
        JLabel                  aprs_ssid_label;
@@ -73,6 +74,7 @@ public class AltosConfigFCUI
        JRadioButton            radio_enable_value;
        JRadioButton            radio_10mw_value;
        JComboBox<String>       report_feet_value;
+       JComboBox<String>       gps_receiver_value;
        AltosUIRateList         rate_value;
        JComboBox<String>       aprs_interval_value;
        JComboBox<Integer>      aprs_ssid_value;
@@ -372,6 +374,13 @@ public class AltosConfigFCUI
                        report_feet_value.setToolTipText("Older firmware always beeps max height in meters");
        }
 
+       void set_gps_receiver_tool_tip() {
+               if (gps_receiver_value.isVisible())
+                       gps_receiver_value.setToolTipText("GPS receiver selection");
+               else
+                       gps_receiver_value.setToolTipText("Only TeleMega with new firmware supports alternate GPS receivers");
+       }
+
        /* Build the UI using a grid bag */
        public AltosConfigFCUI(JFrame in_owner, boolean remote) {
                super (in_owner, title, false);
@@ -656,6 +665,32 @@ public class AltosConfigFCUI
                set_report_feet_tool_tip();
                row++;
 
+               /* GPS Receiver */
+               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;
+               gps_receiver_label = new JLabel("GPS Receiver:");
+               pane.add(gps_receiver_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;
+               gps_receiver_value = new JComboBox<String>(AltosLib.gps_receiver_names);
+               gps_receiver_value.setEditable(false);
+               gps_receiver_value.addItemListener(this);
+               pane.add(gps_receiver_value, c);
+               set_gps_receiver_tool_tip();
+               row++;
+
                /* Telemetry Rate */
                c = new GridBagConstraints();
                c.gridx = 0; c.gridy = row;
@@ -1553,6 +1588,32 @@ public class AltosConfigFCUI
                        return AltosLib.MISSING;
        }
 
+       public void set_gps_receiver(int new_gps_receiver) {
+               System.out.printf("set_gps_receiver %d\n", new_gps_receiver);
+               if (new_gps_receiver != AltosLib.MISSING) {
+                       if (new_gps_receiver >= AltosLib.gps_receiver_names.length)
+                               new_gps_receiver = 0;
+                       if (new_gps_receiver < 0) {
+                               gps_receiver_value.setEnabled(false);
+                               new_gps_receiver = 0;
+                       } else {
+                               gps_receiver_value.setEnabled(true);
+                       }
+                       gps_receiver_value.setSelectedIndex(new_gps_receiver);
+               }
+               gps_receiver_value.setVisible(new_gps_receiver != AltosLib.MISSING);
+               gps_receiver_label.setVisible(new_gps_receiver != AltosLib.MISSING);
+
+               set_gps_receiver_tool_tip();
+       }
+
+       public int gps_receiver() {
+               if (gps_receiver_value.isVisible())
+                       return gps_receiver_value.getSelectedIndex();
+               else
+                       return AltosLib.MISSING;
+       }
+
        String[] tracker_motion_values() {
                if (AltosConvert.imperial_units)
                        return tracker_motion_values_ft;
index b348f702ca707ddee5de949b6bc812152715b008..a4a60b6f267670f07591d1d5f41d5ed56d748d77 100644 (file)
@@ -41,6 +41,7 @@ public class TeleGPSConfigUI
        JLabel                  radio_enable_label;
        JLabel                  radio_10mw_label;
        JLabel                  report_feet_label;
+       JLabel                  gps_receiver_label;
        JLabel                  rate_label;
        JLabel                  aprs_interval_label;
        JLabel                  aprs_ssid_label;
@@ -62,6 +63,7 @@ public class TeleGPSConfigUI
        JRadioButton            radio_enable_value;
        JRadioButton            radio_10mw_value;
        JComboBox<String>       report_feet_value;
+       JComboBox<String>       gps_receiver_value;
        AltosUIRateList         rate_value;
        JComboBox<String>       aprs_interval_value;
        JComboBox<Integer>      aprs_ssid_value;
@@ -200,6 +202,39 @@ public class TeleGPSConfigUI
                        return AltosLib.MISSING;
        }
 
+       void set_gps_receiver_tool_tip() {
+               if (gps_receiver_value.isVisible())
+                       gps_receiver_value.setToolTipText("GPS receiver selection");
+               else
+                       gps_receiver_value.setToolTipText("Only TeleMega with new firmware supports alternate GPS receivers");
+       }
+
+       public void set_gps_receiver(int new_gps_receiver) {
+               System.out.printf("set_gps_receiver %d\n", new_gps_receiver);
+               if (new_gps_receiver != AltosLib.MISSING) {
+                       if (new_gps_receiver >= AltosLib.gps_receiver_names.length)
+                               new_gps_receiver = 0;
+                       if (new_gps_receiver < 0) {
+                               gps_receiver_value.setEnabled(false);
+                               new_gps_receiver = 0;
+                       } else {
+                               gps_receiver_value.setEnabled(true);
+                       }
+                       gps_receiver_value.setSelectedIndex(new_gps_receiver);
+               }
+               gps_receiver_value.setVisible(new_gps_receiver != AltosLib.MISSING);
+               gps_receiver_label.setVisible(new_gps_receiver != AltosLib.MISSING);
+
+               set_gps_receiver_tool_tip();
+       }
+
+       public int gps_receiver() {
+               if (gps_receiver_value.isVisible())
+                       return gps_receiver_value.getSelectedIndex();
+               else
+                       return AltosLib.MISSING;
+       }
+
        void set_rate_tool_tip() {
                if (rate_value.isVisible())
                        rate_value.setToolTipText("Select telemetry baud rate");
@@ -430,6 +465,32 @@ public class TeleGPSConfigUI
                set_report_feet_tool_tip();
                row++;
 
+               /* GPS Receiver */
+               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;
+               gps_receiver_label = new JLabel("GPS Receiver:");
+               pane.add(gps_receiver_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;
+               gps_receiver_value = new JComboBox<String>(AltosLib.gps_receiver_names);
+               gps_receiver_value.setEditable(false);
+               gps_receiver_value.addItemListener(this);
+               pane.add(gps_receiver_value, c);
+               set_gps_receiver_tool_tip();
+               row++;
+
                /* Radio 10mW limit */
                c = new GridBagConstraints();
                c.gridx = 0; c.gridy = row;