first cut at turnon scripts for EasyTimer v2
[fw/altos] / altosui / AltosConfigFCUI.java
index 39752b1dd771f8eaa8e67d5cb072768c28c820f8..3e5bede5169718a291533600d878fe50589a86fc 100644 (file)
@@ -23,8 +23,8 @@ import java.awt.event.*;
 import javax.swing.*;
 import javax.swing.event.*;
 import java.text.*;
-import org.altusmetrum.altoslib_13.*;
-import org.altusmetrum.altosuilib_13.*;
+import org.altusmetrum.altoslib_14.*;
+import org.altusmetrum.altosuilib_14.*;
 
 public class AltosConfigFCUI
        extends AltosUIDialog
@@ -42,10 +42,14 @@ public class AltosConfigFCUI
        JLabel                  radio_calibration_label;
        JLabel                  radio_frequency_label;
        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;
        JLabel                  aprs_format_label;
+       JLabel                  aprs_offset_label;
        JLabel                  flight_log_max_label;
        JLabel                  ignite_mode_label;
        JLabel                  pad_orientation_label;
@@ -68,10 +72,14 @@ public class AltosConfigFCUI
        AltosUIFreqList         radio_frequency_value;
        JLabel                  radio_calibration_value;
        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;
        JComboBox<String>       aprs_format_value;
+       JComboBox<Integer>      aprs_offset_value;
        JComboBox<String>       flight_log_max_value;
        JComboBox<String>       ignite_mode_value;
        JComboBox<String>       pad_orientation_value;
@@ -95,6 +103,8 @@ public class AltosConfigFCUI
 
        ActionListener          listener;
 
+       static final String     title = "Configure Flight Computer";
+
        static String[]         main_deploy_values_m = {
                "100", "150", "200", "250", "300", "350",
                "400", "450", "500"
@@ -117,6 +127,7 @@ public class AltosConfigFCUI
                "Dual Deploy",
                "Redundant Apogee",
                "Redundant Main",
+               "Separation & Apogee",
        };
 
        static String[]         aprs_interval_values = {
@@ -130,17 +141,31 @@ public class AltosConfigFCUI
                0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
        };
 
+       static Integer[]        aprs_offset_values = {
+               0, 2, 4, 6, 8, 10, 12, 14, 16, 18
+       };
+
        static String[]         beep_values = {
+               "2000",
+               "2100",
+               "2200",
                "3750",
                "4000",
                "4250",
        };
 
-       static String[]         pad_orientation_values = {
+       static String[]         pad_orientation_values_radio = {
                "Antenna Up",
                "Antenna Down",
        };
 
+       static String[]         pad_orientation_values_no_radio = {
+               "Beeper Up",
+               "Beeper Down",
+       };
+
+       String[] pad_orientation_values;
+
        static String[]         tracker_motion_values_m = {
                "2",
                "5",
@@ -162,6 +187,11 @@ public class AltosConfigFCUI
                "10"
        };
 
+       static String[]         report_feet_values = {
+               "Meters",
+               "Feet",
+       };
+
        /* A window listener to catch closing events and tell the config code */
        class ConfigListener extends WindowAdapter {
                AltosConfigFCUI ui;
@@ -197,6 +227,25 @@ public class AltosConfigFCUI
                return product != null && product.startsWith("TeleMetrum");
        }
 
+       boolean is_telemega() {
+               String  product = product_value.getText();
+               return product != null && product.startsWith("TeleMega");
+       }
+
+       boolean is_easymega() {
+               String  product = product_value.getText();
+               return product != null && product.startsWith("EasyMega");
+       }
+
+       boolean is_easytimer() {
+               String  product = product_value.getText();
+               return product != null && product.startsWith("EasyTimer");
+       }
+
+       public boolean has_radio() {
+               return is_telemega() || is_telemetrum() || is_telemini();
+       }
+
        void set_radio_enable_tool_tip() {
                if (radio_enable_value.isVisible())
                        radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
@@ -236,6 +285,15 @@ public class AltosConfigFCUI
                        aprs_format_value.setToolTipText("Hardware doesn't support APRS");
        }
 
+       void set_aprs_offset_tool_tip() {
+               if (aprs_offset_value.isVisible())
+                       aprs_offset_value.setToolTipText("Set the APRS offset from top of minute");
+               else if (aprs_offset_value.isVisible())
+                       aprs_offset_value.setToolTipText("Software version doesn't support setting the APRS offset");
+               else
+                       aprs_offset_value.setToolTipText("Hardware doesn't support APRS");
+       }
+
        void set_flight_log_max_tool_tip() {
                if (flight_log_max_value.isVisible())
                        flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
@@ -262,11 +320,29 @@ public class AltosConfigFCUI
                                pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
                        else if (is_telemini() || is_easymini())
                                pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
+                       else if (is_easytimer())
+                               pad_orientation_value.setToolTipText("EasyTimer can be mounted in any of six orientations");
                        else
                                pad_orientation_value.setToolTipText("Can't select orientation");
                }
        }
 
