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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 import java.awt.event.*;
23 import javax.swing.event.*;
24 import org.altusmetrum.altoslib_5.*;
25 import org.altusmetrum.altosuilib_3.*;
27 public class AltosConfigUI
29 implements ActionListener, ItemListener, DocumentListener, AltosConfigValues, AltosUnitsListener
36 JLabel main_deploy_label;
37 JLabel apogee_delay_label;
38 JLabel apogee_lockout_label;
39 JLabel frequency_label;
40 JLabel radio_calibration_label;
41 JLabel radio_frequency_label;
42 JLabel radio_enable_label;
43 JLabel aprs_interval_label;
44 JLabel aprs_ssid_label;
45 JLabel flight_log_max_label;
46 JLabel ignite_mode_label;
47 JLabel pad_orientation_label;
48 JLabel callsign_label;
50 JLabel tracker_motion_label;
51 JLabel tracker_interval_label;
59 JComboBox<String> main_deploy_value;
60 JComboBox<String> apogee_delay_value;
61 JComboBox<String> apogee_lockout_value;
62 AltosFreqList radio_frequency_value;
63 JTextField radio_calibration_value;
64 JRadioButton radio_enable_value;
65 JComboBox<String> aprs_interval_value;
66 JComboBox<Integer> aprs_ssid_value;
67 JComboBox<String> flight_log_max_value;
68 JComboBox<String> ignite_mode_value;
69 JComboBox<String> pad_orientation_value;
70 JTextField callsign_value;
71 JComboBox<String> beep_value;
72 JComboBox<String> tracker_motion_value;
73 JComboBox<String> tracker_interval_value;
83 double pyro_firing_time;
85 ActionListener listener;
87 static String[] main_deploy_values_m = {
88 "100", "150", "200", "250", "300", "350",
92 static String[] main_deploy_values_ft = {
93 "250", "500", "750", "1000", "1250", "1500",
97 static String[] apogee_delay_values = {
98 "0", "1", "2", "3", "4", "5"
101 static String[] apogee_lockout_values = {
102 "0", "5", "10", "15", "20"
105 static String[] ignite_mode_values = {
111 static String[] aprs_interval_values = {
118 static Integer[] aprs_ssid_values = {
119 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
122 static String[] beep_values = {
128 static String[] pad_orientation_values = {
133 static String[] tracker_motion_values_m = {
140 static String[] tracker_motion_values_ft = {
147 static String[] tracker_interval_values = {
154 /* A window listener to catch closing events and tell the config code */
155 class ConfigListener extends WindowAdapter {
158 public ConfigListener(AltosConfigUI this_ui) {
162 public void windowClosing(WindowEvent e) {
163 ui.actionPerformed(new ActionEvent(e.getSource(),
164 ActionEvent.ACTION_PERFORMED,
169 boolean is_telemini_v1() {
170 String product = product_value.getText();
171 return product != null && product.startsWith("TeleMini-v1");
174 boolean is_telemini() {
175 String product = product_value.getText();
176 return product != null && product.startsWith("TeleMini");
179 boolean is_easymini() {
180 String product = product_value.getText();
181 return product != null && product.startsWith("EasyMini");
184 boolean is_telemetrum() {
185 String product = product_value.getText();
186 return product != null && product.startsWith("TeleMetrum");
189 void set_radio_calibration_tool_tip() {
190 if (radio_calibration_value.isEnabled())
191 radio_calibration_value.setToolTipText("Tune radio output to match desired frequency");
193 radio_calibration_value.setToolTipText("Cannot tune radio while connected over packet mode");
196 void set_radio_enable_tool_tip() {
197 if (radio_enable_value.isEnabled())
198 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
200 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
203 void set_aprs_interval_tool_tip() {
204 if (aprs_interval_value.isEnabled())
205 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
207 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
210 void set_aprs_ssid_tool_tip() {
211 if (aprs_ssid_value.isEnabled())
212 aprs_interval_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
213 else if (aprs_interval_value.isEnabled())
214 aprs_interval_value.setToolTipText("Software version doesn't support setting the APRS SSID");
216 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
219 void set_flight_log_max_tool_tip() {
220 if (flight_log_max_value.isEnabled())
221 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
223 if (is_telemini_v1())
224 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
226 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
230 void set_ignite_mode_tool_tip() {
231 if (ignite_mode_value.isEnabled())
232 ignite_mode_value.setToolTipText("Select when igniters will be fired");
234 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
237 void set_pad_orientation_tool_tip() {
238 if (pad_orientation_value.isEnabled())
239 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
242 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
243 else if (is_telemini() || is_easymini())
244 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
246 pad_orientation_value.setToolTipText("Can't select orientation");
250 void set_beep_tool_tip() {
251 if (beep_value.isEnabled())
252 beep_value.setToolTipText("What frequency the beeper will sound at");
254 beep_value.setToolTipText("Older firmware could not select beeper frequency");
257 /* Build the UI using a grid bag */
258 public AltosConfigUI(JFrame in_owner, boolean remote) {
259 super (in_owner, "Configure Flight Computer", false);
262 GridBagConstraints c;
265 Insets il = new Insets(4,4,4,4);
266 Insets ir = new Insets(4,4,4,4);
268 pane = getContentPane();
269 pane.setLayout(new GridBagLayout());
272 c = new GridBagConstraints();
273 c.gridx = 0; c.gridy = row;
275 c.fill = GridBagConstraints.NONE;
276 c.anchor = GridBagConstraints.LINE_START;
278 product_label = new JLabel("Product:");
279 pane.add(product_label, c);
281 c = new GridBagConstraints();
282 c.gridx = 4; c.gridy = row;
284 c.fill = GridBagConstraints.HORIZONTAL;
286 c.anchor = GridBagConstraints.LINE_START;
288 product_value = new JLabel("");
289 pane.add(product_value, c);
293 c = new GridBagConstraints();
294 c.gridx = 0; c.gridy = row;
296 c.fill = GridBagConstraints.NONE;
297 c.anchor = GridBagConstraints.LINE_START;
300 version_label = new JLabel("Software version:");
301 pane.add(version_label, c);
303 c = new GridBagConstraints();
304 c.gridx = 4; c.gridy = row;
306 c.fill = GridBagConstraints.HORIZONTAL;
308 c.anchor = GridBagConstraints.LINE_START;
311 version_value = new JLabel("");
312 pane.add(version_value, c);
316 c = new GridBagConstraints();
317 c.gridx = 0; c.gridy = row;
319 c.fill = GridBagConstraints.NONE;
320 c.anchor = GridBagConstraints.LINE_START;
323 serial_label = new JLabel("Serial:");
324 pane.add(serial_label, c);
326 c = new GridBagConstraints();
327 c.gridx = 4; c.gridy = row;
329 c.fill = GridBagConstraints.HORIZONTAL;
331 c.anchor = GridBagConstraints.LINE_START;
334 serial_value = new JLabel("");
335 pane.add(serial_value, c);
339 c = new GridBagConstraints();
340 c.gridx = 0; c.gridy = row;
342 c.fill = GridBagConstraints.NONE;
343 c.anchor = GridBagConstraints.LINE_START;
346 main_deploy_label = new JLabel(get_main_deploy_label());
347 pane.add(main_deploy_label, c);
349 c = new GridBagConstraints();
350 c.gridx = 4; c.gridy = row;
352 c.fill = GridBagConstraints.HORIZONTAL;
354 c.anchor = GridBagConstraints.LINE_START;
357 main_deploy_value = new JComboBox<String>(main_deploy_values());
358 main_deploy_value.setEditable(true);
359 main_deploy_value.addItemListener(this);
360 pane.add(main_deploy_value, c);
361 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
365 c = new GridBagConstraints();
366 c.gridx = 0; c.gridy = row;
368 c.fill = GridBagConstraints.NONE;
369 c.anchor = GridBagConstraints.LINE_START;
372 apogee_delay_label = new JLabel("Apogee Delay(s):");
373 pane.add(apogee_delay_label, c);
375 c = new GridBagConstraints();
376 c.gridx = 4; c.gridy = row;
378 c.fill = GridBagConstraints.HORIZONTAL;
380 c.anchor = GridBagConstraints.LINE_START;
383 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
384 apogee_delay_value.setEditable(true);
385 apogee_delay_value.addItemListener(this);
386 pane.add(apogee_delay_value, c);
387 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
391 c = new GridBagConstraints();
392 c.gridx = 0; c.gridy = row;
394 c.fill = GridBagConstraints.NONE;
395 c.anchor = GridBagConstraints.LINE_START;
398 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
399 pane.add(apogee_lockout_label, c);
401 c = new GridBagConstraints();
402 c.gridx = 4; c.gridy = row;
404 c.fill = GridBagConstraints.HORIZONTAL;
406 c.anchor = GridBagConstraints.LINE_START;
409 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
410 apogee_lockout_value.setEditable(true);
411 apogee_lockout_value.addItemListener(this);
412 pane.add(apogee_lockout_value, c);
413 apogee_lockout_value.setToolTipText("Time after boost while apogee detection is locked out");
417 c = new GridBagConstraints();
418 c.gridx = 0; c.gridy = row;
420 c.fill = GridBagConstraints.NONE;
421 c.anchor = GridBagConstraints.LINE_START;
424 radio_frequency_label = new JLabel("Frequency:");
425 pane.add(radio_frequency_label, c);
427 c = new GridBagConstraints();
428 c.gridx = 4; c.gridy = row;
430 c.fill = GridBagConstraints.HORIZONTAL;
432 c.anchor = GridBagConstraints.LINE_START;
435 radio_frequency_value = new AltosFreqList();
436 radio_frequency_value.addItemListener(this);
438 JMenuBar menu_bar = new JMenuBar();
439 menu_bar.add(radio_frequency_value);
440 pane.add(menu_bar, c);
441 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
444 /* Radio Calibration */
445 c = new GridBagConstraints();
446 c.gridx = 0; c.gridy = row;
448 c.fill = GridBagConstraints.NONE;
449 c.anchor = GridBagConstraints.LINE_START;
452 radio_calibration_label = new JLabel("RF Calibration:");
453 pane.add(radio_calibration_label, c);
455 c = new GridBagConstraints();
456 c.gridx = 4; c.gridy = row;
458 c.fill = GridBagConstraints.HORIZONTAL;
460 c.anchor = GridBagConstraints.LINE_START;
463 radio_calibration_value = new JTextField(String.format("%d", 1186611));
464 radio_calibration_value.getDocument().addDocumentListener(this);
466 radio_calibration_value.setEnabled(false);
467 pane.add(radio_calibration_value, c);
468 set_radio_calibration_tool_tip();
472 c = new GridBagConstraints();
473 c.gridx = 0; c.gridy = row;
475 c.fill = GridBagConstraints.NONE;
476 c.anchor = GridBagConstraints.LINE_START;
479 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
480 pane.add(radio_enable_label, c);
482 c = new GridBagConstraints();
483 c.gridx = 4; c.gridy = row;
485 c.fill = GridBagConstraints.HORIZONTAL;
487 c.anchor = GridBagConstraints.LINE_START;
490 radio_enable_value = new JRadioButton("Enabled");
491 radio_enable_value.addItemListener(this);
492 pane.add(radio_enable_value, c);
493 set_radio_enable_tool_tip();
497 c = new GridBagConstraints();
498 c.gridx = 0; c.gridy = row;
500 c.fill = GridBagConstraints.NONE;
501 c.anchor = GridBagConstraints.LINE_START;
504 aprs_interval_label = new JLabel("APRS Interval(s):");
505 pane.add(aprs_interval_label, c);
507 c = new GridBagConstraints();
508 c.gridx = 4; c.gridy = row;
510 c.fill = GridBagConstraints.HORIZONTAL;
512 c.anchor = GridBagConstraints.LINE_START;
515 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
516 aprs_interval_value.setEditable(true);
517 aprs_interval_value.addItemListener(this);
518 pane.add(aprs_interval_value, c);
519 set_aprs_interval_tool_tip();
523 c = new GridBagConstraints();
524 c.gridx = 0; c.gridy = row;
526 c.fill = GridBagConstraints.NONE;
527 c.anchor = GridBagConstraints.LINE_START;
530 aprs_ssid_label = new JLabel("APRS SSID:");
531 pane.add(aprs_ssid_label, c);
533 c = new GridBagConstraints();
534 c.gridx = 4; c.gridy = row;
536 c.fill = GridBagConstraints.HORIZONTAL;
538 c.anchor = GridBagConstraints.LINE_START;
541 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
542 aprs_ssid_value.setEditable(false);
543 aprs_ssid_value.addItemListener(this);
544 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
545 pane.add(aprs_ssid_value, c);
546 set_aprs_ssid_tool_tip();
550 c = new GridBagConstraints();
551 c.gridx = 0; c.gridy = row;
553 c.fill = GridBagConstraints.NONE;
554 c.anchor = GridBagConstraints.LINE_START;
557 callsign_label = new JLabel("Callsign:");
558 pane.add(callsign_label, c);
560 c = new GridBagConstraints();
561 c.gridx = 4; c.gridy = row;
563 c.fill = GridBagConstraints.HORIZONTAL;
565 c.anchor = GridBagConstraints.LINE_START;
568 callsign_value = new JTextField(AltosUIPreferences.callsign());
569 callsign_value.getDocument().addDocumentListener(this);
570 pane.add(callsign_value, c);
571 callsign_value.setToolTipText("Callsign reported in telemetry data");
575 c = new GridBagConstraints();
576 c.gridx = 0; c.gridy = row;
578 c.fill = GridBagConstraints.NONE;
579 c.anchor = GridBagConstraints.LINE_START;
582 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
583 pane.add(flight_log_max_label, c);
585 c = new GridBagConstraints();
586 c.gridx = 4; c.gridy = row;
588 c.fill = GridBagConstraints.HORIZONTAL;
590 c.anchor = GridBagConstraints.LINE_START;
593 flight_log_max_value = new JComboBox<String>();
594 flight_log_max_value.setEditable(true);
595 flight_log_max_value.addItemListener(this);
596 pane.add(flight_log_max_value, c);
597 set_flight_log_max_tool_tip();
601 c = new GridBagConstraints();
602 c.gridx = 0; c.gridy = row;
604 c.fill = GridBagConstraints.NONE;
605 c.anchor = GridBagConstraints.LINE_START;
608 ignite_mode_label = new JLabel("Igniter Firing Mode:");
609 pane.add(ignite_mode_label, c);
611 c = new GridBagConstraints();
612 c.gridx = 4; c.gridy = row;
614 c.fill = GridBagConstraints.HORIZONTAL;
616 c.anchor = GridBagConstraints.LINE_START;
619 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
620 ignite_mode_value.setEditable(false);
621 ignite_mode_value.addItemListener(this);
622 pane.add(ignite_mode_value, c);
623 set_ignite_mode_tool_tip();
626 /* Pad orientation */
627 c = new GridBagConstraints();
628 c.gridx = 0; c.gridy = row;
630 c.fill = GridBagConstraints.NONE;
631 c.anchor = GridBagConstraints.LINE_START;
634 pad_orientation_label = new JLabel("Pad Orientation:");
635 pane.add(pad_orientation_label, c);
637 c = new GridBagConstraints();
638 c.gridx = 4; c.gridy = row;
640 c.fill = GridBagConstraints.HORIZONTAL;
642 c.anchor = GridBagConstraints.LINE_START;
645 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
646 pad_orientation_value.setEditable(false);
647 pad_orientation_value.addItemListener(this);
648 pane.add(pad_orientation_value, c);
649 set_pad_orientation_tool_tip();
653 c = new GridBagConstraints();
654 c.gridx = 0; c.gridy = row;
656 c.fill = GridBagConstraints.NONE;
657 c.anchor = GridBagConstraints.LINE_START;
660 beep_label = new JLabel("Beeper Frequency:");
661 pane.add(beep_label, c);
663 c = new GridBagConstraints();
664 c.gridx = 4; c.gridy = row;
666 c.fill = GridBagConstraints.HORIZONTAL;
668 c.anchor = GridBagConstraints.LINE_START;
671 beep_value = new JComboBox<String>(beep_values);
672 beep_value.setEditable(true);
673 beep_value.addItemListener(this);
674 pane.add(beep_value, c);
678 /* Tracker triger horiz distances */
679 c = new GridBagConstraints();
680 c.gridx = 0; c.gridy = row;
682 c.fill = GridBagConstraints.NONE;
683 c.anchor = GridBagConstraints.LINE_START;
686 tracker_motion_label = new JLabel(get_tracker_motion_label());
687 pane.add(tracker_motion_label, c);
689 c = new GridBagConstraints();
690 c.gridx = 4; c.gridy = row;
692 c.fill = GridBagConstraints.HORIZONTAL;
694 c.anchor = GridBagConstraints.LINE_START;
697 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
698 tracker_motion_value.setEditable(true);
699 tracker_motion_value.addItemListener(this);
700 pane.add(tracker_motion_value, c);
703 /* Tracker triger vert distances */
704 c = new GridBagConstraints();
705 c.gridx = 0; c.gridy = row;
707 c.fill = GridBagConstraints.NONE;
708 c.anchor = GridBagConstraints.LINE_START;
711 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
712 pane.add(tracker_interval_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 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
723 tracker_interval_value.setEditable(true);
724 tracker_interval_value.addItemListener(this);
725 pane.add(tracker_interval_value, c);
726 set_tracker_tool_tip();
730 c = new GridBagConstraints();
731 c.gridx = 4; c.gridy = row;
733 c.fill = GridBagConstraints.HORIZONTAL;
734 c.anchor = GridBagConstraints.LINE_START;
737 pyro = new JButton("Configure Pyro Channels");
739 pyro.addActionListener(this);
740 pyro.setActionCommand("Pyro");
744 c = new GridBagConstraints();
745 c.gridx = 0; c.gridy = row;
747 c.fill = GridBagConstraints.NONE;
748 c.anchor = GridBagConstraints.LINE_START;
750 save = new JButton("Save");
752 save.addActionListener(this);
753 save.setActionCommand("Save");
755 c = new GridBagConstraints();
756 c.gridx = 2; c.gridy = row;
758 c.fill = GridBagConstraints.NONE;
759 c.anchor = GridBagConstraints.CENTER;
761 reset = new JButton("Reset");
763 reset.addActionListener(this);
764 reset.setActionCommand("Reset");
766 c = new GridBagConstraints();
767 c.gridx = 4; c.gridy = row;
769 c.fill = GridBagConstraints.NONE;
770 c.anchor = GridBagConstraints.CENTER;
772 reboot = new JButton("Reboot");
774 reboot.addActionListener(this);
775 reboot.setActionCommand("Reboot");
777 c = new GridBagConstraints();
778 c.gridx = 6; c.gridy = row;
780 c.fill = GridBagConstraints.NONE;
781 c.anchor = GridBagConstraints.LINE_END;
783 close = new JButton("Close");
785 close.addActionListener(this);
786 close.setActionCommand("Close");
788 addWindowListener(new ConfigListener(this));
789 AltosPreferences.register_units_listener(this);
792 /* Once the initial values are set, the config code will show the dialog */
793 public void make_visible() {
795 setLocationRelativeTo(owner);
799 /* If any values have been changed, confirm before closing */
800 public boolean check_dirty(String operation) {
802 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
804 i = JOptionPane.showOptionDialog(this,
805 String.format("Configuration modified. %s anyway?", operation),
806 "Configuration Modified",
807 JOptionPane.DEFAULT_OPTION,
808 JOptionPane.WARNING_MESSAGE,
809 null, options, options[1]);
818 save.setEnabled(true);
821 public void set_clean() {
823 save.setEnabled(false);
826 AltosConfigPyroUI pyro_ui;
828 public void dispose() {
831 AltosPreferences.unregister_units_listener(this);
835 /* Listen for events from our buttons */
836 public void actionPerformed(ActionEvent e) {
837 String cmd = e.getActionCommand();
839 if (cmd.equals("Pyro")) {
840 if (pyro_ui == null && pyros != null)
841 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
843 pyro_ui.make_visible();
847 if (cmd.equals("Close") || cmd.equals("Reboot"))
848 if (!check_dirty(cmd))
850 listener.actionPerformed(e);
851 if (cmd.equals("Close") || cmd.equals("Reboot")) {
858 /* ItemListener interface method */
859 public void itemStateChanged(ItemEvent e) {
863 /* DocumentListener interface methods */
864 public void changedUpdate(DocumentEvent e) {
868 public void insertUpdate(DocumentEvent e) {
872 public void removeUpdate(DocumentEvent e) {
876 /* Let the config code hook on a listener */
877 public void addActionListener(ActionListener l) {
881 /* set and get all of the dialog values */
882 public void set_product(String product) {
883 radio_frequency_value.set_product(product);
884 product_value.setText(product);
885 set_pad_orientation_tool_tip();
886 set_flight_log_max_tool_tip();
889 public void set_version(String version) {
890 version_value.setText(version);
893 public void set_serial(int serial) {
894 radio_frequency_value.set_serial(serial);
895 serial_value.setText(String.format("%d", serial));
898 public void set_main_deploy(int new_main_deploy) {
899 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
900 main_deploy_value.setEnabled(new_main_deploy >= 0);
903 public int main_deploy() {
904 return (int) (AltosConvert.height.parse(main_deploy_value.getSelectedItem().toString()) + 0.5);
907 String get_main_deploy_label() {
908 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.show_units());
911 String[] main_deploy_values() {
912 if (AltosConvert.imperial_units)
913 return main_deploy_values_ft;
915 return main_deploy_values_m;
918 void set_main_deploy_values() {
919 String[] v = main_deploy_values();
920 while (main_deploy_value.getItemCount() > 0)
921 main_deploy_value.removeItemAt(0);
922 for (int i = 0; i < v.length; i++)
923 main_deploy_value.addItem(v[i]);
924 main_deploy_value.setMaximumRowCount(v.length);
927 public void units_changed(boolean imperial_units) {
928 String v = main_deploy_value.getSelectedItem().toString();
929 main_deploy_label.setText(get_main_deploy_label());
930 set_main_deploy_values();
931 int m = (int) (AltosConvert.height.parse(v, !imperial_units) + 0.5);
934 if (tracker_motion_value.isEnabled()) {
935 String motion = tracker_motion_value.getSelectedItem().toString();
936 tracker_motion_label.setText(get_tracker_motion_label());
937 set_tracker_motion_values();
938 set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5));
942 public void set_apogee_delay(int new_apogee_delay) {
943 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
944 apogee_delay_value.setEnabled(new_apogee_delay >= 0);
947 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
950 v = s.split("\\s+")[0];
952 return Integer.parseInt(v);
953 } catch (NumberFormatException ne) {
954 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
958 public int apogee_delay() throws AltosConfigDataException {
959 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
962 public void set_apogee_lockout(int new_apogee_lockout) {
963 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
964 apogee_lockout_value.setEnabled(new_apogee_lockout >= 0);
967 public int apogee_lockout() throws AltosConfigDataException {
968 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
971 public void set_radio_frequency(double new_radio_frequency) {
972 radio_frequency_value.set_frequency(new_radio_frequency);
975 public double radio_frequency() {
976 return radio_frequency_value.frequency();
979 public void set_radio_calibration(int new_radio_calibration) {
980 radio_calibration_value.setVisible(new_radio_calibration >= 0);
981 if (new_radio_calibration < 0)
982 radio_calibration_value.setText("Disabled");
984 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
987 public int radio_calibration() throws AltosConfigDataException {
988 return parse_int("radio calibration", radio_calibration_value.getText(), false);
991 public void set_radio_enable(int new_radio_enable) {
992 if (new_radio_enable >= 0) {
993 radio_enable_value.setSelected(new_radio_enable > 0);
994 radio_enable_value.setEnabled(true);
996 radio_enable_value.setSelected(true);
997 radio_enable_value.setVisible(radio_frequency() > 0);
998 radio_enable_value.setEnabled(false);
1000 set_radio_enable_tool_tip();
1003 public int radio_enable() {
1004 if (radio_enable_value.isEnabled())
1005 return radio_enable_value.isSelected() ? 1 : 0;
1010 public void set_callsign(String new_callsign) {
1011 callsign_value.setVisible(new_callsign != null);
1012 callsign_value.setText(new_callsign);
1015 public String callsign() {
1016 return callsign_value.getText();
1019 int flight_log_max_limit;
1022 public String flight_log_max_label(int flight_log_max) {
1023 if (flight_log_max_limit != 0) {
1024 int nflight = flight_log_max_limit / flight_log_max;
1025 String plural = nflight > 1 ? "s" : "";
1027 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1029 return String.format("%d", flight_log_max);
1032 public void set_flight_log_max(int new_flight_log_max) {
1033 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1034 flight_log_max = new_flight_log_max;
1035 set_flight_log_max_tool_tip();
1038 public void set_flight_log_max_enabled(boolean enable) {
1039 flight_log_max_value.setEnabled(enable);
1040 set_flight_log_max_tool_tip();
1043 public int flight_log_max() throws AltosConfigDataException {
1044 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1047 public void set_flight_log_max_limit(int new_flight_log_max_limit) {
1048 flight_log_max_limit = new_flight_log_max_limit;
1049 flight_log_max_value.removeAllItems();
1050 for (int i = 8; i >= 1; i--) {
1051 int size = flight_log_max_limit / i;
1052 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1054 if (flight_log_max != 0)
1055 set_flight_log_max(flight_log_max);
1058 public void set_ignite_mode(int new_ignite_mode) {
1059 if (new_ignite_mode >= ignite_mode_values.length)
1060 new_ignite_mode = 0;
1061 if (new_ignite_mode < 0) {
1062 ignite_mode_value.setEnabled(false);
1063 new_ignite_mode = 0;
1065 ignite_mode_value.setEnabled(true);
1067 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1068 set_ignite_mode_tool_tip();
1071 public int ignite_mode() {
1072 if (ignite_mode_value.isEnabled())
1073 return ignite_mode_value.getSelectedIndex();
1079 public void set_pad_orientation(int new_pad_orientation) {
1080 if (new_pad_orientation >= pad_orientation_values.length)
1081 new_pad_orientation = 0;
1082 if (new_pad_orientation < 0) {
1083 pad_orientation_value.setVisible(false);
1084 new_pad_orientation = 0;
1086 pad_orientation_value.setVisible(true);
1088 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1089 set_pad_orientation_tool_tip();
1092 public int pad_orientation() {
1093 if (pad_orientation_value.isEnabled())
1094 return pad_orientation_value.getSelectedIndex();
1099 public void set_beep(int new_beep) {
1100 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1101 for (int i = 0; i < beep_values.length; i++)
1102 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1103 beep_value.setSelectedIndex(i);
1104 set_beep_tool_tip();
1107 beep_value.setSelectedItem(String.format("%d", new_freq));
1108 beep_value.setEnabled(new_beep >= 0);
1109 set_beep_tool_tip();
1113 if (beep_value.isEnabled())
1114 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1119 String[] tracker_motion_values() {
1120 if (AltosConvert.imperial_units)
1121 return tracker_motion_values_ft;
1123 return tracker_motion_values_m;
1126 void set_tracker_motion_values() {
1127 String[] v = tracker_motion_values();
1128 while (tracker_motion_value.getItemCount() > 0)
1129 tracker_motion_value.removeItemAt(0);
1130 for (int i = 0; i < v.length; i++)
1131 tracker_motion_value.addItem(v[i]);
1132 tracker_motion_value.setMaximumRowCount(v.length);
1135 String get_tracker_motion_label() {
1136 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.show_units());
1139 void set_tracker_tool_tip() {
1140 if (tracker_motion_value.isEnabled())
1141 tracker_motion_value.setToolTipText("How far the device must move before logging");
1143 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1144 if (tracker_interval_value.isEnabled())
1145 tracker_interval_value.setToolTipText("How often to report GPS position");
1147 tracker_interval_value.setToolTipText("This device can't configure interval");
1150 public void set_tracker_motion(int tracker_motion) {
1151 if (tracker_motion < 0) {
1152 tracker_motion_label.setVisible(false);
1153 tracker_motion_value.setVisible(false);
1155 tracker_motion_label.setVisible(true);
1156 tracker_motion_value.setVisible(true);
1157 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1161 public int tracker_motion() throws AltosConfigDataException {
1162 return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString());
1165 public void set_tracker_interval(int tracker_interval) {
1166 if (tracker_interval< 0) {
1167 tracker_interval_label.setVisible(false);
1168 tracker_interval_value.setVisible(false);
1170 tracker_interval_label.setVisible(true);
1171 tracker_interval_value.setVisible(true);
1172 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1176 public int tracker_interval() throws AltosConfigDataException {
1177 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1180 public void set_pyros(AltosPyro[] new_pyros) {
1182 pyro.setVisible(pyros != null);
1183 if (pyros != null && pyro_ui != null)
1184 pyro_ui.set_pyros(pyros);
1187 public AltosPyro[] pyros() throws AltosConfigDataException {
1188 if (pyro_ui != null)
1189 pyros = pyro_ui.get_pyros();
1193 public void set_pyro_firing_time(double new_pyro_firing_time) {
1194 pyro_firing_time = new_pyro_firing_time;
1195 pyro.setVisible(pyro_firing_time >= 0);
1196 if (pyro_firing_time >= 0 && pyro_ui != null)
1197 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1200 public double pyro_firing_time() throws AltosConfigDataException {
1201 if (pyro_ui != null)
1202 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1203 return pyro_firing_time;
1206 public void set_aprs_interval(int new_aprs_interval) {
1209 if (new_aprs_interval <= 0)
1212 s = Integer.toString(new_aprs_interval);
1213 aprs_interval_value.setSelectedItem(s);
1214 aprs_interval_value.setVisible(new_aprs_interval >= 0);
1215 set_aprs_interval_tool_tip();
1218 public int aprs_interval() throws AltosConfigDataException {
1219 String s = aprs_interval_value.getSelectedItem().toString();
1221 if (s.equals("Disabled"))
1223 return parse_int("aprs interval", s, false);
1226 public void set_aprs_ssid(int new_aprs_ssid) {
1227 aprs_ssid_value.setSelectedItem(Math.max(0,new_aprs_ssid));
1228 aprs_ssid_value.setVisible(new_aprs_ssid >= 0);
1229 set_aprs_ssid_tool_tip();
1232 public int aprs_ssid() throws AltosConfigDataException {
1233 Integer i = (Integer) aprs_ssid_value.getSelectedItem();