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() {
957 System.out.printf("set dirty\n");
959 save.setEnabled(true);
962 public void set_clean() {
963 System.out.printf("set clean\n");
965 save.setEnabled(false);
968 AltosConfigPyroUI pyro_ui;
970 public void dispose() {
973 AltosPreferences.unregister_units_listener(this);
977 /* Listen for events from our buttons */
978 public void actionPerformed(ActionEvent e) {
979 String cmd = e.getActionCommand();
981 if (cmd.equals("Pyro")) {
982 if (pyro_ui == null && pyros != null)
983 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
985 pyro_ui.make_visible();
989 if (cmd.equals("Close") || cmd.equals("Reboot"))
990 if (!check_dirty(cmd))
992 listener.actionPerformed(e);
993 if (cmd.equals("Close") || cmd.equals("Reboot")) {
997 if (cmd.equals("Save") || cmd.equals("Reset"))
1001 /* ItemListener interface method */
1002 public void itemStateChanged(ItemEvent e) {
1006 /* DocumentListener interface methods */
1007 public void changedUpdate(DocumentEvent e) {
1011 public void insertUpdate(DocumentEvent e) {
1015 public void removeUpdate(DocumentEvent e) {
1019 /* Let the config code hook on a listener */
1020 public void addActionListener(ActionListener l) {
1024 /* set and get all of the dialog values */
1025 public void set_product(String product) {
1026 radio_frequency_value.set_product(product);
1027 product_value.setText(product);
1028 set_pad_orientation_tool_tip();
1029 set_accel_tool_tips();
1030 set_flight_log_max_tool_tip();
1033 public void set_version(String version) {
1034 version_value.setText(version);
1037 public void set_serial(int serial) {
1038 radio_frequency_value.set_serial(serial);
1039 serial_value.setText(String.format("%d", serial));
1042 public void set_altitude_32(int altitude_32) {
1045 public void set_main_deploy(int new_main_deploy) {
1046 if (new_main_deploy != AltosLib.MISSING)
1047 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
1048 main_deploy_value.setVisible(new_main_deploy != AltosLib.MISSING);
1049 main_deploy_label.setVisible(new_main_deploy != AltosLib.MISSING);
1052 public int main_deploy() throws AltosConfigDataException {
1053 String str = main_deploy_value.getSelectedItem().toString();
1055 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1056 } catch (ParseException pe) {
1057 throw new AltosConfigDataException("invalid main deploy height %s", str);
1061 String get_main_deploy_label() {
1062 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.parse_units());
1065 String[] main_deploy_values() {
1066 if (AltosConvert.imperial_units)
1067 return main_deploy_values_ft;
1069 return main_deploy_values_m;
1072 void set_main_deploy_values() {
1073 String[] v = main_deploy_values();
1074 while (main_deploy_value.getItemCount() > 0)
1075 main_deploy_value.removeItemAt(0);
1076 for (int i = 0; i < v.length; i++)
1077 main_deploy_value.addItem(v[i]);
1078 main_deploy_value.setMaximumRowCount(v.length);
1081 public void units_changed(boolean imperial_units) {
1082 boolean was_dirty = dirty;
1084 String v = main_deploy_value.getSelectedItem().toString();
1085 main_deploy_label.setText(get_main_deploy_label());
1086 set_main_deploy_values();
1088 int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1090 } catch (ParseException pe) {
1093 if (tracker_motion_value.isVisible()) {
1094 String motion = tracker_motion_value.getSelectedItem().toString();
1095 tracker_motion_label.setText(get_tracker_motion_label());
1096 set_tracker_motion_values();
1098 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1099 set_tracker_motion(m);
1100 } catch (ParseException pe) {
1108 public void set_apogee_delay(int new_apogee_delay) {
1109 if (new_apogee_delay != AltosLib.MISSING)
1110 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1111 apogee_delay_value.setVisible(new_apogee_delay != AltosLib.MISSING);
1112 apogee_delay_label.setVisible(new_apogee_delay != AltosLib.MISSING);
1115 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1118 v = s.split("\\s+")[0];
1120 return Integer.parseInt(v);
1121 } catch (NumberFormatException ne) {
1122 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1126 public int apogee_delay() throws AltosConfigDataException {
1127 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1130 public void set_apogee_lockout(int new_apogee_lockout) {
1131 if (new_apogee_lockout != AltosLib.MISSING)
1132 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1134 apogee_lockout_value.setVisible(new_apogee_lockout != AltosLib.MISSING);
1135 apogee_lockout_label.setVisible(new_apogee_lockout != AltosLib.MISSING);
1138 public int apogee_lockout() throws AltosConfigDataException {
1139 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1142 public void set_radio_frequency(double new_radio_frequency) {
1143 if (new_radio_frequency != AltosLib.MISSING)
1144 radio_frequency_value.set_frequency(new_radio_frequency);
1145 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
1146 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
1149 public double radio_frequency() {
1150 return radio_frequency_value.frequency();
1153 public void set_radio_calibration(int new_radio_calibration) {
1154 if (new_radio_calibration != AltosLib.MISSING)
1155 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1156 radio_calibration_value.setVisible(new_radio_calibration != AltosLib.MISSING);
1157 radio_calibration_label.setVisible(new_radio_calibration != AltosLib.MISSING);
1160 public void set_radio_enable(int new_radio_enable) {
1161 if (new_radio_enable != AltosLib.MISSING)
1162 radio_enable_value.setSelected(new_radio_enable != 0);
1163 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
1164 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
1165 set_radio_enable_tool_tip();
1168 public int radio_enable() {
1169 if (radio_enable_value.isVisible())
1170 return radio_enable_value.isSelected() ? 1 : 0;
1172 return AltosLib.MISSING;
1175 public void set_telemetry_rate(int new_rate) {
1176 if (new_rate != AltosLib.MISSING)
1177 rate_value.set_rate(new_rate);
1178 rate_label.setVisible(new_rate != AltosLib.MISSING);
1179 rate_value.setVisible(new_rate != AltosLib.MISSING);
1180 set_rate_tool_tip();
1183 public int telemetry_rate() {
1184 return rate_value.rate();
1187 public void set_callsign(String new_callsign) {
1188 if (new_callsign != null)
1189 callsign_value.setText(new_callsign);
1190 callsign_value.setVisible(new_callsign != null);
1191 callsign_label.setVisible(new_callsign != null);
1194 public String callsign() {
1195 if (callsign_value.isVisible())
1196 return callsign_value.getText();
1200 int flight_log_max_limit;
1203 public String flight_log_max_label(int flight_log_max) {
1204 if (flight_log_max_limit != 0) {
1205 int nflight = flight_log_max_limit / flight_log_max;
1206 String plural = nflight > 1 ? "s" : "";
1208 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1210 return String.format("%d", flight_log_max);
1213 public void set_flight_log_max(int new_flight_log_max) {
1214 if (new_flight_log_max != AltosLib.MISSING) {
1215 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1216 flight_log_max = new_flight_log_max;
1218 flight_log_max_value.setVisible(new_flight_log_max != AltosLib.MISSING);
1219 flight_log_max_label.setVisible(new_flight_log_max != AltosLib.MISSING);
1220 set_flight_log_max_tool_tip();
1223 public void set_flight_log_max_enabled(boolean enable) {
1224 flight_log_max_value.setEnabled(enable);
1225 set_flight_log_max_tool_tip();
1228 public int flight_log_max() throws AltosConfigDataException {
1229 if (flight_log_max_value.isVisible())
1230 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1231 return AltosLib.MISSING;
1234 public void set_flight_log_max_limit(int new_flight_log_max_limit) {
1235 flight_log_max_limit = new_flight_log_max_limit;
1236 if (new_flight_log_max_limit != AltosLib.MISSING) {
1237 flight_log_max_value.removeAllItems();
1238 for (int i = 8; i >= 1; i--) {
1239 int size = flight_log_max_limit / i;
1240 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1243 if (flight_log_max != 0)
1244 set_flight_log_max(flight_log_max);
1247 public void set_ignite_mode(int new_ignite_mode) {
1248 if (new_ignite_mode != AltosLib.MISSING) {
1249 if (new_ignite_mode >= ignite_mode_values.length)
1250 new_ignite_mode = 0;
1251 if (new_ignite_mode < 0) {
1252 ignite_mode_value.setEnabled(false);
1253 new_ignite_mode = 0;
1255 ignite_mode_value.setEnabled(true);
1257 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1259 ignite_mode_value.setVisible(new_ignite_mode != AltosLib.MISSING);
1260 ignite_mode_label.setVisible(new_ignite_mode != AltosLib.MISSING);
1262 set_ignite_mode_tool_tip();
1265 public int ignite_mode() {
1266 if (ignite_mode_value.isVisible())
1267 return ignite_mode_value.getSelectedIndex();
1269 return AltosLib.MISSING;
1273 public void set_pad_orientation(int new_pad_orientation) {
1274 if (new_pad_orientation != AltosLib.MISSING) {
1275 if (new_pad_orientation >= pad_orientation_values.length)
1276 new_pad_orientation = 0;
1277 if (new_pad_orientation < 0)
1278 new_pad_orientation = 0;
1279 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1281 pad_orientation_value.setVisible(new_pad_orientation != AltosLib.MISSING);
1282 pad_orientation_label.setVisible(new_pad_orientation != AltosLib.MISSING);
1283 accel_cal.setVisible(new_pad_orientation != AltosLib.MISSING);
1285 set_pad_orientation_tool_tip();
1288 public int pad_orientation() {
1289 if (pad_orientation_value.isVisible())
1290 return pad_orientation_value.getSelectedIndex();
1292 return AltosLib.MISSING;
1295 public void set_accel_cal(int accel_plus, int accel_minus) {
1296 if (accel_plus != AltosLib.MISSING) {
1297 accel_plus_value.setText(String.format("%d", accel_plus));
1298 accel_minus_value.setText(String.format("%d", accel_minus));
1300 accel_plus_value.setVisible(accel_plus != AltosLib.MISSING);
1301 accel_plus_label.setVisible(accel_plus != AltosLib.MISSING);
1302 accel_minus_value.setVisible(accel_minus != AltosLib.MISSING);
1303 accel_minus_label.setVisible(accel_minus != AltosLib.MISSING);
1305 set_accel_tool_tips();
1308 public int accel_cal_plus() {
1309 if (accel_plus_value.isVisible())
1310 return Integer.parseInt(accel_plus_value.getText());
1311 return AltosLib.MISSING;
1314 public int accel_cal_minus() {
1315 if (accel_minus_value.isVisible())
1316 return Integer.parseInt(accel_minus_value.getText());
1317 return AltosLib.MISSING;
1320 public void set_beep(int new_beep) {
1321 if (new_beep != AltosLib.MISSING) {
1322 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1323 for (int i = 0; i < beep_values.length; i++)
1324 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1325 beep_value.setSelectedIndex(i);
1326 set_beep_tool_tip();
1329 beep_value.setSelectedItem(String.format("%d", new_freq));
1331 beep_value.setVisible(new_beep != AltosLib.MISSING);
1332 beep_label.setVisible(new_beep != AltosLib.MISSING);
1333 set_beep_tool_tip();
1337 if (beep_value.isVisible())
1338 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1340 return AltosLib.MISSING;
1343 String[] tracker_motion_values() {
1344 if (AltosConvert.imperial_units)
1345 return tracker_motion_values_ft;
1347 return tracker_motion_values_m;
1350 void set_tracker_motion_values() {
1351 String[] v = tracker_motion_values();
1352 while (tracker_motion_value.getItemCount() > 0)
1353 tracker_motion_value.removeItemAt(0);
1354 for (int i = 0; i < v.length; i++)
1355 tracker_motion_value.addItem(v[i]);
1356 tracker_motion_value.setMaximumRowCount(v.length);
1359 String get_tracker_motion_label() {
1360 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1363 void set_tracker_tool_tip() {
1364 if (tracker_motion_value.isVisible())
1365 tracker_motion_value.setToolTipText("How far the device must move before logging");
1367 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1368 if (tracker_interval_value.isVisible())
1369 tracker_interval_value.setToolTipText("How often to report GPS position");
1371 tracker_interval_value.setToolTipText("This device can't configure interval");
1374 public void set_tracker_motion(int tracker_motion) {
1375 if (tracker_motion != AltosLib.MISSING)
1376 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1377 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1378 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1381 public int tracker_motion() throws AltosConfigDataException {
1382 if (tracker_motion_value.isVisible()) {
1383 String str = tracker_motion_value.getSelectedItem().toString();
1385 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1386 } catch (ParseException pe) {
1387 throw new AltosConfigDataException("invalid tracker motion %s", str);
1390 return AltosLib.MISSING;
1393 public void set_tracker_interval(int tracker_interval) {
1394 if (tracker_interval != AltosLib.MISSING)
1395 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1396 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1397 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1400 public int tracker_interval() throws AltosConfigDataException {
1401 if (tracker_interval_value.isVisible())
1402 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1403 return AltosLib.MISSING;
1406 public void set_pyros(AltosPyro[] new_pyros) {
1408 if (pyros != null && pyro_ui != null)
1409 pyro_ui.set_pyros(pyros);
1410 pyro.setVisible(pyros != null);
1413 public AltosPyro[] pyros() throws AltosConfigDataException {
1414 if (pyro_ui != null)
1415 pyros = pyro_ui.get_pyros();
1419 public void set_pyro_firing_time(double new_pyro_firing_time) {
1420 pyro_firing_time = new_pyro_firing_time;
1421 if (pyro_firing_time != AltosLib.MISSING && pyro_ui != null)
1422 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1423 pyro.setVisible(pyro_firing_time != AltosLib.MISSING);
1426 public double pyro_firing_time() throws AltosConfigDataException {
1427 if (pyro_ui != null)
1428 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1429 return pyro_firing_time;
1432 public void set_aprs_interval(int new_aprs_interval) {
1433 if (new_aprs_interval != AltosLib.MISSING)
1434 aprs_interval_value.setSelectedItem(Integer.toString(new_aprs_interval));
1435 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1436 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1437 set_aprs_interval_tool_tip();
1440 public int aprs_interval() throws AltosConfigDataException {
1441 if (aprs_interval_value.isVisible()) {
1442 String s = aprs_interval_value.getSelectedItem().toString();
1444 return parse_int("aprs interval", s, false);
1446 return AltosLib.MISSING;
1449 public void set_aprs_ssid(int new_aprs_ssid) {
1450 if (new_aprs_ssid != AltosLib.MISSING)
1451 aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1452 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1453 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1454 set_aprs_ssid_tool_tip();
1457 public int aprs_ssid() throws AltosConfigDataException {
1458 if (aprs_ssid_value.isVisible()) {
1459 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1462 return AltosLib.MISSING;
1465 public void set_aprs_format(int new_aprs_format) {
1466 if (new_aprs_format != AltosLib.MISSING)
1467 aprs_format_value.setSelectedIndex(new_aprs_format);
1468 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1469 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1470 set_aprs_format_tool_tip();
1473 public int aprs_format() throws AltosConfigDataException {
1474 if (aprs_format_value.isVisible())
1475 return aprs_format_value.getSelectedIndex();
1476 return AltosLib.MISSING;