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_14.*;
27 import org.altusmetrum.altosuilib_14.*;
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 aprs_offset_label;
50 JLabel flight_log_max_label;
51 JLabel ignite_mode_label;
52 JLabel pad_orientation_label;
53 JLabel accel_plus_label;
54 JLabel accel_minus_label;
55 JLabel callsign_label;
57 JLabel tracker_motion_label;
58 JLabel tracker_interval_label;
66 JComboBox<String> main_deploy_value;
67 JComboBox<String> apogee_delay_value;
68 JComboBox<String> apogee_lockout_value;
69 AltosUIFreqList radio_frequency_value;
70 JLabel radio_calibration_value;
71 JRadioButton radio_enable_value;
72 AltosUIRateList rate_value;
73 JComboBox<String> aprs_interval_value;
74 JComboBox<Integer> aprs_ssid_value;
75 JComboBox<String> aprs_format_value;
76 JComboBox<Integer> aprs_offset_value;
77 JComboBox<String> flight_log_max_value;
78 JComboBox<String> ignite_mode_value;
79 JComboBox<String> pad_orientation_value;
80 JTextField accel_plus_value;
81 JTextField accel_minus_value;
82 JTextField callsign_value;
83 JComboBox<String> beep_value;
84 JComboBox<String> tracker_motion_value;
85 JComboBox<String> tracker_interval_value;
96 double pyro_firing_time;
98 ActionListener listener;
100 static final String title = "Configure Flight Computer";
102 static String[] main_deploy_values_m = {
103 "100", "150", "200", "250", "300", "350",
107 static String[] main_deploy_values_ft = {
108 "250", "500", "750", "1000", "1250", "1500",
112 static String[] apogee_delay_values = {
113 "0", "1", "2", "3", "4", "5"
116 static String[] apogee_lockout_values = {
117 "0", "5", "10", "15", "20"
120 static String[] ignite_mode_values = {
124 "Separation & Apogee",
127 static String[] aprs_interval_values = {
134 static Integer[] aprs_ssid_values = {
135 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
138 static Integer[] aprs_offset_values = {
139 0, 2, 4, 6, 8, 10, 12, 14, 16, 18
142 static String[] beep_values = {
151 static String[] pad_orientation_values_radio = {
156 static String[] pad_orientation_values_no_radio = {
161 String[] pad_orientation_values;
163 static String[] tracker_motion_values_m = {
170 static String[] tracker_motion_values_ft = {
177 static String[] tracker_interval_values = {
184 /* A window listener to catch closing events and tell the config code */
185 class ConfigListener extends WindowAdapter {
188 public ConfigListener(AltosConfigFCUI this_ui) {
192 public void windowClosing(WindowEvent e) {
193 ui.actionPerformed(new ActionEvent(e.getSource(),
194 ActionEvent.ACTION_PERFORMED,
199 boolean is_telemini_v1() {
200 String product = product_value.getText();
201 return product != null && product.startsWith("TeleMini-v1");
204 boolean is_telemini() {
205 String product = product_value.getText();
206 return product != null && product.startsWith("TeleMini");
209 boolean is_easymini() {
210 String product = product_value.getText();
211 return product != null && product.startsWith("EasyMini");
214 boolean is_telemetrum() {
215 String product = product_value.getText();
216 return product != null && product.startsWith("TeleMetrum");
219 boolean is_telemega() {
220 String product = product_value.getText();
221 return product != null && product.startsWith("TeleMega");
224 boolean is_easymega() {
225 String product = product_value.getText();
226 return product != null && product.startsWith("EasyMega");
229 boolean is_easytimer() {
230 String product = product_value.getText();
231 return product != null && product.startsWith("EasyTimer");
234 boolean has_radio() {
235 return is_telemega() || is_telemetrum() || is_telemini();
238 void set_radio_enable_tool_tip() {
239 if (radio_enable_value.isVisible())
240 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
242 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
245 void set_rate_tool_tip() {
246 if (rate_value.isVisible())
247 rate_value.setToolTipText("Select telemetry baud rate");
249 rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
252 void set_aprs_interval_tool_tip() {
253 if (aprs_interval_value.isVisible())
254 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
256 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
259 void set_aprs_ssid_tool_tip() {
260 if (aprs_ssid_value.isVisible())
261 aprs_ssid_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
262 else if (aprs_ssid_value.isVisible())
263 aprs_ssid_value.setToolTipText("Software version doesn't support setting the APRS SSID");
265 aprs_ssid_value.setToolTipText("Hardware doesn't support APRS");
268 void set_aprs_format_tool_tip() {
269 if (aprs_format_value.isVisible())
270 aprs_format_value.setToolTipText("Set the APRS format (compressed/uncompressed)");
271 else if (aprs_format_value.isVisible())
272 aprs_format_value.setToolTipText("Software version doesn't support setting the APRS format");
274 aprs_format_value.setToolTipText("Hardware doesn't support APRS");
277 void set_aprs_offset_tool_tip() {
278 if (aprs_offset_value.isVisible())
279 aprs_offset_value.setToolTipText("Set the APRS offset from top of minute");
280 else if (aprs_offset_value.isVisible())
281 aprs_offset_value.setToolTipText("Software version doesn't support setting the APRS offset");
283 aprs_offset_value.setToolTipText("Hardware doesn't support APRS");
286 void set_flight_log_max_tool_tip() {
287 if (flight_log_max_value.isVisible())
288 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
290 if (is_telemini_v1())
291 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
293 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
297 void set_ignite_mode_tool_tip() {
298 if (ignite_mode_value.isVisible())
299 ignite_mode_value.setToolTipText("Select when igniters will be fired");
301 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
304 void set_pad_orientation_tool_tip() {
305 if (pad_orientation_value.isVisible()) {
306 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
309 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
310 else if (is_telemini() || is_easymini())
311 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
312 else if (is_easytimer())
313 pad_orientation_value.setToolTipText("EasyTimer can be mounted in any of six orientations");
315 pad_orientation_value.setToolTipText("Can't select orientation");
319 void set_pad_orientation_values() {
320 String [] new_values;
322 new_values = pad_orientation_values_radio;
324 new_values = pad_orientation_values_no_radio;
325 if (new_values != pad_orientation_values) {
326 int id = pad_orientation_value.getSelectedIndex();
327 pad_orientation_value.removeAllItems();
328 pad_orientation_values = new_values;
329 for (int i = 0; i < new_values.length; i++)
330 pad_orientation_value.addItem(pad_orientation_values[i]);
331 pad_orientation_value.setSelectedIndex(id);
335 void set_accel_tool_tips() {
336 if (accel_plus_value.isVisible()) {
337 accel_plus_value.setToolTipText("Pad acceleration value in flight orientation");
338 accel_minus_value.setToolTipText("Upside-down acceleration value");
340 accel_plus_value.setToolTipText("No accelerometer");
341 accel_minus_value.setToolTipText("No accelerometer");
345 void set_beep_tool_tip() {
346 if (beep_value.isVisible())
347 beep_value.setToolTipText("What frequency the beeper will sound at");
349 beep_value.setToolTipText("Older firmware could not select beeper frequency");
352 /* Build the UI using a grid bag */
353 public AltosConfigFCUI(JFrame in_owner, boolean remote) {
354 super (in_owner, title, false);
357 GridBagConstraints c;
360 Insets il = new Insets(4,4,4,4);
361 Insets ir = new Insets(4,4,4,4);
363 pane = getScrollablePane();
365 pane.setLayout(new GridBagLayout());
368 c = new GridBagConstraints();
369 c.gridx = 0; c.gridy = row;
371 c.fill = GridBagConstraints.NONE;
372 c.anchor = GridBagConstraints.LINE_START;
374 product_label = new JLabel("Product:");
375 pane.add(product_label, c);
377 c = new GridBagConstraints();
378 c.gridx = 4; c.gridy = row;
380 c.fill = GridBagConstraints.HORIZONTAL;
382 c.anchor = GridBagConstraints.LINE_START;
384 product_value = new JLabel("");
385 pane.add(product_value, c);
389 c = new GridBagConstraints();
390 c.gridx = 0; c.gridy = row;
392 c.fill = GridBagConstraints.NONE;
393 c.anchor = GridBagConstraints.LINE_START;
396 version_label = new JLabel("Software version:");
397 pane.add(version_label, c);
399 c = new GridBagConstraints();
400 c.gridx = 4; c.gridy = row;
402 c.fill = GridBagConstraints.HORIZONTAL;
404 c.anchor = GridBagConstraints.LINE_START;
407 version_value = new JLabel("");
408 pane.add(version_value, c);
412 c = new GridBagConstraints();
413 c.gridx = 0; c.gridy = row;
415 c.fill = GridBagConstraints.NONE;
416 c.anchor = GridBagConstraints.LINE_START;
419 serial_label = new JLabel("Serial:");
420 pane.add(serial_label, c);
422 c = new GridBagConstraints();
423 c.gridx = 4; c.gridy = row;
425 c.fill = GridBagConstraints.HORIZONTAL;
427 c.anchor = GridBagConstraints.LINE_START;
430 serial_value = new JLabel("");
431 pane.add(serial_value, c);
435 c = new GridBagConstraints();
436 c.gridx = 0; c.gridy = row;
438 c.fill = GridBagConstraints.NONE;
439 c.anchor = GridBagConstraints.LINE_START;
442 main_deploy_label = new JLabel(get_main_deploy_label());
443 pane.add(main_deploy_label, c);
445 c = new GridBagConstraints();
446 c.gridx = 4; c.gridy = row;
448 c.fill = GridBagConstraints.HORIZONTAL;
450 c.anchor = GridBagConstraints.LINE_START;
453 main_deploy_value = new JComboBox<String>(main_deploy_values());
454 main_deploy_value.setEditable(true);
455 main_deploy_value.addItemListener(this);
456 pane.add(main_deploy_value, c);
457 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
461 c = new GridBagConstraints();
462 c.gridx = 0; c.gridy = row;
464 c.fill = GridBagConstraints.NONE;
465 c.anchor = GridBagConstraints.LINE_START;
468 apogee_delay_label = new JLabel("Apogee Delay(s):");
469 pane.add(apogee_delay_label, c);
471 c = new GridBagConstraints();
472 c.gridx = 4; c.gridy = row;
474 c.fill = GridBagConstraints.HORIZONTAL;
476 c.anchor = GridBagConstraints.LINE_START;
479 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
480 apogee_delay_value.setEditable(true);
481 apogee_delay_value.addItemListener(this);
482 pane.add(apogee_delay_value, c);
483 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
487 c = new GridBagConstraints();
488 c.gridx = 0; c.gridy = row;
490 c.fill = GridBagConstraints.NONE;
491 c.anchor = GridBagConstraints.LINE_START;
494 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
495 pane.add(apogee_lockout_label, c);
497 c = new GridBagConstraints();
498 c.gridx = 4; c.gridy = row;
500 c.fill = GridBagConstraints.HORIZONTAL;
502 c.anchor = GridBagConstraints.LINE_START;
505 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
506 apogee_lockout_value.setEditable(true);
507 apogee_lockout_value.addItemListener(this);
508 pane.add(apogee_lockout_value, c);
509 apogee_lockout_value.setToolTipText("Time after launch while apogee detection is locked out");
513 c = new GridBagConstraints();
514 c.gridx = 0; c.gridy = row;
516 c.fill = GridBagConstraints.NONE;
517 c.anchor = GridBagConstraints.LINE_START;
520 radio_frequency_label = new JLabel("Frequency:");
521 pane.add(radio_frequency_label, c);
523 c = new GridBagConstraints();
524 c.gridx = 4; c.gridy = row;
526 c.fill = GridBagConstraints.HORIZONTAL;
528 c.anchor = GridBagConstraints.LINE_START;
531 radio_frequency_value = new AltosUIFreqList();
532 radio_frequency_value.addItemListener(this);
533 pane.add(radio_frequency_value, c);
534 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
537 /* Radio Calibration */
538 c = new GridBagConstraints();
539 c.gridx = 0; c.gridy = row;
541 c.fill = GridBagConstraints.NONE;
542 c.anchor = GridBagConstraints.LINE_START;
545 radio_calibration_label = new JLabel("RF Calibration:");
546 pane.add(radio_calibration_label, c);
548 c = new GridBagConstraints();
549 c.gridx = 4; c.gridy = row;
551 c.fill = GridBagConstraints.HORIZONTAL;
553 c.anchor = GridBagConstraints.LINE_START;
556 radio_calibration_value = new JLabel(String.format("%d", 1186611));
557 pane.add(radio_calibration_value, c);
561 c = new GridBagConstraints();
562 c.gridx = 0; c.gridy = row;
564 c.fill = GridBagConstraints.NONE;
565 c.anchor = GridBagConstraints.LINE_START;
568 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
569 pane.add(radio_enable_label, c);
571 c = new GridBagConstraints();
572 c.gridx = 4; c.gridy = row;
574 c.fill = GridBagConstraints.HORIZONTAL;
576 c.anchor = GridBagConstraints.LINE_START;
579 radio_enable_value = new JRadioButton("Enabled");
580 radio_enable_value.addItemListener(this);
581 pane.add(radio_enable_value, c);
582 set_radio_enable_tool_tip();
586 c = new GridBagConstraints();
587 c.gridx = 0; c.gridy = row;
589 c.fill = GridBagConstraints.NONE;
590 c.anchor = GridBagConstraints.LINE_START;
593 rate_label = new JLabel("Telemetry baud rate:");
594 pane.add(rate_label, c);
596 c = new GridBagConstraints();
597 c.gridx = 4; c.gridy = row;
599 c.fill = GridBagConstraints.HORIZONTAL;
601 c.anchor = GridBagConstraints.LINE_START;
604 rate_value = new AltosUIRateList();
605 rate_value.addItemListener(this);
606 pane.add(rate_value, c);
611 c = new GridBagConstraints();
612 c.gridx = 0; c.gridy = row;
614 c.fill = GridBagConstraints.NONE;
615 c.anchor = GridBagConstraints.LINE_START;
618 aprs_interval_label = new JLabel("APRS Interval(s):");
619 pane.add(aprs_interval_label, c);
621 c = new GridBagConstraints();
622 c.gridx = 4; c.gridy = row;
624 c.fill = GridBagConstraints.HORIZONTAL;
626 c.anchor = GridBagConstraints.LINE_START;
629 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
630 aprs_interval_value.setEditable(true);
631 aprs_interval_value.addItemListener(this);
632 pane.add(aprs_interval_value, c);
633 set_aprs_interval_tool_tip();
637 c = new GridBagConstraints();
638 c.gridx = 0; c.gridy = row;
640 c.fill = GridBagConstraints.NONE;
641 c.anchor = GridBagConstraints.LINE_START;
644 aprs_ssid_label = new JLabel("APRS SSID:");
645 pane.add(aprs_ssid_label, c);
647 c = new GridBagConstraints();
648 c.gridx = 4; c.gridy = row;
650 c.fill = GridBagConstraints.HORIZONTAL;
652 c.anchor = GridBagConstraints.LINE_START;
655 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
656 aprs_ssid_value.setEditable(false);
657 aprs_ssid_value.addItemListener(this);
658 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
659 pane.add(aprs_ssid_value, c);
660 set_aprs_ssid_tool_tip();
664 c = new GridBagConstraints();
665 c.gridx = 0; c.gridy = row;
667 c.fill = GridBagConstraints.NONE;
668 c.anchor = GridBagConstraints.LINE_START;
671 aprs_format_label = new JLabel("APRS format:");
672 pane.add(aprs_format_label, c);
674 c = new GridBagConstraints();
675 c.gridx = 4; c.gridy = row;
677 c.fill = GridBagConstraints.HORIZONTAL;
679 c.anchor = GridBagConstraints.LINE_START;
682 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
683 aprs_format_value.setEditable(false);
684 aprs_format_value.addItemListener(this);
685 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
686 pane.add(aprs_format_value, c);
687 set_aprs_format_tool_tip();
691 c = new GridBagConstraints();
692 c.gridx = 0; c.gridy = row;
694 c.fill = GridBagConstraints.NONE;
695 c.anchor = GridBagConstraints.LINE_START;
698 aprs_offset_label = new JLabel("APRS offset:");
699 pane.add(aprs_offset_label, c);
701 c = new GridBagConstraints();
702 c.gridx = 4; c.gridy = row;
704 c.fill = GridBagConstraints.HORIZONTAL;
706 c.anchor = GridBagConstraints.LINE_START;
709 aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
710 aprs_offset_value.setEditable(false);
711 aprs_offset_value.addItemListener(this);
712 aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
713 pane.add(aprs_offset_value, c);
714 set_aprs_offset_tool_tip();
718 c = new GridBagConstraints();
719 c.gridx = 0; c.gridy = row;
721 c.fill = GridBagConstraints.NONE;
722 c.anchor = GridBagConstraints.LINE_START;
725 callsign_label = new JLabel("Callsign:");
726 pane.add(callsign_label, c);
728 c = new GridBagConstraints();
729 c.gridx = 4; c.gridy = row;
731 c.fill = GridBagConstraints.HORIZONTAL;
733 c.anchor = GridBagConstraints.LINE_START;
736 callsign_value = new JTextField(AltosUIPreferences.callsign());
737 callsign_value.getDocument().addDocumentListener(this);
738 pane.add(callsign_value, c);
739 callsign_value.setToolTipText("Callsign reported in telemetry data");
743 c = new GridBagConstraints();
744 c.gridx = 0; c.gridy = row;
746 c.fill = GridBagConstraints.NONE;
747 c.anchor = GridBagConstraints.LINE_START;
750 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
751 pane.add(flight_log_max_label, c);
753 c = new GridBagConstraints();
754 c.gridx = 4; c.gridy = row;
756 c.fill = GridBagConstraints.HORIZONTAL;
758 c.anchor = GridBagConstraints.LINE_START;
761 flight_log_max_value = new JComboBox<String>();
762 flight_log_max_value.setEditable(true);
763 flight_log_max_value.addItemListener(this);
764 pane.add(flight_log_max_value, c);
765 set_flight_log_max_tool_tip();
769 c = new GridBagConstraints();
770 c.gridx = 0; c.gridy = row;
772 c.fill = GridBagConstraints.NONE;
773 c.anchor = GridBagConstraints.LINE_START;
776 ignite_mode_label = new JLabel("Igniter Firing Mode:");
777 pane.add(ignite_mode_label, c);
779 c = new GridBagConstraints();
780 c.gridx = 4; c.gridy = row;
782 c.fill = GridBagConstraints.HORIZONTAL;
784 c.anchor = GridBagConstraints.LINE_START;
787 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
788 ignite_mode_value.setEditable(false);
789 ignite_mode_value.addItemListener(this);
790 pane.add(ignite_mode_value, c);
791 set_ignite_mode_tool_tip();
794 /* Pad orientation */
795 c = new GridBagConstraints();
796 c.gridx = 0; c.gridy = row;
798 c.fill = GridBagConstraints.NONE;
799 c.anchor = GridBagConstraints.LINE_START;
802 pad_orientation_label = new JLabel("Pad Orientation:");
803 pane.add(pad_orientation_label, c);
805 c = new GridBagConstraints();
806 c.gridx = 4; c.gridy = row;
808 c.fill = GridBagConstraints.HORIZONTAL;
810 c.anchor = GridBagConstraints.LINE_START;
813 pad_orientation_values = pad_orientation_values_no_radio;
815 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
816 pad_orientation_value.setEditable(false);
817 pad_orientation_value.addItemListener(this);
818 pane.add(pad_orientation_value, c);
819 set_pad_orientation_tool_tip();
823 c = new GridBagConstraints();
824 c.gridx = 0; c.gridy = row;
826 c.fill = GridBagConstraints.NONE;
827 c.anchor = GridBagConstraints.LINE_START;
830 accel_plus_label = new JLabel("Accel Plus:");
831 pane.add(accel_plus_label, c);
833 c = new GridBagConstraints();
834 c.gridx = 4; c.gridy = row;
836 c.fill = GridBagConstraints.HORIZONTAL;
838 c.anchor = GridBagConstraints.LINE_START;
841 accel_plus_value = new JTextField(10);
842 accel_plus_value.setEditable(true);
843 accel_plus_value.getDocument().addDocumentListener(this);
844 pane.add(accel_plus_value, c);
848 c = new GridBagConstraints();
849 c.gridx = 0; c.gridy = row;
851 c.fill = GridBagConstraints.NONE;
852 c.anchor = GridBagConstraints.LINE_START;
855 accel_minus_label = new JLabel("Accel Minus:");
856 pane.add(accel_minus_label, c);
858 c = new GridBagConstraints();
859 c.gridx = 4; c.gridy = row;
861 c.fill = GridBagConstraints.HORIZONTAL;
863 c.anchor = GridBagConstraints.LINE_START;
866 accel_minus_value = new JTextField(10);
867 accel_minus_value.setEditable(true);
868 accel_minus_value.getDocument().addDocumentListener(this);
869 pane.add(accel_minus_value, c);
871 set_accel_tool_tips();
874 c = new GridBagConstraints();
875 c.gridx = 0; c.gridy = row;
877 c.fill = GridBagConstraints.NONE;
878 c.anchor = GridBagConstraints.LINE_START;
881 beep_label = new JLabel("Beeper Frequency:");
882 pane.add(beep_label, c);
884 c = new GridBagConstraints();
885 c.gridx = 4; c.gridy = row;
887 c.fill = GridBagConstraints.HORIZONTAL;
889 c.anchor = GridBagConstraints.LINE_START;
892 beep_value = new JComboBox<String>(beep_values);
893 beep_value.setEditable(true);
894 beep_value.addItemListener(this);
895 pane.add(beep_value, c);
899 /* Tracker triger horiz distances */
900 c = new GridBagConstraints();
901 c.gridx = 0; c.gridy = row;
903 c.fill = GridBagConstraints.NONE;
904 c.anchor = GridBagConstraints.LINE_START;
907 tracker_motion_label = new JLabel(get_tracker_motion_label());
908 pane.add(tracker_motion_label, c);
910 c = new GridBagConstraints();
911 c.gridx = 4; c.gridy = row;
913 c.fill = GridBagConstraints.HORIZONTAL;
915 c.anchor = GridBagConstraints.LINE_START;
918 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
919 tracker_motion_value.setEditable(true);
920 tracker_motion_value.addItemListener(this);
921 pane.add(tracker_motion_value, c);
924 /* Tracker triger vert distances */
925 c = new GridBagConstraints();
926 c.gridx = 0; c.gridy = row;
928 c.fill = GridBagConstraints.NONE;
929 c.anchor = GridBagConstraints.LINE_START;
932 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
933 pane.add(tracker_interval_label, c);
935 c = new GridBagConstraints();
936 c.gridx = 4; c.gridy = row;
938 c.fill = GridBagConstraints.HORIZONTAL;
940 c.anchor = GridBagConstraints.LINE_START;
943 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
944 tracker_interval_value.setEditable(true);
945 tracker_interval_value.addItemListener(this);
946 pane.add(tracker_interval_value, c);
947 set_tracker_tool_tip();
951 c = new GridBagConstraints();
952 c.gridx = 4; c.gridy = row;
954 c.fill = GridBagConstraints.HORIZONTAL;
955 c.anchor = GridBagConstraints.LINE_START;
958 pyro = new JButton("Configure Pyro Channels");
960 pyro.addActionListener(this);
961 pyro.setActionCommand("Pyro");
965 c = new GridBagConstraints();
966 c.gridx = 5; c.gridy = row;
968 c.fill = GridBagConstraints.HORIZONTAL;
969 c.anchor = GridBagConstraints.LINE_START;
972 accel_cal = new JButton("Calibrate Accelerometer");
973 pane.add(accel_cal, c);
974 accel_cal.addActionListener(this);
975 accel_cal.setActionCommand("Accel");
979 c = new GridBagConstraints();
980 c.gridx = 0; c.gridy = row;
982 c.fill = GridBagConstraints.NONE;
983 c.anchor = GridBagConstraints.LINE_START;
985 save = new JButton("Save");
987 save.addActionListener(this);
988 save.setActionCommand("Save");
990 c = new GridBagConstraints();
991 c.gridx = 2; c.gridy = row;
993 c.fill = GridBagConstraints.NONE;
994 c.anchor = GridBagConstraints.CENTER;
996 reset = new JButton("Reset");
998 reset.addActionListener(this);
999 reset.setActionCommand("Reset");
1001 c = new GridBagConstraints();
1002 c.gridx = 4; c.gridy = row;
1004 c.fill = GridBagConstraints.NONE;
1005 c.anchor = GridBagConstraints.CENTER;
1007 reboot = new JButton("Reboot");
1008 pane.add(reboot, c);
1009 reboot.addActionListener(this);
1010 reboot.setActionCommand("Reboot");
1012 c = new GridBagConstraints();
1013 c.gridx = 6; c.gridy = row;
1015 c.fill = GridBagConstraints.NONE;
1016 c.anchor = GridBagConstraints.LINE_END;
1018 close = new JButton("Close");
1020 close.addActionListener(this);
1021 close.setActionCommand("Close");
1023 addWindowListener(new ConfigListener(this));
1024 AltosPreferences.register_units_listener(this);
1027 /* Once the initial values are set, the config code will show the dialog */
1028 public void make_visible() {
1030 setLocationRelativeTo(owner);
1034 /* If any values have been changed, confirm before closing */
1035 public boolean check_dirty(String operation) {
1037 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
1039 i = JOptionPane.showOptionDialog(this,
1040 String.format("Configuration modified. %s anyway?", operation),
1041 "Configuration Modified",
1042 JOptionPane.DEFAULT_OPTION,
1043 JOptionPane.WARNING_MESSAGE,
1044 null, options, options[1]);
1051 public void set_dirty() {
1053 setTitle(title + " (modified)");
1054 save.setEnabled(true);
1057 public void set_clean() {
1060 save.setEnabled(false);
1063 AltosConfigPyroUI pyro_ui;
1065 public void dispose() {
1066 if (pyro_ui != null)
1068 AltosPreferences.unregister_units_listener(this);
1072 /* Listen for events from our buttons */
1073 public void actionPerformed(ActionEvent e) {
1074 String cmd = e.getActionCommand();
1076 if (cmd.equals("Pyro")) {
1077 if (pyro_ui == null && pyros != null)
1078 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
1079 if (pyro_ui != null)
1080 pyro_ui.make_visible();
1084 if (cmd.equals("Close") || cmd.equals("Reboot"))
1085 if (!check_dirty(cmd))
1087 if (cmd.equals("Save"))
1088 save.setEnabled(false);
1089 listener.actionPerformed(e);
1090 if (cmd.equals("Close") || cmd.equals("Reboot")) {
1096 /* ItemListener interface method */
1097 public void itemStateChanged(ItemEvent e) {
1101 /* DocumentListener interface methods */
1102 public void changedUpdate(DocumentEvent e) {
1106 public void insertUpdate(DocumentEvent e) {
1110 public void removeUpdate(DocumentEvent e) {
1114 /* Let the config code hook on a listener */
1115 public void addActionListener(ActionListener l) {
1119 /* set and get all of the dialog values */
1120 public void set_product(String product) {
1121 radio_frequency_value.set_product(product);
1122 product_value.setText(product);
1123 set_pad_orientation_tool_tip();
1124 set_accel_tool_tips();
1125 set_flight_log_max_tool_tip();
1126 set_pad_orientation_values();
1129 public void set_version(String version) {
1130 version_value.setText(version);
1133 public void set_serial(int serial) {
1134 radio_frequency_value.set_serial(serial);
1135 serial_value.setText(String.format("%d", serial));
1138 public void set_altitude_32(int altitude_32) {
1141 public void set_main_deploy(int new_main_deploy) {
1142 if (new_main_deploy != AltosLib.MISSING)
1143 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
1144 main_deploy_value.setVisible(new_main_deploy != AltosLib.MISSING);
1145 main_deploy_label.setVisible(new_main_deploy != AltosLib.MISSING);
1148 public int main_deploy() throws AltosConfigDataException {
1149 String str = main_deploy_value.getSelectedItem().toString();
1151 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1152 } catch (ParseException pe) {
1153 throw new AltosConfigDataException("invalid main deploy height %s", str);
1157 String get_main_deploy_label() {
1158 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.parse_units());
1161 String[] main_deploy_values() {
1162 if (AltosConvert.imperial_units)
1163 return main_deploy_values_ft;
1165 return main_deploy_values_m;
1168 void set_main_deploy_values() {
1169 String[] v = main_deploy_values();
1170 while (main_deploy_value.getItemCount() > 0)
1171 main_deploy_value.removeItemAt(0);
1172 for (int i = 0; i < v.length; i++)
1173 main_deploy_value.addItem(v[i]);
1174 main_deploy_value.setMaximumRowCount(v.length);
1177 public void units_changed(boolean imperial_units) {
1178 boolean was_dirty = dirty;
1180 String v = main_deploy_value.getSelectedItem().toString();
1181 main_deploy_label.setText(get_main_deploy_label());
1182 set_main_deploy_values();
1184 int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1186 } catch (ParseException pe) {
1189 if (tracker_motion_value.isVisible()) {
1190 String motion = tracker_motion_value.getSelectedItem().toString();
1191 tracker_motion_label.setText(get_tracker_motion_label());
1192 set_tracker_motion_values();
1194 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1195 set_tracker_motion(m);
1196 } catch (ParseException pe) {
1204 public void set_apogee_delay(int new_apogee_delay) {
1205 if (new_apogee_delay != AltosLib.MISSING)
1206 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1207 apogee_delay_value.setVisible(new_apogee_delay != AltosLib.MISSING);
1208 apogee_delay_label.setVisible(new_apogee_delay != AltosLib.MISSING);
1211 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1214 v = s.split("\\s+")[0];
1216 return Integer.parseInt(v);
1217 } catch (NumberFormatException ne) {
1218 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1222 public int apogee_delay() throws AltosConfigDataException {
1223 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1226 public void set_apogee_lockout(int new_apogee_lockout) {
1227 if (new_apogee_lockout != AltosLib.MISSING)
1228 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1230 apogee_lockout_value.setVisible(new_apogee_lockout != AltosLib.MISSING);
1231 apogee_lockout_label.setVisible(new_apogee_lockout != AltosLib.MISSING);
1234 public int apogee_lockout() throws AltosConfigDataException {
1235 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1238 public void set_radio_frequency(double new_radio_frequency) {
1239 if (new_radio_frequency != AltosLib.MISSING)
1240 radio_frequency_value.set_frequency(new_radio_frequency);
1241 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
1242 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
1245 public double radio_frequency() {
1246 return radio_frequency_value.frequency();
1249 public void set_radio_calibration(int new_radio_calibration) {
1250 if (new_radio_calibration != AltosLib.MISSING)
1251 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1252 radio_calibration_value.setVisible(new_radio_calibration != AltosLib.MISSING);
1253 radio_calibration_label.setVisible(new_radio_calibration != AltosLib.MISSING);
1256 public void set_radio_enable(int new_radio_enable) {
1257 if (new_radio_enable != AltosLib.MISSING)
1258 radio_enable_value.setSelected(new_radio_enable != 0);
1259 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
1260 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
1261 set_radio_enable_tool_tip();
1264 public int radio_enable() {
1265 if (radio_enable_value.isVisible())
1266 return radio_enable_value.isSelected() ? 1 : 0;
1268 return AltosLib.MISSING;
1271 public void set_telemetry_rate(int new_rate) {
1272 if (new_rate != AltosLib.MISSING)
1273 rate_value.set_rate(new_rate);
1274 rate_label.setVisible(new_rate != AltosLib.MISSING);
1275 rate_value.setVisible(new_rate != AltosLib.MISSING);
1276 set_rate_tool_tip();
1279 public int telemetry_rate() {
1280 return rate_value.rate();
1283 public void set_callsign(String new_callsign) {
1284 if (new_callsign != null)
1285 callsign_value.setText(new_callsign);
1286 callsign_value.setVisible(new_callsign != null);
1287 callsign_label.setVisible(new_callsign != null);
1290 public String callsign() {
1291 if (callsign_value.isVisible())
1292 return callsign_value.getText();
1296 int flight_log_max_limit;
1299 public String flight_log_max_label(int flight_log_max) {
1300 if (flight_log_max_limit != 0) {
1301 int nflight = flight_log_max_limit / flight_log_max;
1302 String plural = nflight > 1 ? "s" : "";
1304 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1306 return String.format("%d", flight_log_max);
1309 public void set_flight_log_max(int new_flight_log_max) {
1310 if (new_flight_log_max != AltosLib.MISSING) {
1311 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1312 flight_log_max = new_flight_log_max;
1314 flight_log_max_value.setVisible(new_flight_log_max != AltosLib.MISSING);
1315 flight_log_max_label.setVisible(new_flight_log_max != AltosLib.MISSING);
1316 set_flight_log_max_tool_tip();
1319 public void set_flight_log_max_enabled(boolean enable) {
1320 flight_log_max_value.setEnabled(enable);
1321 set_flight_log_max_tool_tip();
1324 public int flight_log_max() throws AltosConfigDataException {
1325 if (flight_log_max_value.isVisible())
1326 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1327 return AltosLib.MISSING;
1330 public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
1331 flight_log_max_limit = new_flight_log_max_limit;
1332 if (new_flight_log_max_limit != AltosLib.MISSING) {
1333 flight_log_max_value.removeAllItems();
1334 for (int i = 8; i >= 1; i--) {
1335 int size = flight_log_max_limit / i;
1336 if (new_storage_erase_unit != 0)
1337 size &= ~(new_storage_erase_unit - 1);
1338 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1341 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
1342 set_flight_log_max(flight_log_max);
1345 public void set_ignite_mode(int new_ignite_mode) {
1346 if (new_ignite_mode != AltosLib.MISSING) {
1347 if (new_ignite_mode >= ignite_mode_values.length)
1348 new_ignite_mode = 0;
1349 if (new_ignite_mode < 0) {
1350 ignite_mode_value.setEnabled(false);
1351 new_ignite_mode = 0;
1353 ignite_mode_value.setEnabled(true);
1355 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1357 ignite_mode_value.setVisible(new_ignite_mode != AltosLib.MISSING);
1358 ignite_mode_label.setVisible(new_ignite_mode != AltosLib.MISSING);
1360 set_ignite_mode_tool_tip();
1363 public int ignite_mode() {
1364 if (ignite_mode_value.isVisible())
1365 return ignite_mode_value.getSelectedIndex();
1367 return AltosLib.MISSING;
1371 public void set_pad_orientation(int new_pad_orientation) {
1372 if (new_pad_orientation != AltosLib.MISSING) {
1373 if (new_pad_orientation >= pad_orientation_values.length)
1374 new_pad_orientation = 0;
1375 if (new_pad_orientation < 0)
1376 new_pad_orientation = 0;
1377 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1379 pad_orientation_value.setVisible(new_pad_orientation != AltosLib.MISSING);
1380 pad_orientation_label.setVisible(new_pad_orientation != AltosLib.MISSING);
1381 accel_cal.setVisible(new_pad_orientation != AltosLib.MISSING);
1383 set_pad_orientation_tool_tip();
1386 public int pad_orientation() {
1387 if (pad_orientation_value.isVisible())
1388 return pad_orientation_value.getSelectedIndex();
1390 return AltosLib.MISSING;
1393 public void set_accel_cal(int accel_plus, int accel_minus) {
1394 if (accel_plus != AltosLib.MISSING) {
1395 accel_plus_value.setText(String.format("%d", accel_plus));
1396 accel_minus_value.setText(String.format("%d", accel_minus));
1398 accel_plus_value.setVisible(accel_plus != AltosLib.MISSING);
1399 accel_plus_label.setVisible(accel_plus != AltosLib.MISSING);
1400 accel_minus_value.setVisible(accel_minus != AltosLib.MISSING);
1401 accel_minus_label.setVisible(accel_minus != AltosLib.MISSING);
1403 set_accel_tool_tips();
1406 public int accel_cal_plus() {
1407 if (accel_plus_value.isVisible())
1408 return Integer.parseInt(accel_plus_value.getText());
1409 return AltosLib.MISSING;
1412 public int accel_cal_minus() {
1413 if (accel_minus_value.isVisible())
1414 return Integer.parseInt(accel_minus_value.getText());
1415 return AltosLib.MISSING;
1418 public void set_beep(int new_beep) {
1419 if (new_beep != AltosLib.MISSING) {
1420 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1421 for (int i = 0; i < beep_values.length; i++)
1422 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1423 beep_value.setSelectedIndex(i);
1424 set_beep_tool_tip();
1427 beep_value.setSelectedItem(String.format("%d", new_freq));
1429 beep_value.setVisible(new_beep != AltosLib.MISSING);
1430 beep_label.setVisible(new_beep != AltosLib.MISSING);
1431 set_beep_tool_tip();
1435 if (beep_value.isVisible())
1436 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1438 return AltosLib.MISSING;
1441 String[] tracker_motion_values() {
1442 if (AltosConvert.imperial_units)
1443 return tracker_motion_values_ft;
1445 return tracker_motion_values_m;
1448 void set_tracker_motion_values() {
1449 String[] v = tracker_motion_values();
1450 while (tracker_motion_value.getItemCount() > 0)
1451 tracker_motion_value.removeItemAt(0);
1452 for (int i = 0; i < v.length; i++)
1453 tracker_motion_value.addItem(v[i]);
1454 tracker_motion_value.setMaximumRowCount(v.length);
1457 String get_tracker_motion_label() {
1458 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1461 void set_tracker_tool_tip() {
1462 if (tracker_motion_value.isVisible())
1463 tracker_motion_value.setToolTipText("How far the device must move before logging");
1465 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1466 if (tracker_interval_value.isVisible())
1467 tracker_interval_value.setToolTipText("How often to report GPS position");
1469 tracker_interval_value.setToolTipText("This device can't configure interval");
1472 public void set_tracker_motion(int tracker_motion) {
1473 if (tracker_motion != AltosLib.MISSING)
1474 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1475 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1476 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1479 public int tracker_motion() throws AltosConfigDataException {
1480 if (tracker_motion_value.isVisible()) {
1481 String str = tracker_motion_value.getSelectedItem().toString();
1483 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1484 } catch (ParseException pe) {
1485 throw new AltosConfigDataException("invalid tracker motion %s", str);
1488 return AltosLib.MISSING;
1491 public void set_tracker_interval(int tracker_interval) {
1492 if (tracker_interval != AltosLib.MISSING)
1493 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1494 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1495 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1498 public int tracker_interval() throws AltosConfigDataException {
1499 if (tracker_interval_value.isVisible())
1500 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1501 return AltosLib.MISSING;
1504 public void set_pyros(AltosPyro[] new_pyros) {
1506 if (pyros != null && pyro_ui != null)
1507 pyro_ui.set_pyros(pyros);
1508 pyro.setVisible(pyros != null);
1511 public AltosPyro[] pyros() throws AltosConfigDataException {
1512 if (pyro_ui != null)
1513 pyros = pyro_ui.get_pyros();
1517 public void set_pyro_firing_time(double new_pyro_firing_time) {
1518 pyro_firing_time = new_pyro_firing_time;
1519 if (pyro_firing_time != AltosLib.MISSING && pyro_ui != null)
1520 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1521 pyro.setVisible(pyro_firing_time != AltosLib.MISSING);
1524 public double pyro_firing_time() throws AltosConfigDataException {
1525 if (pyro_ui != null)
1526 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1527 return pyro_firing_time;
1530 private String aprs_interval_string(int interval) {
1533 return Integer.toString(interval);
1536 private int aprs_interval_value(String interval) throws AltosConfigDataException {
1537 if (interval.equalsIgnoreCase("Disabled"))
1539 return parse_int("aprs interval", interval, false);
1542 public void set_aprs_interval(int new_aprs_interval) {
1543 if (new_aprs_interval != AltosLib.MISSING)
1544 aprs_interval_value.setSelectedItem(aprs_interval_string(new_aprs_interval));
1545 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1546 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1547 set_aprs_interval_tool_tip();
1550 public int aprs_interval() throws AltosConfigDataException {
1551 if (aprs_interval_value.isVisible())
1552 return aprs_interval_value(aprs_interval_value.getSelectedItem().toString());
1553 return AltosLib.MISSING;
1556 public void set_aprs_ssid(int new_aprs_ssid) {
1557 if (new_aprs_ssid != AltosLib.MISSING)
1558 aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1559 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1560 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1561 set_aprs_ssid_tool_tip();
1564 public int aprs_ssid() throws AltosConfigDataException {
1565 if (aprs_ssid_value.isVisible()) {
1566 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1569 return AltosLib.MISSING;
1572 public void set_aprs_format(int new_aprs_format) {
1573 if (new_aprs_format != AltosLib.MISSING)
1574 aprs_format_value.setSelectedIndex(new_aprs_format);
1575 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1576 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1577 set_aprs_format_tool_tip();
1580 public int aprs_format() throws AltosConfigDataException {
1581 if (aprs_format_value.isVisible())
1582 return aprs_format_value.getSelectedIndex();
1583 return AltosLib.MISSING;
1586 public void set_aprs_offset(int new_aprs_offset) {
1587 if (new_aprs_offset != AltosLib.MISSING)
1588 aprs_offset_value.setSelectedItem(new_aprs_offset);
1589 aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
1590 aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
1591 set_aprs_offset_tool_tip();
1594 public int aprs_offset() throws AltosConfigDataException {
1595 if (aprs_offset_value.isVisible()) {
1596 Integer i = (Integer) aprs_offset_value.getSelectedItem();
1599 return AltosLib.MISSING;