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_4.*;
25 import org.altusmetrum.altosuilib_2.*;
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 flight_log_max_label;
45 JLabel ignite_mode_label;
46 JLabel pad_orientation_label;
47 JLabel callsign_label;
49 JLabel tracker_motion_label;
50 JLabel tracker_interval_label;
58 JComboBox<String> main_deploy_value;
59 JComboBox<String> apogee_delay_value;
60 JComboBox<String> apogee_lockout_value;
61 AltosFreqList radio_frequency_value;
62 JTextField radio_calibration_value;
63 JRadioButton radio_enable_value;
64 JComboBox<String> aprs_interval_value;
65 JComboBox<String> flight_log_max_value;
66 JComboBox<String> ignite_mode_value;
67 JComboBox<String> pad_orientation_value;
68 JTextField callsign_value;
69 JComboBox<String> beep_value;
70 JComboBox<String> tracker_motion_value;
71 JComboBox<String> tracker_interval_value;
81 double pyro_firing_time;
83 ActionListener listener;
85 static String[] main_deploy_values_m = {
86 "100", "150", "200", "250", "300", "350",
90 static String[] main_deploy_values_ft = {
91 "250", "500", "750", "1000", "1250", "1500",
95 static String[] apogee_delay_values = {
96 "0", "1", "2", "3", "4", "5"
99 static String[] apogee_lockout_values = {
100 "0", "5", "10", "15", "20"
103 static String[] ignite_mode_values = {
109 static String[] aprs_interval_values = {
116 static String[] beep_values = {
122 static String[] pad_orientation_values = {
127 static String[] tracker_motion_values_m = {
134 static String[] tracker_motion_values_ft = {
141 static String[] tracker_interval_values = {
148 /* A window listener to catch closing events and tell the config code */
149 class ConfigListener extends WindowAdapter {
152 public ConfigListener(AltosConfigUI this_ui) {
156 public void windowClosing(WindowEvent e) {
157 ui.actionPerformed(new ActionEvent(e.getSource(),
158 ActionEvent.ACTION_PERFORMED,
163 boolean is_telemini_v1() {
164 String product = product_value.getText();
165 return product != null && product.startsWith("TeleMini-v1");
168 boolean is_telemini() {
169 String product = product_value.getText();
170 return product != null && product.startsWith("TeleMini");
173 boolean is_easymini() {
174 String product = product_value.getText();
175 return product != null && product.startsWith("EasyMini");
178 boolean is_telemetrum() {
179 String product = product_value.getText();
180 return product != null && product.startsWith("TeleMetrum");
183 void set_radio_calibration_tool_tip() {
184 if (radio_calibration_value.isEnabled())
185 radio_calibration_value.setToolTipText("Tune radio output to match desired frequency");
187 radio_calibration_value.setToolTipText("Cannot tune radio while connected over packet mode");
190 void set_radio_enable_tool_tip() {
191 if (radio_enable_value.isEnabled())
192 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
194 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
197 void set_aprs_interval_tool_tip() {
198 if (aprs_interval_value.isEnabled())
199 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
201 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
204 void set_flight_log_max_tool_tip() {
205 if (flight_log_max_value.isEnabled())
206 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
208 if (is_telemini_v1())
209 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
211 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
215 void set_ignite_mode_tool_tip() {
216 if (ignite_mode_value.isEnabled())
217 ignite_mode_value.setToolTipText("Select when igniters will be fired");
219 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
222 void set_pad_orientation_tool_tip() {
223 if (pad_orientation_value.isEnabled())
224 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
227 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
228 else if (is_telemini() || is_easymini())
229 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
231 pad_orientation_value.setToolTipText("Can't select orientation");
235 void set_beep_tool_tip() {
236 if (beep_value.isEnabled())
237 beep_value.setToolTipText("What frequency the beeper will sound at");
239 beep_value.setToolTipText("Older firmware could not select beeper frequency");
242 /* Build the UI using a grid bag */
243 public AltosConfigUI(JFrame in_owner, boolean remote) {
244 super (in_owner, "Configure Flight Computer", false);
247 GridBagConstraints c;
250 Insets il = new Insets(4,4,4,4);
251 Insets ir = new Insets(4,4,4,4);
253 pane = getContentPane();
254 pane.setLayout(new GridBagLayout());
257 c = new GridBagConstraints();
258 c.gridx = 0; c.gridy = row;
260 c.fill = GridBagConstraints.NONE;
261 c.anchor = GridBagConstraints.LINE_START;
263 product_label = new JLabel("Product:");
264 pane.add(product_label, c);
266 c = new GridBagConstraints();
267 c.gridx = 4; c.gridy = row;
269 c.fill = GridBagConstraints.HORIZONTAL;
271 c.anchor = GridBagConstraints.LINE_START;
273 product_value = new JLabel("");
274 pane.add(product_value, c);
278 c = new GridBagConstraints();
279 c.gridx = 0; c.gridy = row;
281 c.fill = GridBagConstraints.NONE;
282 c.anchor = GridBagConstraints.LINE_START;
285 version_label = new JLabel("Software version:");
286 pane.add(version_label, c);
288 c = new GridBagConstraints();
289 c.gridx = 4; c.gridy = row;
291 c.fill = GridBagConstraints.HORIZONTAL;
293 c.anchor = GridBagConstraints.LINE_START;
296 version_value = new JLabel("");
297 pane.add(version_value, c);
301 c = new GridBagConstraints();
302 c.gridx = 0; c.gridy = row;
304 c.fill = GridBagConstraints.NONE;
305 c.anchor = GridBagConstraints.LINE_START;
308 serial_label = new JLabel("Serial:");
309 pane.add(serial_label, c);
311 c = new GridBagConstraints();
312 c.gridx = 4; c.gridy = row;
314 c.fill = GridBagConstraints.HORIZONTAL;
316 c.anchor = GridBagConstraints.LINE_START;
319 serial_value = new JLabel("");
320 pane.add(serial_value, c);
324 c = new GridBagConstraints();
325 c.gridx = 0; c.gridy = row;
327 c.fill = GridBagConstraints.NONE;
328 c.anchor = GridBagConstraints.LINE_START;
331 main_deploy_label = new JLabel(get_main_deploy_label());
332 pane.add(main_deploy_label, c);
334 c = new GridBagConstraints();
335 c.gridx = 4; c.gridy = row;
337 c.fill = GridBagConstraints.HORIZONTAL;
339 c.anchor = GridBagConstraints.LINE_START;
342 main_deploy_value = new JComboBox<String>(main_deploy_values());
343 main_deploy_value.setEditable(true);
344 main_deploy_value.addItemListener(this);
345 pane.add(main_deploy_value, c);
346 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
350 c = new GridBagConstraints();
351 c.gridx = 0; c.gridy = row;
353 c.fill = GridBagConstraints.NONE;
354 c.anchor = GridBagConstraints.LINE_START;
357 apogee_delay_label = new JLabel("Apogee Delay(s):");
358 pane.add(apogee_delay_label, c);
360 c = new GridBagConstraints();
361 c.gridx = 4; c.gridy = row;
363 c.fill = GridBagConstraints.HORIZONTAL;
365 c.anchor = GridBagConstraints.LINE_START;
368 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
369 apogee_delay_value.setEditable(true);
370 apogee_delay_value.addItemListener(this);
371 pane.add(apogee_delay_value, c);
372 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
376 c = new GridBagConstraints();
377 c.gridx = 0; c.gridy = row;
379 c.fill = GridBagConstraints.NONE;
380 c.anchor = GridBagConstraints.LINE_START;
383 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
384 pane.add(apogee_lockout_label, c);
386 c = new GridBagConstraints();
387 c.gridx = 4; c.gridy = row;
389 c.fill = GridBagConstraints.HORIZONTAL;
391 c.anchor = GridBagConstraints.LINE_START;
394 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
395 apogee_lockout_value.setEditable(true);
396 apogee_lockout_value.addItemListener(this);
397 pane.add(apogee_lockout_value, c);
398 apogee_lockout_value.setToolTipText("Time after boost while apogee detection is locked out");
402 c = new GridBagConstraints();
403 c.gridx = 0; c.gridy = row;
405 c.fill = GridBagConstraints.NONE;
406 c.anchor = GridBagConstraints.LINE_START;
409 radio_frequency_label = new JLabel("Frequency:");
410 pane.add(radio_frequency_label, c);
412 c = new GridBagConstraints();
413 c.gridx = 4; c.gridy = row;
415 c.fill = GridBagConstraints.HORIZONTAL;
417 c.anchor = GridBagConstraints.LINE_START;
420 radio_frequency_value = new AltosFreqList();
421 radio_frequency_value.addItemListener(this);
422 pane.add(radio_frequency_value, c);
423 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
426 /* Radio Calibration */
427 c = new GridBagConstraints();
428 c.gridx = 0; c.gridy = row;
430 c.fill = GridBagConstraints.NONE;
431 c.anchor = GridBagConstraints.LINE_START;
434 radio_calibration_label = new JLabel("RF Calibration:");
435 pane.add(radio_calibration_label, c);
437 c = new GridBagConstraints();
438 c.gridx = 4; c.gridy = row;
440 c.fill = GridBagConstraints.HORIZONTAL;
442 c.anchor = GridBagConstraints.LINE_START;
445 radio_calibration_value = new JTextField(String.format("%d", 1186611));
446 radio_calibration_value.getDocument().addDocumentListener(this);
448 radio_calibration_value.setEnabled(false);
449 pane.add(radio_calibration_value, c);
450 set_radio_calibration_tool_tip();
454 c = new GridBagConstraints();
455 c.gridx = 0; c.gridy = row;
457 c.fill = GridBagConstraints.NONE;
458 c.anchor = GridBagConstraints.LINE_START;
461 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
462 pane.add(radio_enable_label, c);
464 c = new GridBagConstraints();
465 c.gridx = 4; c.gridy = row;
467 c.fill = GridBagConstraints.HORIZONTAL;
469 c.anchor = GridBagConstraints.LINE_START;
472 radio_enable_value = new JRadioButton("Enabled");
473 radio_enable_value.addItemListener(this);
474 pane.add(radio_enable_value, c);
475 set_radio_enable_tool_tip();
479 c = new GridBagConstraints();
480 c.gridx = 0; c.gridy = row;
482 c.fill = GridBagConstraints.NONE;
483 c.anchor = GridBagConstraints.LINE_START;
486 aprs_interval_label = new JLabel("APRS Interval(s):");
487 pane.add(aprs_interval_label, c);
489 c = new GridBagConstraints();
490 c.gridx = 4; c.gridy = row;
492 c.fill = GridBagConstraints.HORIZONTAL;
494 c.anchor = GridBagConstraints.LINE_START;
497 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
498 aprs_interval_value.setEditable(true);
499 aprs_interval_value.addItemListener(this);
500 pane.add(aprs_interval_value, c);
501 set_aprs_interval_tool_tip();
505 c = new GridBagConstraints();
506 c.gridx = 0; c.gridy = row;
508 c.fill = GridBagConstraints.NONE;
509 c.anchor = GridBagConstraints.LINE_START;
512 callsign_label = new JLabel("Callsign:");
513 pane.add(callsign_label, c);
515 c = new GridBagConstraints();
516 c.gridx = 4; c.gridy = row;
518 c.fill = GridBagConstraints.HORIZONTAL;
520 c.anchor = GridBagConstraints.LINE_START;
523 callsign_value = new JTextField(AltosUIPreferences.callsign());
524 callsign_value.getDocument().addDocumentListener(this);
525 pane.add(callsign_value, c);
526 callsign_value.setToolTipText("Callsign reported in telemetry data");
530 c = new GridBagConstraints();
531 c.gridx = 0; c.gridy = row;
533 c.fill = GridBagConstraints.NONE;
534 c.anchor = GridBagConstraints.LINE_START;
537 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
538 pane.add(flight_log_max_label, c);
540 c = new GridBagConstraints();
541 c.gridx = 4; c.gridy = row;
543 c.fill = GridBagConstraints.HORIZONTAL;
545 c.anchor = GridBagConstraints.LINE_START;
548 flight_log_max_value = new JComboBox<String>();
549 flight_log_max_value.setEditable(true);
550 flight_log_max_value.addItemListener(this);
551 pane.add(flight_log_max_value, c);
552 set_flight_log_max_tool_tip();
556 c = new GridBagConstraints();
557 c.gridx = 0; c.gridy = row;
559 c.fill = GridBagConstraints.NONE;
560 c.anchor = GridBagConstraints.LINE_START;
563 ignite_mode_label = new JLabel("Igniter Firing Mode:");
564 pane.add(ignite_mode_label, c);
566 c = new GridBagConstraints();
567 c.gridx = 4; c.gridy = row;
569 c.fill = GridBagConstraints.HORIZONTAL;
571 c.anchor = GridBagConstraints.LINE_START;
574 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
575 ignite_mode_value.setEditable(false);
576 ignite_mode_value.addItemListener(this);
577 pane.add(ignite_mode_value, c);
578 set_ignite_mode_tool_tip();
581 /* Pad orientation */
582 c = new GridBagConstraints();
583 c.gridx = 0; c.gridy = row;
585 c.fill = GridBagConstraints.NONE;
586 c.anchor = GridBagConstraints.LINE_START;
589 pad_orientation_label = new JLabel("Pad Orientation:");
590 pane.add(pad_orientation_label, c);
592 c = new GridBagConstraints();
593 c.gridx = 4; c.gridy = row;
595 c.fill = GridBagConstraints.HORIZONTAL;
597 c.anchor = GridBagConstraints.LINE_START;
600 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
601 pad_orientation_value.setEditable(false);
602 pad_orientation_value.addItemListener(this);
603 pane.add(pad_orientation_value, c);
604 set_pad_orientation_tool_tip();
608 c = new GridBagConstraints();
609 c.gridx = 0; c.gridy = row;
611 c.fill = GridBagConstraints.NONE;
612 c.anchor = GridBagConstraints.LINE_START;
615 beep_label = new JLabel("Beeper Frequency:");
616 pane.add(beep_label, c);
618 c = new GridBagConstraints();
619 c.gridx = 4; c.gridy = row;
621 c.fill = GridBagConstraints.HORIZONTAL;
623 c.anchor = GridBagConstraints.LINE_START;
626 beep_value = new JComboBox<String>(beep_values);
627 beep_value.setEditable(true);
628 beep_value.addItemListener(this);
629 pane.add(beep_value, c);
633 /* Tracker triger horiz distances */
634 c = new GridBagConstraints();
635 c.gridx = 0; c.gridy = row;
637 c.fill = GridBagConstraints.NONE;
638 c.anchor = GridBagConstraints.LINE_START;
641 tracker_motion_label = new JLabel(get_tracker_motion_label());
642 pane.add(tracker_motion_label, c);
644 c = new GridBagConstraints();
645 c.gridx = 4; c.gridy = row;
647 c.fill = GridBagConstraints.HORIZONTAL;
649 c.anchor = GridBagConstraints.LINE_START;
652 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
653 tracker_motion_value.setEditable(true);
654 tracker_motion_value.addItemListener(this);
655 pane.add(tracker_motion_value, c);
658 /* Tracker triger vert distances */
659 c = new GridBagConstraints();
660 c.gridx = 0; c.gridy = row;
662 c.fill = GridBagConstraints.NONE;
663 c.anchor = GridBagConstraints.LINE_START;
666 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
667 pane.add(tracker_interval_label, c);
669 c = new GridBagConstraints();
670 c.gridx = 4; c.gridy = row;
672 c.fill = GridBagConstraints.HORIZONTAL;
674 c.anchor = GridBagConstraints.LINE_START;
677 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
678 tracker_interval_value.setEditable(true);
679 tracker_interval_value.addItemListener(this);
680 pane.add(tracker_interval_value, c);
681 set_tracker_tool_tip();
685 c = new GridBagConstraints();
686 c.gridx = 4; c.gridy = row;
688 c.fill = GridBagConstraints.HORIZONTAL;
689 c.anchor = GridBagConstraints.LINE_START;
692 pyro = new JButton("Configure Pyro Channels");
694 pyro.addActionListener(this);
695 pyro.setActionCommand("Pyro");
699 c = new GridBagConstraints();
700 c.gridx = 0; c.gridy = row;
702 c.fill = GridBagConstraints.NONE;
703 c.anchor = GridBagConstraints.LINE_START;
705 save = new JButton("Save");
707 save.addActionListener(this);
708 save.setActionCommand("Save");
710 c = new GridBagConstraints();
711 c.gridx = 2; c.gridy = row;
713 c.fill = GridBagConstraints.NONE;
714 c.anchor = GridBagConstraints.CENTER;
716 reset = new JButton("Reset");
718 reset.addActionListener(this);
719 reset.setActionCommand("Reset");
721 c = new GridBagConstraints();
722 c.gridx = 4; c.gridy = row;
724 c.fill = GridBagConstraints.NONE;
725 c.anchor = GridBagConstraints.CENTER;
727 reboot = new JButton("Reboot");
729 reboot.addActionListener(this);
730 reboot.setActionCommand("Reboot");
732 c = new GridBagConstraints();
733 c.gridx = 6; c.gridy = row;
735 c.fill = GridBagConstraints.NONE;
736 c.anchor = GridBagConstraints.LINE_END;
738 close = new JButton("Close");
740 close.addActionListener(this);
741 close.setActionCommand("Close");
743 addWindowListener(new ConfigListener(this));
744 AltosPreferences.register_units_listener(this);
747 /* Once the initial values are set, the config code will show the dialog */
748 public void make_visible() {
750 setLocationRelativeTo(owner);
754 /* If any values have been changed, confirm before closing */
755 public boolean check_dirty(String operation) {
757 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
759 i = JOptionPane.showOptionDialog(this,
760 String.format("Configuration modified. %s anyway?", operation),
761 "Configuration Modified",
762 JOptionPane.DEFAULT_OPTION,
763 JOptionPane.WARNING_MESSAGE,
764 null, options, options[1]);
773 save.setEnabled(true);
776 public void set_clean() {
778 save.setEnabled(false);
781 AltosConfigPyroUI pyro_ui;
783 public void dispose() {
786 AltosPreferences.unregister_units_listener(this);
790 /* Listen for events from our buttons */
791 public void actionPerformed(ActionEvent e) {
792 String cmd = e.getActionCommand();
794 if (cmd.equals("Pyro")) {
795 if (pyro_ui == null && pyros != null)
796 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
798 pyro_ui.make_visible();
802 if (cmd.equals("Close") || cmd.equals("Reboot"))
803 if (!check_dirty(cmd))
805 listener.actionPerformed(e);
806 if (cmd.equals("Close") || cmd.equals("Reboot")) {
813 /* ItemListener interface method */
814 public void itemStateChanged(ItemEvent e) {
818 /* DocumentListener interface methods */
819 public void changedUpdate(DocumentEvent e) {
823 public void insertUpdate(DocumentEvent e) {
827 public void removeUpdate(DocumentEvent e) {
831 /* Let the config code hook on a listener */
832 public void addActionListener(ActionListener l) {
836 /* set and get all of the dialog values */
837 public void set_product(String product) {
838 radio_frequency_value.set_product(product);
839 product_value.setText(product);
840 set_pad_orientation_tool_tip();
841 set_flight_log_max_tool_tip();
844 public void set_version(String version) {
845 version_value.setText(version);
848 public void set_serial(int serial) {
849 radio_frequency_value.set_serial(serial);
850 serial_value.setText(String.format("%d", serial));
853 public void set_main_deploy(int new_main_deploy) {
854 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
855 main_deploy_value.setEnabled(new_main_deploy >= 0);
858 public int main_deploy() {
859 return (int) (AltosConvert.height.parse(main_deploy_value.getSelectedItem().toString()) + 0.5);
862 String get_main_deploy_label() {
863 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.show_units());
866 String[] main_deploy_values() {
867 if (AltosConvert.imperial_units)
868 return main_deploy_values_ft;
870 return main_deploy_values_m;
873 void set_main_deploy_values() {
874 String[] v = main_deploy_values();
875 while (main_deploy_value.getItemCount() > 0)
876 main_deploy_value.removeItemAt(0);
877 for (int i = 0; i < v.length; i++)
878 main_deploy_value.addItem(v[i]);
879 main_deploy_value.setMaximumRowCount(v.length);
882 public void units_changed(boolean imperial_units) {
883 String v = main_deploy_value.getSelectedItem().toString();
884 main_deploy_label.setText(get_main_deploy_label());
885 set_main_deploy_values();
886 int m = (int) (AltosConvert.height.parse(v, !imperial_units) + 0.5);
889 if (tracker_motion_value.isEnabled()) {
890 String motion = tracker_motion_value.getSelectedItem().toString();
891 tracker_motion_label.setText(get_tracker_motion_label());
892 set_tracker_motion_values();
893 set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5));
897 public void set_apogee_delay(int new_apogee_delay) {
898 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
899 apogee_delay_value.setEnabled(new_apogee_delay >= 0);
902 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
905 v = s.split("\\s+")[0];
907 return Integer.parseInt(v);
908 } catch (NumberFormatException ne) {
909 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
913 public int apogee_delay() throws AltosConfigDataException {
914 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
917 public void set_apogee_lockout(int new_apogee_lockout) {
918 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
919 apogee_lockout_value.setEnabled(new_apogee_lockout >= 0);
922 public int apogee_lockout() throws AltosConfigDataException {
923 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
926 public void set_radio_frequency(double new_radio_frequency) {
927 radio_frequency_value.set_frequency(new_radio_frequency);
930 public double radio_frequency() {
931 return radio_frequency_value.frequency();
934 public void set_radio_calibration(int new_radio_calibration) {
935 radio_calibration_value.setVisible(new_radio_calibration >= 0);
936 if (new_radio_calibration < 0)
937 radio_calibration_value.setText("Disabled");
939 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
942 public int radio_calibration() throws AltosConfigDataException {
943 return parse_int("radio calibration", radio_calibration_value.getText(), false);
946 public void set_radio_enable(int new_radio_enable) {
947 if (new_radio_enable >= 0) {
948 radio_enable_value.setSelected(new_radio_enable > 0);
949 radio_enable_value.setEnabled(true);
951 radio_enable_value.setSelected(true);
952 radio_enable_value.setVisible(radio_frequency() > 0);
953 radio_enable_value.setEnabled(false);
955 set_radio_enable_tool_tip();
958 public int radio_enable() {
959 if (radio_enable_value.isEnabled())
960 return radio_enable_value.isSelected() ? 1 : 0;
965 public void set_callsign(String new_callsign) {
966 callsign_value.setVisible(new_callsign != null);
967 callsign_value.setText(new_callsign);
970 public String callsign() {
971 return callsign_value.getText();
974 int flight_log_max_limit;
977 public String flight_log_max_label(int flight_log_max) {
978 if (flight_log_max_limit != 0) {
979 int nflight = flight_log_max_limit / flight_log_max;
980 String plural = nflight > 1 ? "s" : "";
982 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
984 return String.format("%d", flight_log_max);
987 public void set_flight_log_max(int new_flight_log_max) {
988 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
989 flight_log_max = new_flight_log_max;
990 set_flight_log_max_tool_tip();
993 public void set_flight_log_max_enabled(boolean enable) {
994 flight_log_max_value.setEnabled(enable);
995 set_flight_log_max_tool_tip();
998 public int flight_log_max() throws AltosConfigDataException {
999 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1002 public void set_flight_log_max_limit(int new_flight_log_max_limit) {
1003 flight_log_max_limit = new_flight_log_max_limit;
1004 flight_log_max_value.removeAllItems();
1005 for (int i = 8; i >= 1; i--) {
1006 int size = flight_log_max_limit / i;
1007 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1009 if (flight_log_max != 0)
1010 set_flight_log_max(flight_log_max);
1013 public void set_ignite_mode(int new_ignite_mode) {
1014 if (new_ignite_mode >= ignite_mode_values.length)
1015 new_ignite_mode = 0;
1016 if (new_ignite_mode < 0) {
1017 ignite_mode_value.setEnabled(false);
1018 new_ignite_mode = 0;
1020 ignite_mode_value.setEnabled(true);
1022 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1023 set_ignite_mode_tool_tip();
1026 public int ignite_mode() {
1027 if (ignite_mode_value.isEnabled())
1028 return ignite_mode_value.getSelectedIndex();
1034 public void set_pad_orientation(int new_pad_orientation) {
1035 if (new_pad_orientation >= pad_orientation_values.length)
1036 new_pad_orientation = 0;
1037 if (new_pad_orientation < 0) {
1038 pad_orientation_value.setVisible(false);
1039 new_pad_orientation = 0;
1041 pad_orientation_value.setVisible(true);
1043 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1044 set_pad_orientation_tool_tip();
1047 public int pad_orientation() {
1048 if (pad_orientation_value.isEnabled())
1049 return pad_orientation_value.getSelectedIndex();
1054 public void set_beep(int new_beep) {
1055 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1056 for (int i = 0; i < beep_values.length; i++)
1057 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1058 beep_value.setSelectedIndex(i);
1059 set_beep_tool_tip();
1062 beep_value.setSelectedItem(String.format("%d", new_freq));
1063 beep_value.setEnabled(new_beep >= 0);
1064 set_beep_tool_tip();
1068 if (beep_value.isEnabled())
1069 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1074 String[] tracker_motion_values() {
1075 if (AltosConvert.imperial_units)
1076 return tracker_motion_values_ft;
1078 return tracker_motion_values_m;
1081 void set_tracker_motion_values() {
1082 String[] v = tracker_motion_values();
1083 while (tracker_motion_value.getItemCount() > 0)
1084 tracker_motion_value.removeItemAt(0);
1085 for (int i = 0; i < v.length; i++)
1086 tracker_motion_value.addItem(v[i]);
1087 tracker_motion_value.setMaximumRowCount(v.length);
1090 String get_tracker_motion_label() {
1091 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.show_units());
1094 void set_tracker_tool_tip() {
1095 if (tracker_motion_value.isEnabled())
1096 tracker_motion_value.setToolTipText("How far the device must move before logging");
1098 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1099 if (tracker_interval_value.isEnabled())
1100 tracker_interval_value.setToolTipText("How often to report GPS position");
1102 tracker_interval_value.setToolTipText("This device can't configure interval");
1105 public void set_tracker_motion(int tracker_motion) {
1106 if (tracker_motion < 0) {
1107 tracker_motion_label.setVisible(false);
1108 tracker_motion_value.setVisible(false);
1110 tracker_motion_label.setVisible(true);
1111 tracker_motion_value.setVisible(true);
1112 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1116 public int tracker_motion() throws AltosConfigDataException {
1117 return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString());
1120 public void set_tracker_interval(int tracker_interval) {
1121 if (tracker_interval< 0) {
1122 tracker_interval_label.setVisible(false);
1123 tracker_interval_value.setVisible(false);
1125 tracker_interval_label.setVisible(true);
1126 tracker_interval_value.setVisible(true);
1127 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1131 public int tracker_interval() throws AltosConfigDataException {
1132 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1135 public void set_pyros(AltosPyro[] new_pyros) {
1137 pyro.setVisible(pyros != null);
1138 if (pyros != null && pyro_ui != null)
1139 pyro_ui.set_pyros(pyros);
1142 public AltosPyro[] pyros() throws AltosConfigDataException {
1143 if (pyro_ui != null)
1144 pyros = pyro_ui.get_pyros();
1148 public void set_pyro_firing_time(double new_pyro_firing_time) {
1149 pyro_firing_time = new_pyro_firing_time;
1150 pyro.setVisible(pyro_firing_time >= 0);
1151 if (pyro_firing_time >= 0 && pyro_ui != null)
1152 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1155 public double pyro_firing_time() throws AltosConfigDataException {
1156 if (pyro_ui != null)
1157 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1158 return pyro_firing_time;
1161 public void set_aprs_interval(int new_aprs_interval) {
1164 if (new_aprs_interval <= 0)
1167 s = Integer.toString(new_aprs_interval);
1168 aprs_interval_value.setSelectedItem(s);
1169 aprs_interval_value.setVisible(new_aprs_interval >= 0);
1170 set_aprs_interval_tool_tip();
1173 public int aprs_interval() throws AltosConfigDataException {
1174 String s = aprs_interval_value.getSelectedItem().toString();
1176 if (s.equals("Disabled"))
1178 return parse_int("aprs interval", s, false);