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 String[] main_deploy_values_m = {
101 "100", "150", "200", "250", "300", "350",
105 static String[] main_deploy_values_ft = {
106 "250", "500", "750", "1000", "1250", "1500",
110 static String[] apogee_delay_values = {
111 "0", "1", "2", "3", "4", "5"
114 static String[] apogee_lockout_values = {
115 "0", "5", "10", "15", "20"
118 static String[] ignite_mode_values = {
122 "Separation & Apogee",
125 static String[] aprs_interval_values = {
132 static Integer[] aprs_ssid_values = {
133 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
136 static Integer[] aprs_offset_values = {
137 0, 2, 4, 6, 8, 10, 12, 14, 16, 18
140 static String[] beep_values = {
146 static String[] pad_orientation_values_radio = {
151 static String[] pad_orientation_values_no_radio = {
156 String[] pad_orientation_values;
158 static String[] tracker_motion_values_m = {
165 static String[] tracker_motion_values_ft = {
172 static String[] tracker_interval_values = {
179 /* A window listener to catch closing events and tell the config code */
180 class ConfigListener extends WindowAdapter {
183 public ConfigListener(AltosConfigFCUI this_ui) {
187 public void windowClosing(WindowEvent e) {
188 ui.actionPerformed(new ActionEvent(e.getSource(),
189 ActionEvent.ACTION_PERFORMED,
194 boolean is_telemini_v1() {
195 String product = product_value.getText();
196 return product != null && product.startsWith("TeleMini-v1");
199 boolean is_telemini() {
200 String product = product_value.getText();
201 return product != null && product.startsWith("TeleMini");
204 boolean is_easymini() {
205 String product = product_value.getText();
206 return product != null && product.startsWith("EasyMini");
209 boolean is_telemetrum() {
210 String product = product_value.getText();
211 return product != null && product.startsWith("TeleMetrum");
214 boolean is_telemega() {
215 String product = product_value.getText();
216 return product != null && product.startsWith("TeleMega");
219 boolean is_easymega() {
220 String product = product_value.getText();
221 return product != null && product.startsWith("EasyMega");
224 boolean is_easytimer() {
225 String product = product_value.getText();
226 return product != null && product.startsWith("EasyTimer");
229 boolean has_radio() {
230 return is_telemega() || is_telemetrum() || is_telemini();
233 void set_radio_enable_tool_tip() {
234 if (radio_enable_value.isVisible())
235 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
237 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
240 void set_rate_tool_tip() {
241 if (rate_value.isVisible())
242 rate_value.setToolTipText("Select telemetry baud rate");
244 rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
247 void set_aprs_interval_tool_tip() {
248 if (aprs_interval_value.isVisible())
249 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
251 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
254 void set_aprs_ssid_tool_tip() {
255 if (aprs_ssid_value.isVisible())
256 aprs_ssid_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
257 else if (aprs_ssid_value.isVisible())
258 aprs_ssid_value.setToolTipText("Software version doesn't support setting the APRS SSID");
260 aprs_ssid_value.setToolTipText("Hardware doesn't support APRS");
263 void set_aprs_format_tool_tip() {
264 if (aprs_format_value.isVisible())
265 aprs_format_value.setToolTipText("Set the APRS format (compressed/uncompressed)");
266 else if (aprs_format_value.isVisible())
267 aprs_format_value.setToolTipText("Software version doesn't support setting the APRS format");
269 aprs_format_value.setToolTipText("Hardware doesn't support APRS");
272 void set_aprs_offset_tool_tip() {
273 if (aprs_offset_value.isVisible())
274 aprs_offset_value.setToolTipText("Set the APRS offset from top of minute");
275 else if (aprs_offset_value.isVisible())
276 aprs_offset_value.setToolTipText("Software version doesn't support setting the APRS offset");
278 aprs_offset_value.setToolTipText("Hardware doesn't support APRS");
281 void set_flight_log_max_tool_tip() {
282 if (flight_log_max_value.isVisible())
283 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
285 if (is_telemini_v1())
286 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
288 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
292 void set_ignite_mode_tool_tip() {
293 if (ignite_mode_value.isVisible())
294 ignite_mode_value.setToolTipText("Select when igniters will be fired");
296 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
299 void set_pad_orientation_tool_tip() {
300 if (pad_orientation_value.isVisible()) {
301 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
304 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
305 else if (is_telemini() || is_easymini())
306 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
307 else if (is_easytimer())
308 pad_orientation_value.setToolTipText("EasyTimer can be mounted in any of six orientations");
310 pad_orientation_value.setToolTipText("Can't select orientation");
314 void set_pad_orientation_values() {
315 String [] new_values;
317 new_values = pad_orientation_values_radio;
319 new_values = pad_orientation_values_no_radio;
320 if (new_values != pad_orientation_values) {
321 int id = pad_orientation_value.getSelectedIndex();
322 pad_orientation_value.removeAllItems();
323 pad_orientation_values = new_values;
324 for (int i = 0; i < new_values.length; i++)
325 pad_orientation_value.addItem(pad_orientation_values[i]);
326 pad_orientation_value.setSelectedIndex(id);
330 void set_accel_tool_tips() {
331 if (accel_plus_value.isVisible()) {
332 accel_plus_value.setToolTipText("Pad acceleration value in flight orientation");
333 accel_minus_value.setToolTipText("Upside-down acceleration value");
335 accel_plus_value.setToolTipText("No accelerometer");
336 accel_minus_value.setToolTipText("No accelerometer");
340 void set_beep_tool_tip() {
341 if (beep_value.isVisible())
342 beep_value.setToolTipText("What frequency the beeper will sound at");
344 beep_value.setToolTipText("Older firmware could not select beeper frequency");
347 /* Build the UI using a grid bag */
348 public AltosConfigFCUI(JFrame in_owner, boolean remote) {
349 super (in_owner, "Configure Flight Computer", false);
352 GridBagConstraints c;
355 Insets il = new Insets(4,4,4,4);
356 Insets ir = new Insets(4,4,4,4);
358 pane = getContentPane();
359 pane.setLayout(new GridBagLayout());
362 c = new GridBagConstraints();
363 c.gridx = 0; c.gridy = row;
365 c.fill = GridBagConstraints.NONE;
366 c.anchor = GridBagConstraints.LINE_START;
368 product_label = new JLabel("Product:");
369 pane.add(product_label, c);
371 c = new GridBagConstraints();
372 c.gridx = 4; c.gridy = row;
374 c.fill = GridBagConstraints.HORIZONTAL;
376 c.anchor = GridBagConstraints.LINE_START;
378 product_value = new JLabel("");
379 pane.add(product_value, c);
383 c = new GridBagConstraints();
384 c.gridx = 0; c.gridy = row;
386 c.fill = GridBagConstraints.NONE;
387 c.anchor = GridBagConstraints.LINE_START;
390 version_label = new JLabel("Software version:");
391 pane.add(version_label, c);
393 c = new GridBagConstraints();
394 c.gridx = 4; c.gridy = row;
396 c.fill = GridBagConstraints.HORIZONTAL;
398 c.anchor = GridBagConstraints.LINE_START;
401 version_value = new JLabel("");
402 pane.add(version_value, c);
406 c = new GridBagConstraints();
407 c.gridx = 0; c.gridy = row;
409 c.fill = GridBagConstraints.NONE;
410 c.anchor = GridBagConstraints.LINE_START;
413 serial_label = new JLabel("Serial:");
414 pane.add(serial_label, c);
416 c = new GridBagConstraints();
417 c.gridx = 4; c.gridy = row;
419 c.fill = GridBagConstraints.HORIZONTAL;
421 c.anchor = GridBagConstraints.LINE_START;
424 serial_value = new JLabel("");
425 pane.add(serial_value, c);
429 c = new GridBagConstraints();
430 c.gridx = 0; c.gridy = row;
432 c.fill = GridBagConstraints.NONE;
433 c.anchor = GridBagConstraints.LINE_START;
436 main_deploy_label = new JLabel(get_main_deploy_label());
437 pane.add(main_deploy_label, c);
439 c = new GridBagConstraints();
440 c.gridx = 4; c.gridy = row;
442 c.fill = GridBagConstraints.HORIZONTAL;
444 c.anchor = GridBagConstraints.LINE_START;
447 main_deploy_value = new JComboBox<String>(main_deploy_values());
448 main_deploy_value.setEditable(true);
449 main_deploy_value.addItemListener(this);
450 pane.add(main_deploy_value, c);
451 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
455 c = new GridBagConstraints();
456 c.gridx = 0; c.gridy = row;
458 c.fill = GridBagConstraints.NONE;
459 c.anchor = GridBagConstraints.LINE_START;
462 apogee_delay_label = new JLabel("Apogee Delay(s):");
463 pane.add(apogee_delay_label, c);
465 c = new GridBagConstraints();
466 c.gridx = 4; c.gridy = row;
468 c.fill = GridBagConstraints.HORIZONTAL;
470 c.anchor = GridBagConstraints.LINE_START;
473 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
474 apogee_delay_value.setEditable(true);
475 apogee_delay_value.addItemListener(this);
476 pane.add(apogee_delay_value, c);
477 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
481 c = new GridBagConstraints();
482 c.gridx = 0; c.gridy = row;
484 c.fill = GridBagConstraints.NONE;
485 c.anchor = GridBagConstraints.LINE_START;
488 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
489 pane.add(apogee_lockout_label, c);
491 c = new GridBagConstraints();
492 c.gridx = 4; c.gridy = row;
494 c.fill = GridBagConstraints.HORIZONTAL;
496 c.anchor = GridBagConstraints.LINE_START;
499 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
500 apogee_lockout_value.setEditable(true);
501 apogee_lockout_value.addItemListener(this);
502 pane.add(apogee_lockout_value, c);
503 apogee_lockout_value.setToolTipText("Time after launch while apogee detection is locked out");
507 c = new GridBagConstraints();
508 c.gridx = 0; c.gridy = row;
510 c.fill = GridBagConstraints.NONE;
511 c.anchor = GridBagConstraints.LINE_START;
514 radio_frequency_label = new JLabel("Frequency:");
515 pane.add(radio_frequency_label, c);
517 c = new GridBagConstraints();
518 c.gridx = 4; c.gridy = row;
520 c.fill = GridBagConstraints.HORIZONTAL;
522 c.anchor = GridBagConstraints.LINE_START;
525 radio_frequency_value = new AltosUIFreqList();
526 radio_frequency_value.addItemListener(this);
527 pane.add(radio_frequency_value, c);
528 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
531 /* Radio Calibration */
532 c = new GridBagConstraints();
533 c.gridx = 0; c.gridy = row;
535 c.fill = GridBagConstraints.NONE;
536 c.anchor = GridBagConstraints.LINE_START;
539 radio_calibration_label = new JLabel("RF Calibration:");
540 pane.add(radio_calibration_label, c);
542 c = new GridBagConstraints();
543 c.gridx = 4; c.gridy = row;
545 c.fill = GridBagConstraints.HORIZONTAL;
547 c.anchor = GridBagConstraints.LINE_START;
550 radio_calibration_value = new JLabel(String.format("%d", 1186611));
551 pane.add(radio_calibration_value, c);
555 c = new GridBagConstraints();
556 c.gridx = 0; c.gridy = row;
558 c.fill = GridBagConstraints.NONE;
559 c.anchor = GridBagConstraints.LINE_START;
562 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
563 pane.add(radio_enable_label, c);
565 c = new GridBagConstraints();
566 c.gridx = 4; c.gridy = row;
568 c.fill = GridBagConstraints.HORIZONTAL;
570 c.anchor = GridBagConstraints.LINE_START;
573 radio_enable_value = new JRadioButton("Enabled");
574 radio_enable_value.addItemListener(this);
575 pane.add(radio_enable_value, c);
576 set_radio_enable_tool_tip();
580 c = new GridBagConstraints();
581 c.gridx = 0; c.gridy = row;
583 c.fill = GridBagConstraints.NONE;
584 c.anchor = GridBagConstraints.LINE_START;
587 rate_label = new JLabel("Telemetry baud rate:");
588 pane.add(rate_label, c);
590 c = new GridBagConstraints();
591 c.gridx = 4; c.gridy = row;
593 c.fill = GridBagConstraints.HORIZONTAL;
595 c.anchor = GridBagConstraints.LINE_START;
598 rate_value = new AltosUIRateList();
599 rate_value.addItemListener(this);
600 pane.add(rate_value, c);
605 c = new GridBagConstraints();
606 c.gridx = 0; c.gridy = row;
608 c.fill = GridBagConstraints.NONE;
609 c.anchor = GridBagConstraints.LINE_START;
612 aprs_interval_label = new JLabel("APRS Interval(s):");
613 pane.add(aprs_interval_label, c);
615 c = new GridBagConstraints();
616 c.gridx = 4; c.gridy = row;
618 c.fill = GridBagConstraints.HORIZONTAL;
620 c.anchor = GridBagConstraints.LINE_START;
623 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
624 aprs_interval_value.setEditable(true);
625 aprs_interval_value.addItemListener(this);
626 pane.add(aprs_interval_value, c);
627 set_aprs_interval_tool_tip();
631 c = new GridBagConstraints();
632 c.gridx = 0; c.gridy = row;
634 c.fill = GridBagConstraints.NONE;
635 c.anchor = GridBagConstraints.LINE_START;
638 aprs_ssid_label = new JLabel("APRS SSID:");
639 pane.add(aprs_ssid_label, c);
641 c = new GridBagConstraints();
642 c.gridx = 4; c.gridy = row;
644 c.fill = GridBagConstraints.HORIZONTAL;
646 c.anchor = GridBagConstraints.LINE_START;
649 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
650 aprs_ssid_value.setEditable(false);
651 aprs_ssid_value.addItemListener(this);
652 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
653 pane.add(aprs_ssid_value, c);
654 set_aprs_ssid_tool_tip();
658 c = new GridBagConstraints();
659 c.gridx = 0; c.gridy = row;
661 c.fill = GridBagConstraints.NONE;
662 c.anchor = GridBagConstraints.LINE_START;
665 aprs_format_label = new JLabel("APRS format:");
666 pane.add(aprs_format_label, c);
668 c = new GridBagConstraints();
669 c.gridx = 4; c.gridy = row;
671 c.fill = GridBagConstraints.HORIZONTAL;
673 c.anchor = GridBagConstraints.LINE_START;
676 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
677 aprs_format_value.setEditable(false);
678 aprs_format_value.addItemListener(this);
679 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
680 pane.add(aprs_format_value, c);
681 set_aprs_format_tool_tip();
685 c = new GridBagConstraints();
686 c.gridx = 0; c.gridy = row;
688 c.fill = GridBagConstraints.NONE;
689 c.anchor = GridBagConstraints.LINE_START;
692 aprs_offset_label = new JLabel("APRS offset:");
693 pane.add(aprs_offset_label, c);
695 c = new GridBagConstraints();
696 c.gridx = 4; c.gridy = row;
698 c.fill = GridBagConstraints.HORIZONTAL;
700 c.anchor = GridBagConstraints.LINE_START;
703 aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
704 aprs_offset_value.setEditable(false);
705 aprs_offset_value.addItemListener(this);
706 aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
707 pane.add(aprs_offset_value, c);
708 set_aprs_offset_tool_tip();
712 c = new GridBagConstraints();
713 c.gridx = 0; c.gridy = row;
715 c.fill = GridBagConstraints.NONE;
716 c.anchor = GridBagConstraints.LINE_START;
719 callsign_label = new JLabel("Callsign:");
720 pane.add(callsign_label, c);
722 c = new GridBagConstraints();
723 c.gridx = 4; c.gridy = row;
725 c.fill = GridBagConstraints.HORIZONTAL;
727 c.anchor = GridBagConstraints.LINE_START;
730 callsign_value = new JTextField(AltosUIPreferences.callsign());
731 callsign_value.getDocument().addDocumentListener(this);
732 pane.add(callsign_value, c);
733 callsign_value.setToolTipText("Callsign reported in telemetry data");
737 c = new GridBagConstraints();
738 c.gridx = 0; c.gridy = row;
740 c.fill = GridBagConstraints.NONE;
741 c.anchor = GridBagConstraints.LINE_START;
744 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
745 pane.add(flight_log_max_label, c);
747 c = new GridBagConstraints();
748 c.gridx = 4; c.gridy = row;
750 c.fill = GridBagConstraints.HORIZONTAL;
752 c.anchor = GridBagConstraints.LINE_START;
755 flight_log_max_value = new JComboBox<String>();
756 flight_log_max_value.setEditable(true);
757 flight_log_max_value.addItemListener(this);
758 pane.add(flight_log_max_value, c);
759 set_flight_log_max_tool_tip();
763 c = new GridBagConstraints();
764 c.gridx = 0; c.gridy = row;
766 c.fill = GridBagConstraints.NONE;
767 c.anchor = GridBagConstraints.LINE_START;
770 ignite_mode_label = new JLabel("Igniter Firing Mode:");
771 pane.add(ignite_mode_label, c);
773 c = new GridBagConstraints();
774 c.gridx = 4; c.gridy = row;
776 c.fill = GridBagConstraints.HORIZONTAL;
778 c.anchor = GridBagConstraints.LINE_START;
781 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
782 ignite_mode_value.setEditable(false);
783 ignite_mode_value.addItemListener(this);
784 pane.add(ignite_mode_value, c);
785 set_ignite_mode_tool_tip();
788 /* Pad orientation */
789 c = new GridBagConstraints();
790 c.gridx = 0; c.gridy = row;
792 c.fill = GridBagConstraints.NONE;
793 c.anchor = GridBagConstraints.LINE_START;
796 pad_orientation_label = new JLabel("Pad Orientation:");
797 pane.add(pad_orientation_label, c);
799 c = new GridBagConstraints();
800 c.gridx = 4; c.gridy = row;
802 c.fill = GridBagConstraints.HORIZONTAL;
804 c.anchor = GridBagConstraints.LINE_START;
807 pad_orientation_values = pad_orientation_values_no_radio;
809 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
810 pad_orientation_value.setEditable(false);
811 pad_orientation_value.addItemListener(this);
812 pane.add(pad_orientation_value, c);
813 set_pad_orientation_tool_tip();
817 c = new GridBagConstraints();
818 c.gridx = 0; c.gridy = row;
820 c.fill = GridBagConstraints.NONE;
821 c.anchor = GridBagConstraints.LINE_START;
824 accel_plus_label = new JLabel("Accel Plus:");
825 pane.add(accel_plus_label, c);
827 c = new GridBagConstraints();
828 c.gridx = 4; c.gridy = row;
830 c.fill = GridBagConstraints.HORIZONTAL;
832 c.anchor = GridBagConstraints.LINE_START;
835 accel_plus_value = new JTextField(10);
836 accel_plus_value.setEditable(true);
837 accel_plus_value.getDocument().addDocumentListener(this);
838 pane.add(accel_plus_value, c);
842 c = new GridBagConstraints();
843 c.gridx = 0; c.gridy = row;
845 c.fill = GridBagConstraints.NONE;
846 c.anchor = GridBagConstraints.LINE_START;
849 accel_minus_label = new JLabel("Accel Minus:");
850 pane.add(accel_minus_label, c);
852 c = new GridBagConstraints();
853 c.gridx = 4; c.gridy = row;
855 c.fill = GridBagConstraints.HORIZONTAL;
857 c.anchor = GridBagConstraints.LINE_START;
860 accel_minus_value = new JTextField(10);
861 accel_minus_value.setEditable(true);
862 accel_minus_value.getDocument().addDocumentListener(this);
863 pane.add(accel_minus_value, c);
865 set_accel_tool_tips();
868 c = new GridBagConstraints();
869 c.gridx = 0; c.gridy = row;
871 c.fill = GridBagConstraints.NONE;
872 c.anchor = GridBagConstraints.LINE_START;
875 beep_label = new JLabel("Beeper Frequency:");
876 pane.add(beep_label, c);
878 c = new GridBagConstraints();
879 c.gridx = 4; c.gridy = row;
881 c.fill = GridBagConstraints.HORIZONTAL;
883 c.anchor = GridBagConstraints.LINE_START;
886 beep_value = new JComboBox<String>(beep_values);
887 beep_value.setEditable(true);
888 beep_value.addItemListener(this);
889 pane.add(beep_value, c);
893 /* Tracker triger horiz distances */
894 c = new GridBagConstraints();
895 c.gridx = 0; c.gridy = row;
897 c.fill = GridBagConstraints.NONE;
898 c.anchor = GridBagConstraints.LINE_START;
901 tracker_motion_label = new JLabel(get_tracker_motion_label());
902 pane.add(tracker_motion_label, c);
904 c = new GridBagConstraints();
905 c.gridx = 4; c.gridy = row;
907 c.fill = GridBagConstraints.HORIZONTAL;
909 c.anchor = GridBagConstraints.LINE_START;
912 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
913 tracker_motion_value.setEditable(true);
914 tracker_motion_value.addItemListener(this);
915 pane.add(tracker_motion_value, c);
918 /* Tracker triger vert distances */
919 c = new GridBagConstraints();
920 c.gridx = 0; c.gridy = row;
922 c.fill = GridBagConstraints.NONE;
923 c.anchor = GridBagConstraints.LINE_START;
926 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
927 pane.add(tracker_interval_label, c);
929 c = new GridBagConstraints();
930 c.gridx = 4; c.gridy = row;
932 c.fill = GridBagConstraints.HORIZONTAL;
934 c.anchor = GridBagConstraints.LINE_START;
937 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
938 tracker_interval_value.setEditable(true);
939 tracker_interval_value.addItemListener(this);
940 pane.add(tracker_interval_value, c);
941 set_tracker_tool_tip();
945 c = new GridBagConstraints();
946 c.gridx = 4; c.gridy = row;
948 c.fill = GridBagConstraints.HORIZONTAL;
949 c.anchor = GridBagConstraints.LINE_START;
952 pyro = new JButton("Configure Pyro Channels");
954 pyro.addActionListener(this);
955 pyro.setActionCommand("Pyro");
959 c = new GridBagConstraints();
960 c.gridx = 5; c.gridy = row;
962 c.fill = GridBagConstraints.HORIZONTAL;
963 c.anchor = GridBagConstraints.LINE_START;
966 accel_cal = new JButton("Calibrate Accelerometer");
967 pane.add(accel_cal, c);
968 accel_cal.addActionListener(this);
969 accel_cal.setActionCommand("Accel");
973 c = new GridBagConstraints();
974 c.gridx = 0; c.gridy = row;
976 c.fill = GridBagConstraints.NONE;
977 c.anchor = GridBagConstraints.LINE_START;
979 save = new JButton("Save");
981 save.addActionListener(this);
982 save.setActionCommand("Save");
984 c = new GridBagConstraints();
985 c.gridx = 2; c.gridy = row;
987 c.fill = GridBagConstraints.NONE;
988 c.anchor = GridBagConstraints.CENTER;
990 reset = new JButton("Reset");
992 reset.addActionListener(this);
993 reset.setActionCommand("Reset");
995 c = new GridBagConstraints();
996 c.gridx = 4; c.gridy = row;
998 c.fill = GridBagConstraints.NONE;
999 c.anchor = GridBagConstraints.CENTER;
1001 reboot = new JButton("Reboot");
1002 pane.add(reboot, c);
1003 reboot.addActionListener(this);
1004 reboot.setActionCommand("Reboot");
1006 c = new GridBagConstraints();
1007 c.gridx = 6; c.gridy = row;
1009 c.fill = GridBagConstraints.NONE;
1010 c.anchor = GridBagConstraints.LINE_END;
1012 close = new JButton("Close");
1014 close.addActionListener(this);
1015 close.setActionCommand("Close");
1017 addWindowListener(new ConfigListener(this));
1018 AltosPreferences.register_units_listener(this);
1021 /* Once the initial values are set, the config code will show the dialog */
1022 public void make_visible() {
1024 setLocationRelativeTo(owner);
1028 /* If any values have been changed, confirm before closing */
1029 public boolean check_dirty(String operation) {
1031 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
1033 i = JOptionPane.showOptionDialog(this,
1034 String.format("Configuration modified. %s anyway?", operation),
1035 "Configuration Modified",
1036 JOptionPane.DEFAULT_OPTION,
1037 JOptionPane.WARNING_MESSAGE,
1038 null, options, options[1]);
1045 public void set_dirty() {
1047 save.setEnabled(true);
1050 public void set_clean() {
1052 save.setEnabled(false);
1055 AltosConfigPyroUI pyro_ui;
1057 public void dispose() {
1058 if (pyro_ui != null)
1060 AltosPreferences.unregister_units_listener(this);
1064 /* Listen for events from our buttons */
1065 public void actionPerformed(ActionEvent e) {
1066 String cmd = e.getActionCommand();
1068 if (cmd.equals("Pyro")) {
1069 if (pyro_ui == null && pyros != null)
1070 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
1071 if (pyro_ui != null)
1072 pyro_ui.make_visible();
1076 if (cmd.equals("Close") || cmd.equals("Reboot"))
1077 if (!check_dirty(cmd))
1079 listener.actionPerformed(e);
1080 if (cmd.equals("Close") || cmd.equals("Reboot")) {
1084 if (cmd.equals("Save") || cmd.equals("Reset"))
1088 /* ItemListener interface method */
1089 public void itemStateChanged(ItemEvent e) {
1093 /* DocumentListener interface methods */
1094 public void changedUpdate(DocumentEvent e) {
1098 public void insertUpdate(DocumentEvent e) {
1102 public void removeUpdate(DocumentEvent e) {
1106 /* Let the config code hook on a listener */
1107 public void addActionListener(ActionListener l) {
1111 /* set and get all of the dialog values */
1112 public void set_product(String product) {
1113 radio_frequency_value.set_product(product);
1114 product_value.setText(product);
1115 set_pad_orientation_tool_tip();
1116 set_accel_tool_tips();
1117 set_flight_log_max_tool_tip();
1118 set_pad_orientation_values();
1121 public void set_version(String version) {
1122 version_value.setText(version);
1125 public void set_serial(int serial) {
1126 radio_frequency_value.set_serial(serial);
1127 serial_value.setText(String.format("%d", serial));
1130 public void set_altitude_32(int altitude_32) {
1133 public void set_main_deploy(int new_main_deploy) {
1134 if (new_main_deploy != AltosLib.MISSING)
1135 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
1136 main_deploy_value.setVisible(new_main_deploy != AltosLib.MISSING);
1137 main_deploy_label.setVisible(new_main_deploy != AltosLib.MISSING);
1140 public int main_deploy() throws AltosConfigDataException {
1141 String str = main_deploy_value.getSelectedItem().toString();
1143 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1144 } catch (ParseException pe) {
1145 throw new AltosConfigDataException("invalid main deploy height %s", str);
1149 String get_main_deploy_label() {
1150 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.parse_units());
1153 String[] main_deploy_values() {
1154 if (AltosConvert.imperial_units)
1155 return main_deploy_values_ft;
1157 return main_deploy_values_m;
1160 void set_main_deploy_values() {
1161 String[] v = main_deploy_values();
1162 while (main_deploy_value.getItemCount() > 0)
1163 main_deploy_value.removeItemAt(0);
1164 for (int i = 0; i < v.length; i++)
1165 main_deploy_value.addItem(v[i]);
1166 main_deploy_value.setMaximumRowCount(v.length);
1169 public void units_changed(boolean imperial_units) {
1170 boolean was_dirty = dirty;
1172 String v = main_deploy_value.getSelectedItem().toString();
1173 main_deploy_label.setText(get_main_deploy_label());
1174 set_main_deploy_values();
1176 int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1178 } catch (ParseException pe) {
1181 if (tracker_motion_value.isVisible()) {
1182 String motion = tracker_motion_value.getSelectedItem().toString();
1183 tracker_motion_label.setText(get_tracker_motion_label());
1184 set_tracker_motion_values();
1186 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1187 set_tracker_motion(m);
1188 } catch (ParseException pe) {
1196 public void set_apogee_delay(int new_apogee_delay) {
1197 if (new_apogee_delay != AltosLib.MISSING)
1198 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1199 apogee_delay_value.setVisible(new_apogee_delay != AltosLib.MISSING);
1200 apogee_delay_label.setVisible(new_apogee_delay != AltosLib.MISSING);
1203 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1206 v = s.split("\\s+")[0];
1208 return Integer.parseInt(v);
1209 } catch (NumberFormatException ne) {
1210 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1214 public int apogee_delay() throws AltosConfigDataException {
1215 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1218 public void set_apogee_lockout(int new_apogee_lockout) {
1219 if (new_apogee_lockout != AltosLib.MISSING)
1220 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1222 apogee_lockout_value.setVisible(new_apogee_lockout != AltosLib.MISSING);
1223 apogee_lockout_label.setVisible(new_apogee_lockout != AltosLib.MISSING);
1226 public int apogee_lockout() throws AltosConfigDataException {
1227 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1230 public void set_radio_frequency(double new_radio_frequency) {
1231 if (new_radio_frequency != AltosLib.MISSING)
1232 radio_frequency_value.set_frequency(new_radio_frequency);
1233 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
1234 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
1237 public double radio_frequency() {
1238 return radio_frequency_value.frequency();
1241 public void set_radio_calibration(int new_radio_calibration) {
1242 if (new_radio_calibration != AltosLib.MISSING)
1243 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1244 radio_calibration_value.setVisible(new_radio_calibration != AltosLib.MISSING);
1245 radio_calibration_label.setVisible(new_radio_calibration != AltosLib.MISSING);
1248 public void set_radio_enable(int new_radio_enable) {
1249 if (new_radio_enable != AltosLib.MISSING)
1250 radio_enable_value.setSelected(new_radio_enable != 0);
1251 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
1252 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
1253 set_radio_enable_tool_tip();
1256 public int radio_enable() {
1257 if (radio_enable_value.isVisible())
1258 return radio_enable_value.isSelected() ? 1 : 0;
1260 return AltosLib.MISSING;
1263 public void set_telemetry_rate(int new_rate) {
1264 if (new_rate != AltosLib.MISSING)
1265 rate_value.set_rate(new_rate);
1266 rate_label.setVisible(new_rate != AltosLib.MISSING);
1267 rate_value.setVisible(new_rate != AltosLib.MISSING);
1268 set_rate_tool_tip();
1271 public int telemetry_rate() {
1272 return rate_value.rate();
1275 public void set_callsign(String new_callsign) {
1276 if (new_callsign != null)
1277 callsign_value.setText(new_callsign);
1278 callsign_value.setVisible(new_callsign != null);
1279 callsign_label.setVisible(new_callsign != null);
1282 public String callsign() {
1283 if (callsign_value.isVisible())
1284 return callsign_value.getText();
1288 int flight_log_max_limit;
1291 public String flight_log_max_label(int flight_log_max) {
1292 if (flight_log_max_limit != 0) {
1293 int nflight = flight_log_max_limit / flight_log_max;
1294 String plural = nflight > 1 ? "s" : "";
1296 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1298 return String.format("%d", flight_log_max);
1301 public void set_flight_log_max(int new_flight_log_max) {
1302 if (new_flight_log_max != AltosLib.MISSING) {
1303 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1304 flight_log_max = new_flight_log_max;
1306 flight_log_max_value.setVisible(new_flight_log_max != AltosLib.MISSING);
1307 flight_log_max_label.setVisible(new_flight_log_max != AltosLib.MISSING);
1308 set_flight_log_max_tool_tip();
1311 public void set_flight_log_max_enabled(boolean enable) {
1312 flight_log_max_value.setEnabled(enable);
1313 set_flight_log_max_tool_tip();
1316 public int flight_log_max() throws AltosConfigDataException {
1317 if (flight_log_max_value.isVisible())
1318 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1319 return AltosLib.MISSING;
1322 public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
1323 flight_log_max_limit = new_flight_log_max_limit;
1324 if (new_flight_log_max_limit != AltosLib.MISSING) {
1325 flight_log_max_value.removeAllItems();
1326 for (int i = 8; i >= 1; i--) {
1327 int size = flight_log_max_limit / i;
1328 if (new_storage_erase_unit != 0)
1329 size &= ~(new_storage_erase_unit - 1);
1330 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1333 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
1334 set_flight_log_max(flight_log_max);
1337 public void set_ignite_mode(int new_ignite_mode) {
1338 if (new_ignite_mode != AltosLib.MISSING) {
1339 if (new_ignite_mode >= ignite_mode_values.length)
1340 new_ignite_mode = 0;
1341 if (new_ignite_mode < 0) {
1342 ignite_mode_value.setEnabled(false);
1343 new_ignite_mode = 0;
1345 ignite_mode_value.setEnabled(true);
1347 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1349 ignite_mode_value.setVisible(new_ignite_mode != AltosLib.MISSING);
1350 ignite_mode_label.setVisible(new_ignite_mode != AltosLib.MISSING);
1352 set_ignite_mode_tool_tip();
1355 public int ignite_mode() {
1356 if (ignite_mode_value.isVisible())
1357 return ignite_mode_value.getSelectedIndex();
1359 return AltosLib.MISSING;
1363 public void set_pad_orientation(int new_pad_orientation) {
1364 if (new_pad_orientation != AltosLib.MISSING) {
1365 if (new_pad_orientation >= pad_orientation_values.length)
1366 new_pad_orientation = 0;
1367 if (new_pad_orientation < 0)
1368 new_pad_orientation = 0;
1369 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1371 pad_orientation_value.setVisible(new_pad_orientation != AltosLib.MISSING);
1372 pad_orientation_label.setVisible(new_pad_orientation != AltosLib.MISSING);
1373 accel_cal.setVisible(new_pad_orientation != AltosLib.MISSING);
1375 set_pad_orientation_tool_tip();
1378 public int pad_orientation() {
1379 if (pad_orientation_value.isVisible())
1380 return pad_orientation_value.getSelectedIndex();
1382 return AltosLib.MISSING;
1385 public void set_accel_cal(int accel_plus, int accel_minus) {
1386 if (accel_plus != AltosLib.MISSING) {
1387 accel_plus_value.setText(String.format("%d", accel_plus));
1388 accel_minus_value.setText(String.format("%d", accel_minus));
1390 accel_plus_value.setVisible(accel_plus != AltosLib.MISSING);
1391 accel_plus_label.setVisible(accel_plus != AltosLib.MISSING);
1392 accel_minus_value.setVisible(accel_minus != AltosLib.MISSING);
1393 accel_minus_label.setVisible(accel_minus != AltosLib.MISSING);
1395 set_accel_tool_tips();
1398 public int accel_cal_plus() {
1399 if (accel_plus_value.isVisible())
1400 return Integer.parseInt(accel_plus_value.getText());
1401 return AltosLib.MISSING;
1404 public int accel_cal_minus() {
1405 if (accel_minus_value.isVisible())
1406 return Integer.parseInt(accel_minus_value.getText());
1407 return AltosLib.MISSING;
1410 public void set_beep(int new_beep) {
1411 if (new_beep != AltosLib.MISSING) {
1412 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1413 for (int i = 0; i < beep_values.length; i++)
1414 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1415 beep_value.setSelectedIndex(i);
1416 set_beep_tool_tip();
1419 beep_value.setSelectedItem(String.format("%d", new_freq));
1421 beep_value.setVisible(new_beep != AltosLib.MISSING);
1422 beep_label.setVisible(new_beep != AltosLib.MISSING);
1423 set_beep_tool_tip();
1427 if (beep_value.isVisible())
1428 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1430 return AltosLib.MISSING;
1433 String[] tracker_motion_values() {
1434 if (AltosConvert.imperial_units)
1435 return tracker_motion_values_ft;
1437 return tracker_motion_values_m;
1440 void set_tracker_motion_values() {
1441 String[] v = tracker_motion_values();
1442 while (tracker_motion_value.getItemCount() > 0)
1443 tracker_motion_value.removeItemAt(0);
1444 for (int i = 0; i < v.length; i++)
1445 tracker_motion_value.addItem(v[i]);
1446 tracker_motion_value.setMaximumRowCount(v.length);
1449 String get_tracker_motion_label() {
1450 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1453 void set_tracker_tool_tip() {
1454 if (tracker_motion_value.isVisible())
1455 tracker_motion_value.setToolTipText("How far the device must move before logging");
1457 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1458 if (tracker_interval_value.isVisible())
1459 tracker_interval_value.setToolTipText("How often to report GPS position");
1461 tracker_interval_value.setToolTipText("This device can't configure interval");
1464 public void set_tracker_motion(int tracker_motion) {
1465 if (tracker_motion != AltosLib.MISSING)
1466 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1467 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1468 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1471 public int tracker_motion() throws AltosConfigDataException {
1472 if (tracker_motion_value.isVisible()) {
1473 String str = tracker_motion_value.getSelectedItem().toString();
1475 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1476 } catch (ParseException pe) {
1477 throw new AltosConfigDataException("invalid tracker motion %s", str);
1480 return AltosLib.MISSING;
1483 public void set_tracker_interval(int tracker_interval) {
1484 if (tracker_interval != AltosLib.MISSING)
1485 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1486 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1487 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1490 public int tracker_interval() throws AltosConfigDataException {
1491 if (tracker_interval_value.isVisible())
1492 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1493 return AltosLib.MISSING;
1496 public void set_pyros(AltosPyro[] new_pyros) {
1498 if (pyros != null && pyro_ui != null)
1499 pyro_ui.set_pyros(pyros);
1500 pyro.setVisible(pyros != null);
1503 public AltosPyro[] pyros() throws AltosConfigDataException {
1504 if (pyro_ui != null)
1505 pyros = pyro_ui.get_pyros();
1509 public void set_pyro_firing_time(double new_pyro_firing_time) {
1510 pyro_firing_time = new_pyro_firing_time;
1511 if (pyro_firing_time != AltosLib.MISSING && pyro_ui != null)
1512 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1513 pyro.setVisible(pyro_firing_time != AltosLib.MISSING);
1516 public double pyro_firing_time() throws AltosConfigDataException {
1517 if (pyro_ui != null)
1518 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1519 return pyro_firing_time;
1522 private String aprs_interval_string(int interval) {
1525 return Integer.toString(interval);
1528 private int aprs_interval_value(String interval) throws AltosConfigDataException {
1529 if (interval.equalsIgnoreCase("Disabled"))
1531 return parse_int("aprs interval", interval, false);
1534 public void set_aprs_interval(int new_aprs_interval) {
1535 if (new_aprs_interval != AltosLib.MISSING)
1536 aprs_interval_value.setSelectedItem(aprs_interval_string(new_aprs_interval));
1537 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1538 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1539 set_aprs_interval_tool_tip();
1542 public int aprs_interval() throws AltosConfigDataException {
1543 if (aprs_interval_value.isVisible())
1544 return aprs_interval_value(aprs_interval_value.getSelectedItem().toString());
1545 return AltosLib.MISSING;
1548 public void set_aprs_ssid(int new_aprs_ssid) {
1549 if (new_aprs_ssid != AltosLib.MISSING)
1550 aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1551 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1552 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1553 set_aprs_ssid_tool_tip();
1556 public int aprs_ssid() throws AltosConfigDataException {
1557 if (aprs_ssid_value.isVisible()) {
1558 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1561 return AltosLib.MISSING;
1564 public void set_aprs_format(int new_aprs_format) {
1565 if (new_aprs_format != AltosLib.MISSING)
1566 aprs_format_value.setSelectedIndex(new_aprs_format);
1567 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1568 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1569 set_aprs_format_tool_tip();
1572 public int aprs_format() throws AltosConfigDataException {
1573 if (aprs_format_value.isVisible())
1574 return aprs_format_value.getSelectedIndex();
1575 return AltosLib.MISSING;
1578 public void set_aprs_offset(int new_aprs_offset) {
1579 if (new_aprs_offset != AltosLib.MISSING)
1580 aprs_offset_value.setSelectedItem(new_aprs_offset);
1581 aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
1582 aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
1583 set_aprs_offset_tool_tip();
1586 public int aprs_offset() throws AltosConfigDataException {
1587 if (aprs_offset_value.isVisible()) {
1588 Integer i = (Integer) aprs_offset_value.getSelectedItem();
1591 return AltosLib.MISSING;