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 String[] pad_orientation_values;
157 static String[] tracker_motion_values_m = {
164 static String[] tracker_motion_values_ft = {
171 static String[] tracker_interval_values = {
178 /* A window listener to catch closing events and tell the config code */
179 class ConfigListener extends WindowAdapter {
182 public ConfigListener(AltosConfigFCUI this_ui) {
186 public void windowClosing(WindowEvent e) {
187 ui.actionPerformed(new ActionEvent(e.getSource(),
188 ActionEvent.ACTION_PERFORMED,
193 boolean is_telemini_v1() {
194 String product = product_value.getText();
195 return product != null && product.startsWith("TeleMini-v1");
198 boolean is_telemini() {
199 String product = product_value.getText();
200 return product != null && product.startsWith("TeleMini");
203 boolean is_easymini() {
204 String product = product_value.getText();
205 return product != null && product.startsWith("EasyMini");
208 boolean is_telemetrum() {
209 String product = product_value.getText();
210 return product != null && product.startsWith("TeleMetrum");
213 boolean is_telemega() {
214 String product = product_value.getText();
215 return product != null && product.startsWith("TeleMega");
218 boolean is_easymega() {
219 String product = product_value.getText();
220 return product != null && product.startsWith("EasyMega");
223 boolean is_easytimer() {
224 String product = product_value.getText();
225 return product != null && product.startsWith("EasyTimer");
228 boolean has_radio() {
229 return is_telemega() || is_telemetrum() || is_telemini();
232 void set_radio_enable_tool_tip() {
233 if (radio_enable_value.isVisible())
234 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
236 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
239 void set_rate_tool_tip() {
240 if (rate_value.isVisible())
241 rate_value.setToolTipText("Select telemetry baud rate");
243 rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
246 void set_aprs_interval_tool_tip() {
247 if (aprs_interval_value.isVisible())
248 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
250 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
253 void set_aprs_ssid_tool_tip() {
254 if (aprs_ssid_value.isVisible())
255 aprs_ssid_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
256 else if (aprs_ssid_value.isVisible())
257 aprs_ssid_value.setToolTipText("Software version doesn't support setting the APRS SSID");
259 aprs_ssid_value.setToolTipText("Hardware doesn't support APRS");
262 void set_aprs_format_tool_tip() {
263 if (aprs_format_value.isVisible())
264 aprs_format_value.setToolTipText("Set the APRS format (compressed/uncompressed)");
265 else if (aprs_format_value.isVisible())
266 aprs_format_value.setToolTipText("Software version doesn't support setting the APRS format");
268 aprs_format_value.setToolTipText("Hardware doesn't support APRS");
271 void set_aprs_offset_tool_tip() {
272 if (aprs_offset_value.isVisible())
273 aprs_offset_value.setToolTipText("Set the APRS offset from top of minute");
274 else if (aprs_offset_value.isVisible())
275 aprs_offset_value.setToolTipText("Software version doesn't support setting the APRS offset");
277 aprs_offset_value.setToolTipText("Hardware doesn't support APRS");
280 void set_flight_log_max_tool_tip() {
281 if (flight_log_max_value.isVisible())
282 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
284 if (is_telemini_v1())
285 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
287 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
291 void set_ignite_mode_tool_tip() {
292 if (ignite_mode_value.isVisible())
293 ignite_mode_value.setToolTipText("Select when igniters will be fired");
295 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
298 void set_pad_orientation_tool_tip() {
299 if (pad_orientation_value.isVisible()) {
300 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
303 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
304 else if (is_telemini() || is_easymini())
305 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
306 else if (is_easytimer())
307 pad_orientation_value.setToolTipText("EasyTimer can be mounted in any of six orientations");
309 pad_orientation_value.setToolTipText("Can't select orientation");
313 void set_accel_tool_tips() {
314 if (accel_plus_value.isVisible()) {
315 accel_plus_value.setToolTipText("Pad acceleration value in flight orientation");
316 accel_minus_value.setToolTipText("Upside-down acceleration value");
318 accel_plus_value.setToolTipText("No accelerometer");
319 accel_minus_value.setToolTipText("No accelerometer");
323 void set_beep_tool_tip() {
324 if (beep_value.isVisible())
325 beep_value.setToolTipText("What frequency the beeper will sound at");
327 beep_value.setToolTipText("Older firmware could not select beeper frequency");
330 /* Build the UI using a grid bag */
331 public AltosConfigFCUI(JFrame in_owner, boolean remote) {
332 super (in_owner, "Configure Flight Computer", false);
335 GridBagConstraints c;
338 Insets il = new Insets(4,4,4,4);
339 Insets ir = new Insets(4,4,4,4);
341 pane = getContentPane();
342 pane.setLayout(new GridBagLayout());
345 c = new GridBagConstraints();
346 c.gridx = 0; c.gridy = row;
348 c.fill = GridBagConstraints.NONE;
349 c.anchor = GridBagConstraints.LINE_START;
351 product_label = new JLabel("Product:");
352 pane.add(product_label, c);
354 c = new GridBagConstraints();
355 c.gridx = 4; c.gridy = row;
357 c.fill = GridBagConstraints.HORIZONTAL;
359 c.anchor = GridBagConstraints.LINE_START;
361 product_value = new JLabel("");
362 pane.add(product_value, c);
366 c = new GridBagConstraints();
367 c.gridx = 0; c.gridy = row;
369 c.fill = GridBagConstraints.NONE;
370 c.anchor = GridBagConstraints.LINE_START;
373 version_label = new JLabel("Software version:");
374 pane.add(version_label, c);
376 c = new GridBagConstraints();
377 c.gridx = 4; c.gridy = row;
379 c.fill = GridBagConstraints.HORIZONTAL;
381 c.anchor = GridBagConstraints.LINE_START;
384 version_value = new JLabel("");
385 pane.add(version_value, c);
389 c = new GridBagConstraints();
390 c.gridx = 0; c.gridy = row;
392 c.fill = GridBagConstraints.NONE;
393 c.anchor = GridBagConstraints.LINE_START;
396 serial_label = new JLabel("Serial:");
397 pane.add(serial_label, c);
399 c = new GridBagConstraints();
400 c.gridx = 4; c.gridy = row;
402 c.fill = GridBagConstraints.HORIZONTAL;
404 c.anchor = GridBagConstraints.LINE_START;
407 serial_value = new JLabel("");
408 pane.add(serial_value, c);
412 c = new GridBagConstraints();
413 c.gridx = 0; c.gridy = row;
415 c.fill = GridBagConstraints.NONE;
416 c.anchor = GridBagConstraints.LINE_START;
419 main_deploy_label = new JLabel(get_main_deploy_label());
420 pane.add(main_deploy_label, c);
422 c = new GridBagConstraints();
423 c.gridx = 4; c.gridy = row;
425 c.fill = GridBagConstraints.HORIZONTAL;
427 c.anchor = GridBagConstraints.LINE_START;
430 main_deploy_value = new JComboBox<String>(main_deploy_values());
431 main_deploy_value.setEditable(true);
432 main_deploy_value.addItemListener(this);
433 pane.add(main_deploy_value, c);
434 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
438 c = new GridBagConstraints();
439 c.gridx = 0; c.gridy = row;
441 c.fill = GridBagConstraints.NONE;
442 c.anchor = GridBagConstraints.LINE_START;
445 apogee_delay_label = new JLabel("Apogee Delay(s):");
446 pane.add(apogee_delay_label, c);
448 c = new GridBagConstraints();
449 c.gridx = 4; c.gridy = row;
451 c.fill = GridBagConstraints.HORIZONTAL;
453 c.anchor = GridBagConstraints.LINE_START;
456 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
457 apogee_delay_value.setEditable(true);
458 apogee_delay_value.addItemListener(this);
459 pane.add(apogee_delay_value, c);
460 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
464 c = new GridBagConstraints();
465 c.gridx = 0; c.gridy = row;
467 c.fill = GridBagConstraints.NONE;
468 c.anchor = GridBagConstraints.LINE_START;
471 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
472 pane.add(apogee_lockout_label, c);
474 c = new GridBagConstraints();
475 c.gridx = 4; c.gridy = row;
477 c.fill = GridBagConstraints.HORIZONTAL;
479 c.anchor = GridBagConstraints.LINE_START;
482 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
483 apogee_lockout_value.setEditable(true);
484 apogee_lockout_value.addItemListener(this);
485 pane.add(apogee_lockout_value, c);
486 apogee_lockout_value.setToolTipText("Time after launch while apogee detection is locked out");
490 c = new GridBagConstraints();
491 c.gridx = 0; c.gridy = row;
493 c.fill = GridBagConstraints.NONE;
494 c.anchor = GridBagConstraints.LINE_START;
497 radio_frequency_label = new JLabel("Frequency:");
498 pane.add(radio_frequency_label, c);
500 c = new GridBagConstraints();
501 c.gridx = 4; c.gridy = row;
503 c.fill = GridBagConstraints.HORIZONTAL;
505 c.anchor = GridBagConstraints.LINE_START;
508 radio_frequency_value = new AltosUIFreqList();
509 radio_frequency_value.addItemListener(this);
510 pane.add(radio_frequency_value, c);
511 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
514 /* Radio Calibration */
515 c = new GridBagConstraints();
516 c.gridx = 0; c.gridy = row;
518 c.fill = GridBagConstraints.NONE;
519 c.anchor = GridBagConstraints.LINE_START;
522 radio_calibration_label = new JLabel("RF Calibration:");
523 pane.add(radio_calibration_label, c);
525 c = new GridBagConstraints();
526 c.gridx = 4; c.gridy = row;
528 c.fill = GridBagConstraints.HORIZONTAL;
530 c.anchor = GridBagConstraints.LINE_START;
533 radio_calibration_value = new JLabel(String.format("%d", 1186611));
534 pane.add(radio_calibration_value, c);
538 c = new GridBagConstraints();
539 c.gridx = 0; c.gridy = row;
541 c.fill = GridBagConstraints.NONE;
542 c.anchor = GridBagConstraints.LINE_START;
545 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
546 pane.add(radio_enable_label, c);
548 c = new GridBagConstraints();
549 c.gridx = 4; c.gridy = row;
551 c.fill = GridBagConstraints.HORIZONTAL;
553 c.anchor = GridBagConstraints.LINE_START;
556 radio_enable_value = new JRadioButton("Enabled");
557 radio_enable_value.addItemListener(this);
558 pane.add(radio_enable_value, c);
559 set_radio_enable_tool_tip();
563 c = new GridBagConstraints();
564 c.gridx = 0; c.gridy = row;
566 c.fill = GridBagConstraints.NONE;
567 c.anchor = GridBagConstraints.LINE_START;
570 rate_label = new JLabel("Telemetry baud rate:");
571 pane.add(rate_label, c);
573 c = new GridBagConstraints();
574 c.gridx = 4; c.gridy = row;
576 c.fill = GridBagConstraints.HORIZONTAL;
578 c.anchor = GridBagConstraints.LINE_START;
581 rate_value = new AltosUIRateList();
582 rate_value.addItemListener(this);
583 pane.add(rate_value, c);
588 c = new GridBagConstraints();
589 c.gridx = 0; c.gridy = row;
591 c.fill = GridBagConstraints.NONE;
592 c.anchor = GridBagConstraints.LINE_START;
595 aprs_interval_label = new JLabel("APRS Interval(s):");
596 pane.add(aprs_interval_label, c);
598 c = new GridBagConstraints();
599 c.gridx = 4; c.gridy = row;
601 c.fill = GridBagConstraints.HORIZONTAL;
603 c.anchor = GridBagConstraints.LINE_START;
606 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
607 aprs_interval_value.setEditable(true);
608 aprs_interval_value.addItemListener(this);
609 pane.add(aprs_interval_value, c);
610 set_aprs_interval_tool_tip();
614 c = new GridBagConstraints();
615 c.gridx = 0; c.gridy = row;
617 c.fill = GridBagConstraints.NONE;
618 c.anchor = GridBagConstraints.LINE_START;
621 aprs_ssid_label = new JLabel("APRS SSID:");
622 pane.add(aprs_ssid_label, c);
624 c = new GridBagConstraints();
625 c.gridx = 4; c.gridy = row;
627 c.fill = GridBagConstraints.HORIZONTAL;
629 c.anchor = GridBagConstraints.LINE_START;
632 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
633 aprs_ssid_value.setEditable(false);
634 aprs_ssid_value.addItemListener(this);
635 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
636 pane.add(aprs_ssid_value, c);
637 set_aprs_ssid_tool_tip();
641 c = new GridBagConstraints();
642 c.gridx = 0; c.gridy = row;
644 c.fill = GridBagConstraints.NONE;
645 c.anchor = GridBagConstraints.LINE_START;
648 aprs_format_label = new JLabel("APRS format:");
649 pane.add(aprs_format_label, c);
651 c = new GridBagConstraints();
652 c.gridx = 4; c.gridy = row;
654 c.fill = GridBagConstraints.HORIZONTAL;
656 c.anchor = GridBagConstraints.LINE_START;
659 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
660 aprs_format_value.setEditable(false);
661 aprs_format_value.addItemListener(this);
662 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
663 pane.add(aprs_format_value, c);
664 set_aprs_format_tool_tip();
668 c = new GridBagConstraints();
669 c.gridx = 0; c.gridy = row;
671 c.fill = GridBagConstraints.NONE;
672 c.anchor = GridBagConstraints.LINE_START;
675 aprs_offset_label = new JLabel("APRS offset:");
676 pane.add(aprs_offset_label, c);
678 c = new GridBagConstraints();
679 c.gridx = 4; c.gridy = row;
681 c.fill = GridBagConstraints.HORIZONTAL;
683 c.anchor = GridBagConstraints.LINE_START;
686 aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
687 aprs_offset_value.setEditable(false);
688 aprs_offset_value.addItemListener(this);
689 aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
690 pane.add(aprs_offset_value, c);
691 set_aprs_offset_tool_tip();
695 c = new GridBagConstraints();
696 c.gridx = 0; c.gridy = row;
698 c.fill = GridBagConstraints.NONE;
699 c.anchor = GridBagConstraints.LINE_START;
702 callsign_label = new JLabel("Callsign:");
703 pane.add(callsign_label, c);
705 c = new GridBagConstraints();
706 c.gridx = 4; c.gridy = row;
708 c.fill = GridBagConstraints.HORIZONTAL;
710 c.anchor = GridBagConstraints.LINE_START;
713 callsign_value = new JTextField(AltosUIPreferences.callsign());
714 callsign_value.getDocument().addDocumentListener(this);
715 pane.add(callsign_value, c);
716 callsign_value.setToolTipText("Callsign reported in telemetry data");
720 c = new GridBagConstraints();
721 c.gridx = 0; c.gridy = row;
723 c.fill = GridBagConstraints.NONE;
724 c.anchor = GridBagConstraints.LINE_START;
727 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
728 pane.add(flight_log_max_label, c);
730 c = new GridBagConstraints();
731 c.gridx = 4; c.gridy = row;
733 c.fill = GridBagConstraints.HORIZONTAL;
735 c.anchor = GridBagConstraints.LINE_START;
738 flight_log_max_value = new JComboBox<String>();
739 flight_log_max_value.setEditable(true);
740 flight_log_max_value.addItemListener(this);
741 pane.add(flight_log_max_value, c);
742 set_flight_log_max_tool_tip();
746 c = new GridBagConstraints();
747 c.gridx = 0; c.gridy = row;
749 c.fill = GridBagConstraints.NONE;
750 c.anchor = GridBagConstraints.LINE_START;
753 ignite_mode_label = new JLabel("Igniter Firing Mode:");
754 pane.add(ignite_mode_label, c);
756 c = new GridBagConstraints();
757 c.gridx = 4; c.gridy = row;
759 c.fill = GridBagConstraints.HORIZONTAL;
761 c.anchor = GridBagConstraints.LINE_START;
764 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
765 ignite_mode_value.setEditable(false);
766 ignite_mode_value.addItemListener(this);
767 pane.add(ignite_mode_value, c);
768 set_ignite_mode_tool_tip();
771 /* Pad orientation */
772 c = new GridBagConstraints();
773 c.gridx = 0; c.gridy = row;
775 c.fill = GridBagConstraints.NONE;
776 c.anchor = GridBagConstraints.LINE_START;
779 pad_orientation_label = new JLabel("Pad Orientation:");
780 pane.add(pad_orientation_label, c);
782 c = new GridBagConstraints();
783 c.gridx = 4; c.gridy = row;
785 c.fill = GridBagConstraints.HORIZONTAL;
787 c.anchor = GridBagConstraints.LINE_START;
791 pad_orientation_values = pad_orientation_values_radio;
793 pad_orientation_values = pad_orientation_values_no_radio;
795 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
796 pad_orientation_value.setEditable(false);
797 pad_orientation_value.addItemListener(this);
798 pane.add(pad_orientation_value, c);
799 set_pad_orientation_tool_tip();
803 c = new GridBagConstraints();
804 c.gridx = 0; c.gridy = row;
806 c.fill = GridBagConstraints.NONE;
807 c.anchor = GridBagConstraints.LINE_START;
810 accel_plus_label = new JLabel("Accel Plus:");
811 pane.add(accel_plus_label, c);
813 c = new GridBagConstraints();
814 c.gridx = 4; c.gridy = row;
816 c.fill = GridBagConstraints.HORIZONTAL;
818 c.anchor = GridBagConstraints.LINE_START;
821 accel_plus_value = new JTextField(10);
822 accel_plus_value.setEditable(true);
823 accel_plus_value.getDocument().addDocumentListener(this);
824 pane.add(accel_plus_value, c);
828 c = new GridBagConstraints();
829 c.gridx = 0; c.gridy = row;
831 c.fill = GridBagConstraints.NONE;
832 c.anchor = GridBagConstraints.LINE_START;
835 accel_minus_label = new JLabel("Accel Minus:");
836 pane.add(accel_minus_label, c);
838 c = new GridBagConstraints();
839 c.gridx = 4; c.gridy = row;
841 c.fill = GridBagConstraints.HORIZONTAL;
843 c.anchor = GridBagConstraints.LINE_START;
846 accel_minus_value = new JTextField(10);
847 accel_minus_value.setEditable(true);
848 accel_minus_value.getDocument().addDocumentListener(this);
849 pane.add(accel_minus_value, c);
851 set_accel_tool_tips();
854 c = new GridBagConstraints();
855 c.gridx = 0; c.gridy = row;
857 c.fill = GridBagConstraints.NONE;
858 c.anchor = GridBagConstraints.LINE_START;
861 beep_label = new JLabel("Beeper Frequency:");
862 pane.add(beep_label, c);
864 c = new GridBagConstraints();
865 c.gridx = 4; c.gridy = row;
867 c.fill = GridBagConstraints.HORIZONTAL;
869 c.anchor = GridBagConstraints.LINE_START;
872 beep_value = new JComboBox<String>(beep_values);
873 beep_value.setEditable(true);
874 beep_value.addItemListener(this);
875 pane.add(beep_value, c);
879 /* Tracker triger horiz distances */
880 c = new GridBagConstraints();
881 c.gridx = 0; c.gridy = row;
883 c.fill = GridBagConstraints.NONE;
884 c.anchor = GridBagConstraints.LINE_START;
887 tracker_motion_label = new JLabel(get_tracker_motion_label());
888 pane.add(tracker_motion_label, c);
890 c = new GridBagConstraints();
891 c.gridx = 4; c.gridy = row;
893 c.fill = GridBagConstraints.HORIZONTAL;
895 c.anchor = GridBagConstraints.LINE_START;
898 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
899 tracker_motion_value.setEditable(true);
900 tracker_motion_value.addItemListener(this);
901 pane.add(tracker_motion_value, c);
904 /* Tracker triger vert distances */
905 c = new GridBagConstraints();
906 c.gridx = 0; c.gridy = row;
908 c.fill = GridBagConstraints.NONE;
909 c.anchor = GridBagConstraints.LINE_START;
912 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
913 pane.add(tracker_interval_label, c);
915 c = new GridBagConstraints();
916 c.gridx = 4; c.gridy = row;
918 c.fill = GridBagConstraints.HORIZONTAL;
920 c.anchor = GridBagConstraints.LINE_START;
923 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
924 tracker_interval_value.setEditable(true);
925 tracker_interval_value.addItemListener(this);
926 pane.add(tracker_interval_value, c);
927 set_tracker_tool_tip();
931 c = new GridBagConstraints();
932 c.gridx = 4; c.gridy = row;
934 c.fill = GridBagConstraints.HORIZONTAL;
935 c.anchor = GridBagConstraints.LINE_START;
938 pyro = new JButton("Configure Pyro Channels");
940 pyro.addActionListener(this);
941 pyro.setActionCommand("Pyro");
945 c = new GridBagConstraints();
946 c.gridx = 5; c.gridy = row;
948 c.fill = GridBagConstraints.HORIZONTAL;
949 c.anchor = GridBagConstraints.LINE_START;
952 accel_cal = new JButton("Calibrate Accelerometer");
953 pane.add(accel_cal, c);
954 accel_cal.addActionListener(this);
955 accel_cal.setActionCommand("Accel");
959 c = new GridBagConstraints();
960 c.gridx = 0; c.gridy = row;
962 c.fill = GridBagConstraints.NONE;
963 c.anchor = GridBagConstraints.LINE_START;
965 save = new JButton("Save");
967 save.addActionListener(this);
968 save.setActionCommand("Save");
970 c = new GridBagConstraints();
971 c.gridx = 2; c.gridy = row;
973 c.fill = GridBagConstraints.NONE;
974 c.anchor = GridBagConstraints.CENTER;
976 reset = new JButton("Reset");
978 reset.addActionListener(this);
979 reset.setActionCommand("Reset");
981 c = new GridBagConstraints();
982 c.gridx = 4; c.gridy = row;
984 c.fill = GridBagConstraints.NONE;
985 c.anchor = GridBagConstraints.CENTER;
987 reboot = new JButton("Reboot");
989 reboot.addActionListener(this);
990 reboot.setActionCommand("Reboot");
992 c = new GridBagConstraints();
993 c.gridx = 6; c.gridy = row;
995 c.fill = GridBagConstraints.NONE;
996 c.anchor = GridBagConstraints.LINE_END;
998 close = new JButton("Close");
1000 close.addActionListener(this);
1001 close.setActionCommand("Close");
1003 addWindowListener(new ConfigListener(this));
1004 AltosPreferences.register_units_listener(this);
1007 /* Once the initial values are set, the config code will show the dialog */
1008 public void make_visible() {
1010 setLocationRelativeTo(owner);
1014 /* If any values have been changed, confirm before closing */
1015 public boolean check_dirty(String operation) {
1017 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
1019 i = JOptionPane.showOptionDialog(this,
1020 String.format("Configuration modified. %s anyway?", operation),
1021 "Configuration Modified",
1022 JOptionPane.DEFAULT_OPTION,
1023 JOptionPane.WARNING_MESSAGE,
1024 null, options, options[1]);
1031 public void set_dirty() {
1033 save.setEnabled(true);
1036 public void set_clean() {
1038 save.setEnabled(false);
1041 AltosConfigPyroUI pyro_ui;
1043 public void dispose() {
1044 if (pyro_ui != null)
1046 AltosPreferences.unregister_units_listener(this);
1050 /* Listen for events from our buttons */
1051 public void actionPerformed(ActionEvent e) {
1052 String cmd = e.getActionCommand();
1054 if (cmd.equals("Pyro")) {
1055 if (pyro_ui == null && pyros != null)
1056 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
1057 if (pyro_ui != null)
1058 pyro_ui.make_visible();
1062 if (cmd.equals("Close") || cmd.equals("Reboot"))
1063 if (!check_dirty(cmd))
1065 listener.actionPerformed(e);
1066 if (cmd.equals("Close") || cmd.equals("Reboot")) {
1070 if (cmd.equals("Save") || cmd.equals("Reset"))
1074 /* ItemListener interface method */
1075 public void itemStateChanged(ItemEvent e) {
1079 /* DocumentListener interface methods */
1080 public void changedUpdate(DocumentEvent e) {
1084 public void insertUpdate(DocumentEvent e) {
1088 public void removeUpdate(DocumentEvent e) {
1092 /* Let the config code hook on a listener */
1093 public void addActionListener(ActionListener l) {
1097 /* set and get all of the dialog values */
1098 public void set_product(String product) {
1099 radio_frequency_value.set_product(product);
1100 product_value.setText(product);
1101 set_pad_orientation_tool_tip();
1102 set_accel_tool_tips();
1103 set_flight_log_max_tool_tip();
1106 public void set_version(String version) {
1107 version_value.setText(version);
1110 public void set_serial(int serial) {
1111 radio_frequency_value.set_serial(serial);
1112 serial_value.setText(String.format("%d", serial));
1115 public void set_altitude_32(int altitude_32) {
1118 public void set_main_deploy(int new_main_deploy) {
1119 if (new_main_deploy != AltosLib.MISSING)
1120 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
1121 main_deploy_value.setVisible(new_main_deploy != AltosLib.MISSING);
1122 main_deploy_label.setVisible(new_main_deploy != AltosLib.MISSING);
1125 public int main_deploy() throws AltosConfigDataException {
1126 String str = main_deploy_value.getSelectedItem().toString();
1128 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1129 } catch (ParseException pe) {
1130 throw new AltosConfigDataException("invalid main deploy height %s", str);
1134 String get_main_deploy_label() {
1135 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.parse_units());
1138 String[] main_deploy_values() {
1139 if (AltosConvert.imperial_units)
1140 return main_deploy_values_ft;
1142 return main_deploy_values_m;
1145 void set_main_deploy_values() {
1146 String[] v = main_deploy_values();
1147 while (main_deploy_value.getItemCount() > 0)
1148 main_deploy_value.removeItemAt(0);
1149 for (int i = 0; i < v.length; i++)
1150 main_deploy_value.addItem(v[i]);
1151 main_deploy_value.setMaximumRowCount(v.length);
1154 public void units_changed(boolean imperial_units) {
1155 boolean was_dirty = dirty;
1157 String v = main_deploy_value.getSelectedItem().toString();
1158 main_deploy_label.setText(get_main_deploy_label());
1159 set_main_deploy_values();
1161 int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1163 } catch (ParseException pe) {
1166 if (tracker_motion_value.isVisible()) {
1167 String motion = tracker_motion_value.getSelectedItem().toString();
1168 tracker_motion_label.setText(get_tracker_motion_label());
1169 set_tracker_motion_values();
1171 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1172 set_tracker_motion(m);
1173 } catch (ParseException pe) {
1181 public void set_apogee_delay(int new_apogee_delay) {
1182 if (new_apogee_delay != AltosLib.MISSING)
1183 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1184 apogee_delay_value.setVisible(new_apogee_delay != AltosLib.MISSING);
1185 apogee_delay_label.setVisible(new_apogee_delay != AltosLib.MISSING);
1188 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1191 v = s.split("\\s+")[0];
1193 return Integer.parseInt(v);
1194 } catch (NumberFormatException ne) {
1195 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1199 public int apogee_delay() throws AltosConfigDataException {
1200 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1203 public void set_apogee_lockout(int new_apogee_lockout) {
1204 if (new_apogee_lockout != AltosLib.MISSING)
1205 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1207 apogee_lockout_value.setVisible(new_apogee_lockout != AltosLib.MISSING);
1208 apogee_lockout_label.setVisible(new_apogee_lockout != AltosLib.MISSING);
1211 public int apogee_lockout() throws AltosConfigDataException {
1212 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1215 public void set_radio_frequency(double new_radio_frequency) {
1216 if (new_radio_frequency != AltosLib.MISSING)
1217 radio_frequency_value.set_frequency(new_radio_frequency);
1218 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
1219 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
1222 public double radio_frequency() {
1223 return radio_frequency_value.frequency();
1226 public void set_radio_calibration(int new_radio_calibration) {
1227 if (new_radio_calibration != AltosLib.MISSING)
1228 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1229 radio_calibration_value.setVisible(new_radio_calibration != AltosLib.MISSING);
1230 radio_calibration_label.setVisible(new_radio_calibration != AltosLib.MISSING);
1233 public void set_radio_enable(int new_radio_enable) {
1234 if (new_radio_enable != AltosLib.MISSING)
1235 radio_enable_value.setSelected(new_radio_enable != 0);
1236 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
1237 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
1238 set_radio_enable_tool_tip();
1241 public int radio_enable() {
1242 if (radio_enable_value.isVisible())
1243 return radio_enable_value.isSelected() ? 1 : 0;
1245 return AltosLib.MISSING;
1248 public void set_telemetry_rate(int new_rate) {
1249 if (new_rate != AltosLib.MISSING)
1250 rate_value.set_rate(new_rate);
1251 rate_label.setVisible(new_rate != AltosLib.MISSING);
1252 rate_value.setVisible(new_rate != AltosLib.MISSING);
1253 set_rate_tool_tip();
1256 public int telemetry_rate() {
1257 return rate_value.rate();
1260 public void set_callsign(String new_callsign) {
1261 if (new_callsign != null)
1262 callsign_value.setText(new_callsign);
1263 callsign_value.setVisible(new_callsign != null);
1264 callsign_label.setVisible(new_callsign != null);
1267 public String callsign() {
1268 if (callsign_value.isVisible())
1269 return callsign_value.getText();
1273 int flight_log_max_limit;
1276 public String flight_log_max_label(int flight_log_max) {
1277 if (flight_log_max_limit != 0) {
1278 int nflight = flight_log_max_limit / flight_log_max;
1279 String plural = nflight > 1 ? "s" : "";
1281 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1283 return String.format("%d", flight_log_max);
1286 public void set_flight_log_max(int new_flight_log_max) {
1287 if (new_flight_log_max != AltosLib.MISSING) {
1288 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1289 flight_log_max = new_flight_log_max;
1291 flight_log_max_value.setVisible(new_flight_log_max != AltosLib.MISSING);
1292 flight_log_max_label.setVisible(new_flight_log_max != AltosLib.MISSING);
1293 set_flight_log_max_tool_tip();
1296 public void set_flight_log_max_enabled(boolean enable) {
1297 flight_log_max_value.setEnabled(enable);
1298 set_flight_log_max_tool_tip();
1301 public int flight_log_max() throws AltosConfigDataException {
1302 if (flight_log_max_value.isVisible())
1303 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1304 return AltosLib.MISSING;
1307 public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
1308 flight_log_max_limit = new_flight_log_max_limit;
1309 if (new_flight_log_max_limit != AltosLib.MISSING) {
1310 flight_log_max_value.removeAllItems();
1311 for (int i = 8; i >= 1; i--) {
1312 int size = flight_log_max_limit / i;
1313 if (new_storage_erase_unit != 0)
1314 size &= ~(new_storage_erase_unit - 1);
1315 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1318 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
1319 set_flight_log_max(flight_log_max);
1322 public void set_ignite_mode(int new_ignite_mode) {
1323 if (new_ignite_mode != AltosLib.MISSING) {
1324 if (new_ignite_mode >= ignite_mode_values.length)
1325 new_ignite_mode = 0;
1326 if (new_ignite_mode < 0) {
1327 ignite_mode_value.setEnabled(false);
1328 new_ignite_mode = 0;
1330 ignite_mode_value.setEnabled(true);
1332 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1334 ignite_mode_value.setVisible(new_ignite_mode != AltosLib.MISSING);
1335 ignite_mode_label.setVisible(new_ignite_mode != AltosLib.MISSING);
1337 set_ignite_mode_tool_tip();
1340 public int ignite_mode() {
1341 if (ignite_mode_value.isVisible())
1342 return ignite_mode_value.getSelectedIndex();
1344 return AltosLib.MISSING;
1348 public void set_pad_orientation(int new_pad_orientation) {
1349 if (new_pad_orientation != AltosLib.MISSING) {
1350 if (new_pad_orientation >= pad_orientation_values.length)
1351 new_pad_orientation = 0;
1352 if (new_pad_orientation < 0)
1353 new_pad_orientation = 0;
1354 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1356 pad_orientation_value.setVisible(new_pad_orientation != AltosLib.MISSING);
1357 pad_orientation_label.setVisible(new_pad_orientation != AltosLib.MISSING);
1358 accel_cal.setVisible(new_pad_orientation != AltosLib.MISSING);
1360 set_pad_orientation_tool_tip();
1363 public int pad_orientation() {
1364 if (pad_orientation_value.isVisible())
1365 return pad_orientation_value.getSelectedIndex();
1367 return AltosLib.MISSING;
1370 public void set_accel_cal(int accel_plus, int accel_minus) {
1371 if (accel_plus != AltosLib.MISSING) {
1372 accel_plus_value.setText(String.format("%d", accel_plus));
1373 accel_minus_value.setText(String.format("%d", accel_minus));
1375 accel_plus_value.setVisible(accel_plus != AltosLib.MISSING);
1376 accel_plus_label.setVisible(accel_plus != AltosLib.MISSING);
1377 accel_minus_value.setVisible(accel_minus != AltosLib.MISSING);
1378 accel_minus_label.setVisible(accel_minus != AltosLib.MISSING);
1380 set_accel_tool_tips();
1383 public int accel_cal_plus() {
1384 if (accel_plus_value.isVisible())
1385 return Integer.parseInt(accel_plus_value.getText());
1386 return AltosLib.MISSING;
1389 public int accel_cal_minus() {
1390 if (accel_minus_value.isVisible())
1391 return Integer.parseInt(accel_minus_value.getText());
1392 return AltosLib.MISSING;
1395 public void set_beep(int new_beep) {
1396 if (new_beep != AltosLib.MISSING) {
1397 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1398 for (int i = 0; i < beep_values.length; i++)
1399 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1400 beep_value.setSelectedIndex(i);
1401 set_beep_tool_tip();
1404 beep_value.setSelectedItem(String.format("%d", new_freq));
1406 beep_value.setVisible(new_beep != AltosLib.MISSING);
1407 beep_label.setVisible(new_beep != AltosLib.MISSING);
1408 set_beep_tool_tip();
1412 if (beep_value.isVisible())
1413 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1415 return AltosLib.MISSING;
1418 String[] tracker_motion_values() {
1419 if (AltosConvert.imperial_units)
1420 return tracker_motion_values_ft;
1422 return tracker_motion_values_m;
1425 void set_tracker_motion_values() {
1426 String[] v = tracker_motion_values();
1427 while (tracker_motion_value.getItemCount() > 0)
1428 tracker_motion_value.removeItemAt(0);
1429 for (int i = 0; i < v.length; i++)
1430 tracker_motion_value.addItem(v[i]);
1431 tracker_motion_value.setMaximumRowCount(v.length);
1434 String get_tracker_motion_label() {
1435 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1438 void set_tracker_tool_tip() {
1439 if (tracker_motion_value.isVisible())
1440 tracker_motion_value.setToolTipText("How far the device must move before logging");
1442 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1443 if (tracker_interval_value.isVisible())
1444 tracker_interval_value.setToolTipText("How often to report GPS position");
1446 tracker_interval_value.setToolTipText("This device can't configure interval");
1449 public void set_tracker_motion(int tracker_motion) {
1450 if (tracker_motion != AltosLib.MISSING)
1451 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1452 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1453 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1456 public int tracker_motion() throws AltosConfigDataException {
1457 if (tracker_motion_value.isVisible()) {
1458 String str = tracker_motion_value.getSelectedItem().toString();
1460 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1461 } catch (ParseException pe) {
1462 throw new AltosConfigDataException("invalid tracker motion %s", str);
1465 return AltosLib.MISSING;
1468 public void set_tracker_interval(int tracker_interval) {
1469 if (tracker_interval != AltosLib.MISSING)
1470 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1471 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1472 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1475 public int tracker_interval() throws AltosConfigDataException {
1476 if (tracker_interval_value.isVisible())
1477 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1478 return AltosLib.MISSING;
1481 public void set_pyros(AltosPyro[] new_pyros) {
1483 if (pyros != null && pyro_ui != null)
1484 pyro_ui.set_pyros(pyros);
1485 pyro.setVisible(pyros != null);
1488 public AltosPyro[] pyros() throws AltosConfigDataException {
1489 if (pyro_ui != null)
1490 pyros = pyro_ui.get_pyros();
1494 public void set_pyro_firing_time(double new_pyro_firing_time) {
1495 pyro_firing_time = new_pyro_firing_time;
1496 if (pyro_firing_time != AltosLib.MISSING && pyro_ui != null)
1497 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1498 pyro.setVisible(pyro_firing_time != AltosLib.MISSING);
1501 public double pyro_firing_time() throws AltosConfigDataException {
1502 if (pyro_ui != null)
1503 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1504 return pyro_firing_time;
1507 private String aprs_interval_string(int interval) {
1510 return Integer.toString(interval);
1513 private int aprs_interval_value(String interval) throws AltosConfigDataException {
1514 if (interval.equalsIgnoreCase("Disabled"))
1516 return parse_int("aprs interval", interval, false);
1519 public void set_aprs_interval(int new_aprs_interval) {
1520 if (new_aprs_interval != AltosLib.MISSING)
1521 aprs_interval_value.setSelectedItem(aprs_interval_string(new_aprs_interval));
1522 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1523 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1524 set_aprs_interval_tool_tip();
1527 public int aprs_interval() throws AltosConfigDataException {
1528 if (aprs_interval_value.isVisible())
1529 return aprs_interval_value(aprs_interval_value.getSelectedItem().toString());
1530 return AltosLib.MISSING;
1533 public void set_aprs_ssid(int new_aprs_ssid) {
1534 if (new_aprs_ssid != AltosLib.MISSING)
1535 aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1536 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1537 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1538 set_aprs_ssid_tool_tip();
1541 public int aprs_ssid() throws AltosConfigDataException {
1542 if (aprs_ssid_value.isVisible()) {
1543 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1546 return AltosLib.MISSING;
1549 public void set_aprs_format(int new_aprs_format) {
1550 if (new_aprs_format != AltosLib.MISSING)
1551 aprs_format_value.setSelectedIndex(new_aprs_format);
1552 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1553 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1554 set_aprs_format_tool_tip();
1557 public int aprs_format() throws AltosConfigDataException {
1558 if (aprs_format_value.isVisible())
1559 return aprs_format_value.getSelectedIndex();
1560 return AltosLib.MISSING;
1563 public void set_aprs_offset(int new_aprs_offset) {
1564 if (new_aprs_offset != AltosLib.MISSING)
1565 aprs_offset_value.setSelectedItem(new_aprs_offset);
1566 aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
1567 aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
1568 set_aprs_offset_tool_tip();
1571 public int aprs_offset() throws AltosConfigDataException {
1572 if (aprs_offset_value.isVisible()) {
1573 Integer i = (Integer) aprs_offset_value.getSelectedItem();
1576 return AltosLib.MISSING;