2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 import java.awt.event.*;
23 import javax.swing.event.*;
24 import org.altusmetrum.altoslib_4.*;
25 import org.altusmetrum.altosuilib_2.*;
27 public class AltosConfigUI
29 implements ActionListener, ItemListener, DocumentListener, AltosConfigValues, AltosUnitsListener
36 JLabel main_deploy_label;
37 JLabel apogee_delay_label;
38 JLabel apogee_lockout_label;
39 JLabel frequency_label;
40 JLabel radio_calibration_label;
41 JLabel radio_frequency_label;
42 JLabel radio_enable_label;
43 JLabel aprs_interval_label;
44 JLabel flight_log_max_label;
45 JLabel ignite_mode_label;
46 JLabel pad_orientation_label;
47 JLabel callsign_label;
49 JLabel tracker_motion_label;
50 JLabel tracker_interval_label;
58 JComboBox<String> main_deploy_value;
59 JComboBox<String> apogee_delay_value;
60 JComboBox<String> apogee_lockout_value;
61 AltosFreqList radio_frequency_value;
62 JTextField radio_calibration_value;
63 JRadioButton radio_enable_value;
64 JComboBox<String> aprs_interval_value;
65 JComboBox<String> flight_log_max_value;
66 JComboBox<String> ignite_mode_value;
67 JComboBox<String> pad_orientation_value;
68 JTextField callsign_value;
69 JComboBox<String> beep_value;
70 JComboBox<String> tracker_motion_value;
71 JComboBox<String> tracker_interval_value;
82 ActionListener listener;
84 static String[] main_deploy_values_m = {
85 "100", "150", "200", "250", "300", "350",
89 static String[] main_deploy_values_ft = {
90 "250", "500", "750", "1000", "1250", "1500",
94 static String[] apogee_delay_values = {
95 "0", "1", "2", "3", "4", "5"
98 static String[] apogee_lockout_values = {
99 "0", "5", "10", "15", "20"
102 static String[] ignite_mode_values = {
108 static String[] aprs_interval_values = {
115 static String[] beep_values = {
121 static String[] pad_orientation_values = {
126 static String[] tracker_motion_values_m = {
133 static String[] tracker_motion_values_ft = {
140 static String[] tracker_interval_values = {
147 /* A window listener to catch closing events and tell the config code */
148 class ConfigListener extends WindowAdapter {
151 public ConfigListener(AltosConfigUI this_ui) {
155 public void windowClosing(WindowEvent e) {
156 ui.actionPerformed(new ActionEvent(e.getSource(),
157 ActionEvent.ACTION_PERFORMED,
162 boolean is_telemini_v1() {
163 String product = product_value.getText();
164 return product != null && product.startsWith("TeleMini-v1");
167 boolean is_telemini() {
168 String product = product_value.getText();
169 return product != null && product.startsWith("TeleMini");
172 boolean is_easymini() {
173 String product = product_value.getText();
174 return product != null && product.startsWith("EasyMini");
177 boolean is_telemetrum() {
178 String product = product_value.getText();
179 return product != null && product.startsWith("TeleMetrum");
182 void set_radio_calibration_tool_tip() {
183 if (radio_calibration_value.isEnabled())
184 radio_calibration_value.setToolTipText("Tune radio output to match desired frequency");
186 radio_calibration_value.setToolTipText("Cannot tune radio while connected over packet mode");
189 void set_radio_enable_tool_tip() {
190 if (radio_enable_value.isEnabled())
191 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
193 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
196 void set_aprs_interval_tool_tip() {
197 if (aprs_interval_value.isEnabled())
198 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
200 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
203 void set_flight_log_max_tool_tip() {
204 if (flight_log_max_value.isEnabled())
205 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
207 if (is_telemini_v1())
208 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
210 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
214 void set_ignite_mode_tool_tip() {
215 if (ignite_mode_value.isEnabled())
216 ignite_mode_value.setToolTipText("Select when igniters will be fired");
218 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
221 void set_pad_orientation_tool_tip() {
222 if (pad_orientation_value.isEnabled())
223 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
226 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
227 else if (is_telemini() || is_easymini())
228 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
230 pad_orientation_value.setToolTipText("Can't select orientation");
234 void set_beep_tool_tip() {
235 if (beep_value.isEnabled())
236 beep_value.setToolTipText("What frequency the beeper will sound at");
238 beep_value.setToolTipText("Older firmware could not select beeper frequency");
241 /* Build the UI using a grid bag */
242 public AltosConfigUI(JFrame in_owner, boolean remote) {
243 super (in_owner, "Configure Flight Computer", false);
246 GridBagConstraints c;
249 Insets il = new Insets(4,4,4,4);
250 Insets ir = new Insets(4,4,4,4);
252 pane = getContentPane();
253 pane.setLayout(new GridBagLayout());
256 c = new GridBagConstraints();
257 c.gridx = 0; c.gridy = row;
259 c.fill = GridBagConstraints.NONE;
260 c.anchor = GridBagConstraints.LINE_START;
262 product_label = new JLabel("Product:");
263 pane.add(product_label, c);
265 c = new GridBagConstraints();
266 c.gridx = 4; c.gridy = row;
268 c.fill = GridBagConstraints.HORIZONTAL;
270 c.anchor = GridBagConstraints.LINE_START;
272 product_value = new JLabel("");
273 pane.add(product_value, c);
277 c = new GridBagConstraints();
278 c.gridx = 0; c.gridy = row;
280 c.fill = GridBagConstraints.NONE;
281 c.anchor = GridBagConstraints.LINE_START;
284 version_label = new JLabel("Software version:");
285 pane.add(version_label, c);
287 c = new GridBagConstraints();
288 c.gridx = 4; c.gridy = row;
290 c.fill = GridBagConstraints.HORIZONTAL;
292 c.anchor = GridBagConstraints.LINE_START;
295 version_value = new JLabel("");
296 pane.add(version_value, c);
300 c = new GridBagConstraints();
301 c.gridx = 0; c.gridy = row;
303 c.fill = GridBagConstraints.NONE;
304 c.anchor = GridBagConstraints.LINE_START;
307 serial_label = new JLabel("Serial:");
308 pane.add(serial_label, c);
310 c = new GridBagConstraints();
311 c.gridx = 4; c.gridy = row;
313 c.fill = GridBagConstraints.HORIZONTAL;
315 c.anchor = GridBagConstraints.LINE_START;
318 serial_value = new JLabel("");
319 pane.add(serial_value, c);
323 c = new GridBagConstraints();
324 c.gridx = 0; c.gridy = row;
326 c.fill = GridBagConstraints.NONE;
327 c.anchor = GridBagConstraints.LINE_START;
330 main_deploy_label = new JLabel(get_main_deploy_label());
331 pane.add(main_deploy_label, c);
333 c = new GridBagConstraints();
334 c.gridx = 4; c.gridy = row;
336 c.fill = GridBagConstraints.HORIZONTAL;
338 c.anchor = GridBagConstraints.LINE_START;
341 main_deploy_value = new JComboBox<String>(main_deploy_values());
342 main_deploy_value.setEditable(true);
343 main_deploy_value.addItemListener(this);
344 pane.add(main_deploy_value, c);
345 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
349 c = new GridBagConstraints();
350 c.gridx = 0; c.gridy = row;
352 c.fill = GridBagConstraints.NONE;
353 c.anchor = GridBagConstraints.LINE_START;
356 apogee_delay_label = new JLabel("Apogee Delay(s):");
357 pane.add(apogee_delay_label, c);
359 c = new GridBagConstraints();
360 c.gridx = 4; c.gridy = row;
362 c.fill = GridBagConstraints.HORIZONTAL;
364 c.anchor = GridBagConstraints.LINE_START;
367 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
368 apogee_delay_value.setEditable(true);
369 apogee_delay_value.addItemListener(this);
370 pane.add(apogee_delay_value, c);
371 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
375 c = new GridBagConstraints();
376 c.gridx = 0; c.gridy = row;
378 c.fill = GridBagConstraints.NONE;
379 c.anchor = GridBagConstraints.LINE_START;
382 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
383 pane.add(apogee_lockout_label, c);
385 c = new GridBagConstraints();
386 c.gridx = 4; c.gridy = row;
388 c.fill = GridBagConstraints.HORIZONTAL;
390 c.anchor = GridBagConstraints.LINE_START;
393 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
394 apogee_lockout_value.setEditable(true);
395 apogee_lockout_value.addItemListener(this);
396 pane.add(apogee_lockout_value, c);
397 apogee_lockout_value.setToolTipText("Time after boost while apogee detection is locked out");
401 c = new GridBagConstraints();
402 c.gridx = 0; c.gridy = row;
404 c.fill = GridBagConstraints.NONE;
405 c.anchor = GridBagConstraints.LINE_START;
408 radio_frequency_label = new JLabel("Frequency:");
409 pane.add(radio_frequency_label, c);
411 c = new GridBagConstraints();
412 c.gridx = 4; c.gridy = row;
414 c.fill = GridBagConstraints.HORIZONTAL;
416 c.anchor = GridBagConstraints.LINE_START;
419 radio_frequency_value = new AltosFreqList();
420 radio_frequency_value.addItemListener(this);
421 pane.add(radio_frequency_value, c);
422 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
425 /* Radio Calibration */
426 c = new GridBagConstraints();
427 c.gridx = 0; c.gridy = row;
429 c.fill = GridBagConstraints.NONE;
430 c.anchor = GridBagConstraints.LINE_START;
433 radio_calibration_label = new JLabel("RF Calibration:");
434 pane.add(radio_calibration_label, c);
436 c = new GridBagConstraints();
437 c.gridx = 4; c.gridy = row;
439 c.fill = GridBagConstraints.HORIZONTAL;
441 c.anchor = GridBagConstraints.LINE_START;
444 radio_calibration_value = new JTextField(String.format("%d", 1186611));
445 radio_calibration_value.getDocument().addDocumentListener(this);
447 radio_calibration_value.setEnabled(false);
448 pane.add(radio_calibration_value, c);
449 set_radio_calibration_tool_tip();
453 c = new GridBagConstraints();
454 c.gridx = 0; c.gridy = row;
456 c.fill = GridBagConstraints.NONE;
457 c.anchor = GridBagConstraints.LINE_START;
460 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
461 pane.add(radio_enable_label, c);
463 c = new GridBagConstraints();
464 c.gridx = 4; c.gridy = row;
466 c.fill = GridBagConstraints.HORIZONTAL;
468 c.anchor = GridBagConstraints.LINE_START;
471 radio_enable_value = new JRadioButton("Enabled");
472 radio_enable_value.addItemListener(this);
473 pane.add(radio_enable_value, c);
474 set_radio_enable_tool_tip();
478 c = new GridBagConstraints();
479 c.gridx = 0; c.gridy = row;
481 c.fill = GridBagConstraints.NONE;
482 c.anchor = GridBagConstraints.LINE_START;
485 aprs_interval_label = new JLabel("APRS Interval(s):");
486 pane.add(aprs_interval_label, c);
488 c = new GridBagConstraints();
489 c.gridx = 4; c.gridy = row;
491 c.fill = GridBagConstraints.HORIZONTAL;
493 c.anchor = GridBagConstraints.LINE_START;
496 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
497 aprs_interval_value.setEditable(true);
498 aprs_interval_value.addItemListener(this);
499 pane.add(aprs_interval_value, c);
500 set_aprs_interval_tool_tip();
504 c = new GridBagConstraints();
505 c.gridx = 0; c.gridy = row;
507 c.fill = GridBagConstraints.NONE;
508 c.anchor = GridBagConstraints.LINE_START;
511 callsign_label = new JLabel("Callsign:");
512 pane.add(callsign_label, c);
514 c = new GridBagConstraints();
515 c.gridx = 4; c.gridy = row;
517 c.fill = GridBagConstraints.HORIZONTAL;
519 c.anchor = GridBagConstraints.LINE_START;
522 callsign_value = new JTextField(AltosUIPreferences.callsign());
523 callsign_value.getDocument().addDocumentListener(this);
524 pane.add(callsign_value, c);
525 callsign_value.setToolTipText("Callsign reported in telemetry data");
529 c = new GridBagConstraints();
530 c.gridx = 0; c.gridy = row;
532 c.fill = GridBagConstraints.NONE;
533 c.anchor = GridBagConstraints.LINE_START;
536 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
537 pane.add(flight_log_max_label, c);
539 c = new GridBagConstraints();
540 c.gridx = 4; c.gridy = row;
542 c.fill = GridBagConstraints.HORIZONTAL;
544 c.anchor = GridBagConstraints.LINE_START;
547 flight_log_max_value = new JComboBox<String>();
548 flight_log_max_value.setEditable(true);
549 flight_log_max_value.addItemListener(this);
550 pane.add(flight_log_max_value, c);
551 set_flight_log_max_tool_tip();
555 c = new GridBagConstraints();
556 c.gridx = 0; c.gridy = row;
558 c.fill = GridBagConstraints.NONE;
559 c.anchor = GridBagConstraints.LINE_START;
562 ignite_mode_label = new JLabel("Igniter Firing Mode:");
563 pane.add(ignite_mode_label, c);
565 c = new GridBagConstraints();
566 c.gridx = 4; c.gridy = row;
568 c.fill = GridBagConstraints.HORIZONTAL;
570 c.anchor = GridBagConstraints.LINE_START;
573 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
574 ignite_mode_value.setEditable(false);
575 ignite_mode_value.addItemListener(this);
576 pane.add(ignite_mode_value, c);
577 set_ignite_mode_tool_tip();
580 /* Pad orientation */
581 c = new GridBagConstraints();
582 c.gridx = 0; c.gridy = row;
584 c.fill = GridBagConstraints.NONE;
585 c.anchor = GridBagConstraints.LINE_START;
588 pad_orientation_label = new JLabel("Pad Orientation:");
589 pane.add(pad_orientation_label, c);
591 c = new GridBagConstraints();
592 c.gridx = 4; c.gridy = row;
594 c.fill = GridBagConstraints.HORIZONTAL;
596 c.anchor = GridBagConstraints.LINE_START;
599 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
600 pad_orientation_value.setEditable(false);
601 pad_orientation_value.addItemListener(this);
602 pane.add(pad_orientation_value, c);
603 set_pad_orientation_tool_tip();
607 c = new GridBagConstraints();
608 c.gridx = 0; c.gridy = row;
610 c.fill = GridBagConstraints.NONE;
611 c.anchor = GridBagConstraints.LINE_START;
614 beep_label = new JLabel("Beeper Frequency:");
615 pane.add(beep_label, c);
617 c = new GridBagConstraints();
618 c.gridx = 4; c.gridy = row;
620 c.fill = GridBagConstraints.HORIZONTAL;
622 c.anchor = GridBagConstraints.LINE_START;
625 beep_value = new JComboBox<String>(beep_values);
626 beep_value.setEditable(true);
627 beep_value.addItemListener(this);
628 pane.add(beep_value, c);
632 /* Tracker triger horiz distances */
633 c = new GridBagConstraints();
634 c.gridx = 0; c.gridy = row;
636 c.fill = GridBagConstraints.NONE;
637 c.anchor = GridBagConstraints.LINE_START;
640 tracker_motion_label = new JLabel(get_tracker_motion_label());
641 pane.add(tracker_motion_label, c);
643 c = new GridBagConstraints();
644 c.gridx = 4; c.gridy = row;
646 c.fill = GridBagConstraints.HORIZONTAL;
648 c.anchor = GridBagConstraints.LINE_START;
651 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
652 tracker_motion_value.setEditable(true);
653 tracker_motion_value.addItemListener(this);
654 pane.add(tracker_motion_value, c);
657 /* Tracker triger vert distances */
658 c = new GridBagConstraints();
659 c.gridx = 0; c.gridy = row;
661 c.fill = GridBagConstraints.NONE;
662 c.anchor = GridBagConstraints.LINE_START;
665 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
666 pane.add(tracker_interval_label, c);
668 c = new GridBagConstraints();
669 c.gridx = 4; c.gridy = row;
671 c.fill = GridBagConstraints.HORIZONTAL;
673 c.anchor = GridBagConstraints.LINE_START;
676 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
677 tracker_interval_value.setEditable(true);
678 tracker_interval_value.addItemListener(this);
679 pane.add(tracker_interval_value, c);
680 set_tracker_tool_tip();
684 c = new GridBagConstraints();
685 c.gridx = 4; c.gridy = row;
687 c.fill = GridBagConstraints.HORIZONTAL;
688 c.anchor = GridBagConstraints.LINE_START;
691 pyro = new JButton("Configure Pyro Channels");
693 pyro.addActionListener(this);
694 pyro.setActionCommand("Pyro");
698 c = new GridBagConstraints();
699 c.gridx = 0; c.gridy = row;
701 c.fill = GridBagConstraints.NONE;
702 c.anchor = GridBagConstraints.LINE_START;
704 save = new JButton("Save");
706 save.addActionListener(this);
707 save.setActionCommand("Save");
709 c = new GridBagConstraints();
710 c.gridx = 2; c.gridy = row;
712 c.fill = GridBagConstraints.NONE;
713 c.anchor = GridBagConstraints.CENTER;
715 reset = new JButton("Reset");
717 reset.addActionListener(this);
718 reset.setActionCommand("Reset");
720 c = new GridBagConstraints();
721 c.gridx = 4; c.gridy = row;
723 c.fill = GridBagConstraints.NONE;
724 c.anchor = GridBagConstraints.CENTER;
726 reboot = new JButton("Reboot");
728 reboot.addActionListener(this);
729 reboot.setActionCommand("Reboot");
731 c = new GridBagConstraints();
732 c.gridx = 6; c.gridy = row;
734 c.fill = GridBagConstraints.NONE;
735 c.anchor = GridBagConstraints.LINE_END;
737 close = new JButton("Close");
739 close.addActionListener(this);
740 close.setActionCommand("Close");
742 addWindowListener(new ConfigListener(this));
743 AltosPreferences.register_units_listener(this);
746 /* Once the initial values are set, the config code will show the dialog */
747 public void make_visible() {
749 setLocationRelativeTo(owner);
753 /* If any values have been changed, confirm before closing */
754 public boolean check_dirty(String operation) {
756 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
758 i = JOptionPane.showOptionDialog(this,
759 String.format("Configuration modified. %s anyway?", operation),
760 "Configuration Modified",
761 JOptionPane.DEFAULT_OPTION,
762 JOptionPane.WARNING_MESSAGE,
763 null, options, options[1]);
772 save.setEnabled(true);
775 public void set_clean() {
777 save.setEnabled(false);
780 AltosConfigPyroUI pyro_ui;
782 public void dispose() {
785 AltosPreferences.unregister_units_listener(this);
789 /* Listen for events from our buttons */
790 public void actionPerformed(ActionEvent e) {
791 String cmd = e.getActionCommand();
793 if (cmd.equals("Pyro")) {
794 if (pyro_ui == null && pyros != null)
795 pyro_ui = new AltosConfigPyroUI(this, pyros);
797 pyro_ui.make_visible();
801 if (cmd.equals("Close") || cmd.equals("Reboot"))
802 if (!check_dirty(cmd))
804 listener.actionPerformed(e);
805 if (cmd.equals("Close") || cmd.equals("Reboot")) {
812 /* ItemListener interface method */
813 public void itemStateChanged(ItemEvent e) {
817 /* DocumentListener interface methods */
818 public void changedUpdate(DocumentEvent e) {
822 public void insertUpdate(DocumentEvent e) {
826 public void removeUpdate(DocumentEvent e) {
830 /* Let the config code hook on a listener */
831 public void addActionListener(ActionListener l) {
835 /* set and get all of the dialog values */
836 public void set_product(String product) {
837 radio_frequency_value.set_product(product);
838 product_value.setText(product);
839 set_pad_orientation_tool_tip();
840 set_flight_log_max_tool_tip();
843 public void set_version(String version) {
844 version_value.setText(version);
847 public void set_serial(int serial) {
848 radio_frequency_value.set_serial(serial);
849 serial_value.setText(String.format("%d", serial));
852 public void set_main_deploy(int new_main_deploy) {
853 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
854 main_deploy_value.setEnabled(new_main_deploy >= 0);
857 public int main_deploy() {
858 return (int) (AltosConvert.height.parse(main_deploy_value.getSelectedItem().toString()) + 0.5);
861 String get_main_deploy_label() {
862 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.show_units());
865 String[] main_deploy_values() {
866 if (AltosConvert.imperial_units)
867 return main_deploy_values_ft;
869 return main_deploy_values_m;
872 void set_main_deploy_values() {
873 String[] v = main_deploy_values();
874 while (main_deploy_value.getItemCount() > 0)
875 main_deploy_value.removeItemAt(0);
876 for (int i = 0; i < v.length; i++)
877 main_deploy_value.addItem(v[i]);
878 main_deploy_value.setMaximumRowCount(v.length);
881 public void units_changed(boolean imperial_units) {
882 String v = main_deploy_value.getSelectedItem().toString();
883 main_deploy_label.setText(get_main_deploy_label());
884 set_main_deploy_values();
885 int m = (int) (AltosConvert.height.parse(v, !imperial_units) + 0.5);
888 if (tracker_motion_value.isEnabled()) {
889 String motion = tracker_motion_value.getSelectedItem().toString();
890 tracker_motion_label.setText(get_tracker_motion_label());
891 set_tracker_motion_values();
892 set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5));
896 public void set_apogee_delay(int new_apogee_delay) {
897 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
898 apogee_delay_value.setEnabled(new_apogee_delay >= 0);
901 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
904 v = s.split("\\s+")[0];
906 return Integer.parseInt(v);
907 } catch (NumberFormatException ne) {
908 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
912 public int apogee_delay() throws AltosConfigDataException {
913 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
916 public void set_apogee_lockout(int new_apogee_lockout) {
917 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
918 apogee_lockout_value.setEnabled(new_apogee_lockout >= 0);
921 public int apogee_lockout() throws AltosConfigDataException {
922 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
925 public void set_radio_frequency(double new_radio_frequency) {
926 radio_frequency_value.set_frequency(new_radio_frequency);
929 public double radio_frequency() {
930 return radio_frequency_value.frequency();
933 public void set_radio_calibration(int new_radio_calibration) {
934 radio_calibration_value.setVisible(new_radio_calibration >= 0);
935 if (new_radio_calibration < 0)
936 radio_calibration_value.setText("Disabled");
938 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
941 public int radio_calibration() throws AltosConfigDataException {
942 return parse_int("radio calibration", radio_calibration_value.getText(), false);
945 public void set_radio_enable(int new_radio_enable) {
946 if (new_radio_enable >= 0) {
947 radio_enable_value.setSelected(new_radio_enable > 0);
948 radio_enable_value.setEnabled(true);
950 radio_enable_value.setSelected(true);
951 radio_enable_value.setVisible(radio_frequency() > 0);
952 radio_enable_value.setEnabled(false);
954 set_radio_enable_tool_tip();
957 public int radio_enable() {
958 if (radio_enable_value.isEnabled())
959 return radio_enable_value.isSelected() ? 1 : 0;
964 public void set_callsign(String new_callsign) {
965 callsign_value.setVisible(new_callsign != null);
966 callsign_value.setText(new_callsign);
969 public String callsign() {
970 return callsign_value.getText();
973 int flight_log_max_limit;
976 public String flight_log_max_label(int flight_log_max) {
977 if (flight_log_max_limit != 0) {
978 int nflight = flight_log_max_limit / flight_log_max;
979 String plural = nflight > 1 ? "s" : "";
981 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
983 return String.format("%d", flight_log_max);
986 public void set_flight_log_max(int new_flight_log_max) {
987 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
988 flight_log_max = new_flight_log_max;
989 set_flight_log_max_tool_tip();
992 public void set_flight_log_max_enabled(boolean enable) {
993 flight_log_max_value.setEnabled(enable);
994 set_flight_log_max_tool_tip();
997 public int flight_log_max() throws AltosConfigDataException {
998 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1001 public void set_flight_log_max_limit(int new_flight_log_max_limit) {
1002 flight_log_max_limit = new_flight_log_max_limit;
1003 flight_log_max_value.removeAllItems();
1004 for (int i = 8; i >= 1; i--) {
1005 int size = flight_log_max_limit / i;
1006 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1008 if (flight_log_max != 0)
1009 set_flight_log_max(flight_log_max);
1012 public void set_ignite_mode(int new_ignite_mode) {
1013 if (new_ignite_mode >= ignite_mode_values.length)
1014 new_ignite_mode = 0;
1015 if (new_ignite_mode < 0) {
1016 ignite_mode_value.setEnabled(false);
1017 new_ignite_mode = 0;
1019 ignite_mode_value.setEnabled(true);
1021 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1022 set_ignite_mode_tool_tip();
1025 public int ignite_mode() {
1026 if (ignite_mode_value.isEnabled())
1027 return ignite_mode_value.getSelectedIndex();
1033 public void set_pad_orientation(int new_pad_orientation) {
1034 if (new_pad_orientation >= pad_orientation_values.length)
1035 new_pad_orientation = 0;
1036 if (new_pad_orientation < 0) {
1037 pad_orientation_value.setVisible(false);
1038 new_pad_orientation = 0;
1040 pad_orientation_value.setVisible(true);
1042 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1043 set_pad_orientation_tool_tip();
1046 public int pad_orientation() {
1047 if (pad_orientation_value.isEnabled())
1048 return pad_orientation_value.getSelectedIndex();
1053 public void set_beep(int new_beep) {
1054 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1055 for (int i = 0; i < beep_values.length; i++)
1056 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1057 beep_value.setSelectedIndex(i);
1058 set_beep_tool_tip();
1061 beep_value.setSelectedItem(String.format("%d", new_freq));
1062 beep_value.setEnabled(new_beep >= 0);
1063 set_beep_tool_tip();
1067 if (beep_value.isEnabled())
1068 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1073 String[] tracker_motion_values() {
1074 if (AltosConvert.imperial_units)
1075 return tracker_motion_values_ft;
1077 return tracker_motion_values_m;
1080 void set_tracker_motion_values() {
1081 String[] v = tracker_motion_values();
1082 while (tracker_motion_value.getItemCount() > 0)
1083 tracker_motion_value.removeItemAt(0);
1084 for (int i = 0; i < v.length; i++)
1085 tracker_motion_value.addItem(v[i]);
1086 tracker_motion_value.setMaximumRowCount(v.length);
1089 String get_tracker_motion_label() {
1090 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.show_units());
1093 void set_tracker_tool_tip() {
1094 if (tracker_motion_value.isEnabled())
1095 tracker_motion_value.setToolTipText("How far the device must move before logging");
1097 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1098 if (tracker_interval_value.isEnabled())
1099 tracker_interval_value.setToolTipText("How often to report GPS position");
1101 tracker_interval_value.setToolTipText("This device can't configure interval");
1104 public void set_tracker_motion(int tracker_motion) {
1105 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1108 public int tracker_motion() throws AltosConfigDataException {
1109 return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString());
1112 public void set_tracker_interval(int tracker_interval) {
1113 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1116 public int tracker_interval() throws AltosConfigDataException {
1117 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1120 public void set_pyros(AltosPyro[] new_pyros) {
1122 pyro.setVisible(pyros != null);
1123 if (pyros != null && pyro_ui != null)
1124 pyro_ui.set_pyros(pyros);
1127 public AltosPyro[] pyros() throws AltosConfigDataException {
1128 if (pyro_ui != null)
1129 pyros = pyro_ui.get_pyros();
1133 public void set_aprs_interval(int new_aprs_interval) {
1136 if (new_aprs_interval <= 0)
1139 s = Integer.toString(new_aprs_interval);
1140 aprs_interval_value.setSelectedItem(s);
1141 aprs_interval_value.setVisible(new_aprs_interval >= 0);
1142 set_aprs_interval_tool_tip();
1145 public int aprs_interval() throws AltosConfigDataException {
1146 String s = aprs_interval_value.getSelectedItem().toString();
1148 if (s.equals("Disabled"))
1150 return parse_int("aprs interval", s, false);