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 = {
148 static String[] pad_orientation_values_radio = {
153 static String[] pad_orientation_values_no_radio = {
158 String[] pad_orientation_values;
160 static String[] tracker_motion_values_m = {
167 static String[] tracker_motion_values_ft = {
174 static String[] tracker_interval_values = {
181 /* A window listener to catch closing events and tell the config code */
182 class ConfigListener extends WindowAdapter {
185 public ConfigListener(AltosConfigFCUI this_ui) {
189 public void windowClosing(WindowEvent e) {
190 ui.actionPerformed(new ActionEvent(e.getSource(),
191 ActionEvent.ACTION_PERFORMED,
196 boolean is_telemini_v1() {
197 String product = product_value.getText();
198 return product != null && product.startsWith("TeleMini-v1");
201 boolean is_telemini() {
202 String product = product_value.getText();
203 return product != null && product.startsWith("TeleMini");
206 boolean is_easymini() {
207 String product = product_value.getText();
208 return product != null && product.startsWith("EasyMini");
211 boolean is_telemetrum() {
212 String product = product_value.getText();
213 return product != null && product.startsWith("TeleMetrum");
216 boolean is_telemega() {
217 String product = product_value.getText();
218 return product != null && product.startsWith("TeleMega");
221 boolean is_easymega() {
222 String product = product_value.getText();
223 return product != null && product.startsWith("EasyMega");
226 boolean is_easytimer() {
227 String product = product_value.getText();
228 return product != null && product.startsWith("EasyTimer");
231 boolean has_radio() {
232 return is_telemega() || is_telemetrum() || is_telemini();
235 void set_radio_enable_tool_tip() {
236 if (radio_enable_value.isVisible())
237 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
239 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
242 void set_rate_tool_tip() {
243 if (rate_value.isVisible())
244 rate_value.setToolTipText("Select telemetry baud rate");
246 rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
249 void set_aprs_interval_tool_tip() {
250 if (aprs_interval_value.isVisible())
251 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
253 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
256 void set_aprs_ssid_tool_tip() {
257 if (aprs_ssid_value.isVisible())
258 aprs_ssid_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
259 else if (aprs_ssid_value.isVisible())
260 aprs_ssid_value.setToolTipText("Software version doesn't support setting the APRS SSID");
262 aprs_ssid_value.setToolTipText("Hardware doesn't support APRS");
265 void set_aprs_format_tool_tip() {
266 if (aprs_format_value.isVisible())
267 aprs_format_value.setToolTipText("Set the APRS format (compressed/uncompressed)");
268 else if (aprs_format_value.isVisible())
269 aprs_format_value.setToolTipText("Software version doesn't support setting the APRS format");
271 aprs_format_value.setToolTipText("Hardware doesn't support APRS");
274 void set_aprs_offset_tool_tip() {
275 if (aprs_offset_value.isVisible())
276 aprs_offset_value.setToolTipText("Set the APRS offset from top of minute");
277 else if (aprs_offset_value.isVisible())
278 aprs_offset_value.setToolTipText("Software version doesn't support setting the APRS offset");
280 aprs_offset_value.setToolTipText("Hardware doesn't support APRS");
283 void set_flight_log_max_tool_tip() {
284 if (flight_log_max_value.isVisible())
285 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
287 if (is_telemini_v1())
288 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
290 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
294 void set_ignite_mode_tool_tip() {
295 if (ignite_mode_value.isVisible())
296 ignite_mode_value.setToolTipText("Select when igniters will be fired");
298 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
301 void set_pad_orientation_tool_tip() {
302 if (pad_orientation_value.isVisible()) {
303 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
306 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
307 else if (is_telemini() || is_easymini())
308 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
309 else if (is_easytimer())
310 pad_orientation_value.setToolTipText("EasyTimer can be mounted in any of six orientations");
312 pad_orientation_value.setToolTipText("Can't select orientation");
316 void set_pad_orientation_values() {
317 String [] new_values;
319 new_values = pad_orientation_values_radio;
321 new_values = pad_orientation_values_no_radio;
322 if (new_values != pad_orientation_values) {
323 int id = pad_orientation_value.getSelectedIndex();
324 pad_orientation_value.removeAllItems();
325 pad_orientation_values = new_values;
326 for (int i = 0; i < new_values.length; i++)
327 pad_orientation_value.addItem(pad_orientation_values[i]);
328 pad_orientation_value.setSelectedIndex(id);
332 void set_accel_tool_tips() {
333 if (accel_plus_value.isVisible()) {
334 accel_plus_value.setToolTipText("Pad acceleration value in flight orientation");
335 accel_minus_value.setToolTipText("Upside-down acceleration value");
337 accel_plus_value.setToolTipText("No accelerometer");
338 accel_minus_value.setToolTipText("No accelerometer");
342 void set_beep_tool_tip() {
343 if (beep_value.isVisible())
344 beep_value.setToolTipText("What frequency the beeper will sound at");
346 beep_value.setToolTipText("Older firmware could not select beeper frequency");
349 /* Build the UI using a grid bag */
350 public AltosConfigFCUI(JFrame in_owner, boolean remote) {
351 super (in_owner, title, false);
354 GridBagConstraints c;
357 Insets il = new Insets(4,4,4,4);
358 Insets ir = new Insets(4,4,4,4);
360 pane = getContentPane();
361 pane.setLayout(new GridBagLayout());
364 c = new GridBagConstraints();
365 c.gridx = 0; c.gridy = row;
367 c.fill = GridBagConstraints.NONE;
368 c.anchor = GridBagConstraints.LINE_START;
370 product_label = new JLabel("Product:");
371 pane.add(product_label, c);
373 c = new GridBagConstraints();
374 c.gridx = 4; c.gridy = row;
376 c.fill = GridBagConstraints.HORIZONTAL;
378 c.anchor = GridBagConstraints.LINE_START;
380 product_value = new JLabel("");
381 pane.add(product_value, c);
385 c = new GridBagConstraints();
386 c.gridx = 0; c.gridy = row;
388 c.fill = GridBagConstraints.NONE;
389 c.anchor = GridBagConstraints.LINE_START;
392 version_label = new JLabel("Software version:");
393 pane.add(version_label, c);
395 c = new GridBagConstraints();
396 c.gridx = 4; c.gridy = row;
398 c.fill = GridBagConstraints.HORIZONTAL;
400 c.anchor = GridBagConstraints.LINE_START;
403 version_value = new JLabel("");
404 pane.add(version_value, c);
408 c = new GridBagConstraints();
409 c.gridx = 0; c.gridy = row;
411 c.fill = GridBagConstraints.NONE;
412 c.anchor = GridBagConstraints.LINE_START;
415 serial_label = new JLabel("Serial:");
416 pane.add(serial_label, c);
418 c = new GridBagConstraints();
419 c.gridx = 4; c.gridy = row;
421 c.fill = GridBagConstraints.HORIZONTAL;
423 c.anchor = GridBagConstraints.LINE_START;
426 serial_value = new JLabel("");
427 pane.add(serial_value, c);
431 c = new GridBagConstraints();
432 c.gridx = 0; c.gridy = row;
434 c.fill = GridBagConstraints.NONE;
435 c.anchor = GridBagConstraints.LINE_START;
438 main_deploy_label = new JLabel(get_main_deploy_label());
439 pane.add(main_deploy_label, c);
441 c = new GridBagConstraints();
442 c.gridx = 4; c.gridy = row;
444 c.fill = GridBagConstraints.HORIZONTAL;
446 c.anchor = GridBagConstraints.LINE_START;
449 main_deploy_value = new JComboBox<String>(main_deploy_values());
450 main_deploy_value.setEditable(true);
451 main_deploy_value.addItemListener(this);
452 pane.add(main_deploy_value, c);
453 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
457 c = new GridBagConstraints();
458 c.gridx = 0; c.gridy = row;
460 c.fill = GridBagConstraints.NONE;
461 c.anchor = GridBagConstraints.LINE_START;
464 apogee_delay_label = new JLabel("Apogee Delay(s):");
465 pane.add(apogee_delay_label, c);
467 c = new GridBagConstraints();
468 c.gridx = 4; c.gridy = row;
470 c.fill = GridBagConstraints.HORIZONTAL;
472 c.anchor = GridBagConstraints.LINE_START;
475 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
476 apogee_delay_value.setEditable(true);
477 apogee_delay_value.addItemListener(this);
478 pane.add(apogee_delay_value, c);
479 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
483 c = new GridBagConstraints();
484 c.gridx = 0; c.gridy = row;
486 c.fill = GridBagConstraints.NONE;
487 c.anchor = GridBagConstraints.LINE_START;
490 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
491 pane.add(apogee_lockout_label, c);
493 c = new GridBagConstraints();
494 c.gridx = 4; c.gridy = row;
496 c.fill = GridBagConstraints.HORIZONTAL;
498 c.anchor = GridBagConstraints.LINE_START;
501 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
502 apogee_lockout_value.setEditable(true);
503 apogee_lockout_value.addItemListener(this);
504 pane.add(apogee_lockout_value, c);
505 apogee_lockout_value.setToolTipText("Time after launch while apogee detection is locked out");
509 c = new GridBagConstraints();
510 c.gridx = 0; c.gridy = row;
512 c.fill = GridBagConstraints.NONE;
513 c.anchor = GridBagConstraints.LINE_START;
516 radio_frequency_label = new JLabel("Frequency:");
517 pane.add(radio_frequency_label, c);
519 c = new GridBagConstraints();
520 c.gridx = 4; c.gridy = row;
522 c.fill = GridBagConstraints.HORIZONTAL;
524 c.anchor = GridBagConstraints.LINE_START;
527 radio_frequency_value = new AltosUIFreqList();
528 radio_frequency_value.addItemListener(this);
529 pane.add(radio_frequency_value, c);
530 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
533 /* Radio Calibration */
534 c = new GridBagConstraints();
535 c.gridx = 0; c.gridy = row;
537 c.fill = GridBagConstraints.NONE;
538 c.anchor = GridBagConstraints.LINE_START;
541 radio_calibration_label = new JLabel("RF Calibration:");
542 pane.add(radio_calibration_label, c);
544 c = new GridBagConstraints();
545 c.gridx = 4; c.gridy = row;
547 c.fill = GridBagConstraints.HORIZONTAL;
549 c.anchor = GridBagConstraints.LINE_START;
552 radio_calibration_value = new JLabel(String.format("%d", 1186611));
553 pane.add(radio_calibration_value, c);
557 c = new GridBagConstraints();
558 c.gridx = 0; c.gridy = row;
560 c.fill = GridBagConstraints.NONE;
561 c.anchor = GridBagConstraints.LINE_START;
564 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
565 pane.add(radio_enable_label, c);
567 c = new GridBagConstraints();
568 c.gridx = 4; c.gridy = row;
570 c.fill = GridBagConstraints.HORIZONTAL;
572 c.anchor = GridBagConstraints.LINE_START;
575 radio_enable_value = new JRadioButton("Enabled");
576 radio_enable_value.addItemListener(this);
577 pane.add(radio_enable_value, c);
578 set_radio_enable_tool_tip();
582 c = new GridBagConstraints();
583 c.gridx = 0; c.gridy = row;
585 c.fill = GridBagConstraints.NONE;
586 c.anchor = GridBagConstraints.LINE_START;
589 rate_label = new JLabel("Telemetry baud rate:");
590 pane.add(rate_label, c);
592 c = new GridBagConstraints();
593 c.gridx = 4; c.gridy = row;
595 c.fill = GridBagConstraints.HORIZONTAL;
597 c.anchor = GridBagConstraints.LINE_START;
600 rate_value = new AltosUIRateList();
601 rate_value.addItemListener(this);
602 pane.add(rate_value, c);
607 c = new GridBagConstraints();
608 c.gridx = 0; c.gridy = row;
610 c.fill = GridBagConstraints.NONE;
611 c.anchor = GridBagConstraints.LINE_START;
614 aprs_interval_label = new JLabel("APRS Interval(s):");
615 pane.add(aprs_interval_label, c);
617 c = new GridBagConstraints();
618 c.gridx = 4; c.gridy = row;
620 c.fill = GridBagConstraints.HORIZONTAL;
622 c.anchor = GridBagConstraints.LINE_START;
625 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
626 aprs_interval_value.setEditable(true);
627 aprs_interval_value.addItemListener(this);
628 pane.add(aprs_interval_value, c);
629 set_aprs_interval_tool_tip();
633 c = new GridBagConstraints();
634 c.gridx = 0; c.gridy = row;
636 c.fill = GridBagConstraints.NONE;
637 c.anchor = GridBagConstraints.LINE_START;
640 aprs_ssid_label = new JLabel("APRS SSID:");
641 pane.add(aprs_ssid_label, c);
643 c = new GridBagConstraints();
644 c.gridx = 4; c.gridy = row;
646 c.fill = GridBagConstraints.HORIZONTAL;
648 c.anchor = GridBagConstraints.LINE_START;
651 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
652 aprs_ssid_value.setEditable(false);
653 aprs_ssid_value.addItemListener(this);
654 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
655 pane.add(aprs_ssid_value, c);
656 set_aprs_ssid_tool_tip();
660 c = new GridBagConstraints();
661 c.gridx = 0; c.gridy = row;
663 c.fill = GridBagConstraints.NONE;
664 c.anchor = GridBagConstraints.LINE_START;
667 aprs_format_label = new JLabel("APRS format:");
668 pane.add(aprs_format_label, c);
670 c = new GridBagConstraints();
671 c.gridx = 4; c.gridy = row;
673 c.fill = GridBagConstraints.HORIZONTAL;
675 c.anchor = GridBagConstraints.LINE_START;
678 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
679 aprs_format_value.setEditable(false);
680 aprs_format_value.addItemListener(this);
681 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
682 pane.add(aprs_format_value, c);
683 set_aprs_format_tool_tip();
687 c = new GridBagConstraints();
688 c.gridx = 0; c.gridy = row;
690 c.fill = GridBagConstraints.NONE;
691 c.anchor = GridBagConstraints.LINE_START;
694 aprs_offset_label = new JLabel("APRS offset:");
695 pane.add(aprs_offset_label, c);
697 c = new GridBagConstraints();
698 c.gridx = 4; c.gridy = row;
700 c.fill = GridBagConstraints.HORIZONTAL;
702 c.anchor = GridBagConstraints.LINE_START;
705 aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
706 aprs_offset_value.setEditable(false);
707 aprs_offset_value.addItemListener(this);
708 aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
709 pane.add(aprs_offset_value, c);
710 set_aprs_offset_tool_tip();
714 c = new GridBagConstraints();
715 c.gridx = 0; c.gridy = row;
717 c.fill = GridBagConstraints.NONE;
718 c.anchor = GridBagConstraints.LINE_START;
721 callsign_label = new JLabel("Callsign:");
722 pane.add(callsign_label, c);
724 c = new GridBagConstraints();
725 c.gridx = 4; c.gridy = row;
727 c.fill = GridBagConstraints.HORIZONTAL;
729 c.anchor = GridBagConstraints.LINE_START;
732 callsign_value = new JTextField(AltosUIPreferences.callsign());
733 callsign_value.getDocument().addDocumentListener(this);
734 pane.add(callsign_value, c);
735 callsign_value.setToolTipText("Callsign reported in telemetry data");
739 c = new GridBagConstraints();
740 c.gridx = 0; c.gridy = row;
742 c.fill = GridBagConstraints.NONE;
743 c.anchor = GridBagConstraints.LINE_START;
746 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
747 pane.add(flight_log_max_label, c);
749 c = new GridBagConstraints();
750 c.gridx = 4; c.gridy = row;
752 c.fill = GridBagConstraints.HORIZONTAL;
754 c.anchor = GridBagConstraints.LINE_START;
757 flight_log_max_value = new JComboBox<String>();
758 flight_log_max_value.setEditable(true);
759 flight_log_max_value.addItemListener(this);
760 pane.add(flight_log_max_value, c);
761 set_flight_log_max_tool_tip();
765 c = new GridBagConstraints();
766 c.gridx = 0; c.gridy = row;
768 c.fill = GridBagConstraints.NONE;
769 c.anchor = GridBagConstraints.LINE_START;
772 ignite_mode_label = new JLabel("Igniter Firing Mode:");
773 pane.add(ignite_mode_label, c);
775 c = new GridBagConstraints();
776 c.gridx = 4; c.gridy = row;
778 c.fill = GridBagConstraints.HORIZONTAL;
780 c.anchor = GridBagConstraints.LINE_START;
783 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
784 ignite_mode_value.setEditable(false);
785 ignite_mode_value.addItemListener(this);
786 pane.add(ignite_mode_value, c);
787 set_ignite_mode_tool_tip();
790 /* Pad orientation */
791 c = new GridBagConstraints();
792 c.gridx = 0; c.gridy = row;
794 c.fill = GridBagConstraints.NONE;
795 c.anchor = GridBagConstraints.LINE_START;
798 pad_orientation_label = new JLabel("Pad Orientation:");
799 pane.add(pad_orientation_label, c);
801 c = new GridBagConstraints();
802 c.gridx = 4; c.gridy = row;
804 c.fill = GridBagConstraints.HORIZONTAL;
806 c.anchor = GridBagConstraints.LINE_START;
809 pad_orientation_values = pad_orientation_values_no_radio;
811 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
812 pad_orientation_value.setEditable(false);
813 pad_orientation_value.addItemListener(this);
814 pane.add(pad_orientation_value, c);
815 set_pad_orientation_tool_tip();
819 c = new GridBagConstraints();
820 c.gridx = 0; c.gridy = row;
822 c.fill = GridBagConstraints.NONE;
823 c.anchor = GridBagConstraints.LINE_START;
826 accel_plus_label = new JLabel("Accel Plus:");
827 pane.add(accel_plus_label, c);
829 c = new GridBagConstraints();
830 c.gridx = 4; c.gridy = row;
832 c.fill = GridBagConstraints.HORIZONTAL;
834 c.anchor = GridBagConstraints.LINE_START;
837 accel_plus_value = new JTextField(10);
838 accel_plus_value.setEditable(true);
839 accel_plus_value.getDocument().addDocumentListener(this);
840 pane.add(accel_plus_value, c);
844 c = new GridBagConstraints();
845 c.gridx = 0; c.gridy = row;
847 c.fill = GridBagConstraints.NONE;
848 c.anchor = GridBagConstraints.LINE_START;
851 accel_minus_label = new JLabel("Accel Minus:");
852 pane.add(accel_minus_label, c);
854 c = new GridBagConstraints();
855 c.gridx = 4; c.gridy = row;
857 c.fill = GridBagConstraints.HORIZONTAL;
859 c.anchor = GridBagConstraints.LINE_START;
862 accel_minus_value = new JTextField(10);
863 accel_minus_value.setEditable(true);
864 accel_minus_value.getDocument().addDocumentListener(this);
865 pane.add(accel_minus_value, c);
867 set_accel_tool_tips();
870 c = new GridBagConstraints();
871 c.gridx = 0; c.gridy = row;
873 c.fill = GridBagConstraints.NONE;
874 c.anchor = GridBagConstraints.LINE_START;
877 beep_label = new JLabel("Beeper Frequency:");
878 pane.add(beep_label, c);
880 c = new GridBagConstraints();
881 c.gridx = 4; c.gridy = row;
883 c.fill = GridBagConstraints.HORIZONTAL;
885 c.anchor = GridBagConstraints.LINE_START;
888 beep_value = new JComboBox<String>(beep_values);
889 beep_value.setEditable(true);
890 beep_value.addItemListener(this);
891 pane.add(beep_value, c);
895 /* Tracker triger horiz distances */
896 c = new GridBagConstraints();
897 c.gridx = 0; c.gridy = row;
899 c.fill = GridBagConstraints.NONE;
900 c.anchor = GridBagConstraints.LINE_START;
903 tracker_motion_label = new JLabel(get_tracker_motion_label());
904 pane.add(tracker_motion_label, c);
906 c = new GridBagConstraints();
907 c.gridx = 4; c.gridy = row;
909 c.fill = GridBagConstraints.HORIZONTAL;
911 c.anchor = GridBagConstraints.LINE_START;
914 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
915 tracker_motion_value.setEditable(true);
916 tracker_motion_value.addItemListener(this);
917 pane.add(tracker_motion_value, c);
920 /* Tracker triger vert distances */
921 c = new GridBagConstraints();
922 c.gridx = 0; c.gridy = row;
924 c.fill = GridBagConstraints.NONE;
925 c.anchor = GridBagConstraints.LINE_START;
928 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
929 pane.add(tracker_interval_label, c);
931 c = new GridBagConstraints();
932 c.gridx = 4; c.gridy = row;
934 c.fill = GridBagConstraints.HORIZONTAL;
936 c.anchor = GridBagConstraints.LINE_START;
939 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
940 tracker_interval_value.setEditable(true);
941 tracker_interval_value.addItemListener(this);
942 pane.add(tracker_interval_value, c);
943 set_tracker_tool_tip();
947 c = new GridBagConstraints();
948 c.gridx = 4; c.gridy = row;
950 c.fill = GridBagConstraints.HORIZONTAL;
951 c.anchor = GridBagConstraints.LINE_START;
954 pyro = new JButton("Configure Pyro Channels");
956 pyro.addActionListener(this);
957 pyro.setActionCommand("Pyro");
961 c = new GridBagConstraints();
962 c.gridx = 5; c.gridy = row;
964 c.fill = GridBagConstraints.HORIZONTAL;
965 c.anchor = GridBagConstraints.LINE_START;
968 accel_cal = new JButton("Calibrate Accelerometer");
969 pane.add(accel_cal, c);
970 accel_cal.addActionListener(this);
971 accel_cal.setActionCommand("Accel");
975 c = new GridBagConstraints();
976 c.gridx = 0; c.gridy = row;
978 c.fill = GridBagConstraints.NONE;
979 c.anchor = GridBagConstraints.LINE_START;
981 save = new JButton("Save");
983 save.addActionListener(this);
984 save.setActionCommand("Save");
986 c = new GridBagConstraints();
987 c.gridx = 2; c.gridy = row;
989 c.fill = GridBagConstraints.NONE;
990 c.anchor = GridBagConstraints.CENTER;
992 reset = new JButton("Reset");
994 reset.addActionListener(this);
995 reset.setActionCommand("Reset");
997 c = new GridBagConstraints();
998 c.gridx = 4; c.gridy = row;
1000 c.fill = GridBagConstraints.NONE;
1001 c.anchor = GridBagConstraints.CENTER;
1003 reboot = new JButton("Reboot");
1004 pane.add(reboot, c);
1005 reboot.addActionListener(this);
1006 reboot.setActionCommand("Reboot");
1008 c = new GridBagConstraints();
1009 c.gridx = 6; c.gridy = row;
1011 c.fill = GridBagConstraints.NONE;
1012 c.anchor = GridBagConstraints.LINE_END;
1014 close = new JButton("Close");
1016 close.addActionListener(this);
1017 close.setActionCommand("Close");
1019 addWindowListener(new ConfigListener(this));
1020 AltosPreferences.register_units_listener(this);
1023 /* Once the initial values are set, the config code will show the dialog */
1024 public void make_visible() {
1026 setLocationRelativeTo(owner);
1030 /* If any values have been changed, confirm before closing */
1031 public boolean check_dirty(String operation) {
1033 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
1035 i = JOptionPane.showOptionDialog(this,
1036 String.format("Configuration modified. %s anyway?", operation),
1037 "Configuration Modified",
1038 JOptionPane.DEFAULT_OPTION,
1039 JOptionPane.WARNING_MESSAGE,
1040 null, options, options[1]);
1047 public void set_dirty() {
1049 setTitle(title + " (modified)");
1050 save.setEnabled(true);
1053 public void set_clean() {
1056 save.setEnabled(false);
1059 AltosConfigPyroUI pyro_ui;
1061 public void dispose() {
1062 if (pyro_ui != null)
1064 AltosPreferences.unregister_units_listener(this);
1068 /* Listen for events from our buttons */
1069 public void actionPerformed(ActionEvent e) {
1070 String cmd = e.getActionCommand();
1072 if (cmd.equals("Pyro")) {
1073 if (pyro_ui == null && pyros != null)
1074 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
1075 if (pyro_ui != null)
1076 pyro_ui.make_visible();
1080 if (cmd.equals("Close") || cmd.equals("Reboot"))
1081 if (!check_dirty(cmd))
1083 if (cmd.equals("Save"))
1084 save.setEnabled(false);
1085 listener.actionPerformed(e);
1086 if (cmd.equals("Close") || cmd.equals("Reboot")) {
1092 /* ItemListener interface method */
1093 public void itemStateChanged(ItemEvent e) {
1097 /* DocumentListener interface methods */
1098 public void changedUpdate(DocumentEvent e) {
1102 public void insertUpdate(DocumentEvent e) {
1106 public void removeUpdate(DocumentEvent e) {
1110 /* Let the config code hook on a listener */
1111 public void addActionListener(ActionListener l) {
1115 /* set and get all of the dialog values */
1116 public void set_product(String product) {
1117 radio_frequency_value.set_product(product);
1118 product_value.setText(product);
1119 set_pad_orientation_tool_tip();
1120 set_accel_tool_tips();
1121 set_flight_log_max_tool_tip();
1122 set_pad_orientation_values();
1125 public void set_version(String version) {
1126 version_value.setText(version);
1129 public void set_serial(int serial) {
1130 radio_frequency_value.set_serial(serial);
1131 serial_value.setText(String.format("%d", serial));
1134 public void set_altitude_32(int altitude_32) {
1137 public void set_main_deploy(int new_main_deploy) {
1138 if (new_main_deploy != AltosLib.MISSING)
1139 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
1140 main_deploy_value.setVisible(new_main_deploy != AltosLib.MISSING);
1141 main_deploy_label.setVisible(new_main_deploy != AltosLib.MISSING);
1144 public int main_deploy() throws AltosConfigDataException {
1145 String str = main_deploy_value.getSelectedItem().toString();
1147 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1148 } catch (ParseException pe) {
1149 throw new AltosConfigDataException("invalid main deploy height %s", str);
1153 String get_main_deploy_label() {
1154 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.parse_units());
1157 String[] main_deploy_values() {
1158 if (AltosConvert.imperial_units)
1159 return main_deploy_values_ft;
1161 return main_deploy_values_m;
1164 void set_main_deploy_values() {
1165 String[] v = main_deploy_values();
1166 while (main_deploy_value.getItemCount() > 0)
1167 main_deploy_value.removeItemAt(0);
1168 for (int i = 0; i < v.length; i++)
1169 main_deploy_value.addItem(v[i]);
1170 main_deploy_value.setMaximumRowCount(v.length);
1173 public void units_changed(boolean imperial_units) {
1174 boolean was_dirty = dirty;
1176 String v = main_deploy_value.getSelectedItem().toString();
1177 main_deploy_label.setText(get_main_deploy_label());
1178 set_main_deploy_values();
1180 int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1182 } catch (ParseException pe) {
1185 if (tracker_motion_value.isVisible()) {
1186 String motion = tracker_motion_value.getSelectedItem().toString();
1187 tracker_motion_label.setText(get_tracker_motion_label());
1188 set_tracker_motion_values();
1190 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1191 set_tracker_motion(m);
1192 } catch (ParseException pe) {
1200 public void set_apogee_delay(int new_apogee_delay) {
1201 if (new_apogee_delay != AltosLib.MISSING)
1202 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1203 apogee_delay_value.setVisible(new_apogee_delay != AltosLib.MISSING);
1204 apogee_delay_label.setVisible(new_apogee_delay != AltosLib.MISSING);
1207 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1210 v = s.split("\\s+")[0];
1212 return Integer.parseInt(v);
1213 } catch (NumberFormatException ne) {
1214 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1218 public int apogee_delay() throws AltosConfigDataException {
1219 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1222 public void set_apogee_lockout(int new_apogee_lockout) {
1223 if (new_apogee_lockout != AltosLib.MISSING)
1224 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1226 apogee_lockout_value.setVisible(new_apogee_lockout != AltosLib.MISSING);
1227 apogee_lockout_label.setVisible(new_apogee_lockout != AltosLib.MISSING);
1230 public int apogee_lockout() throws AltosConfigDataException {
1231 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1234 public void set_radio_frequency(double new_radio_frequency) {
1235 if (new_radio_frequency != AltosLib.MISSING)
1236 radio_frequency_value.set_frequency(new_radio_frequency);
1237 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
1238 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
1241 public double radio_frequency() {
1242 return radio_frequency_value.frequency();
1245 public void set_radio_calibration(int new_radio_calibration) {
1246 if (new_radio_calibration != AltosLib.MISSING)
1247 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1248 radio_calibration_value.setVisible(new_radio_calibration != AltosLib.MISSING);
1249 radio_calibration_label.setVisible(new_radio_calibration != AltosLib.MISSING);
1252 public void set_radio_enable(int new_radio_enable) {
1253 if (new_radio_enable != AltosLib.MISSING)
1254 radio_enable_value.setSelected(new_radio_enable != 0);
1255 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
1256 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
1257 set_radio_enable_tool_tip();
1260 public int radio_enable() {
1261 if (radio_enable_value.isVisible())
1262 return radio_enable_value.isSelected() ? 1 : 0;
1264 return AltosLib.MISSING;
1267 public void set_telemetry_rate(int new_rate) {
1268 if (new_rate != AltosLib.MISSING)
1269 rate_value.set_rate(new_rate);
1270 rate_label.setVisible(new_rate != AltosLib.MISSING);
1271 rate_value.setVisible(new_rate != AltosLib.MISSING);
1272 set_rate_tool_tip();
1275 public int telemetry_rate() {
1276 return rate_value.rate();
1279 public void set_callsign(String new_callsign) {
1280 if (new_callsign != null)
1281 callsign_value.setText(new_callsign);
1282 callsign_value.setVisible(new_callsign != null);
1283 callsign_label.setVisible(new_callsign != null);
1286 public String callsign() {
1287 if (callsign_value.isVisible())
1288 return callsign_value.getText();
1292 int flight_log_max_limit;
1295 public String flight_log_max_label(int flight_log_max) {
1296 if (flight_log_max_limit != 0) {
1297 int nflight = flight_log_max_limit / flight_log_max;
1298 String plural = nflight > 1 ? "s" : "";
1300 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1302 return String.format("%d", flight_log_max);
1305 public void set_flight_log_max(int new_flight_log_max) {
1306 if (new_flight_log_max != AltosLib.MISSING) {
1307 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1308 flight_log_max = new_flight_log_max;
1310 flight_log_max_value.setVisible(new_flight_log_max != AltosLib.MISSING);
1311 flight_log_max_label.setVisible(new_flight_log_max != AltosLib.MISSING);
1312 set_flight_log_max_tool_tip();
1315 public void set_flight_log_max_enabled(boolean enable) {
1316 flight_log_max_value.setEnabled(enable);
1317 set_flight_log_max_tool_tip();
1320 public int flight_log_max() throws AltosConfigDataException {
1321 if (flight_log_max_value.isVisible())
1322 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1323 return AltosLib.MISSING;
1326 public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
1327 flight_log_max_limit = new_flight_log_max_limit;
1328 if (new_flight_log_max_limit != AltosLib.MISSING) {
1329 flight_log_max_value.removeAllItems();
1330 for (int i = 8; i >= 1; i--) {
1331 int size = flight_log_max_limit / i;
1332 if (new_storage_erase_unit != 0)
1333 size &= ~(new_storage_erase_unit - 1);
1334 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1337 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
1338 set_flight_log_max(flight_log_max);
1341 public void set_ignite_mode(int new_ignite_mode) {
1342 if (new_ignite_mode != AltosLib.MISSING) {
1343 if (new_ignite_mode >= ignite_mode_values.length)
1344 new_ignite_mode = 0;
1345 if (new_ignite_mode < 0) {
1346 ignite_mode_value.setEnabled(false);
1347 new_ignite_mode = 0;
1349 ignite_mode_value.setEnabled(true);
1351 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1353 ignite_mode_value.setVisible(new_ignite_mode != AltosLib.MISSING);
1354 ignite_mode_label.setVisible(new_ignite_mode != AltosLib.MISSING);
1356 set_ignite_mode_tool_tip();
1359 public int ignite_mode() {
1360 if (ignite_mode_value.isVisible())
1361 return ignite_mode_value.getSelectedIndex();
1363 return AltosLib.MISSING;
1367 public void set_pad_orientation(int new_pad_orientation) {
1368 if (new_pad_orientation != AltosLib.MISSING) {
1369 if (new_pad_orientation >= pad_orientation_values.length)
1370 new_pad_orientation = 0;
1371 if (new_pad_orientation < 0)
1372 new_pad_orientation = 0;
1373 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1375 pad_orientation_value.setVisible(new_pad_orientation != AltosLib.MISSING);
1376 pad_orientation_label.setVisible(new_pad_orientation != AltosLib.MISSING);
1377 accel_cal.setVisible(new_pad_orientation != AltosLib.MISSING);
1379 set_pad_orientation_tool_tip();
1382 public int pad_orientation() {
1383 if (pad_orientation_value.isVisible())
1384 return pad_orientation_value.getSelectedIndex();
1386 return AltosLib.MISSING;
1389 public void set_accel_cal(int accel_plus, int accel_minus) {
1390 if (accel_plus != AltosLib.MISSING) {
1391 accel_plus_value.setText(String.format("%d", accel_plus));
1392 accel_minus_value.setText(String.format("%d", accel_minus));
1394 accel_plus_value.setVisible(accel_plus != AltosLib.MISSING);
1395 accel_plus_label.setVisible(accel_plus != AltosLib.MISSING);
1396 accel_minus_value.setVisible(accel_minus != AltosLib.MISSING);
1397 accel_minus_label.setVisible(accel_minus != AltosLib.MISSING);
1399 set_accel_tool_tips();
1402 public int accel_cal_plus() {
1403 if (accel_plus_value.isVisible())
1404 return Integer.parseInt(accel_plus_value.getText());
1405 return AltosLib.MISSING;
1408 public int accel_cal_minus() {
1409 if (accel_minus_value.isVisible())
1410 return Integer.parseInt(accel_minus_value.getText());
1411 return AltosLib.MISSING;
1414 public void set_beep(int new_beep) {
1415 if (new_beep != AltosLib.MISSING) {
1416 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1417 for (int i = 0; i < beep_values.length; i++)
1418 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1419 beep_value.setSelectedIndex(i);
1420 set_beep_tool_tip();
1423 beep_value.setSelectedItem(String.format("%d", new_freq));
1425 beep_value.setVisible(new_beep != AltosLib.MISSING);
1426 beep_label.setVisible(new_beep != AltosLib.MISSING);
1427 set_beep_tool_tip();
1431 if (beep_value.isVisible())
1432 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1434 return AltosLib.MISSING;
1437 String[] tracker_motion_values() {
1438 if (AltosConvert.imperial_units)
1439 return tracker_motion_values_ft;
1441 return tracker_motion_values_m;
1444 void set_tracker_motion_values() {
1445 String[] v = tracker_motion_values();
1446 while (tracker_motion_value.getItemCount() > 0)
1447 tracker_motion_value.removeItemAt(0);
1448 for (int i = 0; i < v.length; i++)
1449 tracker_motion_value.addItem(v[i]);
1450 tracker_motion_value.setMaximumRowCount(v.length);
1453 String get_tracker_motion_label() {
1454 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1457 void set_tracker_tool_tip() {
1458 if (tracker_motion_value.isVisible())
1459 tracker_motion_value.setToolTipText("How far the device must move before logging");
1461 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1462 if (tracker_interval_value.isVisible())
1463 tracker_interval_value.setToolTipText("How often to report GPS position");
1465 tracker_interval_value.setToolTipText("This device can't configure interval");
1468 public void set_tracker_motion(int tracker_motion) {
1469 if (tracker_motion != AltosLib.MISSING)
1470 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1471 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1472 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1475 public int tracker_motion() throws AltosConfigDataException {
1476 if (tracker_motion_value.isVisible()) {
1477 String str = tracker_motion_value.getSelectedItem().toString();
1479 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1480 } catch (ParseException pe) {
1481 throw new AltosConfigDataException("invalid tracker motion %s", str);
1484 return AltosLib.MISSING;
1487 public void set_tracker_interval(int tracker_interval) {
1488 if (tracker_interval != AltosLib.MISSING)
1489 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1490 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1491 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1494 public int tracker_interval() throws AltosConfigDataException {
1495 if (tracker_interval_value.isVisible())
1496 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1497 return AltosLib.MISSING;
1500 public void set_pyros(AltosPyro[] new_pyros) {
1502 if (pyros != null && pyro_ui != null)
1503 pyro_ui.set_pyros(pyros);
1504 pyro.setVisible(pyros != null);
1507 public AltosPyro[] pyros() throws AltosConfigDataException {
1508 if (pyro_ui != null)
1509 pyros = pyro_ui.get_pyros();
1513 public void set_pyro_firing_time(double new_pyro_firing_time) {
1514 pyro_firing_time = new_pyro_firing_time;
1515 if (pyro_firing_time != AltosLib.MISSING && pyro_ui != null)
1516 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1517 pyro.setVisible(pyro_firing_time != AltosLib.MISSING);
1520 public double pyro_firing_time() throws AltosConfigDataException {
1521 if (pyro_ui != null)
1522 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1523 return pyro_firing_time;
1526 private String aprs_interval_string(int interval) {
1529 return Integer.toString(interval);
1532 private int aprs_interval_value(String interval) throws AltosConfigDataException {
1533 if (interval.equalsIgnoreCase("Disabled"))
1535 return parse_int("aprs interval", interval, false);
1538 public void set_aprs_interval(int new_aprs_interval) {
1539 if (new_aprs_interval != AltosLib.MISSING)
1540 aprs_interval_value.setSelectedItem(aprs_interval_string(new_aprs_interval));
1541 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1542 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1543 set_aprs_interval_tool_tip();
1546 public int aprs_interval() throws AltosConfigDataException {
1547 if (aprs_interval_value.isVisible())
1548 return aprs_interval_value(aprs_interval_value.getSelectedItem().toString());
1549 return AltosLib.MISSING;
1552 public void set_aprs_ssid(int new_aprs_ssid) {
1553 if (new_aprs_ssid != AltosLib.MISSING)
1554 aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1555 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1556 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1557 set_aprs_ssid_tool_tip();
1560 public int aprs_ssid() throws AltosConfigDataException {
1561 if (aprs_ssid_value.isVisible()) {
1562 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1565 return AltosLib.MISSING;
1568 public void set_aprs_format(int new_aprs_format) {
1569 if (new_aprs_format != AltosLib.MISSING)
1570 aprs_format_value.setSelectedIndex(new_aprs_format);
1571 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1572 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1573 set_aprs_format_tool_tip();
1576 public int aprs_format() throws AltosConfigDataException {
1577 if (aprs_format_value.isVisible())
1578 return aprs_format_value.getSelectedIndex();
1579 return AltosLib.MISSING;
1582 public void set_aprs_offset(int new_aprs_offset) {
1583 if (new_aprs_offset != AltosLib.MISSING)
1584 aprs_offset_value.setSelectedItem(new_aprs_offset);
1585 aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
1586 aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
1587 set_aprs_offset_tool_tip();
1590 public int aprs_offset() throws AltosConfigDataException {
1591 if (aprs_offset_value.isVisible()) {
1592 Integer i = (Integer) aprs_offset_value.getSelectedItem();
1595 return AltosLib.MISSING;