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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 import java.awt.event.*;
24 import javax.swing.event.*;
26 import org.altusmetrum.altoslib_12.*;
27 import org.altusmetrum.altosuilib_12.*;
29 public class AltosConfigFCUI
31 implements ActionListener, ItemListener, DocumentListener, AltosConfigValues, AltosUnitsListener
38 JLabel main_deploy_label;
39 JLabel apogee_delay_label;
40 JLabel apogee_lockout_label;
41 JLabel frequency_label;
42 JLabel radio_calibration_label;
43 JLabel radio_frequency_label;
44 JLabel radio_enable_label;
46 JLabel aprs_interval_label;
47 JLabel aprs_ssid_label;
48 JLabel aprs_format_label;
49 JLabel flight_log_max_label;
50 JLabel ignite_mode_label;
51 JLabel pad_orientation_label;
52 JLabel accel_plus_label;
53 JLabel accel_minus_label;
54 JLabel callsign_label;
56 JLabel tracker_motion_label;
57 JLabel tracker_interval_label;
65 JComboBox<String> main_deploy_value;
66 JComboBox<String> apogee_delay_value;
67 JComboBox<String> apogee_lockout_value;
68 AltosUIFreqList radio_frequency_value;
69 JLabel radio_calibration_value;
70 JRadioButton radio_enable_value;
71 AltosUIRateList rate_value;
72 JComboBox<String> aprs_interval_value;
73 JComboBox<Integer> aprs_ssid_value;
74 JComboBox<String> aprs_format_value;
75 JComboBox<String> flight_log_max_value;
76 JComboBox<String> ignite_mode_value;
77 JComboBox<String> pad_orientation_value;
78 JTextField accel_plus_value;
79 JTextField accel_minus_value;
80 JTextField callsign_value;
81 JComboBox<String> beep_value;
82 JComboBox<String> tracker_motion_value;
83 JComboBox<String> tracker_interval_value;
94 double pyro_firing_time;
96 ActionListener listener;
98 static String[] main_deploy_values_m = {
99 "100", "150", "200", "250", "300", "350",
103 static String[] main_deploy_values_ft = {
104 "250", "500", "750", "1000", "1250", "1500",
108 static String[] apogee_delay_values = {
109 "0", "1", "2", "3", "4", "5"
112 static String[] apogee_lockout_values = {
113 "0", "5", "10", "15", "20"
116 static String[] ignite_mode_values = {
122 static String[] aprs_interval_values = {
129 static Integer[] aprs_ssid_values = {
130 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
133 static String[] beep_values = {
139 static String[] pad_orientation_values = {
144 static String[] tracker_motion_values_m = {
151 static String[] tracker_motion_values_ft = {
158 static String[] tracker_interval_values = {
165 /* A window listener to catch closing events and tell the config code */
166 class ConfigListener extends WindowAdapter {
169 public ConfigListener(AltosConfigFCUI this_ui) {
173 public void windowClosing(WindowEvent e) {
174 ui.actionPerformed(new ActionEvent(e.getSource(),
175 ActionEvent.ACTION_PERFORMED,
180 boolean is_telemini_v1() {
181 String product = product_value.getText();
182 return product != null && product.startsWith("TeleMini-v1");
185 boolean is_telemini() {
186 String product = product_value.getText();
187 return product != null && product.startsWith("TeleMini");
190 boolean is_easymini() {
191 String product = product_value.getText();
192 return product != null && product.startsWith("EasyMini");
195 boolean is_telemetrum() {
196 String product = product_value.getText();
197 return product != null && product.startsWith("TeleMetrum");
200 void set_radio_enable_tool_tip() {
201 if (radio_enable_value.isVisible())
202 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
204 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
207 void set_rate_tool_tip() {
208 if (rate_value.isVisible())
209 rate_value.setToolTipText("Select telemetry baud rate");
211 rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
214 void set_aprs_interval_tool_tip() {
215 if (aprs_interval_value.isVisible())
216 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
218 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
221 void set_aprs_ssid_tool_tip() {
222 if (aprs_ssid_value.isVisible())
223 aprs_ssid_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
224 else if (aprs_ssid_value.isVisible())
225 aprs_ssid_value.setToolTipText("Software version doesn't support setting the APRS SSID");
227 aprs_ssid_value.setToolTipText("Hardware doesn't support APRS");
230 void set_aprs_format_tool_tip() {
231 if (aprs_format_value.isVisible())
232 aprs_format_value.setToolTipText("Set the APRS format (compressed/uncompressed)");
233 else if (aprs_format_value.isVisible())
234 aprs_format_value.setToolTipText("Software version doesn't support setting the APRS format");
236 aprs_format_value.setToolTipText("Hardware doesn't support APRS");
239 void set_flight_log_max_tool_tip() {
240 if (flight_log_max_value.isVisible())
241 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
243 if (is_telemini_v1())
244 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
246 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
250 void set_ignite_mode_tool_tip() {
251 if (ignite_mode_value.isVisible())
252 ignite_mode_value.setToolTipText("Select when igniters will be fired");
254 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
257 void set_pad_orientation_tool_tip() {
258 if (pad_orientation_value.isVisible()) {
259 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
262 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
263 else if (is_telemini() || is_easymini())
264 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
266 pad_orientation_value.setToolTipText("Can't select orientation");
270 void set_accel_tool_tips() {
271 if (accel_plus_value.isVisible()) {
272 accel_plus_value.setToolTipText("Pad acceleration value in flight orientation");
273 accel_minus_value.setToolTipText("Upside-down acceleration value");
275 accel_plus_value.setToolTipText("No accelerometer");
276 accel_minus_value.setToolTipText("No accelerometer");
280 void set_beep_tool_tip() {
281 if (beep_value.isVisible())
282 beep_value.setToolTipText("What frequency the beeper will sound at");
284 beep_value.setToolTipText("Older firmware could not select beeper frequency");
287 /* Build the UI using a grid bag */
288 public AltosConfigFCUI(JFrame in_owner, boolean remote) {
289 super (in_owner, "Configure Flight Computer", false);
292 GridBagConstraints c;
295 Insets il = new Insets(4,4,4,4);
296 Insets ir = new Insets(4,4,4,4);
298 pane = getContentPane();
299 pane.setLayout(new GridBagLayout());
302 c = new GridBagConstraints();
303 c.gridx = 0; c.gridy = row;
305 c.fill = GridBagConstraints.NONE;
306 c.anchor = GridBagConstraints.LINE_START;
308 product_label = new JLabel("Product:");
309 pane.add(product_label, c);
311 c = new GridBagConstraints();
312 c.gridx = 4; c.gridy = row;
314 c.fill = GridBagConstraints.HORIZONTAL;
316 c.anchor = GridBagConstraints.LINE_START;
318 product_value = new JLabel("");
319 pane.add(product_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 version_label = new JLabel("Software version:");
331 pane.add(version_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 version_value = new JLabel("");
342 pane.add(version_value, c);
346 c = new GridBagConstraints();
347 c.gridx = 0; c.gridy = row;
349 c.fill = GridBagConstraints.NONE;
350 c.anchor = GridBagConstraints.LINE_START;
353 serial_label = new JLabel("Serial:");
354 pane.add(serial_label, c);
356 c = new GridBagConstraints();
357 c.gridx = 4; c.gridy = row;
359 c.fill = GridBagConstraints.HORIZONTAL;
361 c.anchor = GridBagConstraints.LINE_START;
364 serial_value = new JLabel("");
365 pane.add(serial_value, c);
369 c = new GridBagConstraints();
370 c.gridx = 0; c.gridy = row;
372 c.fill = GridBagConstraints.NONE;
373 c.anchor = GridBagConstraints.LINE_START;
376 main_deploy_label = new JLabel(get_main_deploy_label());
377 pane.add(main_deploy_label, c);
379 c = new GridBagConstraints();
380 c.gridx = 4; c.gridy = row;
382 c.fill = GridBagConstraints.HORIZONTAL;
384 c.anchor = GridBagConstraints.LINE_START;
387 main_deploy_value = new JComboBox<String>(main_deploy_values());
388 main_deploy_value.setEditable(true);
389 main_deploy_value.addItemListener(this);
390 pane.add(main_deploy_value, c);
391 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
395 c = new GridBagConstraints();
396 c.gridx = 0; c.gridy = row;
398 c.fill = GridBagConstraints.NONE;
399 c.anchor = GridBagConstraints.LINE_START;
402 apogee_delay_label = new JLabel("Apogee Delay(s):");
403 pane.add(apogee_delay_label, c);
405 c = new GridBagConstraints();
406 c.gridx = 4; c.gridy = row;
408 c.fill = GridBagConstraints.HORIZONTAL;
410 c.anchor = GridBagConstraints.LINE_START;
413 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
414 apogee_delay_value.setEditable(true);
415 apogee_delay_value.addItemListener(this);
416 pane.add(apogee_delay_value, c);
417 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
421 c = new GridBagConstraints();
422 c.gridx = 0; c.gridy = row;
424 c.fill = GridBagConstraints.NONE;
425 c.anchor = GridBagConstraints.LINE_START;
428 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
429 pane.add(apogee_lockout_label, c);
431 c = new GridBagConstraints();
432 c.gridx = 4; c.gridy = row;
434 c.fill = GridBagConstraints.HORIZONTAL;
436 c.anchor = GridBagConstraints.LINE_START;
439 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
440 apogee_lockout_value.setEditable(true);
441 apogee_lockout_value.addItemListener(this);
442 pane.add(apogee_lockout_value, c);
443 apogee_lockout_value.setToolTipText("Time after boost while apogee detection is locked out");
447 c = new GridBagConstraints();
448 c.gridx = 0; c.gridy = row;
450 c.fill = GridBagConstraints.NONE;
451 c.anchor = GridBagConstraints.LINE_START;
454 radio_frequency_label = new JLabel("Frequency:");
455 pane.add(radio_frequency_label, c);
457 c = new GridBagConstraints();
458 c.gridx = 4; c.gridy = row;
460 c.fill = GridBagConstraints.HORIZONTAL;
462 c.anchor = GridBagConstraints.LINE_START;
465 radio_frequency_value = new AltosUIFreqList();
466 radio_frequency_value.addItemListener(this);
467 pane.add(radio_frequency_value, c);
468 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
471 /* Radio Calibration */
472 c = new GridBagConstraints();
473 c.gridx = 0; c.gridy = row;
475 c.fill = GridBagConstraints.NONE;
476 c.anchor = GridBagConstraints.LINE_START;
479 radio_calibration_label = new JLabel("RF Calibration:");
480 pane.add(radio_calibration_label, c);
482 c = new GridBagConstraints();
483 c.gridx = 4; c.gridy = row;
485 c.fill = GridBagConstraints.HORIZONTAL;
487 c.anchor = GridBagConstraints.LINE_START;
490 radio_calibration_value = new JLabel(String.format("%d", 1186611));
491 pane.add(radio_calibration_value, c);
495 c = new GridBagConstraints();
496 c.gridx = 0; c.gridy = row;
498 c.fill = GridBagConstraints.NONE;
499 c.anchor = GridBagConstraints.LINE_START;
502 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
503 pane.add(radio_enable_label, c);
505 c = new GridBagConstraints();
506 c.gridx = 4; c.gridy = row;
508 c.fill = GridBagConstraints.HORIZONTAL;
510 c.anchor = GridBagConstraints.LINE_START;
513 radio_enable_value = new JRadioButton("Enabled");
514 radio_enable_value.addItemListener(this);
515 pane.add(radio_enable_value, c);
516 set_radio_enable_tool_tip();
520 c = new GridBagConstraints();
521 c.gridx = 0; c.gridy = row;
523 c.fill = GridBagConstraints.NONE;
524 c.anchor = GridBagConstraints.LINE_START;
527 rate_label = new JLabel("Telemetry baud rate:");
528 pane.add(rate_label, c);
530 c = new GridBagConstraints();
531 c.gridx = 4; c.gridy = row;
533 c.fill = GridBagConstraints.HORIZONTAL;
535 c.anchor = GridBagConstraints.LINE_START;
538 rate_value = new AltosUIRateList();
539 rate_value.addItemListener(this);
540 pane.add(rate_value, c);
545 c = new GridBagConstraints();
546 c.gridx = 0; c.gridy = row;
548 c.fill = GridBagConstraints.NONE;
549 c.anchor = GridBagConstraints.LINE_START;
552 aprs_interval_label = new JLabel("APRS Interval(s):");
553 pane.add(aprs_interval_label, c);
555 c = new GridBagConstraints();
556 c.gridx = 4; c.gridy = row;
558 c.fill = GridBagConstraints.HORIZONTAL;
560 c.anchor = GridBagConstraints.LINE_START;
563 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
564 aprs_interval_value.setEditable(true);
565 aprs_interval_value.addItemListener(this);
566 pane.add(aprs_interval_value, c);
567 set_aprs_interval_tool_tip();
571 c = new GridBagConstraints();
572 c.gridx = 0; c.gridy = row;
574 c.fill = GridBagConstraints.NONE;
575 c.anchor = GridBagConstraints.LINE_START;
578 aprs_ssid_label = new JLabel("APRS SSID:");
579 pane.add(aprs_ssid_label, c);
581 c = new GridBagConstraints();
582 c.gridx = 4; c.gridy = row;
584 c.fill = GridBagConstraints.HORIZONTAL;
586 c.anchor = GridBagConstraints.LINE_START;
589 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
590 aprs_ssid_value.setEditable(false);
591 aprs_ssid_value.addItemListener(this);
592 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
593 pane.add(aprs_ssid_value, c);
594 set_aprs_ssid_tool_tip();
598 c = new GridBagConstraints();
599 c.gridx = 0; c.gridy = row;
601 c.fill = GridBagConstraints.NONE;
602 c.anchor = GridBagConstraints.LINE_START;
605 aprs_format_label = new JLabel("APRS format:");
606 pane.add(aprs_format_label, c);
608 c = new GridBagConstraints();
609 c.gridx = 4; c.gridy = row;
611 c.fill = GridBagConstraints.HORIZONTAL;
613 c.anchor = GridBagConstraints.LINE_START;
616 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
617 aprs_format_value.setEditable(false);
618 aprs_format_value.addItemListener(this);
619 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
620 pane.add(aprs_format_value, c);
621 set_aprs_format_tool_tip();
625 c = new GridBagConstraints();
626 c.gridx = 0; c.gridy = row;
628 c.fill = GridBagConstraints.NONE;
629 c.anchor = GridBagConstraints.LINE_START;
632 callsign_label = new JLabel("Callsign:");
633 pane.add(callsign_label, c);
635 c = new GridBagConstraints();
636 c.gridx = 4; c.gridy = row;
638 c.fill = GridBagConstraints.HORIZONTAL;
640 c.anchor = GridBagConstraints.LINE_START;
643 callsign_value = new JTextField(AltosUIPreferences.callsign());
644 callsign_value.getDocument().addDocumentListener(this);
645 pane.add(callsign_value, c);
646 callsign_value.setToolTipText("Callsign reported in telemetry data");
650 c = new GridBagConstraints();
651 c.gridx = 0; c.gridy = row;
653 c.fill = GridBagConstraints.NONE;
654 c.anchor = GridBagConstraints.LINE_START;
657 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
658 pane.add(flight_log_max_label, c);
660 c = new GridBagConstraints();
661 c.gridx = 4; c.gridy = row;
663 c.fill = GridBagConstraints.HORIZONTAL;
665 c.anchor = GridBagConstraints.LINE_START;
668 flight_log_max_value = new JComboBox<String>();
669 flight_log_max_value.setEditable(true);
670 flight_log_max_value.addItemListener(this);
671 pane.add(flight_log_max_value, c);
672 set_flight_log_max_tool_tip();
676 c = new GridBagConstraints();
677 c.gridx = 0; c.gridy = row;
679 c.fill = GridBagConstraints.NONE;
680 c.anchor = GridBagConstraints.LINE_START;
683 ignite_mode_label = new JLabel("Igniter Firing Mode:");
684 pane.add(ignite_mode_label, c);
686 c = new GridBagConstraints();
687 c.gridx = 4; c.gridy = row;
689 c.fill = GridBagConstraints.HORIZONTAL;
691 c.anchor = GridBagConstraints.LINE_START;
694 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
695 ignite_mode_value.setEditable(false);
696 ignite_mode_value.addItemListener(this);
697 pane.add(ignite_mode_value, c);
698 set_ignite_mode_tool_tip();
701 /* Pad orientation */
702 c = new GridBagConstraints();
703 c.gridx = 0; c.gridy = row;
705 c.fill = GridBagConstraints.NONE;
706 c.anchor = GridBagConstraints.LINE_START;
709 pad_orientation_label = new JLabel("Pad Orientation:");
710 pane.add(pad_orientation_label, c);
712 c = new GridBagConstraints();
713 c.gridx = 4; c.gridy = row;
715 c.fill = GridBagConstraints.HORIZONTAL;
717 c.anchor = GridBagConstraints.LINE_START;
720 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
721 pad_orientation_value.setEditable(false);
722 pad_orientation_value.addItemListener(this);
723 pane.add(pad_orientation_value, c);
724 set_pad_orientation_tool_tip();
728 c = new GridBagConstraints();
729 c.gridx = 0; c.gridy = row;
731 c.fill = GridBagConstraints.NONE;
732 c.anchor = GridBagConstraints.LINE_START;
735 accel_plus_label = new JLabel("Accel Plus:");
736 pane.add(accel_plus_label, c);
738 c = new GridBagConstraints();
739 c.gridx = 4; c.gridy = row;
741 c.fill = GridBagConstraints.HORIZONTAL;
743 c.anchor = GridBagConstraints.LINE_START;
746 accel_plus_value = new JTextField(10);
747 accel_plus_value.setEditable(true);
748 accel_plus_value.getDocument().addDocumentListener(this);
749 pane.add(accel_plus_value, c);
753 c = new GridBagConstraints();
754 c.gridx = 0; c.gridy = row;
756 c.fill = GridBagConstraints.NONE;
757 c.anchor = GridBagConstraints.LINE_START;
760 accel_minus_label = new JLabel("Accel Minus:");
761 pane.add(accel_minus_label, c);
763 c = new GridBagConstraints();
764 c.gridx = 4; c.gridy = row;
766 c.fill = GridBagConstraints.HORIZONTAL;
768 c.anchor = GridBagConstraints.LINE_START;
771 accel_minus_value = new JTextField(10);
772 accel_minus_value.setEditable(true);
773 accel_minus_value.getDocument().addDocumentListener(this);
774 pane.add(accel_minus_value, c);
776 set_accel_tool_tips();
779 c = new GridBagConstraints();
780 c.gridx = 0; c.gridy = row;
782 c.fill = GridBagConstraints.NONE;
783 c.anchor = GridBagConstraints.LINE_START;
786 beep_label = new JLabel("Beeper Frequency:");
787 pane.add(beep_label, c);
789 c = new GridBagConstraints();
790 c.gridx = 4; c.gridy = row;
792 c.fill = GridBagConstraints.HORIZONTAL;
794 c.anchor = GridBagConstraints.LINE_START;
797 beep_value = new JComboBox<String>(beep_values);
798 beep_value.setEditable(true);
799 beep_value.addItemListener(this);
800 pane.add(beep_value, c);
804 /* Tracker triger horiz distances */
805 c = new GridBagConstraints();
806 c.gridx = 0; c.gridy = row;
808 c.fill = GridBagConstraints.NONE;
809 c.anchor = GridBagConstraints.LINE_START;
812 tracker_motion_label = new JLabel(get_tracker_motion_label());
813 pane.add(tracker_motion_label, c);
815 c = new GridBagConstraints();
816 c.gridx = 4; c.gridy = row;
818 c.fill = GridBagConstraints.HORIZONTAL;
820 c.anchor = GridBagConstraints.LINE_START;
823 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
824 tracker_motion_value.setEditable(true);
825 tracker_motion_value.addItemListener(this);
826 pane.add(tracker_motion_value, c);
829 /* Tracker triger vert distances */
830 c = new GridBagConstraints();
831 c.gridx = 0; c.gridy = row;
833 c.fill = GridBagConstraints.NONE;
834 c.anchor = GridBagConstraints.LINE_START;
837 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
838 pane.add(tracker_interval_label, c);
840 c = new GridBagConstraints();
841 c.gridx = 4; c.gridy = row;
843 c.fill = GridBagConstraints.HORIZONTAL;
845 c.anchor = GridBagConstraints.LINE_START;
848 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
849 tracker_interval_value.setEditable(true);
850 tracker_interval_value.addItemListener(this);
851 pane.add(tracker_interval_value, c);
852 set_tracker_tool_tip();
856 c = new GridBagConstraints();
857 c.gridx = 4; c.gridy = row;
859 c.fill = GridBagConstraints.HORIZONTAL;
860 c.anchor = GridBagConstraints.LINE_START;
863 pyro = new JButton("Configure Pyro Channels");
865 pyro.addActionListener(this);
866 pyro.setActionCommand("Pyro");
870 c = new GridBagConstraints();
871 c.gridx = 5; c.gridy = row;
873 c.fill = GridBagConstraints.HORIZONTAL;
874 c.anchor = GridBagConstraints.LINE_START;
877 accel_cal = new JButton("Calibrate Accelerometer");
878 pane.add(accel_cal, c);
879 accel_cal.addActionListener(this);
880 accel_cal.setActionCommand("Accel");
884 c = new GridBagConstraints();
885 c.gridx = 0; c.gridy = row;
887 c.fill = GridBagConstraints.NONE;
888 c.anchor = GridBagConstraints.LINE_START;
890 save = new JButton("Save");
892 save.addActionListener(this);
893 save.setActionCommand("Save");
895 c = new GridBagConstraints();
896 c.gridx = 2; c.gridy = row;
898 c.fill = GridBagConstraints.NONE;
899 c.anchor = GridBagConstraints.CENTER;
901 reset = new JButton("Reset");
903 reset.addActionListener(this);
904 reset.setActionCommand("Reset");
906 c = new GridBagConstraints();
907 c.gridx = 4; c.gridy = row;
909 c.fill = GridBagConstraints.NONE;
910 c.anchor = GridBagConstraints.CENTER;
912 reboot = new JButton("Reboot");
914 reboot.addActionListener(this);
915 reboot.setActionCommand("Reboot");
917 c = new GridBagConstraints();
918 c.gridx = 6; c.gridy = row;
920 c.fill = GridBagConstraints.NONE;
921 c.anchor = GridBagConstraints.LINE_END;
923 close = new JButton("Close");
925 close.addActionListener(this);
926 close.setActionCommand("Close");
928 addWindowListener(new ConfigListener(this));
929 AltosPreferences.register_units_listener(this);
932 /* Once the initial values are set, the config code will show the dialog */
933 public void make_visible() {
935 setLocationRelativeTo(owner);
939 /* If any values have been changed, confirm before closing */
940 public boolean check_dirty(String operation) {
942 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
944 i = JOptionPane.showOptionDialog(this,
945 String.format("Configuration modified. %s anyway?", operation),
946 "Configuration Modified",
947 JOptionPane.DEFAULT_OPTION,
948 JOptionPane.WARNING_MESSAGE,
949 null, options, options[1]);
956 public void set_dirty() {
958 save.setEnabled(true);
961 public void set_clean() {
963 save.setEnabled(false);
966 AltosConfigPyroUI pyro_ui;
968 public void dispose() {
971 AltosPreferences.unregister_units_listener(this);
975 /* Listen for events from our buttons */
976 public void actionPerformed(ActionEvent e) {
977 String cmd = e.getActionCommand();
979 if (cmd.equals("Pyro")) {
980 if (pyro_ui == null && pyros != null)
981 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
983 pyro_ui.make_visible();
987 if (cmd.equals("Close") || cmd.equals("Reboot"))
988 if (!check_dirty(cmd))
990 listener.actionPerformed(e);
991 if (cmd.equals("Close") || cmd.equals("Reboot")) {
995 if (cmd.equals("Save") || cmd.equals("Reset"))
999 /* ItemListener interface method */
1000 public void itemStateChanged(ItemEvent e) {
1004 /* DocumentListener interface methods */
1005 public void changedUpdate(DocumentEvent e) {
1009 public void insertUpdate(DocumentEvent e) {
1013 public void removeUpdate(DocumentEvent e) {
1017 /* Let the config code hook on a listener */
1018 public void addActionListener(ActionListener l) {
1022 /* set and get all of the dialog values */
1023 public void set_product(String product) {
1024 radio_frequency_value.set_product(product);
1025 product_value.setText(product);
1026 set_pad_orientation_tool_tip();
1027 set_accel_tool_tips();
1028 set_flight_log_max_tool_tip();
1031 public void set_version(String version) {
1032 version_value.setText(version);
1035 public void set_serial(int serial) {
1036 radio_frequency_value.set_serial(serial);
1037 serial_value.setText(String.format("%d", serial));
1040 public void set_altitude_32(int altitude_32) {
1043 public void set_main_deploy(int new_main_deploy) {
1044 if (new_main_deploy != AltosLib.MISSING)
1045 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
1046 main_deploy_value.setVisible(new_main_deploy != AltosLib.MISSING);
1047 main_deploy_label.setVisible(new_main_deploy != AltosLib.MISSING);
1050 public int main_deploy() throws AltosConfigDataException {
1051 String str = main_deploy_value.getSelectedItem().toString();
1053 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1054 } catch (ParseException pe) {
1055 throw new AltosConfigDataException("invalid main deploy height %s", str);
1059 String get_main_deploy_label() {
1060 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.parse_units());
1063 String[] main_deploy_values() {
1064 if (AltosConvert.imperial_units)
1065 return main_deploy_values_ft;
1067 return main_deploy_values_m;
1070 void set_main_deploy_values() {
1071 String[] v = main_deploy_values();
1072 while (main_deploy_value.getItemCount() > 0)
1073 main_deploy_value.removeItemAt(0);
1074 for (int i = 0; i < v.length; i++)
1075 main_deploy_value.addItem(v[i]);
1076 main_deploy_value.setMaximumRowCount(v.length);
1079 public void units_changed(boolean imperial_units) {
1080 boolean was_dirty = dirty;
1082 String v = main_deploy_value.getSelectedItem().toString();
1083 main_deploy_label.setText(get_main_deploy_label());
1084 set_main_deploy_values();
1086 int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1088 } catch (ParseException pe) {
1091 if (tracker_motion_value.isVisible()) {
1092 String motion = tracker_motion_value.getSelectedItem().toString();
1093 tracker_motion_label.setText(get_tracker_motion_label());
1094 set_tracker_motion_values();
1096 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1097 set_tracker_motion(m);
1098 } catch (ParseException pe) {
1106 public void set_apogee_delay(int new_apogee_delay) {
1107 if (new_apogee_delay != AltosLib.MISSING)
1108 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1109 apogee_delay_value.setVisible(new_apogee_delay != AltosLib.MISSING);
1110 apogee_delay_label.setVisible(new_apogee_delay != AltosLib.MISSING);
1113 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1116 v = s.split("\\s+")[0];
1118 return Integer.parseInt(v);
1119 } catch (NumberFormatException ne) {
1120 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1124 public int apogee_delay() throws AltosConfigDataException {
1125 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1128 public void set_apogee_lockout(int new_apogee_lockout) {
1129 if (new_apogee_lockout != AltosLib.MISSING)
1130 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1132 apogee_lockout_value.setVisible(new_apogee_lockout != AltosLib.MISSING);
1133 apogee_lockout_label.setVisible(new_apogee_lockout != AltosLib.MISSING);
1136 public int apogee_lockout() throws AltosConfigDataException {
1137 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1140 public void set_radio_frequency(double new_radio_frequency) {
1141 if (new_radio_frequency != AltosLib.MISSING)
1142 radio_frequency_value.set_frequency(new_radio_frequency);
1143 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
1144 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
1147 public double radio_frequency() {
1148 return radio_frequency_value.frequency();
1151 public void set_radio_calibration(int new_radio_calibration) {
1152 if (new_radio_calibration != AltosLib.MISSING)
1153 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1154 radio_calibration_value.setVisible(new_radio_calibration != AltosLib.MISSING);
1155 radio_calibration_label.setVisible(new_radio_calibration != AltosLib.MISSING);
1158 public void set_radio_enable(int new_radio_enable) {
1159 if (new_radio_enable != AltosLib.MISSING)
1160 radio_enable_value.setSelected(new_radio_enable != 0);
1161 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
1162 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
1163 set_radio_enable_tool_tip();
1166 public int radio_enable() {
1167 if (radio_enable_value.isVisible())
1168 return radio_enable_value.isSelected() ? 1 : 0;
1170 return AltosLib.MISSING;
1173 public void set_telemetry_rate(int new_rate) {
1174 if (new_rate != AltosLib.MISSING)
1175 rate_value.set_rate(new_rate);
1176 rate_label.setVisible(new_rate != AltosLib.MISSING);
1177 rate_value.setVisible(new_rate != AltosLib.MISSING);
1178 set_rate_tool_tip();
1181 public int telemetry_rate() {
1182 return rate_value.rate();
1185 public void set_callsign(String new_callsign) {
1186 if (new_callsign != null)
1187 callsign_value.setText(new_callsign);
1188 callsign_value.setVisible(new_callsign != null);
1189 callsign_label.setVisible(new_callsign != null);
1192 public String callsign() {
1193 if (callsign_value.isVisible())
1194 return callsign_value.getText();
1198 int flight_log_max_limit;
1201 public String flight_log_max_label(int flight_log_max) {
1202 if (flight_log_max_limit != 0) {
1203 int nflight = flight_log_max_limit / flight_log_max;
1204 String plural = nflight > 1 ? "s" : "";
1206 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1208 return String.format("%d", flight_log_max);
1211 public void set_flight_log_max(int new_flight_log_max) {
1212 if (new_flight_log_max != AltosLib.MISSING) {
1213 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1214 flight_log_max = new_flight_log_max;
1216 flight_log_max_value.setVisible(new_flight_log_max != AltosLib.MISSING);
1217 flight_log_max_label.setVisible(new_flight_log_max != AltosLib.MISSING);
1218 set_flight_log_max_tool_tip();
1221 public void set_flight_log_max_enabled(boolean enable) {
1222 flight_log_max_value.setEnabled(enable);
1223 set_flight_log_max_tool_tip();
1226 public int flight_log_max() throws AltosConfigDataException {
1227 if (flight_log_max_value.isVisible())
1228 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1229 return AltosLib.MISSING;
1232 public void set_flight_log_max_limit(int new_flight_log_max_limit) {
1233 flight_log_max_limit = new_flight_log_max_limit;
1234 if (new_flight_log_max_limit != AltosLib.MISSING) {
1235 flight_log_max_value.removeAllItems();
1236 for (int i = 8; i >= 1; i--) {
1237 int size = flight_log_max_limit / i;
1238 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1241 if (flight_log_max != 0)
1242 set_flight_log_max(flight_log_max);
1245 public void set_ignite_mode(int new_ignite_mode) {
1246 if (new_ignite_mode != AltosLib.MISSING) {
1247 if (new_ignite_mode >= ignite_mode_values.length)
1248 new_ignite_mode = 0;
1249 if (new_ignite_mode < 0) {
1250 ignite_mode_value.setEnabled(false);
1251 new_ignite_mode = 0;
1253 ignite_mode_value.setEnabled(true);
1255 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1257 ignite_mode_value.setVisible(new_ignite_mode != AltosLib.MISSING);
1258 ignite_mode_label.setVisible(new_ignite_mode != AltosLib.MISSING);
1260 set_ignite_mode_tool_tip();
1263 public int ignite_mode() {
1264 if (ignite_mode_value.isVisible())
1265 return ignite_mode_value.getSelectedIndex();
1267 return AltosLib.MISSING;
1271 public void set_pad_orientation(int new_pad_orientation) {
1272 if (new_pad_orientation != AltosLib.MISSING) {
1273 if (new_pad_orientation >= pad_orientation_values.length)
1274 new_pad_orientation = 0;
1275 if (new_pad_orientation < 0)
1276 new_pad_orientation = 0;
1277 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1279 pad_orientation_value.setVisible(new_pad_orientation != AltosLib.MISSING);
1280 pad_orientation_label.setVisible(new_pad_orientation != AltosLib.MISSING);
1281 accel_cal.setVisible(new_pad_orientation != AltosLib.MISSING);
1283 set_pad_orientation_tool_tip();
1286 public int pad_orientation() {
1287 if (pad_orientation_value.isVisible())
1288 return pad_orientation_value.getSelectedIndex();
1290 return AltosLib.MISSING;
1293 public void set_accel_cal(int accel_plus, int accel_minus) {
1294 if (accel_plus != AltosLib.MISSING) {
1295 accel_plus_value.setText(String.format("%d", accel_plus));
1296 accel_minus_value.setText(String.format("%d", accel_minus));
1298 accel_plus_value.setVisible(accel_plus != AltosLib.MISSING);
1299 accel_plus_label.setVisible(accel_plus != AltosLib.MISSING);
1300 accel_minus_value.setVisible(accel_minus != AltosLib.MISSING);
1301 accel_minus_label.setVisible(accel_minus != AltosLib.MISSING);
1303 set_accel_tool_tips();
1306 public int accel_cal_plus() {
1307 if (accel_plus_value.isVisible())
1308 return Integer.parseInt(accel_plus_value.getText());
1309 return AltosLib.MISSING;
1312 public int accel_cal_minus() {
1313 if (accel_minus_value.isVisible())
1314 return Integer.parseInt(accel_minus_value.getText());
1315 return AltosLib.MISSING;
1318 public void set_beep(int new_beep) {
1319 if (new_beep != AltosLib.MISSING) {
1320 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1321 for (int i = 0; i < beep_values.length; i++)
1322 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1323 beep_value.setSelectedIndex(i);
1324 set_beep_tool_tip();
1327 beep_value.setSelectedItem(String.format("%d", new_freq));
1329 beep_value.setVisible(new_beep != AltosLib.MISSING);
1330 beep_label.setVisible(new_beep != AltosLib.MISSING);
1331 set_beep_tool_tip();
1335 if (beep_value.isVisible())
1336 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1338 return AltosLib.MISSING;
1341 String[] tracker_motion_values() {
1342 if (AltosConvert.imperial_units)
1343 return tracker_motion_values_ft;
1345 return tracker_motion_values_m;
1348 void set_tracker_motion_values() {
1349 String[] v = tracker_motion_values();
1350 while (tracker_motion_value.getItemCount() > 0)
1351 tracker_motion_value.removeItemAt(0);
1352 for (int i = 0; i < v.length; i++)
1353 tracker_motion_value.addItem(v[i]);
1354 tracker_motion_value.setMaximumRowCount(v.length);
1357 String get_tracker_motion_label() {
1358 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1361 void set_tracker_tool_tip() {
1362 if (tracker_motion_value.isVisible())
1363 tracker_motion_value.setToolTipText("How far the device must move before logging");
1365 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1366 if (tracker_interval_value.isVisible())
1367 tracker_interval_value.setToolTipText("How often to report GPS position");
1369 tracker_interval_value.setToolTipText("This device can't configure interval");
1372 public void set_tracker_motion(int tracker_motion) {
1373 if (tracker_motion != AltosLib.MISSING)
1374 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1375 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1376 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1379 public int tracker_motion() throws AltosConfigDataException {
1380 if (tracker_motion_value.isVisible()) {
1381 String str = tracker_motion_value.getSelectedItem().toString();
1383 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1384 } catch (ParseException pe) {
1385 throw new AltosConfigDataException("invalid tracker motion %s", str);
1388 return AltosLib.MISSING;
1391 public void set_tracker_interval(int tracker_interval) {
1392 if (tracker_interval != AltosLib.MISSING)
1393 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1394 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1395 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1398 public int tracker_interval() throws AltosConfigDataException {
1399 if (tracker_interval_value.isVisible())
1400 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1401 return AltosLib.MISSING;
1404 public void set_pyros(AltosPyro[] new_pyros) {
1406 if (pyros != null && pyro_ui != null)
1407 pyro_ui.set_pyros(pyros);
1408 pyro.setVisible(pyros != null);
1411 public AltosPyro[] pyros() throws AltosConfigDataException {
1412 if (pyro_ui != null)
1413 pyros = pyro_ui.get_pyros();
1417 public void set_pyro_firing_time(double new_pyro_firing_time) {
1418 pyro_firing_time = new_pyro_firing_time;
1419 if (pyro_firing_time != AltosLib.MISSING && pyro_ui != null)
1420 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1421 pyro.setVisible(pyro_firing_time != AltosLib.MISSING);
1424 public double pyro_firing_time() throws AltosConfigDataException {
1425 if (pyro_ui != null)
1426 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1427 return pyro_firing_time;
1430 public void set_aprs_interval(int new_aprs_interval) {
1431 if (new_aprs_interval != AltosLib.MISSING)
1432 aprs_interval_value.setSelectedItem(Integer.toString(new_aprs_interval));
1433 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1434 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1435 set_aprs_interval_tool_tip();
1438 public int aprs_interval() throws AltosConfigDataException {
1439 if (aprs_interval_value.isVisible()) {
1440 String s = aprs_interval_value.getSelectedItem().toString();
1442 return parse_int("aprs interval", s, false);
1444 return AltosLib.MISSING;
1447 public void set_aprs_ssid(int new_aprs_ssid) {
1448 if (new_aprs_ssid != AltosLib.MISSING)
1449 aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1450 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1451 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1452 set_aprs_ssid_tool_tip();
1455 public int aprs_ssid() throws AltosConfigDataException {
1456 if (aprs_ssid_value.isVisible()) {
1457 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1460 return AltosLib.MISSING;
1463 public void set_aprs_format(int new_aprs_format) {
1464 if (new_aprs_format != AltosLib.MISSING)
1465 aprs_format_value.setSelectedIndex(new_aprs_format);
1466 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1467 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1468 set_aprs_format_tool_tip();
1471 public int aprs_format() throws AltosConfigDataException {
1472 if (aprs_format_value.isVisible())
1473 return aprs_format_value.getSelectedIndex();
1474 return AltosLib.MISSING;