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 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);
423 JMenuBar menu_bar = new JMenuBar();
424 menu_bar.add(radio_frequency_value);
425 pane.add(menu_bar, c);
426 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
429 /* Radio Calibration */
430 c = new GridBagConstraints();
431 c.gridx = 0; c.gridy = row;
433 c.fill = GridBagConstraints.NONE;
434 c.anchor = GridBagConstraints.LINE_START;
437 radio_calibration_label = new JLabel("RF Calibration:");
438 pane.add(radio_calibration_label, c);
440 c = new GridBagConstraints();
441 c.gridx = 4; c.gridy = row;
443 c.fill = GridBagConstraints.HORIZONTAL;
445 c.anchor = GridBagConstraints.LINE_START;
448 radio_calibration_value = new JTextField(String.format("%d", 1186611));
449 radio_calibration_value.getDocument().addDocumentListener(this);
451 radio_calibration_value.setEnabled(false);
452 pane.add(radio_calibration_value, c);
453 set_radio_calibration_tool_tip();
457 c = new GridBagConstraints();
458 c.gridx = 0; c.gridy = row;
460 c.fill = GridBagConstraints.NONE;
461 c.anchor = GridBagConstraints.LINE_START;
464 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
465 pane.add(radio_enable_label, c);
467 c = new GridBagConstraints();
468 c.gridx = 4; c.gridy = row;
470 c.fill = GridBagConstraints.HORIZONTAL;
472 c.anchor = GridBagConstraints.LINE_START;
475 radio_enable_value = new JRadioButton("Enabled");
476 radio_enable_value.addItemListener(this);
477 pane.add(radio_enable_value, c);
478 set_radio_enable_tool_tip();
482 c = new GridBagConstraints();
483 c.gridx = 0; c.gridy = row;
485 c.fill = GridBagConstraints.NONE;
486 c.anchor = GridBagConstraints.LINE_START;
489 aprs_interval_label = new JLabel("APRS Interval(s):");
490 pane.add(aprs_interval_label, c);
492 c = new GridBagConstraints();
493 c.gridx = 4; c.gridy = row;
495 c.fill = GridBagConstraints.HORIZONTAL;
497 c.anchor = GridBagConstraints.LINE_START;
500 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
501 aprs_interval_value.setEditable(true);
502 aprs_interval_value.addItemListener(this);
503 pane.add(aprs_interval_value, c);
504 set_aprs_interval_tool_tip();
508 c = new GridBagConstraints();
509 c.gridx = 0; c.gridy = row;
511 c.fill = GridBagConstraints.NONE;
512 c.anchor = GridBagConstraints.LINE_START;
515 callsign_label = new JLabel("Callsign:");
516 pane.add(callsign_label, c);
518 c = new GridBagConstraints();
519 c.gridx = 4; c.gridy = row;
521 c.fill = GridBagConstraints.HORIZONTAL;
523 c.anchor = GridBagConstraints.LINE_START;
526 callsign_value = new JTextField(AltosUIPreferences.callsign());
527 callsign_value.getDocument().addDocumentListener(this);
528 pane.add(callsign_value, c);
529 callsign_value.setToolTipText("Callsign reported in telemetry data");
533 c = new GridBagConstraints();
534 c.gridx = 0; c.gridy = row;
536 c.fill = GridBagConstraints.NONE;
537 c.anchor = GridBagConstraints.LINE_START;
540 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
541 pane.add(flight_log_max_label, c);
543 c = new GridBagConstraints();
544 c.gridx = 4; c.gridy = row;
546 c.fill = GridBagConstraints.HORIZONTAL;
548 c.anchor = GridBagConstraints.LINE_START;
551 flight_log_max_value = new JComboBox<String>();
552 flight_log_max_value.setEditable(true);
553 flight_log_max_value.addItemListener(this);
554 pane.add(flight_log_max_value, c);
555 set_flight_log_max_tool_tip();
559 c = new GridBagConstraints();
560 c.gridx = 0; c.gridy = row;
562 c.fill = GridBagConstraints.NONE;
563 c.anchor = GridBagConstraints.LINE_START;
566 ignite_mode_label = new JLabel("Igniter Firing Mode:");
567 pane.add(ignite_mode_label, c);
569 c = new GridBagConstraints();
570 c.gridx = 4; c.gridy = row;
572 c.fill = GridBagConstraints.HORIZONTAL;
574 c.anchor = GridBagConstraints.LINE_START;
577 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
578 ignite_mode_value.setEditable(false);
579 ignite_mode_value.addItemListener(this);
580 pane.add(ignite_mode_value, c);
581 set_ignite_mode_tool_tip();
584 /* Pad orientation */
585 c = new GridBagConstraints();
586 c.gridx = 0; c.gridy = row;
588 c.fill = GridBagConstraints.NONE;
589 c.anchor = GridBagConstraints.LINE_START;
592 pad_orientation_label = new JLabel("Pad Orientation:");
593 pane.add(pad_orientation_label, c);
595 c = new GridBagConstraints();
596 c.gridx = 4; c.gridy = row;
598 c.fill = GridBagConstraints.HORIZONTAL;
600 c.anchor = GridBagConstraints.LINE_START;
603 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
604 pad_orientation_value.setEditable(false);
605 pad_orientation_value.addItemListener(this);
606 pane.add(pad_orientation_value, c);
607 set_pad_orientation_tool_tip();
611 c = new GridBagConstraints();
612 c.gridx = 0; c.gridy = row;
614 c.fill = GridBagConstraints.NONE;
615 c.anchor = GridBagConstraints.LINE_START;
618 beep_label = new JLabel("Beeper Frequency:");
619 pane.add(beep_label, c);
621 c = new GridBagConstraints();
622 c.gridx = 4; c.gridy = row;
624 c.fill = GridBagConstraints.HORIZONTAL;
626 c.anchor = GridBagConstraints.LINE_START;
629 beep_value = new JComboBox<String>(beep_values);
630 beep_value.setEditable(true);
631 beep_value.addItemListener(this);
632 pane.add(beep_value, c);
636 /* Tracker triger horiz distances */
637 c = new GridBagConstraints();
638 c.gridx = 0; c.gridy = row;
640 c.fill = GridBagConstraints.NONE;
641 c.anchor = GridBagConstraints.LINE_START;
644 tracker_motion_label = new JLabel(get_tracker_motion_label());
645 pane.add(tracker_motion_label, c);
647 c = new GridBagConstraints();
648 c.gridx = 4; c.gridy = row;
650 c.fill = GridBagConstraints.HORIZONTAL;
652 c.anchor = GridBagConstraints.LINE_START;
655 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
656 tracker_motion_value.setEditable(true);
657 tracker_motion_value.addItemListener(this);
658 pane.add(tracker_motion_value, c);
661 /* Tracker triger vert distances */
662 c = new GridBagConstraints();
663 c.gridx = 0; c.gridy = row;
665 c.fill = GridBagConstraints.NONE;
666 c.anchor = GridBagConstraints.LINE_START;
669 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
670 pane.add(tracker_interval_label, c);
672 c = new GridBagConstraints();
673 c.gridx = 4; c.gridy = row;
675 c.fill = GridBagConstraints.HORIZONTAL;
677 c.anchor = GridBagConstraints.LINE_START;
680 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
681 tracker_interval_value.setEditable(true);
682 tracker_interval_value.addItemListener(this);
683 pane.add(tracker_interval_value, c);
684 set_tracker_tool_tip();
688 c = new GridBagConstraints();
689 c.gridx = 4; c.gridy = row;
691 c.fill = GridBagConstraints.HORIZONTAL;
692 c.anchor = GridBagConstraints.LINE_START;
695 pyro = new JButton("Configure Pyro Channels");
697 pyro.addActionListener(this);
698 pyro.setActionCommand("Pyro");
702 c = new GridBagConstraints();
703 c.gridx = 0; c.gridy = row;
705 c.fill = GridBagConstraints.NONE;
706 c.anchor = GridBagConstraints.LINE_START;
708 save = new JButton("Save");
710 save.addActionListener(this);
711 save.setActionCommand("Save");
713 c = new GridBagConstraints();
714 c.gridx = 2; c.gridy = row;
716 c.fill = GridBagConstraints.NONE;
717 c.anchor = GridBagConstraints.CENTER;
719 reset = new JButton("Reset");
721 reset.addActionListener(this);
722 reset.setActionCommand("Reset");
724 c = new GridBagConstraints();
725 c.gridx = 4; c.gridy = row;
727 c.fill = GridBagConstraints.NONE;
728 c.anchor = GridBagConstraints.CENTER;
730 reboot = new JButton("Reboot");
732 reboot.addActionListener(this);
733 reboot.setActionCommand("Reboot");
735 c = new GridBagConstraints();
736 c.gridx = 6; c.gridy = row;
738 c.fill = GridBagConstraints.NONE;
739 c.anchor = GridBagConstraints.LINE_END;
741 close = new JButton("Close");
743 close.addActionListener(this);
744 close.setActionCommand("Close");
746 addWindowListener(new ConfigListener(this));
747 AltosPreferences.register_units_listener(this);
750 /* Once the initial values are set, the config code will show the dialog */
751 public void make_visible() {
753 setLocationRelativeTo(owner);
757 /* If any values have been changed, confirm before closing */
758 public boolean check_dirty(String operation) {
760 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
762 i = JOptionPane.showOptionDialog(this,
763 String.format("Configuration modified. %s anyway?", operation),
764 "Configuration Modified",
765 JOptionPane.DEFAULT_OPTION,
766 JOptionPane.WARNING_MESSAGE,
767 null, options, options[1]);
776 save.setEnabled(true);
779 public void set_clean() {
781 save.setEnabled(false);
784 AltosConfigPyroUI pyro_ui;
786 public void dispose() {
789 AltosPreferences.unregister_units_listener(this);
793 /* Listen for events from our buttons */
794 public void actionPerformed(ActionEvent e) {
795 String cmd = e.getActionCommand();
797 if (cmd.equals("Pyro")) {
798 if (pyro_ui == null && pyros != null)
799 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
801 pyro_ui.make_visible();
805 if (cmd.equals("Close") || cmd.equals("Reboot"))
806 if (!check_dirty(cmd))
808 listener.actionPerformed(e);
809 if (cmd.equals("Close") || cmd.equals("Reboot")) {
816 /* ItemListener interface method */
817 public void itemStateChanged(ItemEvent e) {
821 /* DocumentListener interface methods */
822 public void changedUpdate(DocumentEvent e) {
826 public void insertUpdate(DocumentEvent e) {
830 public void removeUpdate(DocumentEvent e) {
834 /* Let the config code hook on a listener */
835 public void addActionListener(ActionListener l) {
839 /* set and get all of the dialog values */
840 public void set_product(String product) {
841 radio_frequency_value.set_product(product);
842 product_value.setText(product);
843 set_pad_orientation_tool_tip();
844 set_flight_log_max_tool_tip();
847 public void set_version(String version) {
848 version_value.setText(version);
851 public void set_serial(int serial) {
852 radio_frequency_value.set_serial(serial);
853 serial_value.setText(String.format("%d", serial));
856 public void set_main_deploy(int new_main_deploy) {
857 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
858 main_deploy_value.setEnabled(new_main_deploy >= 0);
861 public int main_deploy() {
862 return (int) (AltosConvert.height.parse(main_deploy_value.getSelectedItem().toString()) + 0.5);
865 String get_main_deploy_label() {
866 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.show_units());
869 String[] main_deploy_values() {
870 if (AltosConvert.imperial_units)
871 return main_deploy_values_ft;
873 return main_deploy_values_m;
876 void set_main_deploy_values() {
877 String[] v = main_deploy_values();
878 while (main_deploy_value.getItemCount() > 0)
879 main_deploy_value.removeItemAt(0);
880 for (int i = 0; i < v.length; i++)
881 main_deploy_value.addItem(v[i]);
882 main_deploy_value.setMaximumRowCount(v.length);
885 public void units_changed(boolean imperial_units) {
886 String v = main_deploy_value.getSelectedItem().toString();
887 main_deploy_label.setText(get_main_deploy_label());
888 set_main_deploy_values();
889 int m = (int) (AltosConvert.height.parse(v, !imperial_units) + 0.5);
892 if (tracker_motion_value.isEnabled()) {
893 String motion = tracker_motion_value.getSelectedItem().toString();
894 tracker_motion_label.setText(get_tracker_motion_label());
895 set_tracker_motion_values();
896 set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5));
900 public void set_apogee_delay(int new_apogee_delay) {
901 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
902 apogee_delay_value.setEnabled(new_apogee_delay >= 0);
905 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
908 v = s.split("\\s+")[0];
910 return Integer.parseInt(v);
911 } catch (NumberFormatException ne) {
912 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
916 public int apogee_delay() throws AltosConfigDataException {
917 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
920 public void set_apogee_lockout(int new_apogee_lockout) {
921 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
922 apogee_lockout_value.setEnabled(new_apogee_lockout >= 0);
925 public int apogee_lockout() throws AltosConfigDataException {
926 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
929 public void set_radio_frequency(double new_radio_frequency) {
930 radio_frequency_value.set_frequency(new_radio_frequency);
933 public double radio_frequency() {
934 return radio_frequency_value.frequency();
937 public void set_radio_calibration(int new_radio_calibration) {
938 radio_calibration_value.setVisible(new_radio_calibration >= 0);
939 if (new_radio_calibration < 0)
940 radio_calibration_value.setText("Disabled");
942 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
945 public int radio_calibration() throws AltosConfigDataException {
946 return parse_int("radio calibration", radio_calibration_value.getText(), false);
949 public void set_radio_enable(int new_radio_enable) {
950 if (new_radio_enable >= 0) {
951 radio_enable_value.setSelected(new_radio_enable > 0);
952 radio_enable_value.setEnabled(true);
954 radio_enable_value.setSelected(true);
955 radio_enable_value.setVisible(radio_frequency() > 0);
956 radio_enable_value.setEnabled(false);
958 set_radio_enable_tool_tip();
961 public int radio_enable() {
962 if (radio_enable_value.isEnabled())
963 return radio_enable_value.isSelected() ? 1 : 0;
968 public void set_callsign(String new_callsign) {
969 callsign_value.setVisible(new_callsign != null);
970 callsign_value.setText(new_callsign);
973 public String callsign() {
974 return callsign_value.getText();
977 int flight_log_max_limit;
980 public String flight_log_max_label(int flight_log_max) {
981 if (flight_log_max_limit != 0) {
982 int nflight = flight_log_max_limit / flight_log_max;
983 String plural = nflight > 1 ? "s" : "";
985 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
987 return String.format("%d", flight_log_max);
990 public void set_flight_log_max(int new_flight_log_max) {
991 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
992 flight_log_max = new_flight_log_max;
993 set_flight_log_max_tool_tip();
996 public void set_flight_log_max_enabled(boolean enable) {
997 flight_log_max_value.setEnabled(enable);
998 set_flight_log_max_tool_tip();
1001 public int flight_log_max() throws AltosConfigDataException {
1002 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1005 public void set_flight_log_max_limit(int new_flight_log_max_limit) {
1006 flight_log_max_limit = new_flight_log_max_limit;
1007 flight_log_max_value.removeAllItems();
1008 for (int i = 8; i >= 1; i--) {
1009 int size = flight_log_max_limit / i;
1010 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1012 if (flight_log_max != 0)
1013 set_flight_log_max(flight_log_max);
1016 public void set_ignite_mode(int new_ignite_mode) {
1017 if (new_ignite_mode >= ignite_mode_values.length)
1018 new_ignite_mode = 0;
1019 if (new_ignite_mode < 0) {
1020 ignite_mode_value.setEnabled(false);
1021 new_ignite_mode = 0;
1023 ignite_mode_value.setEnabled(true);
1025 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1026 set_ignite_mode_tool_tip();
1029 public int ignite_mode() {
1030 if (ignite_mode_value.isEnabled())
1031 return ignite_mode_value.getSelectedIndex();
1037 public void set_pad_orientation(int new_pad_orientation) {
1038 if (new_pad_orientation >= pad_orientation_values.length)
1039 new_pad_orientation = 0;
1040 if (new_pad_orientation < 0) {
1041 pad_orientation_value.setVisible(false);
1042 new_pad_orientation = 0;
1044 pad_orientation_value.setVisible(true);
1046 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1047 set_pad_orientation_tool_tip();
1050 public int pad_orientation() {
1051 if (pad_orientation_value.isEnabled())
1052 return pad_orientation_value.getSelectedIndex();
1057 public void set_beep(int new_beep) {
1058 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1059 for (int i = 0; i < beep_values.length; i++)
1060 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1061 beep_value.setSelectedIndex(i);
1062 set_beep_tool_tip();
1065 beep_value.setSelectedItem(String.format("%d", new_freq));
1066 beep_value.setEnabled(new_beep >= 0);
1067 set_beep_tool_tip();
1071 if (beep_value.isEnabled())
1072 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1077 String[] tracker_motion_values() {
1078 if (AltosConvert.imperial_units)
1079 return tracker_motion_values_ft;
1081 return tracker_motion_values_m;
1084 void set_tracker_motion_values() {
1085 String[] v = tracker_motion_values();
1086 while (tracker_motion_value.getItemCount() > 0)
1087 tracker_motion_value.removeItemAt(0);
1088 for (int i = 0; i < v.length; i++)
1089 tracker_motion_value.addItem(v[i]);
1090 tracker_motion_value.setMaximumRowCount(v.length);
1093 String get_tracker_motion_label() {
1094 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.show_units());
1097 void set_tracker_tool_tip() {
1098 if (tracker_motion_value.isEnabled())
1099 tracker_motion_value.setToolTipText("How far the device must move before logging");
1101 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1102 if (tracker_interval_value.isEnabled())
1103 tracker_interval_value.setToolTipText("How often to report GPS position");
1105 tracker_interval_value.setToolTipText("This device can't configure interval");
1108 public void set_tracker_motion(int tracker_motion) {
1109 if (tracker_motion < 0) {
1110 tracker_motion_label.setVisible(false);
1111 tracker_motion_value.setVisible(false);
1113 tracker_motion_label.setVisible(true);
1114 tracker_motion_value.setVisible(true);
1115 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1119 public int tracker_motion() throws AltosConfigDataException {
1120 return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString());
1123 public void set_tracker_interval(int tracker_interval) {
1124 if (tracker_interval< 0) {
1125 tracker_interval_label.setVisible(false);
1126 tracker_interval_value.setVisible(false);
1128 tracker_interval_label.setVisible(true);
1129 tracker_interval_value.setVisible(true);
1130 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1134 public int tracker_interval() throws AltosConfigDataException {
1135 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1138 public void set_pyros(AltosPyro[] new_pyros) {
1140 pyro.setVisible(pyros != null);
1141 if (pyros != null && pyro_ui != null)
1142 pyro_ui.set_pyros(pyros);
1145 public AltosPyro[] pyros() throws AltosConfigDataException {
1146 if (pyro_ui != null)
1147 pyros = pyro_ui.get_pyros();
1151 public void set_pyro_firing_time(double new_pyro_firing_time) {
1152 pyro_firing_time = new_pyro_firing_time;
1153 pyro.setVisible(pyro_firing_time >= 0);
1154 if (pyro_firing_time >= 0 && pyro_ui != null)
1155 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1158 public double pyro_firing_time() throws AltosConfigDataException {
1159 if (pyro_ui != null)
1160 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1161 return pyro_firing_time;
1164 public void set_aprs_interval(int new_aprs_interval) {
1167 if (new_aprs_interval <= 0)
1170 s = Integer.toString(new_aprs_interval);
1171 aprs_interval_value.setSelectedItem(s);
1172 aprs_interval_value.setVisible(new_aprs_interval >= 0);
1173 set_aprs_interval_tool_tip();
1176 public int aprs_interval() throws AltosConfigDataException {
1177 String s = aprs_interval_value.getSelectedItem().toString();
1179 if (s.equals("Disabled"))
1181 return parse_int("aprs interval", s, false);