+       void set_pad_orientation_values() {
+               String [] new_values;
+               if (has_radio())
+                       new_values = pad_orientation_values_radio;
+               else
+                       new_values = pad_orientation_values_no_radio;
+               if (new_values != pad_orientation_values) {
+                       int id = pad_orientation_value.getSelectedIndex();
+                       pad_orientation_value.removeAllItems();
+                       pad_orientation_values = new_values;
+                       for (int i = 0; i < new_values.length; i++)
+                               pad_orientation_value.addItem(pad_orientation_values[i]);
+                       pad_orientation_value.setSelectedIndex(id);
+               }
+       }
+
        void set_accel_tool_tips() {
                if (accel_plus_value.isVisible()) {
                        accel_plus_value.setToolTipText("Pad acceleration value in flight orientation");
@@ -279,14 +355,35 @@ public class AltosConfigFCUI
 
        void set_beep_tool_tip() {
                if (beep_value.isVisible())
-                       beep_value.setToolTipText("What frequency the beeper will sound at");
+                       beep_value.setToolTipText("What frequency the beeper will sound at (0 for off)");
                else
                        beep_value.setToolTipText("Older firmware could not select beeper frequency");
        }
 
+       void set_radio_10mw_tool_tip() {
+               if (radio_10mw_value.isVisible())
+                       radio_10mw_value.setToolTipText("Should transmitter power be limited to 10mW");
+               else
+                       radio_10mw_value.setToolTipText("Older firmware could not limit radio power");
+       }
+
+       void set_report_feet_tool_tip() {
+               if (report_feet_value.isVisible())
+                       report_feet_value.setToolTipText("Units used after landing to beep max height");
+               else
+                       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, "Configure Flight Computer", false);
+               super (in_owner, title, false);
 
                owner = in_owner;
                GridBagConstraints c;
@@ -295,7 +392,8 @@ public class AltosConfigFCUI
                Insets il = new Insets(4,4,4,4);
                Insets ir = new Insets(4,4,4,4);
 
-               pane = getContentPane();
+               pane = getScrollablePane();
+
                pane.setLayout(new GridBagLayout());
 
                /* Product */
@@ -516,6 +614,83 @@ public class AltosConfigFCUI
                set_radio_enable_tool_tip();
                row++;
 
+               /* Radio 10mW limit */
+               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;
+               radio_10mw_label = new JLabel("Limit transmit to 10mW:");
+               pane.add(radio_10mw_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;
+               radio_10mw_value = new JRadioButton("Limited");
+               radio_10mw_value.addItemListener(this);
+               pane.add(radio_10mw_value, c);
+               set_radio_10mw_tool_tip();
+               row++;
+
+               /* Report feet */
+               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;
+               report_feet_label = new JLabel("Beep max height in:");
+               pane.add(report_feet_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;
+               report_feet_value = new JComboBox<String>(report_feet_values);
+               report_feet_value.setEditable(false);
+               report_feet_value.addItemListener(this);
+               pane.add(report_feet_value, c);
+               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;
@@ -621,6 +796,33 @@ public class AltosConfigFCUI
                set_aprs_format_tool_tip();
                row++;
 
+               /* APRS offset */
+               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;
+               aprs_offset_label = new JLabel("APRS offset:");
+               pane.add(aprs_offset_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;
+               aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
+               aprs_offset_value.setEditable(false);
+               aprs_offset_value.addItemListener(this);
+               aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
+               pane.add(aprs_offset_value, c);
+               set_aprs_offset_tool_tip();
+               row++;
+
                /* Callsign */
                c = new GridBagConstraints();
                c.gridx = 0; c.gridy = row;
@@ -717,6 +919,8 @@ public class AltosConfigFCUI
                c.anchor = GridBagConstraints.LINE_START;
                c.insets = ir;
                c.ipady = 5;
+               pad_orientation_values = pad_orientation_values_no_radio;
+
                pad_orientation_value = new JComboBox<String>(pad_orientation_values);
                pad_orientation_value.setEditable(false);
                pad_orientation_value.addItemListener(this);
@@ -955,11 +1159,13 @@ public class AltosConfigFCUI
 
        public void set_dirty() {
                dirty = true;
+               setTitle(title + " (modified)");
                save.setEnabled(true);
        }
 
        public void set_clean() {
                dirty = false;
+               setTitle(title);
                save.setEnabled(false);
        }
 
@@ -987,13 +1193,13 @@ public class AltosConfigFCUI
                if (cmd.equals("Close") || cmd.equals("Reboot"))
                        if (!check_dirty(cmd))
                                return;
+               if (cmd.equals("Save"))
+                       save.setEnabled(false);
                listener.actionPerformed(e);
                if (cmd.equals("Close") || cmd.equals("Reboot")) {
                        setVisible(false);
                        dispose();
                }
-               if (cmd.equals("Save") || cmd.equals("Reset"))
-                       set_clean();
        }
 
        /* ItemListener interface method */
@@ -1026,6 +1232,7 @@ public class AltosConfigFCUI
                set_pad_orientation_tool_tip();
                set_accel_tool_tips();
                set_flight_log_max_tool_tip();
+               set_pad_orientation_values();
        }
 
        public void set_version(String version) {
@@ -1229,16 +1436,18 @@ public class AltosConfigFCUI
                return AltosLib.MISSING;
        }
 
-       public void set_flight_log_max_limit(int new_flight_log_max_limit) {
+       public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
                flight_log_max_limit = new_flight_log_max_limit;
                if (new_flight_log_max_limit != AltosLib.MISSING) {
                        flight_log_max_value.removeAllItems();
                        for (int i = 8; i >= 1; i--) {
                                int     size = flight_log_max_limit / i;
+                               if (new_storage_erase_unit != 0)
+                                       size &= ~(new_storage_erase_unit - 1);
                                flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
                        }
                }
-               if (flight_log_max != 0)
+               if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
                        set_flight_log_max(flight_log_max);
        }
 
@@ -1338,6 +1547,73 @@ public class AltosConfigFCUI
                        return AltosLib.MISSING;
        }
 
+       public void set_radio_10mw(int new_radio_10mw) {
+               if (new_radio_10mw != AltosLib.MISSING) {
+                       radio_10mw_value.setSelected(new_radio_10mw != 0);
+               }
+               radio_10mw_value.setVisible(new_radio_10mw != AltosLib.MISSING);
+               radio_10mw_label.setVisible(new_radio_10mw != AltosLib.MISSING);
+               set_radio_10mw_tool_tip();
+       }
+
+       public int radio_10mw() {
+               if (radio_10mw_value.isVisible())
+                       return radio_10mw_value.isSelected() ? 1 : 0;
+               else
+                       return AltosLib.MISSING;
+       }
+
+       public void set_report_feet(int new_report_feet) {
+               if (new_report_feet != AltosLib.MISSING) {
+                       if (new_report_feet >= report_feet_values.length)
+                               new_report_feet = 0;
+                       if (new_report_feet < 0) {
+                               report_feet_value.setEnabled(false);
+                               new_report_feet = 0;
+                       } else {
+                               report_feet_value.setEnabled(true);
+                       }
+                       report_feet_value.setSelectedIndex(new_report_feet);
+               }
+               report_feet_value.setVisible(new_report_feet != AltosLib.MISSING);
+               report_feet_label.setVisible(new_report_feet != AltosLib.MISSING);
+
+               set_report_feet_tool_tip();
+       }
+
+       public int report_feet() {
+               if (report_feet_value.isVisible())
+                       return report_feet_value.getSelectedIndex();
+               else
+                       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;
@@ -1482,4 +1758,20 @@ public class AltosConfigFCUI
                        return aprs_format_value.getSelectedIndex();
                return AltosLib.MISSING;
        }
+
+       public void set_aprs_offset(int new_aprs_offset) {
+               if (new_aprs_offset != AltosLib.MISSING)
+                       aprs_offset_value.setSelectedItem(new_aprs_offset);
+               aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
+               aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
+               set_aprs_offset_tool_tip();
+       }
+
+       public int aprs_offset() throws AltosConfigDataException {
+               if (aprs_offset_value.isVisible()) {
+                       Integer i = (Integer) aprs_offset_value.getSelectedItem();
+                       return i;
+               }
+               return AltosLib.MISSING;
+       }
 }