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 = getScrollablePane();
362 pane.setLayout(new GridBagLayout());
365 c = new GridBagConstraints();
366 c.gridx = 0; c.gridy = row;
368 c.fill = GridBagConstraints.NONE;
369 c.anchor = GridBagConstraints.LINE_START;
371 product_label = new JLabel("Product:");
372 pane.add(product_label, c);
374 c = new GridBagConstraints();
375 c.gridx = 4; c.gridy = row;
377 c.fill = GridBagConstraints.HORIZONTAL;
379 c.anchor = GridBagConstraints.LINE_START;
381 product_value = new JLabel("");
382 pane.add(product_value, c);
386 c = new GridBagConstraints();
387 c.gridx = 0; c.gridy = row;
389 c.fill = GridBagConstraints.NONE;
390 c.anchor = GridBagConstraints.LINE_START;
393 version_label = new JLabel("Software version:");
394 pane.add(version_label, c);
396 c = new GridBagConstraints();
397 c.gridx = 4; c.gridy = row;
399 c.fill = GridBagConstraints.HORIZONTAL;
401 c.anchor = GridBagConstraints.LINE_START;
404 version_value = new JLabel("");
405 pane.add(version_value, c);
409 c = new GridBagConstraints();
410 c.gridx = 0; c.gridy = row;
412 c.fill = GridBagConstraints.NONE;
413 c.anchor = GridBagConstraints.LINE_START;
416 serial_label = new JLabel("Serial:");
417 pane.add(serial_label, c);
419 c = new GridBagConstraints();
420 c.gridx = 4; c.gridy = row;
422 c.fill = GridBagConstraints.HORIZONTAL;
424 c.anchor = GridBagConstraints.LINE_START;
427 serial_value = new JLabel("");
428 pane.add(serial_value, c);
432 c = new GridBagConstraints();
433 c.gridx = 0; c.gridy = row;
435 c.fill = GridBagConstraints.NONE;
436 c.anchor = GridBagConstraints.LINE_START;
439 main_deploy_label = new JLabel(get_main_deploy_label());
440 pane.add(main_deploy_label, c);
442 c = new GridBagConstraints();
443 c.gridx = 4; c.gridy = row;
445 c.fill = GridBagConstraints.HORIZONTAL;
447 c.anchor = GridBagConstraints.LINE_START;
450 main_deploy_value = new JComboBox<String>(main_deploy_values());
451 main_deploy_value.setEditable(true);
452 main_deploy_value.addItemListener(this);
453 pane.add(main_deploy_value, c);
454 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
458 c = new GridBagConstraints();
459 c.gridx = 0; c.gridy = row;
461 c.fill = GridBagConstraints.NONE;
462 c.anchor = GridBagConstraints.LINE_START;
465 apogee_delay_label = new JLabel("Apogee Delay(s):");
466 pane.add(apogee_delay_label, c);
468 c = new GridBagConstraints();
469 c.gridx = 4; c.gridy = row;
471 c.fill = GridBagConstraints.HORIZONTAL;
473 c.anchor = GridBagConstraints.LINE_START;
476 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
477 apogee_delay_value.setEditable(true);
478 apogee_delay_value.addItemListener(this);
479 pane.add(apogee_delay_value, c);
480 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
484 c = new GridBagConstraints();
485 c.gridx = 0; c.gridy = row;
487 c.fill = GridBagConstraints.NONE;
488 c.anchor = GridBagConstraints.LINE_START;
491 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
492 pane.add(apogee_lockout_label, c);
494 c = new GridBagConstraints();
495 c.gridx = 4; c.gridy = row;
497 c.fill = GridBagConstraints.HORIZONTAL;
499 c.anchor = GridBagConstraints.LINE_START;
502 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
503 apogee_lockout_value.setEditable(true);
504 apogee_lockout_value.addItemListener(this);
505 pane.add(apogee_lockout_value, c);
506 apogee_lockout_value.setToolTipText("Time after launch while apogee detection is locked out");
510 c = new GridBagConstraints();
511 c.gridx = 0; c.gridy = row;
513 c.fill = GridBagConstraints.NONE;
514 c.anchor = GridBagConstraints.LINE_START;
517 radio_frequency_label = new JLabel("Frequency:");
518 pane.add(radio_frequency_label, c);
520 c = new GridBagConstraints();
521 c.gridx = 4; c.gridy = row;
523 c.fill = GridBagConstraints.HORIZONTAL;
525 c.anchor = GridBagConstraints.LINE_START;
528 radio_frequency_value = new AltosUIFreqList();
529 radio_frequency_value.addItemListener(this);
530 pane.add(radio_frequency_value, c);
531 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
534 /* Radio Calibration */
535 c = new GridBagConstraints();
536 c.gridx = 0; c.gridy = row;
538 c.fill = GridBagConstraints.NONE;
539 c.anchor = GridBagConstraints.LINE_START;
542 radio_calibration_label = new JLabel("RF Calibration:");
543 pane.add(radio_calibration_label, c);
545 c = new GridBagConstraints();
546 c.gridx = 4; c.gridy = row;
548 c.fill = GridBagConstraints.HORIZONTAL;
550 c.anchor = GridBagConstraints.LINE_START;
553 radio_calibration_value = new JLabel(String.format("%d", 1186611));
554 pane.add(radio_calibration_value, c);
558 c = new GridBagConstraints();
559 c.gridx = 0; c.gridy = row;
561 c.fill = GridBagConstraints.NONE;
562 c.anchor = GridBagConstraints.LINE_START;
565 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
566 pane.add(radio_enable_label, c);
568 c = new GridBagConstraints();
569 c.gridx = 4; c.gridy = row;
571 c.fill = GridBagConstraints.HORIZONTAL;
573 c.anchor = GridBagConstraints.LINE_START;
576 radio_enable_value = new JRadioButton("Enabled");
577 radio_enable_value.addItemListener(this);
578 pane.add(radio_enable_value, c);
579 set_radio_enable_tool_tip();
583 c = new GridBagConstraints();
584 c.gridx = 0; c.gridy = row;
586 c.fill = GridBagConstraints.NONE;
587 c.anchor = GridBagConstraints.LINE_START;
590 rate_label = new JLabel("Telemetry baud rate:");
591 pane.add(rate_label, c);
593 c = new GridBagConstraints();
594 c.gridx = 4; c.gridy = row;
596 c.fill = GridBagConstraints.HORIZONTAL;
598 c.anchor = GridBagConstraints.LINE_START;
601 rate_value = new AltosUIRateList();
602 rate_value.addItemListener(this);
603 pane.add(rate_value, c);
608 c = new GridBagConstraints();
609 c.gridx = 0; c.gridy = row;
611 c.fill = GridBagConstraints.NONE;
612 c.anchor = GridBagConstraints.LINE_START;
615 aprs_interval_label = new JLabel("APRS Interval(s):");
616 pane.add(aprs_interval_label, c);
618 c = new GridBagConstraints();
619 c.gridx = 4; c.gridy = row;
621 c.fill = GridBagConstraints.HORIZONTAL;
623 c.anchor = GridBagConstraints.LINE_START;
626 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
627 aprs_interval_value.setEditable(true);
628 aprs_interval_value.addItemListener(this);
629 pane.add(aprs_interval_value, c);
630 set_aprs_interval_tool_tip();
634 c = new GridBagConstraints();
635 c.gridx = 0; c.gridy = row;
637 c.fill = GridBagConstraints.NONE;
638 c.anchor = GridBagConstraints.LINE_START;
641 aprs_ssid_label = new JLabel("APRS SSID:");
642 pane.add(aprs_ssid_label, c);
644 c = new GridBagConstraints();
645 c.gridx = 4; c.gridy = row;
647 c.fill = GridBagConstraints.HORIZONTAL;
649 c.anchor = GridBagConstraints.LINE_START;
652 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
653 aprs_ssid_value.setEditable(false);
654 aprs_ssid_value.addItemListener(this);
655 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
656 pane.add(aprs_ssid_value, c);
657 set_aprs_ssid_tool_tip();
661 c = new GridBagConstraints();
662 c.gridx = 0; c.gridy = row;
664 c.fill = GridBagConstraints.NONE;
665 c.anchor = GridBagConstraints.LINE_START;
668 aprs_format_label = new JLabel("APRS format:");
669 pane.add(aprs_format_label, c);
671 c = new GridBagConstraints();
672 c.gridx = 4; c.gridy = row;
674 c.fill = GridBagConstraints.HORIZONTAL;
676 c.anchor = GridBagConstraints.LINE_START;
679 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
680 aprs_format_value.setEditable(false);
681 aprs_format_value.addItemListener(this);
682 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
683 pane.add(aprs_format_value, c);
684 set_aprs_format_tool_tip();
688 c = new GridBagConstraints();
689 c.gridx = 0; c.gridy = row;
691 c.fill = GridBagConstraints.NONE;
692 c.anchor = GridBagConstraints.LINE_START;
695 aprs_offset_label = new JLabel("APRS offset:");
696 pane.add(aprs_offset_label, c);
698 c = new GridBagConstraints();
699 c.gridx = 4; c.gridy = row;
701 c.fill = GridBagConstraints.HORIZONTAL;
703 c.anchor = GridBagConstraints.LINE_START;
706 aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
707 aprs_offset_value.setEditable(false);
708 aprs_offset_value.addItemListener(this);
709 aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
710 pane.add(aprs_offset_value, c);
711 set_aprs_offset_tool_tip();
715 c = new GridBagConstraints();
716 c.gridx = 0; c.gridy = row;
718 c.fill = GridBagConstraints.NONE;
719 c.anchor = GridBagConstraints.LINE_START;
722 callsign_label = new JLabel("Callsign:");
723 pane.add(callsign_label, c);
725 c = new GridBagConstraints();
726 c.gridx = 4; c.gridy = row;
728 c.fill = GridBagConstraints.HORIZONTAL;
730 c.anchor = GridBagConstraints.LINE_START;
733 callsign_value = new JTextField(AltosUIPreferences.callsign());
734 callsign_value.getDocument().addDocumentListener(this);
735 pane.add(callsign_value, c);
736 callsign_value.setToolTipText("Callsign reported in telemetry data");
740 c = new GridBagConstraints();
741 c.gridx = 0; c.gridy = row;
743 c.fill = GridBagConstraints.NONE;
744 c.anchor = GridBagConstraints.LINE_START;
747 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
748 pane.add(flight_log_max_label, c);
750 c = new GridBagConstraints();
751 c.gridx = 4; c.gridy = row;
753 c.fill = GridBagConstraints.HORIZONTAL;
755 c.anchor = GridBagConstraints.LINE_START;
758 flight_log_max_value = new JComboBox<String>();
759 flight_log_max_value.setEditable(true);
760 flight_log_max_value.addItemListener(this);
761 pane.add(flight_log_max_value, c);
762 set_flight_log_max_tool_tip();
766 c = new GridBagConstraints();
767 c.gridx = 0; c.gridy = row;
769 c.fill = GridBagConstraints.NONE;
770 c.anchor = GridBagConstraints.LINE_START;
773 ignite_mode_label = new JLabel("Igniter Firing Mode:");
774 pane.add(ignite_mode_label, c);
776 c = new GridBagConstraints();
777 c.gridx = 4; c.gridy = row;
779 c.fill = GridBagConstraints.HORIZONTAL;
781 c.anchor = GridBagConstraints.LINE_START;
784 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
785 ignite_mode_value.setEditable(false);
786 ignite_mode_value.addItemListener(this);
787 pane.add(ignite_mode_value, c);
788 set_ignite_mode_tool_tip();
791 /* Pad orientation */
792 c = new GridBagConstraints();
793 c.gridx = 0; c.gridy = row;
795 c.fill = GridBagConstraints.NONE;
796 c.anchor = GridBagConstraints.LINE_START;
799 pad_orientation_label = new JLabel("Pad Orientation:");
800 pane.add(pad_orientation_label, c);
802 c = new GridBagConstraints();
803 c.gridx = 4; c.gridy = row;
805 c.fill = GridBagConstraints.HORIZONTAL;
807 c.anchor = GridBagConstraints.LINE_START;
810 pad_orientation_values = pad_orientation_values_no_radio;
812 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
813 pad_orientation_value.setEditable(false);
814 pad_orientation_value.addItemListener(this);
815 pane.add(pad_orientation_value, c);
816 set_pad_orientation_tool_tip();
820 c = new GridBagConstraints();
821 c.gridx = 0; c.gridy = row;
823 c.fill = GridBagConstraints.NONE;
824 c.anchor = GridBagConstraints.LINE_START;
827 accel_plus_label = new JLabel("Accel Plus:");
828 pane.add(accel_plus_label, c);
830 c = new GridBagConstraints();
831 c.gridx = 4; c.gridy = row;
833 c.fill = GridBagConstraints.HORIZONTAL;
835 c.anchor = GridBagConstraints.LINE_START;
838 accel_plus_value = new JTextField(10);
839 accel_plus_value.setEditable(true);
840 accel_plus_value.getDocument().addDocumentListener(this);
841 pane.add(accel_plus_value, c);
845 c = new GridBagConstraints();
846 c.gridx = 0; c.gridy = row;
848 c.fill = GridBagConstraints.NONE;
849 c.anchor = GridBagConstraints.LINE_START;
852 accel_minus_label = new JLabel("Accel Minus:");
853 pane.add(accel_minus_label, c);
855 c = new GridBagConstraints();
856 c.gridx = 4; c.gridy = row;
858 c.fill = GridBagConstraints.HORIZONTAL;
860 c.anchor = GridBagConstraints.LINE_START;
863 accel_minus_value = new JTextField(10);
864 accel_minus_value.setEditable(true);
865 accel_minus_value.getDocument().addDocumentListener(this);
866 pane.add(accel_minus_value, c);
868 set_accel_tool_tips();
871 c = new GridBagConstraints();
872 c.gridx = 0; c.gridy = row;
874 c.fill = GridBagConstraints.NONE;
875 c.anchor = GridBagConstraints.LINE_START;
878 beep_label = new JLabel("Beeper Frequency:");
879 pane.add(beep_label, c);
881 c = new GridBagConstraints();
882 c.gridx = 4; c.gridy = row;
884 c.fill = GridBagConstraints.HORIZONTAL;
886 c.anchor = GridBagConstraints.LINE_START;
889 beep_value = new JComboBox<String>(beep_values);
890 beep_value.setEditable(true);
891 beep_value.addItemListener(this);
892 pane.add(beep_value, c);
896 /* Tracker triger horiz distances */
897 c = new GridBagConstraints();
898 c.gridx = 0; c.gridy = row;
900 c.fill = GridBagConstraints.NONE;
901 c.anchor = GridBagConstraints.LINE_START;
904 tracker_motion_label = new JLabel(get_tracker_motion_label());
905 pane.add(tracker_motion_label, c);
907 c = new GridBagConstraints();
908 c.gridx = 4; c.gridy = row;
910 c.fill = GridBagConstraints.HORIZONTAL;
912 c.anchor = GridBagConstraints.LINE_START;
915 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
916 tracker_motion_value.setEditable(true);
917 tracker_motion_value.addItemListener(this);
918 pane.add(tracker_motion_value, c);
921 /* Tracker triger vert distances */
922 c = new GridBagConstraints();
923 c.gridx = 0; c.gridy = row;
925 c.fill = GridBagConstraints.NONE;
926 c.anchor = GridBagConstraints.LINE_START;
929 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
930 pane.add(tracker_interval_label, c);
932 c = new GridBagConstraints();
933 c.gridx = 4; c.gridy = row;
935 c.fill = GridBagConstraints.HORIZONTAL;
937 c.anchor = GridBagConstraints.LINE_START;
940 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
941 tracker_interval_value.setEditable(true);
942 tracker_interval_value.addItemListener(this);
943 pane.add(tracker_interval_value, c);
944 set_tracker_tool_tip();
948 c = new GridBagConstraints();
949 c.gridx = 4; c.gridy = row;
951 c.fill = GridBagConstraints.HORIZONTAL;
952 c.anchor = GridBagConstraints.LINE_START;
955 pyro = new JButton("Configure Pyro Channels");
957 pyro.addActionListener(this);
958 pyro.setActionCommand("Pyro");
962 c = new GridBagConstraints();
963 c.gridx = 5; c.gridy = row;
965 c.fill = GridBagConstraints.HORIZONTAL;
966 c.anchor = GridBagConstraints.LINE_START;
969 accel_cal = new JButton("Calibrate Accelerometer");
970 pane.add(accel_cal, c);
971 accel_cal.addActionListener(this);
972 accel_cal.setActionCommand("Accel");
976 c = new GridBagConstraints();
977 c.gridx = 0; c.gridy = row;
979 c.fill = GridBagConstraints.NONE;
980 c.anchor = GridBagConstraints.LINE_START;
982 save = new JButton("Save");
984 save.addActionListener(this);
985 save.setActionCommand("Save");
987 c = new GridBagConstraints();
988 c.gridx = 2; c.gridy = row;
990 c.fill = GridBagConstraints.NONE;
991 c.anchor = GridBagConstraints.CENTER;
993 reset = new JButton("Reset");
995 reset.addActionListener(this);
996 reset.setActionCommand("Reset");
998 c = new GridBagConstraints();
999 c.gridx = 4; c.gridy = row;
1001 c.fill = GridBagConstraints.NONE;
1002 c.anchor = GridBagConstraints.CENTER;
1004 reboot = new JButton("Reboot");
1005 pane.add(reboot, c);
1006 reboot.addActionListener(this);
1007 reboot.setActionCommand("Reboot");
1009 c = new GridBagConstraints();
1010 c.gridx = 6; c.gridy = row;
1012 c.fill = GridBagConstraints.NONE;
1013 c.anchor = GridBagConstraints.LINE_END;
1015 close = new JButton("Close");
1017 close.addActionListener(this);
1018 close.setActionCommand("Close");
1020 addWindowListener(new ConfigListener(this));
1021 AltosPreferences.register_units_listener(this);
1024 /* Once the initial values are set, the config code will show the dialog */
1025 public void make_visible() {
1027 setLocationRelativeTo(owner);
1031 /* If any values have been changed, confirm before closing */
1032 public boolean check_dirty(String operation) {
1034 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
1036 i = JOptionPane.showOptionDialog(this,
1037 String.format("Configuration modified. %s anyway?", operation),
1038 "Configuration Modified",
1039 JOptionPane.DEFAULT_OPTION,
1040 JOptionPane.WARNING_MESSAGE,
1041 null, options, options[1]);
1048 public void set_dirty() {
1050 setTitle(title + " (modified)");
1051 save.setEnabled(true);
1054 public void set_clean() {
1057 save.setEnabled(false);
1060 AltosConfigPyroUI pyro_ui;
1062 public void dispose() {
1063 if (pyro_ui != null)
1065 AltosPreferences.unregister_units_listener(this);
1069 /* Listen for events from our buttons */
1070 public void actionPerformed(ActionEvent e) {
1071 String cmd = e.getActionCommand();
1073 if (cmd.equals("Pyro")) {
1074 if (pyro_ui == null && pyros != null)
1075 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
1076 if (pyro_ui != null)
1077 pyro_ui.make_visible();
1081 if (cmd.equals("Close") || cmd.equals("Reboot"))
1082 if (!check_dirty(cmd))
1084 if (cmd.equals("Save"))
1085 save.setEnabled(false);
1086 listener.actionPerformed(e);
1087 if (cmd.equals("Close") || cmd.equals("Reboot")) {
1093 /* ItemListener interface method */
1094 public void itemStateChanged(ItemEvent e) {
1098 /* DocumentListener interface methods */
1099 public void changedUpdate(DocumentEvent e) {
1103 public void insertUpdate(DocumentEvent e) {
1107 public void removeUpdate(DocumentEvent e) {
1111 /* Let the config code hook on a listener */
1112 public void addActionListener(ActionListener l) {
1116 /* set and get all of the dialog values */
1117 public void set_product(String product) {
1118 radio_frequency_value.set_product(product);
1119 product_value.setText(product);
1120 set_pad_orientation_tool_tip();
1121 set_accel_tool_tips();
1122 set_flight_log_max_tool_tip();
1123 set_pad_orientation_values();
1126 public void set_version(String version) {
1127 version_value.setText(version);
1130 public void set_serial(int serial) {
1131 radio_frequency_value.set_serial(serial);
1132 serial_value.setText(String.format("%d", serial));
1135 public void set_altitude_32(int altitude_32) {
1138 public void set_main_deploy(int new_main_deploy) {
1139 if (new_main_deploy != AltosLib.MISSING)
1140 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
1141 main_deploy_value.setVisible(new_main_deploy != AltosLib.MISSING);
1142 main_deploy_label.setVisible(new_main_deploy != AltosLib.MISSING);
1145 public int main_deploy() throws AltosConfigDataException {
1146 String str = main_deploy_value.getSelectedItem().toString();
1148 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1149 } catch (ParseException pe) {
1150 throw new AltosConfigDataException("invalid main deploy height %s", str);
1154 String get_main_deploy_label() {
1155 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.parse_units());
1158 String[] main_deploy_values() {
1159 if (AltosConvert.imperial_units)
1160 return main_deploy_values_ft;
1162 return main_deploy_values_m;
1165 void set_main_deploy_values() {
1166 String[] v = main_deploy_values();
1167 while (main_deploy_value.getItemCount() > 0)
1168 main_deploy_value.removeItemAt(0);
1169 for (int i = 0; i < v.length; i++)
1170 main_deploy_value.addItem(v[i]);
1171 main_deploy_value.setMaximumRowCount(v.length);
1174 public void units_changed(boolean imperial_units) {
1175 boolean was_dirty = dirty;
1177 String v = main_deploy_value.getSelectedItem().toString();
1178 main_deploy_label.setText(get_main_deploy_label());
1179 set_main_deploy_values();
1181 int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1183 } catch (ParseException pe) {
1186 if (tracker_motion_value.isVisible()) {
1187 String motion = tracker_motion_value.getSelectedItem().toString();
1188 tracker_motion_label.setText(get_tracker_motion_label());
1189 set_tracker_motion_values();
1191 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1192 set_tracker_motion(m);
1193 } catch (ParseException pe) {
1201 public void set_apogee_delay(int new_apogee_delay) {
1202 if (new_apogee_delay != AltosLib.MISSING)
1203 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1204 apogee_delay_value.setVisible(new_apogee_delay != AltosLib.MISSING);
1205 apogee_delay_label.setVisible(new_apogee_delay != AltosLib.MISSING);
1208 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1211 v = s.split("\\s+")[0];
1213 return Integer.parseInt(v);
1214 } catch (NumberFormatException ne) {
1215 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1219 public int apogee_delay() throws AltosConfigDataException {
1220 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1223 public void set_apogee_lockout(int new_apogee_lockout) {
1224 if (new_apogee_lockout != AltosLib.MISSING)
1225 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1227 apogee_lockout_value.setVisible(new_apogee_lockout != AltosLib.MISSING);
1228 apogee_lockout_label.setVisible(new_apogee_lockout != AltosLib.MISSING);
1231 public int apogee_lockout() throws AltosConfigDataException {
1232 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1235 public void set_radio_frequency(double new_radio_frequency) {
1236 if (new_radio_frequency != AltosLib.MISSING)
1237 radio_frequency_value.set_frequency(new_radio_frequency);
1238 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
1239 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
1242 public double radio_frequency() {
1243 return radio_frequency_value.frequency();
1246 public void set_radio_calibration(int new_radio_calibration) {
1247 if (new_radio_calibration != AltosLib.MISSING)
1248 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1249 radio_calibration_value.setVisible(new_radio_calibration != AltosLib.MISSING);
1250 radio_calibration_label.setVisible(new_radio_calibration != AltosLib.MISSING);
1253 public void set_radio_enable(int new_radio_enable) {
1254 if (new_radio_enable != AltosLib.MISSING)
1255 radio_enable_value.setSelected(new_radio_enable != 0);
1256 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
1257 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
1258 set_radio_enable_tool_tip();
1261 public int radio_enable() {
1262 if (radio_enable_value.isVisible())
1263 return radio_enable_value.isSelected() ? 1 : 0;
1265 return AltosLib.MISSING;
1268 public void set_telemetry_rate(int new_rate) {
1269 if (new_rate != AltosLib.MISSING)
1270 rate_value.set_rate(new_rate);
1271 rate_label.setVisible(new_rate != AltosLib.MISSING);
1272 rate_value.setVisible(new_rate != AltosLib.MISSING);
1273 set_rate_tool_tip();
1276 public int telemetry_rate() {
1277 return rate_value.rate();
1280 public void set_callsign(String new_callsign) {
1281 if (new_callsign != null)
1282 callsign_value.setText(new_callsign);
1283 callsign_value.setVisible(new_callsign != null);
1284 callsign_label.setVisible(new_callsign != null);
1287 public String callsign() {
1288 if (callsign_value.isVisible())
1289 return callsign_value.getText();
1293 int flight_log_max_limit;
1296 public String flight_log_max_label(int flight_log_max) {
1297 if (flight_log_max_limit != 0) {
1298 int nflight = flight_log_max_limit / flight_log_max;
1299 String plural = nflight > 1 ? "s" : "";
1301 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1303 return String.format("%d", flight_log_max);
1306 public void set_flight_log_max(int new_flight_log_max) {
1307 if (new_flight_log_max != AltosLib.MISSING) {
1308 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1309 flight_log_max = new_flight_log_max;
1311 flight_log_max_value.setVisible(new_flight_log_max != AltosLib.MISSING);
1312 flight_log_max_label.setVisible(new_flight_log_max != AltosLib.MISSING);
1313 set_flight_log_max_tool_tip();
1316 public void set_flight_log_max_enabled(boolean enable) {
1317 flight_log_max_value.setEnabled(enable);
1318 set_flight_log_max_tool_tip();
1321 public int flight_log_max() throws AltosConfigDataException {
1322 if (flight_log_max_value.isVisible())
1323 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1324 return AltosLib.MISSING;
1327 public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
1328 flight_log_max_limit = new_flight_log_max_limit;
1329 if (new_flight_log_max_limit != AltosLib.MISSING) {
1330 flight_log_max_value.removeAllItems();
1331 for (int i = 8; i >= 1; i--) {
1332 int size = flight_log_max_limit / i;
1333 if (new_storage_erase_unit != 0)
1334 size &= ~(new_storage_erase_unit - 1);
1335 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1338 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
1339 set_flight_log_max(flight_log_max);
1342 public void set_ignite_mode(int new_ignite_mode) {
1343 if (new_ignite_mode != AltosLib.MISSING) {
1344 if (new_ignite_mode >= ignite_mode_values.length)
1345 new_ignite_mode = 0;
1346 if (new_ignite_mode < 0) {
1347 ignite_mode_value.setEnabled(false);
1348 new_ignite_mode = 0;
1350 ignite_mode_value.setEnabled(true);
1352 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1354 ignite_mode_value.setVisible(new_ignite_mode != AltosLib.MISSING);
1355 ignite_mode_label.setVisible(new_ignite_mode != AltosLib.MISSING);
1357 set_ignite_mode_tool_tip();
1360 public int ignite_mode() {
1361 if (ignite_mode_value.isVisible())
1362 return ignite_mode_value.getSelectedIndex();
1364 return AltosLib.MISSING;
1368 public void set_pad_orientation(int new_pad_orientation) {
1369 if (new_pad_orientation != AltosLib.MISSING) {
1370 if (new_pad_orientation >= pad_orientation_values.length)
1371 new_pad_orientation = 0;
1372 if (new_pad_orientation < 0)
1373 new_pad_orientation = 0;
1374 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1376 pad_orientation_value.setVisible(new_pad_orientation != AltosLib.MISSING);
1377 pad_orientation_label.setVisible(new_pad_orientation != AltosLib.MISSING);
1378 accel_cal.setVisible(new_pad_orientation != AltosLib.MISSING);
1380 set_pad_orientation_tool_tip();
1383 public int pad_orientation() {
1384 if (pad_orientation_value.isVisible())
1385 return pad_orientation_value.getSelectedIndex();
1387 return AltosLib.MISSING;
1390 public void set_accel_cal(int accel_plus, int accel_minus) {
1391 if (accel_plus != AltosLib.MISSING) {
1392 accel_plus_value.setText(String.format("%d", accel_plus));
1393 accel_minus_value.setText(String.format("%d", accel_minus));
1395 accel_plus_value.setVisible(accel_plus != AltosLib.MISSING);
1396 accel_plus_label.setVisible(accel_plus != AltosLib.MISSING);
1397 accel_minus_value.setVisible(accel_minus != AltosLib.MISSING);
1398 accel_minus_label.setVisible(accel_minus != AltosLib.MISSING);
1400 set_accel_tool_tips();
1403 public int accel_cal_plus() {
1404 if (accel_plus_value.isVisible())
1405 return Integer.parseInt(accel_plus_value.getText());
1406 return AltosLib.MISSING;
1409 public int accel_cal_minus() {
1410 if (accel_minus_value.isVisible())
1411 return Integer.parseInt(accel_minus_value.getText());
1412 return AltosLib.MISSING;
1415 public void set_beep(int new_beep) {
1416 if (new_beep != AltosLib.MISSING) {
1417 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1418 for (int i = 0; i < beep_values.length; i++)
1419 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1420 beep_value.setSelectedIndex(i);
1421 set_beep_tool_tip();
1424 beep_value.setSelectedItem(String.format("%d", new_freq));
1426 beep_value.setVisible(new_beep != AltosLib.MISSING);
1427 beep_label.setVisible(new_beep != AltosLib.MISSING);
1428 set_beep_tool_tip();
1432 if (beep_value.isVisible())
1433 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1435 return AltosLib.MISSING;
1438 String[] tracker_motion_values() {
1439 if (AltosConvert.imperial_units)
1440 return tracker_motion_values_ft;
1442 return tracker_motion_values_m;
1445 void set_tracker_motion_values() {
1446 String[] v = tracker_motion_values();
1447 while (tracker_motion_value.getItemCount() > 0)
1448 tracker_motion_value.removeItemAt(0);
1449 for (int i = 0; i < v.length; i++)
1450 tracker_motion_value.addItem(v[i]);
1451 tracker_motion_value.setMaximumRowCount(v.length);
1454 String get_tracker_motion_label() {
1455 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1458 void set_tracker_tool_tip() {
1459 if (tracker_motion_value.isVisible())
1460 tracker_motion_value.setToolTipText("How far the device must move before logging");
1462 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1463 if (tracker_interval_value.isVisible())
1464 tracker_interval_value.setToolTipText("How often to report GPS position");
1466 tracker_interval_value.setToolTipText("This device can't configure interval");
1469 public void set_tracker_motion(int tracker_motion) {
1470 if (tracker_motion != AltosLib.MISSING)
1471 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1472 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1473 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1476 public int tracker_motion() throws AltosConfigDataException {
1477 if (tracker_motion_value.isVisible()) {
1478 String str = tracker_motion_value.getSelectedItem().toString();
1480 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1481 } catch (ParseException pe) {
1482 throw new AltosConfigDataException("invalid tracker motion %s", str);
1485 return AltosLib.MISSING;
1488 public void set_tracker_interval(int tracker_interval) {
1489 if (tracker_interval != AltosLib.MISSING)
1490 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1491 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1492 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1495 public int tracker_interval() throws AltosConfigDataException {
1496 if (tracker_interval_value.isVisible())
1497 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1498 return AltosLib.MISSING;
1501 public void set_pyros(AltosPyro[] new_pyros) {
1503 if (pyros != null && pyro_ui != null)
1504 pyro_ui.set_pyros(pyros);
1505 pyro.setVisible(pyros != null);
1508 public AltosPyro[] pyros() throws AltosConfigDataException {
1509 if (pyro_ui != null)
1510 pyros = pyro_ui.get_pyros();
1514 public void set_pyro_firing_time(double new_pyro_firing_time) {
1515 pyro_firing_time = new_pyro_firing_time;
1516 if (pyro_firing_time != AltosLib.MISSING && pyro_ui != null)
1517 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1518 pyro.setVisible(pyro_firing_time != AltosLib.MISSING);
1521 public double pyro_firing_time() throws AltosConfigDataException {
1522 if (pyro_ui != null)
1523 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1524 return pyro_firing_time;
1527 private String aprs_interval_string(int interval) {
1530 return Integer.toString(interval);
1533 private int aprs_interval_value(String interval) throws AltosConfigDataException {
1534 if (interval.equalsIgnoreCase("Disabled"))
1536 return parse_int("aprs interval", interval, false);
1539 public void set_aprs_interval(int new_aprs_interval) {
1540 if (new_aprs_interval != AltosLib.MISSING)
1541 aprs_interval_value.setSelectedItem(aprs_interval_string(new_aprs_interval));
1542 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1543 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1544 set_aprs_interval_tool_tip();
1547 public int aprs_interval() throws AltosConfigDataException {
1548 if (aprs_interval_value.isVisible())
1549 return aprs_interval_value(aprs_interval_value.getSelectedItem().toString());
1550 return AltosLib.MISSING;
1553 public void set_aprs_ssid(int new_aprs_ssid) {
1554 if (new_aprs_ssid != AltosLib.MISSING)
1555 aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1556 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1557 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1558 set_aprs_ssid_tool_tip();
1561 public int aprs_ssid() throws AltosConfigDataException {
1562 if (aprs_ssid_value.isVisible()) {
1563 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1566 return AltosLib.MISSING;
1569 public void set_aprs_format(int new_aprs_format) {
1570 if (new_aprs_format != AltosLib.MISSING)
1571 aprs_format_value.setSelectedIndex(new_aprs_format);
1572 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1573 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1574 set_aprs_format_tool_tip();
1577 public int aprs_format() throws AltosConfigDataException {
1578 if (aprs_format_value.isVisible())
1579 return aprs_format_value.getSelectedIndex();
1580 return AltosLib.MISSING;
1583 public void set_aprs_offset(int new_aprs_offset) {
1584 if (new_aprs_offset != AltosLib.MISSING)
1585 aprs_offset_value.setSelectedItem(new_aprs_offset);
1586 aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
1587 aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
1588 set_aprs_offset_tool_tip();
1591 public int aprs_offset() throws AltosConfigDataException {
1592 if (aprs_offset_value.isVisible()) {
1593 Integer i = (Integer) aprs_offset_value.getSelectedItem();
1596 return AltosLib.MISSING;