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 = {
124 static String[] aprs_interval_values = {
131 static Integer[] aprs_ssid_values = {
132 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
135 static Integer[] aprs_offset_values = {
136 0, 2, 4, 6, 8, 10, 12, 14, 16, 18
139 static String[] beep_values = {
145 static String[] pad_orientation_values_radio = {
150 static String[] pad_orientation_values_no_radio = {
155 static String[] pad_orientation_values_six_axis = {
164 String[] pad_orientation_values;
166 static String[] tracker_motion_values_m = {
173 static String[] tracker_motion_values_ft = {
180 static String[] tracker_interval_values = {
187 /* A window listener to catch closing events and tell the config code */
188 class ConfigListener extends WindowAdapter {
191 public ConfigListener(AltosConfigFCUI this_ui) {
195 public void windowClosing(WindowEvent e) {
196 ui.actionPerformed(new ActionEvent(e.getSource(),
197 ActionEvent.ACTION_PERFORMED,
202 boolean is_telemini_v1() {
203 String product = product_value.getText();
204 return product != null && product.startsWith("TeleMini-v1");
207 boolean is_telemini() {
208 String product = product_value.getText();
209 return product != null && product.startsWith("TeleMini");
212 boolean is_easymini() {
213 String product = product_value.getText();
214 return product != null && product.startsWith("EasyMini");
217 boolean is_telemetrum() {
218 String product = product_value.getText();
219 return product != null && product.startsWith("TeleMetrum");
222 boolean is_telemega() {
223 String product = product_value.getText();
224 return product != null && product.startsWith("TeleMega");
227 boolean is_easymega() {
228 String product = product_value.getText();
229 return product != null && product.startsWith("EasyMega");
232 boolean is_easytimer() {
233 String product = product_value.getText();
234 return product != null && product.startsWith("EasyTimer");
237 boolean has_radio() {
238 return is_telemega() || is_telemetrum() || is_telemini();
241 void set_radio_enable_tool_tip() {
242 if (radio_enable_value.isVisible())
243 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
245 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
248 void set_rate_tool_tip() {
249 if (rate_value.isVisible())
250 rate_value.setToolTipText("Select telemetry baud rate");
252 rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
255 void set_aprs_interval_tool_tip() {
256 if (aprs_interval_value.isVisible())
257 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
259 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
262 void set_aprs_ssid_tool_tip() {
263 if (aprs_ssid_value.isVisible())
264 aprs_ssid_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
265 else if (aprs_ssid_value.isVisible())
266 aprs_ssid_value.setToolTipText("Software version doesn't support setting the APRS SSID");
268 aprs_ssid_value.setToolTipText("Hardware doesn't support APRS");
271 void set_aprs_format_tool_tip() {
272 if (aprs_format_value.isVisible())
273 aprs_format_value.setToolTipText("Set the APRS format (compressed/uncompressed)");
274 else if (aprs_format_value.isVisible())
275 aprs_format_value.setToolTipText("Software version doesn't support setting the APRS format");
277 aprs_format_value.setToolTipText("Hardware doesn't support APRS");
280 void set_aprs_offset_tool_tip() {
281 if (aprs_offset_value.isVisible())
282 aprs_offset_value.setToolTipText("Set the APRS offset from top of minute");
283 else if (aprs_offset_value.isVisible())
284 aprs_offset_value.setToolTipText("Software version doesn't support setting the APRS offset");
286 aprs_offset_value.setToolTipText("Hardware doesn't support APRS");
289 void set_flight_log_max_tool_tip() {
290 if (flight_log_max_value.isVisible())
291 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
293 if (is_telemini_v1())
294 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
296 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
300 void set_ignite_mode_tool_tip() {
301 if (ignite_mode_value.isVisible())
302 ignite_mode_value.setToolTipText("Select when igniters will be fired");
304 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
307 void set_pad_orientation_tool_tip() {
308 if (pad_orientation_value.isVisible()) {
309 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
312 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
313 else if (is_telemini() || is_easymini())
314 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
315 else if (is_easytimer())
316 pad_orientation_value.setToolTipText("EasyTimer can be mounted in any of six orientations");
318 pad_orientation_value.setToolTipText("Can't select orientation");
322 void set_accel_tool_tips() {
323 if (accel_plus_value.isVisible()) {
324 accel_plus_value.setToolTipText("Pad acceleration value in flight orientation");
325 accel_minus_value.setToolTipText("Upside-down acceleration value");
327 accel_plus_value.setToolTipText("No accelerometer");
328 accel_minus_value.setToolTipText("No accelerometer");
332 void set_beep_tool_tip() {
333 if (beep_value.isVisible())
334 beep_value.setToolTipText("What frequency the beeper will sound at");
336 beep_value.setToolTipText("Older firmware could not select beeper frequency");
339 /* Build the UI using a grid bag */
340 public AltosConfigFCUI(JFrame in_owner, boolean remote) {
341 super (in_owner, "Configure Flight Computer", false);
344 GridBagConstraints c;
347 Insets il = new Insets(4,4,4,4);
348 Insets ir = new Insets(4,4,4,4);
350 pane = getContentPane();
351 pane.setLayout(new GridBagLayout());
354 c = new GridBagConstraints();
355 c.gridx = 0; c.gridy = row;
357 c.fill = GridBagConstraints.NONE;
358 c.anchor = GridBagConstraints.LINE_START;
360 product_label = new JLabel("Product:");
361 pane.add(product_label, c);
363 c = new GridBagConstraints();
364 c.gridx = 4; c.gridy = row;
366 c.fill = GridBagConstraints.HORIZONTAL;
368 c.anchor = GridBagConstraints.LINE_START;
370 product_value = new JLabel("");
371 pane.add(product_value, c);
375 c = new GridBagConstraints();
376 c.gridx = 0; c.gridy = row;
378 c.fill = GridBagConstraints.NONE;
379 c.anchor = GridBagConstraints.LINE_START;
382 version_label = new JLabel("Software version:");
383 pane.add(version_label, c);
385 c = new GridBagConstraints();
386 c.gridx = 4; c.gridy = row;
388 c.fill = GridBagConstraints.HORIZONTAL;
390 c.anchor = GridBagConstraints.LINE_START;
393 version_value = new JLabel("");
394 pane.add(version_value, c);
398 c = new GridBagConstraints();
399 c.gridx = 0; c.gridy = row;
401 c.fill = GridBagConstraints.NONE;
402 c.anchor = GridBagConstraints.LINE_START;
405 serial_label = new JLabel("Serial:");
406 pane.add(serial_label, c);
408 c = new GridBagConstraints();
409 c.gridx = 4; c.gridy = row;
411 c.fill = GridBagConstraints.HORIZONTAL;
413 c.anchor = GridBagConstraints.LINE_START;
416 serial_value = new JLabel("");
417 pane.add(serial_value, c);
421 c = new GridBagConstraints();
422 c.gridx = 0; c.gridy = row;
424 c.fill = GridBagConstraints.NONE;
425 c.anchor = GridBagConstraints.LINE_START;
428 main_deploy_label = new JLabel(get_main_deploy_label());
429 pane.add(main_deploy_label, c);
431 c = new GridBagConstraints();
432 c.gridx = 4; c.gridy = row;
434 c.fill = GridBagConstraints.HORIZONTAL;
436 c.anchor = GridBagConstraints.LINE_START;
439 main_deploy_value = new JComboBox<String>(main_deploy_values());
440 main_deploy_value.setEditable(true);
441 main_deploy_value.addItemListener(this);
442 pane.add(main_deploy_value, c);
443 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
447 c = new GridBagConstraints();
448 c.gridx = 0; c.gridy = row;
450 c.fill = GridBagConstraints.NONE;
451 c.anchor = GridBagConstraints.LINE_START;
454 apogee_delay_label = new JLabel("Apogee Delay(s):");
455 pane.add(apogee_delay_label, c);
457 c = new GridBagConstraints();
458 c.gridx = 4; c.gridy = row;
460 c.fill = GridBagConstraints.HORIZONTAL;
462 c.anchor = GridBagConstraints.LINE_START;
465 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
466 apogee_delay_value.setEditable(true);
467 apogee_delay_value.addItemListener(this);
468 pane.add(apogee_delay_value, c);
469 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
473 c = new GridBagConstraints();
474 c.gridx = 0; c.gridy = row;
476 c.fill = GridBagConstraints.NONE;
477 c.anchor = GridBagConstraints.LINE_START;
480 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
481 pane.add(apogee_lockout_label, c);
483 c = new GridBagConstraints();
484 c.gridx = 4; c.gridy = row;
486 c.fill = GridBagConstraints.HORIZONTAL;
488 c.anchor = GridBagConstraints.LINE_START;
491 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
492 apogee_lockout_value.setEditable(true);
493 apogee_lockout_value.addItemListener(this);
494 pane.add(apogee_lockout_value, c);
495 apogee_lockout_value.setToolTipText("Time after launch while apogee detection is locked out");
499 c = new GridBagConstraints();
500 c.gridx = 0; c.gridy = row;
502 c.fill = GridBagConstraints.NONE;
503 c.anchor = GridBagConstraints.LINE_START;
506 radio_frequency_label = new JLabel("Frequency:");
507 pane.add(radio_frequency_label, c);
509 c = new GridBagConstraints();
510 c.gridx = 4; c.gridy = row;
512 c.fill = GridBagConstraints.HORIZONTAL;
514 c.anchor = GridBagConstraints.LINE_START;
517 radio_frequency_value = new AltosUIFreqList();
518 radio_frequency_value.addItemListener(this);
519 pane.add(radio_frequency_value, c);
520 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
523 /* Radio Calibration */
524 c = new GridBagConstraints();
525 c.gridx = 0; c.gridy = row;
527 c.fill = GridBagConstraints.NONE;
528 c.anchor = GridBagConstraints.LINE_START;
531 radio_calibration_label = new JLabel("RF Calibration:");
532 pane.add(radio_calibration_label, c);
534 c = new GridBagConstraints();
535 c.gridx = 4; c.gridy = row;
537 c.fill = GridBagConstraints.HORIZONTAL;
539 c.anchor = GridBagConstraints.LINE_START;
542 radio_calibration_value = new JLabel(String.format("%d", 1186611));
543 pane.add(radio_calibration_value, c);
547 c = new GridBagConstraints();
548 c.gridx = 0; c.gridy = row;
550 c.fill = GridBagConstraints.NONE;
551 c.anchor = GridBagConstraints.LINE_START;
554 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
555 pane.add(radio_enable_label, c);
557 c = new GridBagConstraints();
558 c.gridx = 4; c.gridy = row;
560 c.fill = GridBagConstraints.HORIZONTAL;
562 c.anchor = GridBagConstraints.LINE_START;
565 radio_enable_value = new JRadioButton("Enabled");
566 radio_enable_value.addItemListener(this);
567 pane.add(radio_enable_value, c);
568 set_radio_enable_tool_tip();
572 c = new GridBagConstraints();
573 c.gridx = 0; c.gridy = row;
575 c.fill = GridBagConstraints.NONE;
576 c.anchor = GridBagConstraints.LINE_START;
579 rate_label = new JLabel("Telemetry baud rate:");
580 pane.add(rate_label, c);
582 c = new GridBagConstraints();
583 c.gridx = 4; c.gridy = row;
585 c.fill = GridBagConstraints.HORIZONTAL;
587 c.anchor = GridBagConstraints.LINE_START;
590 rate_value = new AltosUIRateList();
591 rate_value.addItemListener(this);
592 pane.add(rate_value, c);
597 c = new GridBagConstraints();
598 c.gridx = 0; c.gridy = row;
600 c.fill = GridBagConstraints.NONE;
601 c.anchor = GridBagConstraints.LINE_START;
604 aprs_interval_label = new JLabel("APRS Interval(s):");
605 pane.add(aprs_interval_label, c);
607 c = new GridBagConstraints();
608 c.gridx = 4; c.gridy = row;
610 c.fill = GridBagConstraints.HORIZONTAL;
612 c.anchor = GridBagConstraints.LINE_START;
615 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
616 aprs_interval_value.setEditable(true);
617 aprs_interval_value.addItemListener(this);
618 pane.add(aprs_interval_value, c);
619 set_aprs_interval_tool_tip();
623 c = new GridBagConstraints();
624 c.gridx = 0; c.gridy = row;
626 c.fill = GridBagConstraints.NONE;
627 c.anchor = GridBagConstraints.LINE_START;
630 aprs_ssid_label = new JLabel("APRS SSID:");
631 pane.add(aprs_ssid_label, c);
633 c = new GridBagConstraints();
634 c.gridx = 4; c.gridy = row;
636 c.fill = GridBagConstraints.HORIZONTAL;
638 c.anchor = GridBagConstraints.LINE_START;
641 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
642 aprs_ssid_value.setEditable(false);
643 aprs_ssid_value.addItemListener(this);
644 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
645 pane.add(aprs_ssid_value, c);
646 set_aprs_ssid_tool_tip();
650 c = new GridBagConstraints();
651 c.gridx = 0; c.gridy = row;
653 c.fill = GridBagConstraints.NONE;
654 c.anchor = GridBagConstraints.LINE_START;
657 aprs_format_label = new JLabel("APRS format:");
658 pane.add(aprs_format_label, c);
660 c = new GridBagConstraints();
661 c.gridx = 4; c.gridy = row;
663 c.fill = GridBagConstraints.HORIZONTAL;
665 c.anchor = GridBagConstraints.LINE_START;
668 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
669 aprs_format_value.setEditable(false);
670 aprs_format_value.addItemListener(this);
671 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
672 pane.add(aprs_format_value, c);
673 set_aprs_format_tool_tip();
677 c = new GridBagConstraints();
678 c.gridx = 0; c.gridy = row;
680 c.fill = GridBagConstraints.NONE;
681 c.anchor = GridBagConstraints.LINE_START;
684 aprs_offset_label = new JLabel("APRS offset:");
685 pane.add(aprs_offset_label, c);
687 c = new GridBagConstraints();
688 c.gridx = 4; c.gridy = row;
690 c.fill = GridBagConstraints.HORIZONTAL;
692 c.anchor = GridBagConstraints.LINE_START;
695 aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
696 aprs_offset_value.setEditable(false);
697 aprs_offset_value.addItemListener(this);
698 aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
699 pane.add(aprs_offset_value, c);
700 set_aprs_offset_tool_tip();
704 c = new GridBagConstraints();
705 c.gridx = 0; c.gridy = row;
707 c.fill = GridBagConstraints.NONE;
708 c.anchor = GridBagConstraints.LINE_START;
711 callsign_label = new JLabel("Callsign:");
712 pane.add(callsign_label, c);
714 c = new GridBagConstraints();
715 c.gridx = 4; c.gridy = row;
717 c.fill = GridBagConstraints.HORIZONTAL;
719 c.anchor = GridBagConstraints.LINE_START;
722 callsign_value = new JTextField(AltosUIPreferences.callsign());
723 callsign_value.getDocument().addDocumentListener(this);
724 pane.add(callsign_value, c);
725 callsign_value.setToolTipText("Callsign reported in telemetry data");
729 c = new GridBagConstraints();
730 c.gridx = 0; c.gridy = row;
732 c.fill = GridBagConstraints.NONE;
733 c.anchor = GridBagConstraints.LINE_START;
736 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
737 pane.add(flight_log_max_label, c);
739 c = new GridBagConstraints();
740 c.gridx = 4; c.gridy = row;
742 c.fill = GridBagConstraints.HORIZONTAL;
744 c.anchor = GridBagConstraints.LINE_START;
747 flight_log_max_value = new JComboBox<String>();
748 flight_log_max_value.setEditable(true);
749 flight_log_max_value.addItemListener(this);
750 pane.add(flight_log_max_value, c);
751 set_flight_log_max_tool_tip();
755 c = new GridBagConstraints();
756 c.gridx = 0; c.gridy = row;
758 c.fill = GridBagConstraints.NONE;
759 c.anchor = GridBagConstraints.LINE_START;
762 ignite_mode_label = new JLabel("Igniter Firing Mode:");
763 pane.add(ignite_mode_label, c);
765 c = new GridBagConstraints();
766 c.gridx = 4; c.gridy = row;
768 c.fill = GridBagConstraints.HORIZONTAL;
770 c.anchor = GridBagConstraints.LINE_START;
773 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
774 ignite_mode_value.setEditable(false);
775 ignite_mode_value.addItemListener(this);
776 pane.add(ignite_mode_value, c);
777 set_ignite_mode_tool_tip();
780 /* Pad orientation */
781 c = new GridBagConstraints();
782 c.gridx = 0; c.gridy = row;
784 c.fill = GridBagConstraints.NONE;
785 c.anchor = GridBagConstraints.LINE_START;
788 pad_orientation_label = new JLabel("Pad Orientation:");
789 pane.add(pad_orientation_label, c);
791 c = new GridBagConstraints();
792 c.gridx = 4; c.gridy = row;
794 c.fill = GridBagConstraints.HORIZONTAL;
796 c.anchor = GridBagConstraints.LINE_START;
800 pad_orientation_values = pad_orientation_values_radio;
801 else if (is_easytimer())
802 pad_orientation_values = pad_orientation_values_six_axis;
804 pad_orientation_values = pad_orientation_values_no_radio;
806 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
807 pad_orientation_value.setEditable(false);
808 pad_orientation_value.addItemListener(this);
809 pane.add(pad_orientation_value, c);
810 set_pad_orientation_tool_tip();
814 c = new GridBagConstraints();
815 c.gridx = 0; c.gridy = row;
817 c.fill = GridBagConstraints.NONE;
818 c.anchor = GridBagConstraints.LINE_START;
821 accel_plus_label = new JLabel("Accel Plus:");
822 pane.add(accel_plus_label, c);
824 c = new GridBagConstraints();
825 c.gridx = 4; c.gridy = row;
827 c.fill = GridBagConstraints.HORIZONTAL;
829 c.anchor = GridBagConstraints.LINE_START;
832 accel_plus_value = new JTextField(10);
833 accel_plus_value.setEditable(true);
834 accel_plus_value.getDocument().addDocumentListener(this);
835 pane.add(accel_plus_value, c);
839 c = new GridBagConstraints();
840 c.gridx = 0; c.gridy = row;
842 c.fill = GridBagConstraints.NONE;
843 c.anchor = GridBagConstraints.LINE_START;
846 accel_minus_label = new JLabel("Accel Minus:");
847 pane.add(accel_minus_label, c);
849 c = new GridBagConstraints();
850 c.gridx = 4; c.gridy = row;
852 c.fill = GridBagConstraints.HORIZONTAL;
854 c.anchor = GridBagConstraints.LINE_START;
857 accel_minus_value = new JTextField(10);
858 accel_minus_value.setEditable(true);
859 accel_minus_value.getDocument().addDocumentListener(this);
860 pane.add(accel_minus_value, c);
862 set_accel_tool_tips();
865 c = new GridBagConstraints();
866 c.gridx = 0; c.gridy = row;
868 c.fill = GridBagConstraints.NONE;
869 c.anchor = GridBagConstraints.LINE_START;
872 beep_label = new JLabel("Beeper Frequency:");
873 pane.add(beep_label, c);
875 c = new GridBagConstraints();
876 c.gridx = 4; c.gridy = row;
878 c.fill = GridBagConstraints.HORIZONTAL;
880 c.anchor = GridBagConstraints.LINE_START;
883 beep_value = new JComboBox<String>(beep_values);
884 beep_value.setEditable(true);
885 beep_value.addItemListener(this);
886 pane.add(beep_value, c);
890 /* Tracker triger horiz distances */
891 c = new GridBagConstraints();
892 c.gridx = 0; c.gridy = row;
894 c.fill = GridBagConstraints.NONE;
895 c.anchor = GridBagConstraints.LINE_START;
898 tracker_motion_label = new JLabel(get_tracker_motion_label());
899 pane.add(tracker_motion_label, c);
901 c = new GridBagConstraints();
902 c.gridx = 4; c.gridy = row;
904 c.fill = GridBagConstraints.HORIZONTAL;
906 c.anchor = GridBagConstraints.LINE_START;
909 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
910 tracker_motion_value.setEditable(true);
911 tracker_motion_value.addItemListener(this);
912 pane.add(tracker_motion_value, c);
915 /* Tracker triger vert distances */
916 c = new GridBagConstraints();
917 c.gridx = 0; c.gridy = row;
919 c.fill = GridBagConstraints.NONE;
920 c.anchor = GridBagConstraints.LINE_START;
923 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
924 pane.add(tracker_interval_label, c);
926 c = new GridBagConstraints();
927 c.gridx = 4; c.gridy = row;
929 c.fill = GridBagConstraints.HORIZONTAL;
931 c.anchor = GridBagConstraints.LINE_START;
934 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
935 tracker_interval_value.setEditable(true);
936 tracker_interval_value.addItemListener(this);
937 pane.add(tracker_interval_value, c);
938 set_tracker_tool_tip();
942 c = new GridBagConstraints();
943 c.gridx = 4; c.gridy = row;
945 c.fill = GridBagConstraints.HORIZONTAL;
946 c.anchor = GridBagConstraints.LINE_START;
949 pyro = new JButton("Configure Pyro Channels");
951 pyro.addActionListener(this);
952 pyro.setActionCommand("Pyro");
956 c = new GridBagConstraints();
957 c.gridx = 5; c.gridy = row;
959 c.fill = GridBagConstraints.HORIZONTAL;
960 c.anchor = GridBagConstraints.LINE_START;
963 accel_cal = new JButton("Calibrate Accelerometer");
964 pane.add(accel_cal, c);
965 accel_cal.addActionListener(this);
966 accel_cal.setActionCommand("Accel");
970 c = new GridBagConstraints();
971 c.gridx = 0; c.gridy = row;
973 c.fill = GridBagConstraints.NONE;
974 c.anchor = GridBagConstraints.LINE_START;
976 save = new JButton("Save");
978 save.addActionListener(this);
979 save.setActionCommand("Save");
981 c = new GridBagConstraints();
982 c.gridx = 2; c.gridy = row;
984 c.fill = GridBagConstraints.NONE;
985 c.anchor = GridBagConstraints.CENTER;
987 reset = new JButton("Reset");
989 reset.addActionListener(this);
990 reset.setActionCommand("Reset");
992 c = new GridBagConstraints();
993 c.gridx = 4; c.gridy = row;
995 c.fill = GridBagConstraints.NONE;
996 c.anchor = GridBagConstraints.CENTER;
998 reboot = new JButton("Reboot");
1000 reboot.addActionListener(this);
1001 reboot.setActionCommand("Reboot");
1003 c = new GridBagConstraints();
1004 c.gridx = 6; c.gridy = row;
1006 c.fill = GridBagConstraints.NONE;
1007 c.anchor = GridBagConstraints.LINE_END;
1009 close = new JButton("Close");
1011 close.addActionListener(this);
1012 close.setActionCommand("Close");
1014 addWindowListener(new ConfigListener(this));
1015 AltosPreferences.register_units_listener(this);
1018 /* Once the initial values are set, the config code will show the dialog */
1019 public void make_visible() {
1021 setLocationRelativeTo(owner);
1025 /* If any values have been changed, confirm before closing */
1026 public boolean check_dirty(String operation) {
1028 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
1030 i = JOptionPane.showOptionDialog(this,
1031 String.format("Configuration modified. %s anyway?", operation),
1032 "Configuration Modified",
1033 JOptionPane.DEFAULT_OPTION,
1034 JOptionPane.WARNING_MESSAGE,
1035 null, options, options[1]);
1042 public void set_dirty() {
1044 save.setEnabled(true);
1047 public void set_clean() {
1049 save.setEnabled(false);
1052 AltosConfigPyroUI pyro_ui;
1054 public void dispose() {
1055 if (pyro_ui != null)
1057 AltosPreferences.unregister_units_listener(this);
1061 /* Listen for events from our buttons */
1062 public void actionPerformed(ActionEvent e) {
1063 String cmd = e.getActionCommand();
1065 if (cmd.equals("Pyro")) {
1066 if (pyro_ui == null && pyros != null)
1067 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
1068 if (pyro_ui != null)
1069 pyro_ui.make_visible();
1073 if (cmd.equals("Close") || cmd.equals("Reboot"))
1074 if (!check_dirty(cmd))
1076 listener.actionPerformed(e);
1077 if (cmd.equals("Close") || cmd.equals("Reboot")) {
1081 if (cmd.equals("Save") || cmd.equals("Reset"))
1085 /* ItemListener interface method */
1086 public void itemStateChanged(ItemEvent e) {
1090 /* DocumentListener interface methods */
1091 public void changedUpdate(DocumentEvent e) {
1095 public void insertUpdate(DocumentEvent e) {
1099 public void removeUpdate(DocumentEvent e) {
1103 /* Let the config code hook on a listener */
1104 public void addActionListener(ActionListener l) {
1108 /* set and get all of the dialog values */
1109 public void set_product(String product) {
1110 radio_frequency_value.set_product(product);
1111 product_value.setText(product);
1112 set_pad_orientation_tool_tip();
1113 set_accel_tool_tips();
1114 set_flight_log_max_tool_tip();
1117 public void set_version(String version) {
1118 version_value.setText(version);
1121 public void set_serial(int serial) {
1122 radio_frequency_value.set_serial(serial);
1123 serial_value.setText(String.format("%d", serial));
1126 public void set_altitude_32(int altitude_32) {
1129 public void set_main_deploy(int new_main_deploy) {
1130 if (new_main_deploy != AltosLib.MISSING)
1131 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
1132 main_deploy_value.setVisible(new_main_deploy != AltosLib.MISSING);
1133 main_deploy_label.setVisible(new_main_deploy != AltosLib.MISSING);
1136 public int main_deploy() throws AltosConfigDataException {
1137 String str = main_deploy_value.getSelectedItem().toString();
1139 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1140 } catch (ParseException pe) {
1141 throw new AltosConfigDataException("invalid main deploy height %s", str);
1145 String get_main_deploy_label() {
1146 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.parse_units());
1149 String[] main_deploy_values() {
1150 if (AltosConvert.imperial_units)
1151 return main_deploy_values_ft;
1153 return main_deploy_values_m;
1156 void set_main_deploy_values() {
1157 String[] v = main_deploy_values();
1158 while (main_deploy_value.getItemCount() > 0)
1159 main_deploy_value.removeItemAt(0);
1160 for (int i = 0; i < v.length; i++)
1161 main_deploy_value.addItem(v[i]);
1162 main_deploy_value.setMaximumRowCount(v.length);
1165 public void units_changed(boolean imperial_units) {
1166 boolean was_dirty = dirty;
1168 String v = main_deploy_value.getSelectedItem().toString();
1169 main_deploy_label.setText(get_main_deploy_label());
1170 set_main_deploy_values();
1172 int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1174 } catch (ParseException pe) {
1177 if (tracker_motion_value.isVisible()) {
1178 String motion = tracker_motion_value.getSelectedItem().toString();
1179 tracker_motion_label.setText(get_tracker_motion_label());
1180 set_tracker_motion_values();
1182 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1183 set_tracker_motion(m);
1184 } catch (ParseException pe) {
1192 public void set_apogee_delay(int new_apogee_delay) {
1193 if (new_apogee_delay != AltosLib.MISSING)
1194 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1195 apogee_delay_value.setVisible(new_apogee_delay != AltosLib.MISSING);
1196 apogee_delay_label.setVisible(new_apogee_delay != AltosLib.MISSING);
1199 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1202 v = s.split("\\s+")[0];
1204 return Integer.parseInt(v);
1205 } catch (NumberFormatException ne) {
1206 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1210 public int apogee_delay() throws AltosConfigDataException {
1211 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1214 public void set_apogee_lockout(int new_apogee_lockout) {
1215 if (new_apogee_lockout != AltosLib.MISSING)
1216 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1218 apogee_lockout_value.setVisible(new_apogee_lockout != AltosLib.MISSING);
1219 apogee_lockout_label.setVisible(new_apogee_lockout != AltosLib.MISSING);
1222 public int apogee_lockout() throws AltosConfigDataException {
1223 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1226 public void set_radio_frequency(double new_radio_frequency) {
1227 if (new_radio_frequency != AltosLib.MISSING)
1228 radio_frequency_value.set_frequency(new_radio_frequency);
1229 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
1230 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
1233 public double radio_frequency() {
1234 return radio_frequency_value.frequency();
1237 public void set_radio_calibration(int new_radio_calibration) {
1238 if (new_radio_calibration != AltosLib.MISSING)
1239 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1240 radio_calibration_value.setVisible(new_radio_calibration != AltosLib.MISSING);
1241 radio_calibration_label.setVisible(new_radio_calibration != AltosLib.MISSING);
1244 public void set_radio_enable(int new_radio_enable) {
1245 if (new_radio_enable != AltosLib.MISSING)
1246 radio_enable_value.setSelected(new_radio_enable != 0);
1247 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
1248 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
1249 set_radio_enable_tool_tip();
1252 public int radio_enable() {
1253 if (radio_enable_value.isVisible())
1254 return radio_enable_value.isSelected() ? 1 : 0;
1256 return AltosLib.MISSING;
1259 public void set_telemetry_rate(int new_rate) {
1260 if (new_rate != AltosLib.MISSING)
1261 rate_value.set_rate(new_rate);
1262 rate_label.setVisible(new_rate != AltosLib.MISSING);
1263 rate_value.setVisible(new_rate != AltosLib.MISSING);
1264 set_rate_tool_tip();
1267 public int telemetry_rate() {
1268 return rate_value.rate();
1271 public void set_callsign(String new_callsign) {
1272 if (new_callsign != null)
1273 callsign_value.setText(new_callsign);
1274 callsign_value.setVisible(new_callsign != null);
1275 callsign_label.setVisible(new_callsign != null);
1278 public String callsign() {
1279 if (callsign_value.isVisible())
1280 return callsign_value.getText();
1284 int flight_log_max_limit;
1287 public String flight_log_max_label(int flight_log_max) {
1288 if (flight_log_max_limit != 0) {
1289 int nflight = flight_log_max_limit / flight_log_max;
1290 String plural = nflight > 1 ? "s" : "";
1292 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1294 return String.format("%d", flight_log_max);
1297 public void set_flight_log_max(int new_flight_log_max) {
1298 if (new_flight_log_max != AltosLib.MISSING) {
1299 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1300 flight_log_max = new_flight_log_max;
1302 flight_log_max_value.setVisible(new_flight_log_max != AltosLib.MISSING);
1303 flight_log_max_label.setVisible(new_flight_log_max != AltosLib.MISSING);
1304 set_flight_log_max_tool_tip();
1307 public void set_flight_log_max_enabled(boolean enable) {
1308 flight_log_max_value.setEnabled(enable);
1309 set_flight_log_max_tool_tip();
1312 public int flight_log_max() throws AltosConfigDataException {
1313 if (flight_log_max_value.isVisible())
1314 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1315 return AltosLib.MISSING;
1318 public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
1319 flight_log_max_limit = new_flight_log_max_limit;
1320 if (new_flight_log_max_limit != AltosLib.MISSING) {
1321 flight_log_max_value.removeAllItems();
1322 for (int i = 8; i >= 1; i--) {
1323 int size = flight_log_max_limit / i;
1324 if (new_storage_erase_unit != 0)
1325 size &= ~(new_storage_erase_unit - 1);
1326 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1329 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
1330 set_flight_log_max(flight_log_max);
1333 public void set_ignite_mode(int new_ignite_mode) {
1334 if (new_ignite_mode != AltosLib.MISSING) {
1335 if (new_ignite_mode >= ignite_mode_values.length)
1336 new_ignite_mode = 0;
1337 if (new_ignite_mode < 0) {
1338 ignite_mode_value.setEnabled(false);
1339 new_ignite_mode = 0;
1341 ignite_mode_value.setEnabled(true);
1343 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1345 ignite_mode_value.setVisible(new_ignite_mode != AltosLib.MISSING);
1346 ignite_mode_label.setVisible(new_ignite_mode != AltosLib.MISSING);
1348 set_ignite_mode_tool_tip();
1351 public int ignite_mode() {
1352 if (ignite_mode_value.isVisible())
1353 return ignite_mode_value.getSelectedIndex();
1355 return AltosLib.MISSING;
1359 public void set_pad_orientation(int new_pad_orientation) {
1360 if (new_pad_orientation != AltosLib.MISSING) {
1361 if (new_pad_orientation >= pad_orientation_values.length)
1362 new_pad_orientation = 0;
1363 if (new_pad_orientation < 0)
1364 new_pad_orientation = 0;
1365 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1367 pad_orientation_value.setVisible(new_pad_orientation != AltosLib.MISSING);
1368 pad_orientation_label.setVisible(new_pad_orientation != AltosLib.MISSING);
1369 accel_cal.setVisible(new_pad_orientation != AltosLib.MISSING);
1371 set_pad_orientation_tool_tip();
1374 public int pad_orientation() {
1375 if (pad_orientation_value.isVisible())
1376 return pad_orientation_value.getSelectedIndex();
1378 return AltosLib.MISSING;
1381 public void set_accel_cal(int accel_plus, int accel_minus) {
1382 if (accel_plus != AltosLib.MISSING) {
1383 accel_plus_value.setText(String.format("%d", accel_plus));
1384 accel_minus_value.setText(String.format("%d", accel_minus));
1386 accel_plus_value.setVisible(accel_plus != AltosLib.MISSING);
1387 accel_plus_label.setVisible(accel_plus != AltosLib.MISSING);
1388 accel_minus_value.setVisible(accel_minus != AltosLib.MISSING);
1389 accel_minus_label.setVisible(accel_minus != AltosLib.MISSING);
1391 set_accel_tool_tips();
1394 public int accel_cal_plus() {
1395 if (accel_plus_value.isVisible())
1396 return Integer.parseInt(accel_plus_value.getText());
1397 return AltosLib.MISSING;
1400 public int accel_cal_minus() {
1401 if (accel_minus_value.isVisible())
1402 return Integer.parseInt(accel_minus_value.getText());
1403 return AltosLib.MISSING;
1406 public void set_beep(int new_beep) {
1407 if (new_beep != AltosLib.MISSING) {
1408 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1409 for (int i = 0; i < beep_values.length; i++)
1410 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1411 beep_value.setSelectedIndex(i);
1412 set_beep_tool_tip();
1415 beep_value.setSelectedItem(String.format("%d", new_freq));
1417 beep_value.setVisible(new_beep != AltosLib.MISSING);
1418 beep_label.setVisible(new_beep != AltosLib.MISSING);
1419 set_beep_tool_tip();
1423 if (beep_value.isVisible())
1424 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1426 return AltosLib.MISSING;
1429 String[] tracker_motion_values() {
1430 if (AltosConvert.imperial_units)
1431 return tracker_motion_values_ft;
1433 return tracker_motion_values_m;
1436 void set_tracker_motion_values() {
1437 String[] v = tracker_motion_values();
1438 while (tracker_motion_value.getItemCount() > 0)
1439 tracker_motion_value.removeItemAt(0);
1440 for (int i = 0; i < v.length; i++)
1441 tracker_motion_value.addItem(v[i]);
1442 tracker_motion_value.setMaximumRowCount(v.length);
1445 String get_tracker_motion_label() {
1446 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1449 void set_tracker_tool_tip() {
1450 if (tracker_motion_value.isVisible())
1451 tracker_motion_value.setToolTipText("How far the device must move before logging");
1453 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1454 if (tracker_interval_value.isVisible())
1455 tracker_interval_value.setToolTipText("How often to report GPS position");
1457 tracker_interval_value.setToolTipText("This device can't configure interval");
1460 public void set_tracker_motion(int tracker_motion) {
1461 if (tracker_motion != AltosLib.MISSING)
1462 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1463 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1464 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1467 public int tracker_motion() throws AltosConfigDataException {
1468 if (tracker_motion_value.isVisible()) {
1469 String str = tracker_motion_value.getSelectedItem().toString();
1471 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1472 } catch (ParseException pe) {
1473 throw new AltosConfigDataException("invalid tracker motion %s", str);
1476 return AltosLib.MISSING;
1479 public void set_tracker_interval(int tracker_interval) {
1480 if (tracker_interval != AltosLib.MISSING)
1481 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1482 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1483 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1486 public int tracker_interval() throws AltosConfigDataException {
1487 if (tracker_interval_value.isVisible())
1488 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1489 return AltosLib.MISSING;
1492 public void set_pyros(AltosPyro[] new_pyros) {
1494 if (pyros != null && pyro_ui != null)
1495 pyro_ui.set_pyros(pyros);
1496 pyro.setVisible(pyros != null);
1499 public AltosPyro[] pyros() throws AltosConfigDataException {
1500 if (pyro_ui != null)
1501 pyros = pyro_ui.get_pyros();
1505 public void set_pyro_firing_time(double new_pyro_firing_time) {
1506 pyro_firing_time = new_pyro_firing_time;
1507 if (pyro_firing_time != AltosLib.MISSING && pyro_ui != null)
1508 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1509 pyro.setVisible(pyro_firing_time != AltosLib.MISSING);
1512 public double pyro_firing_time() throws AltosConfigDataException {
1513 if (pyro_ui != null)
1514 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1515 return pyro_firing_time;
1518 private String aprs_interval_string(int interval) {
1521 return Integer.toString(interval);
1524 private int aprs_interval_value(String interval) throws AltosConfigDataException {
1525 if (interval.equalsIgnoreCase("Disabled"))
1527 return parse_int("aprs interval", interval, false);
1530 public void set_aprs_interval(int new_aprs_interval) {
1531 if (new_aprs_interval != AltosLib.MISSING)
1532 aprs_interval_value.setSelectedItem(aprs_interval_string(new_aprs_interval));
1533 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1534 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1535 set_aprs_interval_tool_tip();
1538 public int aprs_interval() throws AltosConfigDataException {
1539 if (aprs_interval_value.isVisible())
1540 return aprs_interval_value(aprs_interval_value.getSelectedItem().toString());
1541 return AltosLib.MISSING;
1544 public void set_aprs_ssid(int new_aprs_ssid) {
1545 if (new_aprs_ssid != AltosLib.MISSING)
1546 aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1547 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1548 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1549 set_aprs_ssid_tool_tip();
1552 public int aprs_ssid() throws AltosConfigDataException {
1553 if (aprs_ssid_value.isVisible()) {
1554 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1557 return AltosLib.MISSING;
1560 public void set_aprs_format(int new_aprs_format) {
1561 if (new_aprs_format != AltosLib.MISSING)
1562 aprs_format_value.setSelectedIndex(new_aprs_format);
1563 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1564 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1565 set_aprs_format_tool_tip();
1568 public int aprs_format() throws AltosConfigDataException {
1569 if (aprs_format_value.isVisible())
1570 return aprs_format_value.getSelectedIndex();
1571 return AltosLib.MISSING;
1574 public void set_aprs_offset(int new_aprs_offset) {
1575 if (new_aprs_offset != AltosLib.MISSING)
1576 aprs_offset_value.setSelectedItem(new_aprs_offset);
1577 aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
1578 aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
1579 set_aprs_offset_tool_tip();
1582 public int aprs_offset() throws AltosConfigDataException {
1583 if (aprs_offset_value.isVisible()) {
1584 Integer i = (Integer) aprs_offset_value.getSelectedItem();
1587 return AltosLib.MISSING;