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_accel_tool_tips() {
315 if (accel_plus_value.isVisible()) {
316 accel_plus_value.setToolTipText("Pad acceleration value in flight orientation");
317 accel_minus_value.setToolTipText("Upside-down acceleration value");
319 accel_plus_value.setToolTipText("No accelerometer");
320 accel_minus_value.setToolTipText("No accelerometer");
324 void set_beep_tool_tip() {
325 if (beep_value.isVisible())
326 beep_value.setToolTipText("What frequency the beeper will sound at");
328 beep_value.setToolTipText("Older firmware could not select beeper frequency");
331 /* Build the UI using a grid bag */
332 public AltosConfigFCUI(JFrame in_owner, boolean remote) {
333 super (in_owner, "Configure Flight Computer", false);
336 GridBagConstraints c;
339 Insets il = new Insets(4,4,4,4);
340 Insets ir = new Insets(4,4,4,4);
342 pane = getContentPane();
343 pane.setLayout(new GridBagLayout());
346 c = new GridBagConstraints();
347 c.gridx = 0; c.gridy = row;
349 c.fill = GridBagConstraints.NONE;
350 c.anchor = GridBagConstraints.LINE_START;
352 product_label = new JLabel("Product:");
353 pane.add(product_label, c);
355 c = new GridBagConstraints();
356 c.gridx = 4; c.gridy = row;
358 c.fill = GridBagConstraints.HORIZONTAL;
360 c.anchor = GridBagConstraints.LINE_START;
362 product_value = new JLabel("");
363 pane.add(product_value, c);
367 c = new GridBagConstraints();
368 c.gridx = 0; c.gridy = row;
370 c.fill = GridBagConstraints.NONE;
371 c.anchor = GridBagConstraints.LINE_START;
374 version_label = new JLabel("Software version:");
375 pane.add(version_label, c);
377 c = new GridBagConstraints();
378 c.gridx = 4; c.gridy = row;
380 c.fill = GridBagConstraints.HORIZONTAL;
382 c.anchor = GridBagConstraints.LINE_START;
385 version_value = new JLabel("");
386 pane.add(version_value, c);
390 c = new GridBagConstraints();
391 c.gridx = 0; c.gridy = row;
393 c.fill = GridBagConstraints.NONE;
394 c.anchor = GridBagConstraints.LINE_START;
397 serial_label = new JLabel("Serial:");
398 pane.add(serial_label, c);
400 c = new GridBagConstraints();
401 c.gridx = 4; c.gridy = row;
403 c.fill = GridBagConstraints.HORIZONTAL;
405 c.anchor = GridBagConstraints.LINE_START;
408 serial_value = new JLabel("");
409 pane.add(serial_value, c);
413 c = new GridBagConstraints();
414 c.gridx = 0; c.gridy = row;
416 c.fill = GridBagConstraints.NONE;
417 c.anchor = GridBagConstraints.LINE_START;
420 main_deploy_label = new JLabel(get_main_deploy_label());
421 pane.add(main_deploy_label, c);
423 c = new GridBagConstraints();
424 c.gridx = 4; c.gridy = row;
426 c.fill = GridBagConstraints.HORIZONTAL;
428 c.anchor = GridBagConstraints.LINE_START;
431 main_deploy_value = new JComboBox<String>(main_deploy_values());
432 main_deploy_value.setEditable(true);
433 main_deploy_value.addItemListener(this);
434 pane.add(main_deploy_value, c);
435 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
439 c = new GridBagConstraints();
440 c.gridx = 0; c.gridy = row;
442 c.fill = GridBagConstraints.NONE;
443 c.anchor = GridBagConstraints.LINE_START;
446 apogee_delay_label = new JLabel("Apogee Delay(s):");
447 pane.add(apogee_delay_label, c);
449 c = new GridBagConstraints();
450 c.gridx = 4; c.gridy = row;
452 c.fill = GridBagConstraints.HORIZONTAL;
454 c.anchor = GridBagConstraints.LINE_START;
457 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
458 apogee_delay_value.setEditable(true);
459 apogee_delay_value.addItemListener(this);
460 pane.add(apogee_delay_value, c);
461 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
465 c = new GridBagConstraints();
466 c.gridx = 0; c.gridy = row;
468 c.fill = GridBagConstraints.NONE;
469 c.anchor = GridBagConstraints.LINE_START;
472 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
473 pane.add(apogee_lockout_label, c);
475 c = new GridBagConstraints();
476 c.gridx = 4; c.gridy = row;
478 c.fill = GridBagConstraints.HORIZONTAL;
480 c.anchor = GridBagConstraints.LINE_START;
483 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
484 apogee_lockout_value.setEditable(true);
485 apogee_lockout_value.addItemListener(this);
486 pane.add(apogee_lockout_value, c);
487 apogee_lockout_value.setToolTipText("Time after launch while apogee detection is locked out");
491 c = new GridBagConstraints();
492 c.gridx = 0; c.gridy = row;
494 c.fill = GridBagConstraints.NONE;
495 c.anchor = GridBagConstraints.LINE_START;
498 radio_frequency_label = new JLabel("Frequency:");
499 pane.add(radio_frequency_label, c);
501 c = new GridBagConstraints();
502 c.gridx = 4; c.gridy = row;
504 c.fill = GridBagConstraints.HORIZONTAL;
506 c.anchor = GridBagConstraints.LINE_START;
509 radio_frequency_value = new AltosUIFreqList();
510 radio_frequency_value.addItemListener(this);
511 pane.add(radio_frequency_value, c);
512 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
515 /* Radio Calibration */
516 c = new GridBagConstraints();
517 c.gridx = 0; c.gridy = row;
519 c.fill = GridBagConstraints.NONE;
520 c.anchor = GridBagConstraints.LINE_START;
523 radio_calibration_label = new JLabel("RF Calibration:");
524 pane.add(radio_calibration_label, c);
526 c = new GridBagConstraints();
527 c.gridx = 4; c.gridy = row;
529 c.fill = GridBagConstraints.HORIZONTAL;
531 c.anchor = GridBagConstraints.LINE_START;
534 radio_calibration_value = new JLabel(String.format("%d", 1186611));
535 pane.add(radio_calibration_value, c);
539 c = new GridBagConstraints();
540 c.gridx = 0; c.gridy = row;
542 c.fill = GridBagConstraints.NONE;
543 c.anchor = GridBagConstraints.LINE_START;
546 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
547 pane.add(radio_enable_label, c);
549 c = new GridBagConstraints();
550 c.gridx = 4; c.gridy = row;
552 c.fill = GridBagConstraints.HORIZONTAL;
554 c.anchor = GridBagConstraints.LINE_START;
557 radio_enable_value = new JRadioButton("Enabled");
558 radio_enable_value.addItemListener(this);
559 pane.add(radio_enable_value, c);
560 set_radio_enable_tool_tip();
564 c = new GridBagConstraints();
565 c.gridx = 0; c.gridy = row;
567 c.fill = GridBagConstraints.NONE;
568 c.anchor = GridBagConstraints.LINE_START;
571 rate_label = new JLabel("Telemetry baud rate:");
572 pane.add(rate_label, c);
574 c = new GridBagConstraints();
575 c.gridx = 4; c.gridy = row;
577 c.fill = GridBagConstraints.HORIZONTAL;
579 c.anchor = GridBagConstraints.LINE_START;
582 rate_value = new AltosUIRateList();
583 rate_value.addItemListener(this);
584 pane.add(rate_value, c);
589 c = new GridBagConstraints();
590 c.gridx = 0; c.gridy = row;
592 c.fill = GridBagConstraints.NONE;
593 c.anchor = GridBagConstraints.LINE_START;
596 aprs_interval_label = new JLabel("APRS Interval(s):");
597 pane.add(aprs_interval_label, c);
599 c = new GridBagConstraints();
600 c.gridx = 4; c.gridy = row;
602 c.fill = GridBagConstraints.HORIZONTAL;
604 c.anchor = GridBagConstraints.LINE_START;
607 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
608 aprs_interval_value.setEditable(true);
609 aprs_interval_value.addItemListener(this);
610 pane.add(aprs_interval_value, c);
611 set_aprs_interval_tool_tip();
615 c = new GridBagConstraints();
616 c.gridx = 0; c.gridy = row;
618 c.fill = GridBagConstraints.NONE;
619 c.anchor = GridBagConstraints.LINE_START;
622 aprs_ssid_label = new JLabel("APRS SSID:");
623 pane.add(aprs_ssid_label, c);
625 c = new GridBagConstraints();
626 c.gridx = 4; c.gridy = row;
628 c.fill = GridBagConstraints.HORIZONTAL;
630 c.anchor = GridBagConstraints.LINE_START;
633 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
634 aprs_ssid_value.setEditable(false);
635 aprs_ssid_value.addItemListener(this);
636 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
637 pane.add(aprs_ssid_value, c);
638 set_aprs_ssid_tool_tip();
642 c = new GridBagConstraints();
643 c.gridx = 0; c.gridy = row;
645 c.fill = GridBagConstraints.NONE;
646 c.anchor = GridBagConstraints.LINE_START;
649 aprs_format_label = new JLabel("APRS format:");
650 pane.add(aprs_format_label, c);
652 c = new GridBagConstraints();
653 c.gridx = 4; c.gridy = row;
655 c.fill = GridBagConstraints.HORIZONTAL;
657 c.anchor = GridBagConstraints.LINE_START;
660 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
661 aprs_format_value.setEditable(false);
662 aprs_format_value.addItemListener(this);
663 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
664 pane.add(aprs_format_value, c);
665 set_aprs_format_tool_tip();
669 c = new GridBagConstraints();
670 c.gridx = 0; c.gridy = row;
672 c.fill = GridBagConstraints.NONE;
673 c.anchor = GridBagConstraints.LINE_START;
676 aprs_offset_label = new JLabel("APRS offset:");
677 pane.add(aprs_offset_label, c);
679 c = new GridBagConstraints();
680 c.gridx = 4; c.gridy = row;
682 c.fill = GridBagConstraints.HORIZONTAL;
684 c.anchor = GridBagConstraints.LINE_START;
687 aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
688 aprs_offset_value.setEditable(false);
689 aprs_offset_value.addItemListener(this);
690 aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
691 pane.add(aprs_offset_value, c);
692 set_aprs_offset_tool_tip();
696 c = new GridBagConstraints();
697 c.gridx = 0; c.gridy = row;
699 c.fill = GridBagConstraints.NONE;
700 c.anchor = GridBagConstraints.LINE_START;
703 callsign_label = new JLabel("Callsign:");
704 pane.add(callsign_label, c);
706 c = new GridBagConstraints();
707 c.gridx = 4; c.gridy = row;
709 c.fill = GridBagConstraints.HORIZONTAL;
711 c.anchor = GridBagConstraints.LINE_START;
714 callsign_value = new JTextField(AltosUIPreferences.callsign());
715 callsign_value.getDocument().addDocumentListener(this);
716 pane.add(callsign_value, c);
717 callsign_value.setToolTipText("Callsign reported in telemetry data");
721 c = new GridBagConstraints();
722 c.gridx = 0; c.gridy = row;
724 c.fill = GridBagConstraints.NONE;
725 c.anchor = GridBagConstraints.LINE_START;
728 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
729 pane.add(flight_log_max_label, c);
731 c = new GridBagConstraints();
732 c.gridx = 4; c.gridy = row;
734 c.fill = GridBagConstraints.HORIZONTAL;
736 c.anchor = GridBagConstraints.LINE_START;
739 flight_log_max_value = new JComboBox<String>();
740 flight_log_max_value.setEditable(true);
741 flight_log_max_value.addItemListener(this);
742 pane.add(flight_log_max_value, c);
743 set_flight_log_max_tool_tip();
747 c = new GridBagConstraints();
748 c.gridx = 0; c.gridy = row;
750 c.fill = GridBagConstraints.NONE;
751 c.anchor = GridBagConstraints.LINE_START;
754 ignite_mode_label = new JLabel("Igniter Firing Mode:");
755 pane.add(ignite_mode_label, c);
757 c = new GridBagConstraints();
758 c.gridx = 4; c.gridy = row;
760 c.fill = GridBagConstraints.HORIZONTAL;
762 c.anchor = GridBagConstraints.LINE_START;
765 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
766 ignite_mode_value.setEditable(false);
767 ignite_mode_value.addItemListener(this);
768 pane.add(ignite_mode_value, c);
769 set_ignite_mode_tool_tip();
772 /* Pad orientation */
773 c = new GridBagConstraints();
774 c.gridx = 0; c.gridy = row;
776 c.fill = GridBagConstraints.NONE;
777 c.anchor = GridBagConstraints.LINE_START;
780 pad_orientation_label = new JLabel("Pad Orientation:");
781 pane.add(pad_orientation_label, c);
783 c = new GridBagConstraints();
784 c.gridx = 4; c.gridy = row;
786 c.fill = GridBagConstraints.HORIZONTAL;
788 c.anchor = GridBagConstraints.LINE_START;
792 pad_orientation_values = pad_orientation_values_radio;
794 pad_orientation_values = pad_orientation_values_no_radio;
796 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
797 pad_orientation_value.setEditable(false);
798 pad_orientation_value.addItemListener(this);
799 pane.add(pad_orientation_value, c);
800 set_pad_orientation_tool_tip();
804 c = new GridBagConstraints();
805 c.gridx = 0; c.gridy = row;
807 c.fill = GridBagConstraints.NONE;
808 c.anchor = GridBagConstraints.LINE_START;
811 accel_plus_label = new JLabel("Accel Plus:");
812 pane.add(accel_plus_label, c);
814 c = new GridBagConstraints();
815 c.gridx = 4; c.gridy = row;
817 c.fill = GridBagConstraints.HORIZONTAL;
819 c.anchor = GridBagConstraints.LINE_START;
822 accel_plus_value = new JTextField(10);
823 accel_plus_value.setEditable(true);
824 accel_plus_value.getDocument().addDocumentListener(this);
825 pane.add(accel_plus_value, c);
829 c = new GridBagConstraints();
830 c.gridx = 0; c.gridy = row;
832 c.fill = GridBagConstraints.NONE;
833 c.anchor = GridBagConstraints.LINE_START;
836 accel_minus_label = new JLabel("Accel Minus:");
837 pane.add(accel_minus_label, c);
839 c = new GridBagConstraints();
840 c.gridx = 4; c.gridy = row;
842 c.fill = GridBagConstraints.HORIZONTAL;
844 c.anchor = GridBagConstraints.LINE_START;
847 accel_minus_value = new JTextField(10);
848 accel_minus_value.setEditable(true);
849 accel_minus_value.getDocument().addDocumentListener(this);
850 pane.add(accel_minus_value, c);
852 set_accel_tool_tips();
855 c = new GridBagConstraints();
856 c.gridx = 0; c.gridy = row;
858 c.fill = GridBagConstraints.NONE;
859 c.anchor = GridBagConstraints.LINE_START;
862 beep_label = new JLabel("Beeper Frequency:");
863 pane.add(beep_label, c);
865 c = new GridBagConstraints();
866 c.gridx = 4; c.gridy = row;
868 c.fill = GridBagConstraints.HORIZONTAL;
870 c.anchor = GridBagConstraints.LINE_START;
873 beep_value = new JComboBox<String>(beep_values);
874 beep_value.setEditable(true);
875 beep_value.addItemListener(this);
876 pane.add(beep_value, c);
880 /* Tracker triger horiz distances */
881 c = new GridBagConstraints();
882 c.gridx = 0; c.gridy = row;
884 c.fill = GridBagConstraints.NONE;
885 c.anchor = GridBagConstraints.LINE_START;
888 tracker_motion_label = new JLabel(get_tracker_motion_label());
889 pane.add(tracker_motion_label, c);
891 c = new GridBagConstraints();
892 c.gridx = 4; c.gridy = row;
894 c.fill = GridBagConstraints.HORIZONTAL;
896 c.anchor = GridBagConstraints.LINE_START;
899 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
900 tracker_motion_value.setEditable(true);
901 tracker_motion_value.addItemListener(this);
902 pane.add(tracker_motion_value, c);
905 /* Tracker triger vert distances */
906 c = new GridBagConstraints();
907 c.gridx = 0; c.gridy = row;
909 c.fill = GridBagConstraints.NONE;
910 c.anchor = GridBagConstraints.LINE_START;
913 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
914 pane.add(tracker_interval_label, c);
916 c = new GridBagConstraints();
917 c.gridx = 4; c.gridy = row;
919 c.fill = GridBagConstraints.HORIZONTAL;
921 c.anchor = GridBagConstraints.LINE_START;
924 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
925 tracker_interval_value.setEditable(true);
926 tracker_interval_value.addItemListener(this);
927 pane.add(tracker_interval_value, c);
928 set_tracker_tool_tip();
932 c = new GridBagConstraints();
933 c.gridx = 4; c.gridy = row;
935 c.fill = GridBagConstraints.HORIZONTAL;
936 c.anchor = GridBagConstraints.LINE_START;
939 pyro = new JButton("Configure Pyro Channels");
941 pyro.addActionListener(this);
942 pyro.setActionCommand("Pyro");
946 c = new GridBagConstraints();
947 c.gridx = 5; c.gridy = row;
949 c.fill = GridBagConstraints.HORIZONTAL;
950 c.anchor = GridBagConstraints.LINE_START;
953 accel_cal = new JButton("Calibrate Accelerometer");
954 pane.add(accel_cal, c);
955 accel_cal.addActionListener(this);
956 accel_cal.setActionCommand("Accel");
960 c = new GridBagConstraints();
961 c.gridx = 0; c.gridy = row;
963 c.fill = GridBagConstraints.NONE;
964 c.anchor = GridBagConstraints.LINE_START;
966 save = new JButton("Save");
968 save.addActionListener(this);
969 save.setActionCommand("Save");
971 c = new GridBagConstraints();
972 c.gridx = 2; c.gridy = row;
974 c.fill = GridBagConstraints.NONE;
975 c.anchor = GridBagConstraints.CENTER;
977 reset = new JButton("Reset");
979 reset.addActionListener(this);
980 reset.setActionCommand("Reset");
982 c = new GridBagConstraints();
983 c.gridx = 4; c.gridy = row;
985 c.fill = GridBagConstraints.NONE;
986 c.anchor = GridBagConstraints.CENTER;
988 reboot = new JButton("Reboot");
990 reboot.addActionListener(this);
991 reboot.setActionCommand("Reboot");
993 c = new GridBagConstraints();
994 c.gridx = 6; c.gridy = row;
996 c.fill = GridBagConstraints.NONE;
997 c.anchor = GridBagConstraints.LINE_END;
999 close = new JButton("Close");
1001 close.addActionListener(this);
1002 close.setActionCommand("Close");
1004 addWindowListener(new ConfigListener(this));
1005 AltosPreferences.register_units_listener(this);
1008 /* Once the initial values are set, the config code will show the dialog */
1009 public void make_visible() {
1011 setLocationRelativeTo(owner);
1015 /* If any values have been changed, confirm before closing */
1016 public boolean check_dirty(String operation) {
1018 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
1020 i = JOptionPane.showOptionDialog(this,
1021 String.format("Configuration modified. %s anyway?", operation),
1022 "Configuration Modified",
1023 JOptionPane.DEFAULT_OPTION,
1024 JOptionPane.WARNING_MESSAGE,
1025 null, options, options[1]);
1032 public void set_dirty() {
1034 save.setEnabled(true);
1037 public void set_clean() {
1039 save.setEnabled(false);
1042 AltosConfigPyroUI pyro_ui;
1044 public void dispose() {
1045 if (pyro_ui != null)
1047 AltosPreferences.unregister_units_listener(this);
1051 /* Listen for events from our buttons */
1052 public void actionPerformed(ActionEvent e) {
1053 String cmd = e.getActionCommand();
1055 if (cmd.equals("Pyro")) {
1056 if (pyro_ui == null && pyros != null)
1057 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
1058 if (pyro_ui != null)
1059 pyro_ui.make_visible();
1063 if (cmd.equals("Close") || cmd.equals("Reboot"))
1064 if (!check_dirty(cmd))
1066 listener.actionPerformed(e);
1067 if (cmd.equals("Close") || cmd.equals("Reboot")) {
1071 if (cmd.equals("Save") || cmd.equals("Reset"))
1075 /* ItemListener interface method */
1076 public void itemStateChanged(ItemEvent e) {
1080 /* DocumentListener interface methods */
1081 public void changedUpdate(DocumentEvent e) {
1085 public void insertUpdate(DocumentEvent e) {
1089 public void removeUpdate(DocumentEvent e) {
1093 /* Let the config code hook on a listener */
1094 public void addActionListener(ActionListener l) {
1098 /* set and get all of the dialog values */
1099 public void set_product(String product) {
1100 radio_frequency_value.set_product(product);
1101 product_value.setText(product);
1102 set_pad_orientation_tool_tip();
1103 set_accel_tool_tips();
1104 set_flight_log_max_tool_tip();
1107 public void set_version(String version) {
1108 version_value.setText(version);
1111 public void set_serial(int serial) {
1112 radio_frequency_value.set_serial(serial);
1113 serial_value.setText(String.format("%d", serial));
1116 public void set_altitude_32(int altitude_32) {
1119 public void set_main_deploy(int new_main_deploy) {
1120 if (new_main_deploy != AltosLib.MISSING)
1121 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
1122 main_deploy_value.setVisible(new_main_deploy != AltosLib.MISSING);
1123 main_deploy_label.setVisible(new_main_deploy != AltosLib.MISSING);
1126 public int main_deploy() throws AltosConfigDataException {
1127 String str = main_deploy_value.getSelectedItem().toString();
1129 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1130 } catch (ParseException pe) {
1131 throw new AltosConfigDataException("invalid main deploy height %s", str);
1135 String get_main_deploy_label() {
1136 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.parse_units());
1139 String[] main_deploy_values() {
1140 if (AltosConvert.imperial_units)
1141 return main_deploy_values_ft;
1143 return main_deploy_values_m;
1146 void set_main_deploy_values() {
1147 String[] v = main_deploy_values();
1148 while (main_deploy_value.getItemCount() > 0)
1149 main_deploy_value.removeItemAt(0);
1150 for (int i = 0; i < v.length; i++)
1151 main_deploy_value.addItem(v[i]);
1152 main_deploy_value.setMaximumRowCount(v.length);
1155 public void units_changed(boolean imperial_units) {
1156 boolean was_dirty = dirty;
1158 String v = main_deploy_value.getSelectedItem().toString();
1159 main_deploy_label.setText(get_main_deploy_label());
1160 set_main_deploy_values();
1162 int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1164 } catch (ParseException pe) {
1167 if (tracker_motion_value.isVisible()) {
1168 String motion = tracker_motion_value.getSelectedItem().toString();
1169 tracker_motion_label.setText(get_tracker_motion_label());
1170 set_tracker_motion_values();
1172 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1173 set_tracker_motion(m);
1174 } catch (ParseException pe) {
1182 public void set_apogee_delay(int new_apogee_delay) {
1183 if (new_apogee_delay != AltosLib.MISSING)
1184 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1185 apogee_delay_value.setVisible(new_apogee_delay != AltosLib.MISSING);
1186 apogee_delay_label.setVisible(new_apogee_delay != AltosLib.MISSING);
1189 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1192 v = s.split("\\s+")[0];
1194 return Integer.parseInt(v);
1195 } catch (NumberFormatException ne) {
1196 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1200 public int apogee_delay() throws AltosConfigDataException {
1201 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1204 public void set_apogee_lockout(int new_apogee_lockout) {
1205 if (new_apogee_lockout != AltosLib.MISSING)
1206 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1208 apogee_lockout_value.setVisible(new_apogee_lockout != AltosLib.MISSING);
1209 apogee_lockout_label.setVisible(new_apogee_lockout != AltosLib.MISSING);
1212 public int apogee_lockout() throws AltosConfigDataException {
1213 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1216 public void set_radio_frequency(double new_radio_frequency) {
1217 if (new_radio_frequency != AltosLib.MISSING)
1218 radio_frequency_value.set_frequency(new_radio_frequency);
1219 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
1220 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
1223 public double radio_frequency() {
1224 return radio_frequency_value.frequency();
1227 public void set_radio_calibration(int new_radio_calibration) {
1228 if (new_radio_calibration != AltosLib.MISSING)
1229 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1230 radio_calibration_value.setVisible(new_radio_calibration != AltosLib.MISSING);
1231 radio_calibration_label.setVisible(new_radio_calibration != AltosLib.MISSING);
1234 public void set_radio_enable(int new_radio_enable) {
1235 if (new_radio_enable != AltosLib.MISSING)
1236 radio_enable_value.setSelected(new_radio_enable != 0);
1237 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
1238 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
1239 set_radio_enable_tool_tip();
1242 public int radio_enable() {
1243 if (radio_enable_value.isVisible())
1244 return radio_enable_value.isSelected() ? 1 : 0;
1246 return AltosLib.MISSING;
1249 public void set_telemetry_rate(int new_rate) {
1250 if (new_rate != AltosLib.MISSING)
1251 rate_value.set_rate(new_rate);
1252 rate_label.setVisible(new_rate != AltosLib.MISSING);
1253 rate_value.setVisible(new_rate != AltosLib.MISSING);
1254 set_rate_tool_tip();
1257 public int telemetry_rate() {
1258 return rate_value.rate();
1261 public void set_callsign(String new_callsign) {
1262 if (new_callsign != null)
1263 callsign_value.setText(new_callsign);
1264 callsign_value.setVisible(new_callsign != null);
1265 callsign_label.setVisible(new_callsign != null);
1268 public String callsign() {
1269 if (callsign_value.isVisible())
1270 return callsign_value.getText();
1274 int flight_log_max_limit;
1277 public String flight_log_max_label(int flight_log_max) {
1278 if (flight_log_max_limit != 0) {
1279 int nflight = flight_log_max_limit / flight_log_max;
1280 String plural = nflight > 1 ? "s" : "";
1282 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1284 return String.format("%d", flight_log_max);
1287 public void set_flight_log_max(int new_flight_log_max) {
1288 if (new_flight_log_max != AltosLib.MISSING) {
1289 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1290 flight_log_max = new_flight_log_max;
1292 flight_log_max_value.setVisible(new_flight_log_max != AltosLib.MISSING);
1293 flight_log_max_label.setVisible(new_flight_log_max != AltosLib.MISSING);
1294 set_flight_log_max_tool_tip();
1297 public void set_flight_log_max_enabled(boolean enable) {
1298 flight_log_max_value.setEnabled(enable);
1299 set_flight_log_max_tool_tip();
1302 public int flight_log_max() throws AltosConfigDataException {
1303 if (flight_log_max_value.isVisible())
1304 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1305 return AltosLib.MISSING;
1308 public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
1309 flight_log_max_limit = new_flight_log_max_limit;
1310 if (new_flight_log_max_limit != AltosLib.MISSING) {
1311 flight_log_max_value.removeAllItems();
1312 for (int i = 8; i >= 1; i--) {
1313 int size = flight_log_max_limit / i;
1314 if (new_storage_erase_unit != 0)
1315 size &= ~(new_storage_erase_unit - 1);
1316 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1319 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
1320 set_flight_log_max(flight_log_max);
1323 public void set_ignite_mode(int new_ignite_mode) {
1324 if (new_ignite_mode != AltosLib.MISSING) {
1325 if (new_ignite_mode >= ignite_mode_values.length)
1326 new_ignite_mode = 0;
1327 if (new_ignite_mode < 0) {
1328 ignite_mode_value.setEnabled(false);
1329 new_ignite_mode = 0;
1331 ignite_mode_value.setEnabled(true);
1333 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1335 ignite_mode_value.setVisible(new_ignite_mode != AltosLib.MISSING);
1336 ignite_mode_label.setVisible(new_ignite_mode != AltosLib.MISSING);
1338 set_ignite_mode_tool_tip();
1341 public int ignite_mode() {
1342 if (ignite_mode_value.isVisible())
1343 return ignite_mode_value.getSelectedIndex();
1345 return AltosLib.MISSING;
1349 public void set_pad_orientation(int new_pad_orientation) {
1350 if (new_pad_orientation != AltosLib.MISSING) {
1351 if (new_pad_orientation >= pad_orientation_values.length)
1352 new_pad_orientation = 0;
1353 if (new_pad_orientation < 0)
1354 new_pad_orientation = 0;
1355 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1357 pad_orientation_value.setVisible(new_pad_orientation != AltosLib.MISSING);
1358 pad_orientation_label.setVisible(new_pad_orientation != AltosLib.MISSING);
1359 accel_cal.setVisible(new_pad_orientation != AltosLib.MISSING);
1361 set_pad_orientation_tool_tip();
1364 public int pad_orientation() {
1365 if (pad_orientation_value.isVisible())
1366 return pad_orientation_value.getSelectedIndex();
1368 return AltosLib.MISSING;
1371 public void set_accel_cal(int accel_plus, int accel_minus) {
1372 if (accel_plus != AltosLib.MISSING) {
1373 accel_plus_value.setText(String.format("%d", accel_plus));
1374 accel_minus_value.setText(String.format("%d", accel_minus));
1376 accel_plus_value.setVisible(accel_plus != AltosLib.MISSING);
1377 accel_plus_label.setVisible(accel_plus != AltosLib.MISSING);
1378 accel_minus_value.setVisible(accel_minus != AltosLib.MISSING);
1379 accel_minus_label.setVisible(accel_minus != AltosLib.MISSING);
1381 set_accel_tool_tips();
1384 public int accel_cal_plus() {
1385 if (accel_plus_value.isVisible())
1386 return Integer.parseInt(accel_plus_value.getText());
1387 return AltosLib.MISSING;
1390 public int accel_cal_minus() {
1391 if (accel_minus_value.isVisible())
1392 return Integer.parseInt(accel_minus_value.getText());
1393 return AltosLib.MISSING;
1396 public void set_beep(int new_beep) {
1397 if (new_beep != AltosLib.MISSING) {
1398 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1399 for (int i = 0; i < beep_values.length; i++)
1400 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1401 beep_value.setSelectedIndex(i);
1402 set_beep_tool_tip();
1405 beep_value.setSelectedItem(String.format("%d", new_freq));
1407 beep_value.setVisible(new_beep != AltosLib.MISSING);
1408 beep_label.setVisible(new_beep != AltosLib.MISSING);
1409 set_beep_tool_tip();
1413 if (beep_value.isVisible())
1414 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1416 return AltosLib.MISSING;
1419 String[] tracker_motion_values() {
1420 if (AltosConvert.imperial_units)
1421 return tracker_motion_values_ft;
1423 return tracker_motion_values_m;
1426 void set_tracker_motion_values() {
1427 String[] v = tracker_motion_values();
1428 while (tracker_motion_value.getItemCount() > 0)
1429 tracker_motion_value.removeItemAt(0);
1430 for (int i = 0; i < v.length; i++)
1431 tracker_motion_value.addItem(v[i]);
1432 tracker_motion_value.setMaximumRowCount(v.length);
1435 String get_tracker_motion_label() {
1436 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1439 void set_tracker_tool_tip() {
1440 if (tracker_motion_value.isVisible())
1441 tracker_motion_value.setToolTipText("How far the device must move before logging");
1443 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1444 if (tracker_interval_value.isVisible())
1445 tracker_interval_value.setToolTipText("How often to report GPS position");
1447 tracker_interval_value.setToolTipText("This device can't configure interval");
1450 public void set_tracker_motion(int tracker_motion) {
1451 if (tracker_motion != AltosLib.MISSING)
1452 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1453 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1454 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1457 public int tracker_motion() throws AltosConfigDataException {
1458 if (tracker_motion_value.isVisible()) {
1459 String str = tracker_motion_value.getSelectedItem().toString();
1461 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1462 } catch (ParseException pe) {
1463 throw new AltosConfigDataException("invalid tracker motion %s", str);
1466 return AltosLib.MISSING;
1469 public void set_tracker_interval(int tracker_interval) {
1470 if (tracker_interval != AltosLib.MISSING)
1471 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1472 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1473 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1476 public int tracker_interval() throws AltosConfigDataException {
1477 if (tracker_interval_value.isVisible())
1478 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1479 return AltosLib.MISSING;
1482 public void set_pyros(AltosPyro[] new_pyros) {
1484 if (pyros != null && pyro_ui != null)
1485 pyro_ui.set_pyros(pyros);
1486 pyro.setVisible(pyros != null);
1489 public AltosPyro[] pyros() throws AltosConfigDataException {
1490 if (pyro_ui != null)
1491 pyros = pyro_ui.get_pyros();
1495 public void set_pyro_firing_time(double new_pyro_firing_time) {
1496 pyro_firing_time = new_pyro_firing_time;
1497 if (pyro_firing_time != AltosLib.MISSING && pyro_ui != null)
1498 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1499 pyro.setVisible(pyro_firing_time != AltosLib.MISSING);
1502 public double pyro_firing_time() throws AltosConfigDataException {
1503 if (pyro_ui != null)
1504 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1505 return pyro_firing_time;
1508 private String aprs_interval_string(int interval) {
1511 return Integer.toString(interval);
1514 private int aprs_interval_value(String interval) throws AltosConfigDataException {
1515 if (interval.equalsIgnoreCase("Disabled"))
1517 return parse_int("aprs interval", interval, false);
1520 public void set_aprs_interval(int new_aprs_interval) {
1521 if (new_aprs_interval != AltosLib.MISSING)
1522 aprs_interval_value.setSelectedItem(aprs_interval_string(new_aprs_interval));
1523 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1524 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1525 set_aprs_interval_tool_tip();
1528 public int aprs_interval() throws AltosConfigDataException {
1529 if (aprs_interval_value.isVisible())
1530 return aprs_interval_value(aprs_interval_value.getSelectedItem().toString());
1531 return AltosLib.MISSING;
1534 public void set_aprs_ssid(int new_aprs_ssid) {
1535 if (new_aprs_ssid != AltosLib.MISSING)
1536 aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1537 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1538 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1539 set_aprs_ssid_tool_tip();
1542 public int aprs_ssid() throws AltosConfigDataException {
1543 if (aprs_ssid_value.isVisible()) {
1544 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1547 return AltosLib.MISSING;
1550 public void set_aprs_format(int new_aprs_format) {
1551 if (new_aprs_format != AltosLib.MISSING)
1552 aprs_format_value.setSelectedIndex(new_aprs_format);
1553 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1554 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1555 set_aprs_format_tool_tip();
1558 public int aprs_format() throws AltosConfigDataException {
1559 if (aprs_format_value.isVisible())
1560 return aprs_format_value.getSelectedIndex();
1561 return AltosLib.MISSING;
1564 public void set_aprs_offset(int new_aprs_offset) {
1565 if (new_aprs_offset != AltosLib.MISSING)
1566 aprs_offset_value.setSelectedItem(new_aprs_offset);
1567 aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
1568 aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
1569 set_aprs_offset_tool_tip();
1572 public int aprs_offset() throws AltosConfigDataException {
1573 if (aprs_offset_value.isVisible()) {
1574 Integer i = (Integer) aprs_offset_value.getSelectedItem();
1577 return AltosLib.MISSING;