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_horiz_label;
50 JLabel tracker_vert_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_horiz_value;
71 JComboBox<String> tracker_vert_value;
82 ActionListener listener;
84 static String[] main_deploy_values_m = {
85 "100", "150", "200", "250", "300", "350",
89 static String[] main_deploy_values_ft = {
90 "250", "500", "750", "1000", "1250", "1500",
94 static String[] apogee_delay_values = {
95 "0", "1", "2", "3", "4", "5"
98 static String[] apogee_lockout_values = {
99 "0", "5", "10", "15", "20"
102 static String[] ignite_mode_values = {
108 static String[] aprs_interval_values = {
115 static String[] beep_values = {
121 static String[] pad_orientation_values = {
126 static String[] tracker_horiz_values_m = {
133 static String[] tracker_horiz_values_ft = {
140 static String[] tracker_vert_values_m = {
147 static String[] tracker_vert_values_ft = {
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_flight_log_max_tool_tip() {
211 if (flight_log_max_value.isEnabled())
212 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
214 if (is_telemini_v1())
215 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
217 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
221 void set_ignite_mode_tool_tip() {
222 if (ignite_mode_value.isEnabled())
223 ignite_mode_value.setToolTipText("Select when igniters will be fired");
225 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
228 void set_pad_orientation_tool_tip() {
229 if (pad_orientation_value.isEnabled())
230 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
233 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
234 else if (is_telemini() || is_easymini())
235 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
237 pad_orientation_value.setToolTipText("Can't select orientation");
241 void set_beep_tool_tip() {
242 if (beep_value.isEnabled())
243 beep_value.setToolTipText("What frequency the beeper will sound at");
245 beep_value.setToolTipText("Older firmware could not select beeper frequency");
248 /* Build the UI using a grid bag */
249 public AltosConfigUI(JFrame in_owner, boolean remote) {
250 super (in_owner, "Configure Flight Computer", false);
253 GridBagConstraints c;
256 Insets il = new Insets(4,4,4,4);
257 Insets ir = new Insets(4,4,4,4);
259 pane = getContentPane();
260 pane.setLayout(new GridBagLayout());
263 c = new GridBagConstraints();
264 c.gridx = 0; c.gridy = row;
266 c.fill = GridBagConstraints.NONE;
267 c.anchor = GridBagConstraints.LINE_START;
269 product_label = new JLabel("Product:");
270 pane.add(product_label, c);
272 c = new GridBagConstraints();
273 c.gridx = 4; c.gridy = row;
275 c.fill = GridBagConstraints.HORIZONTAL;
277 c.anchor = GridBagConstraints.LINE_START;
279 product_value = new JLabel("");
280 pane.add(product_value, c);
284 c = new GridBagConstraints();
285 c.gridx = 0; c.gridy = row;
287 c.fill = GridBagConstraints.NONE;
288 c.anchor = GridBagConstraints.LINE_START;
291 version_label = new JLabel("Software version:");
292 pane.add(version_label, c);
294 c = new GridBagConstraints();
295 c.gridx = 4; c.gridy = row;
297 c.fill = GridBagConstraints.HORIZONTAL;
299 c.anchor = GridBagConstraints.LINE_START;
302 version_value = new JLabel("");
303 pane.add(version_value, c);
307 c = new GridBagConstraints();
308 c.gridx = 0; c.gridy = row;
310 c.fill = GridBagConstraints.NONE;
311 c.anchor = GridBagConstraints.LINE_START;
314 serial_label = new JLabel("Serial:");
315 pane.add(serial_label, c);
317 c = new GridBagConstraints();
318 c.gridx = 4; c.gridy = row;
320 c.fill = GridBagConstraints.HORIZONTAL;
322 c.anchor = GridBagConstraints.LINE_START;
325 serial_value = new JLabel("");
326 pane.add(serial_value, c);
330 c = new GridBagConstraints();
331 c.gridx = 0; c.gridy = row;
333 c.fill = GridBagConstraints.NONE;
334 c.anchor = GridBagConstraints.LINE_START;
337 main_deploy_label = new JLabel(get_main_deploy_label());
338 pane.add(main_deploy_label, c);
340 c = new GridBagConstraints();
341 c.gridx = 4; c.gridy = row;
343 c.fill = GridBagConstraints.HORIZONTAL;
345 c.anchor = GridBagConstraints.LINE_START;
348 main_deploy_value = new JComboBox<String>(main_deploy_values());
349 main_deploy_value.setEditable(true);
350 main_deploy_value.addItemListener(this);
351 pane.add(main_deploy_value, c);
352 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
356 c = new GridBagConstraints();
357 c.gridx = 0; c.gridy = row;
359 c.fill = GridBagConstraints.NONE;
360 c.anchor = GridBagConstraints.LINE_START;
363 apogee_delay_label = new JLabel("Apogee Delay(s):");
364 pane.add(apogee_delay_label, c);
366 c = new GridBagConstraints();
367 c.gridx = 4; c.gridy = row;
369 c.fill = GridBagConstraints.HORIZONTAL;
371 c.anchor = GridBagConstraints.LINE_START;
374 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
375 apogee_delay_value.setEditable(true);
376 apogee_delay_value.addItemListener(this);
377 pane.add(apogee_delay_value, c);
378 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
382 c = new GridBagConstraints();
383 c.gridx = 0; c.gridy = row;
385 c.fill = GridBagConstraints.NONE;
386 c.anchor = GridBagConstraints.LINE_START;
389 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
390 pane.add(apogee_lockout_label, c);
392 c = new GridBagConstraints();
393 c.gridx = 4; c.gridy = row;
395 c.fill = GridBagConstraints.HORIZONTAL;
397 c.anchor = GridBagConstraints.LINE_START;
400 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
401 apogee_lockout_value.setEditable(true);
402 apogee_lockout_value.addItemListener(this);
403 pane.add(apogee_lockout_value, c);
404 apogee_lockout_value.setToolTipText("Time after boost while apogee detection is locked out");
408 c = new GridBagConstraints();
409 c.gridx = 0; c.gridy = row;
411 c.fill = GridBagConstraints.NONE;
412 c.anchor = GridBagConstraints.LINE_START;
415 radio_frequency_label = new JLabel("Frequency:");
416 pane.add(radio_frequency_label, c);
418 c = new GridBagConstraints();
419 c.gridx = 4; c.gridy = row;
421 c.fill = GridBagConstraints.HORIZONTAL;
423 c.anchor = GridBagConstraints.LINE_START;
426 radio_frequency_value = new AltosFreqList();
427 radio_frequency_value.addItemListener(this);
428 pane.add(radio_frequency_value, c);
429 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
432 /* Radio Calibration */
433 c = new GridBagConstraints();
434 c.gridx = 0; c.gridy = row;
436 c.fill = GridBagConstraints.NONE;
437 c.anchor = GridBagConstraints.LINE_START;
440 radio_calibration_label = new JLabel("RF Calibration:");
441 pane.add(radio_calibration_label, c);
443 c = new GridBagConstraints();
444 c.gridx = 4; c.gridy = row;
446 c.fill = GridBagConstraints.HORIZONTAL;
448 c.anchor = GridBagConstraints.LINE_START;
451 radio_calibration_value = new JTextField(String.format("%d", 1186611));
452 radio_calibration_value.getDocument().addDocumentListener(this);
454 radio_calibration_value.setEnabled(false);
455 pane.add(radio_calibration_value, c);
456 set_radio_calibration_tool_tip();
460 c = new GridBagConstraints();
461 c.gridx = 0; c.gridy = row;
463 c.fill = GridBagConstraints.NONE;
464 c.anchor = GridBagConstraints.LINE_START;
467 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
468 pane.add(radio_enable_label, c);
470 c = new GridBagConstraints();
471 c.gridx = 4; c.gridy = row;
473 c.fill = GridBagConstraints.HORIZONTAL;
475 c.anchor = GridBagConstraints.LINE_START;
478 radio_enable_value = new JRadioButton("Enabled");
479 radio_enable_value.addItemListener(this);
480 pane.add(radio_enable_value, c);
481 set_radio_enable_tool_tip();
485 c = new GridBagConstraints();
486 c.gridx = 0; c.gridy = row;
488 c.fill = GridBagConstraints.NONE;
489 c.anchor = GridBagConstraints.LINE_START;
492 aprs_interval_label = new JLabel("APRS Interval(s):");
493 pane.add(aprs_interval_label, c);
495 c = new GridBagConstraints();
496 c.gridx = 4; c.gridy = row;
498 c.fill = GridBagConstraints.HORIZONTAL;
500 c.anchor = GridBagConstraints.LINE_START;
503 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
504 aprs_interval_value.setEditable(true);
505 aprs_interval_value.addItemListener(this);
506 pane.add(aprs_interval_value, c);
507 set_aprs_interval_tool_tip();
511 c = new GridBagConstraints();
512 c.gridx = 0; c.gridy = row;
514 c.fill = GridBagConstraints.NONE;
515 c.anchor = GridBagConstraints.LINE_START;
518 callsign_label = new JLabel("Callsign:");
519 pane.add(callsign_label, c);
521 c = new GridBagConstraints();
522 c.gridx = 4; c.gridy = row;
524 c.fill = GridBagConstraints.HORIZONTAL;
526 c.anchor = GridBagConstraints.LINE_START;
529 callsign_value = new JTextField(AltosUIPreferences.callsign());
530 callsign_value.getDocument().addDocumentListener(this);
531 pane.add(callsign_value, c);
532 callsign_value.setToolTipText("Callsign reported in telemetry data");
536 c = new GridBagConstraints();
537 c.gridx = 0; c.gridy = row;
539 c.fill = GridBagConstraints.NONE;
540 c.anchor = GridBagConstraints.LINE_START;
543 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
544 pane.add(flight_log_max_label, c);
546 c = new GridBagConstraints();
547 c.gridx = 4; c.gridy = row;
549 c.fill = GridBagConstraints.HORIZONTAL;
551 c.anchor = GridBagConstraints.LINE_START;
554 flight_log_max_value = new JComboBox<String>();
555 flight_log_max_value.setEditable(true);
556 flight_log_max_value.addItemListener(this);
557 pane.add(flight_log_max_value, c);
558 set_flight_log_max_tool_tip();
562 c = new GridBagConstraints();
563 c.gridx = 0; c.gridy = row;
565 c.fill = GridBagConstraints.NONE;
566 c.anchor = GridBagConstraints.LINE_START;
569 ignite_mode_label = new JLabel("Igniter Firing Mode:");
570 pane.add(ignite_mode_label, c);
572 c = new GridBagConstraints();
573 c.gridx = 4; c.gridy = row;
575 c.fill = GridBagConstraints.HORIZONTAL;
577 c.anchor = GridBagConstraints.LINE_START;
580 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
581 ignite_mode_value.setEditable(false);
582 ignite_mode_value.addItemListener(this);
583 pane.add(ignite_mode_value, c);
584 set_ignite_mode_tool_tip();
587 /* Pad orientation */
588 c = new GridBagConstraints();
589 c.gridx = 0; c.gridy = row;
591 c.fill = GridBagConstraints.NONE;
592 c.anchor = GridBagConstraints.LINE_START;
595 pad_orientation_label = new JLabel("Pad Orientation:");
596 pane.add(pad_orientation_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 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
607 pad_orientation_value.setEditable(false);
608 pad_orientation_value.addItemListener(this);
609 pane.add(pad_orientation_value, c);
610 set_pad_orientation_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 beep_label = new JLabel("Beeper Frequency:");
622 pane.add(beep_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 beep_value = new JComboBox<String>(beep_values);
633 beep_value.setEditable(true);
634 beep_value.addItemListener(this);
635 pane.add(beep_value, c);
639 /* Tracker triger horiz distances */
640 c = new GridBagConstraints();
641 c.gridx = 0; c.gridy = row;
643 c.fill = GridBagConstraints.NONE;
644 c.anchor = GridBagConstraints.LINE_START;
647 tracker_horiz_label = new JLabel(get_tracker_horiz_label());
648 pane.add(tracker_horiz_label, c);
650 c = new GridBagConstraints();
651 c.gridx = 4; c.gridy = row;
653 c.fill = GridBagConstraints.HORIZONTAL;
655 c.anchor = GridBagConstraints.LINE_START;
658 tracker_horiz_value = new JComboBox<String>(tracker_horiz_values());
659 tracker_horiz_value.setEditable(true);
660 tracker_horiz_value.addItemListener(this);
661 pane.add(tracker_horiz_value, c);
664 /* Tracker triger vert distances */
665 c = new GridBagConstraints();
666 c.gridx = 0; c.gridy = row;
668 c.fill = GridBagConstraints.NONE;
669 c.anchor = GridBagConstraints.LINE_START;
672 tracker_vert_label = new JLabel(get_tracker_vert_label());
673 pane.add(tracker_vert_label, c);
675 c = new GridBagConstraints();
676 c.gridx = 4; c.gridy = row;
678 c.fill = GridBagConstraints.HORIZONTAL;
680 c.anchor = GridBagConstraints.LINE_START;
683 tracker_vert_value = new JComboBox<String>(tracker_vert_values());
684 tracker_vert_value.setEditable(true);
685 tracker_vert_value.addItemListener(this);
686 pane.add(tracker_vert_value, c);
687 set_tracker_tool_tip();
691 c = new GridBagConstraints();
692 c.gridx = 4; c.gridy = row;
694 c.fill = GridBagConstraints.HORIZONTAL;
695 c.anchor = GridBagConstraints.LINE_START;
698 pyro = new JButton("Configure Pyro Channels");
700 pyro.addActionListener(this);
701 pyro.setActionCommand("Pyro");
705 c = new GridBagConstraints();
706 c.gridx = 0; c.gridy = row;
708 c.fill = GridBagConstraints.NONE;
709 c.anchor = GridBagConstraints.LINE_START;
711 save = new JButton("Save");
713 save.addActionListener(this);
714 save.setActionCommand("Save");
716 c = new GridBagConstraints();
717 c.gridx = 2; c.gridy = row;
719 c.fill = GridBagConstraints.NONE;
720 c.anchor = GridBagConstraints.CENTER;
722 reset = new JButton("Reset");
724 reset.addActionListener(this);
725 reset.setActionCommand("Reset");
727 c = new GridBagConstraints();
728 c.gridx = 4; c.gridy = row;
730 c.fill = GridBagConstraints.NONE;
731 c.anchor = GridBagConstraints.CENTER;
733 reboot = new JButton("Reboot");
735 reboot.addActionListener(this);
736 reboot.setActionCommand("Reboot");
738 c = new GridBagConstraints();
739 c.gridx = 6; c.gridy = row;
741 c.fill = GridBagConstraints.NONE;
742 c.anchor = GridBagConstraints.LINE_END;
744 close = new JButton("Close");
746 close.addActionListener(this);
747 close.setActionCommand("Close");
749 addWindowListener(new ConfigListener(this));
750 AltosPreferences.register_units_listener(this);
753 /* Once the initial values are set, the config code will show the dialog */
754 public void make_visible() {
756 setLocationRelativeTo(owner);
760 /* If any values have been changed, confirm before closing */
761 public boolean check_dirty(String operation) {
763 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
765 i = JOptionPane.showOptionDialog(this,
766 String.format("Configuration modified. %s anyway?", operation),
767 "Configuration Modified",
768 JOptionPane.DEFAULT_OPTION,
769 JOptionPane.WARNING_MESSAGE,
770 null, options, options[1]);
779 save.setEnabled(true);
782 public void set_clean() {
784 save.setEnabled(false);
787 AltosConfigPyroUI pyro_ui;
789 public void dispose() {
792 AltosPreferences.unregister_units_listener(this);
796 /* Listen for events from our buttons */
797 public void actionPerformed(ActionEvent e) {
798 String cmd = e.getActionCommand();
800 if (cmd.equals("Pyro")) {
801 if (pyro_ui == null && pyros != null)
802 pyro_ui = new AltosConfigPyroUI(this, pyros);
804 pyro_ui.make_visible();
808 if (cmd.equals("Close") || cmd.equals("Reboot"))
809 if (!check_dirty(cmd))
811 listener.actionPerformed(e);
812 if (cmd.equals("Close") || cmd.equals("Reboot")) {
819 /* ItemListener interface method */
820 public void itemStateChanged(ItemEvent e) {
824 /* DocumentListener interface methods */
825 public void changedUpdate(DocumentEvent e) {
829 public void insertUpdate(DocumentEvent e) {
833 public void removeUpdate(DocumentEvent e) {
837 /* Let the config code hook on a listener */
838 public void addActionListener(ActionListener l) {
842 /* set and get all of the dialog values */
843 public void set_product(String product) {
844 radio_frequency_value.set_product(product);
845 product_value.setText(product);
846 set_pad_orientation_tool_tip();
847 set_flight_log_max_tool_tip();
850 public void set_version(String version) {
851 version_value.setText(version);
854 public void set_serial(int serial) {
855 radio_frequency_value.set_serial(serial);
856 serial_value.setText(String.format("%d", serial));
859 public void set_main_deploy(int new_main_deploy) {
860 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
861 main_deploy_value.setEnabled(new_main_deploy >= 0);
864 public int main_deploy() {
865 return (int) (AltosConvert.height.parse(main_deploy_value.getSelectedItem().toString()) + 0.5);
868 String get_main_deploy_label() {
869 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.show_units());
872 String[] main_deploy_values() {
873 if (AltosConvert.imperial_units)
874 return main_deploy_values_ft;
876 return main_deploy_values_m;
879 void set_main_deploy_values() {
880 String[] v = main_deploy_values();
881 while (main_deploy_value.getItemCount() > 0)
882 main_deploy_value.removeItemAt(0);
883 for (int i = 0; i < v.length; i++)
884 main_deploy_value.addItem(v[i]);
885 main_deploy_value.setMaximumRowCount(v.length);
888 public void units_changed(boolean imperial_units) {
889 String v = main_deploy_value.getSelectedItem().toString();
890 main_deploy_label.setText(get_main_deploy_label());
891 set_main_deploy_values();
892 int m = (int) (AltosConvert.height.parse(v, !imperial_units) + 0.5);
895 if (tracker_horiz_value.isEnabled() && tracker_vert_value.isEnabled()) {
896 String th = tracker_horiz_value.getSelectedItem().toString();
897 String tv = tracker_vert_value.getSelectedItem().toString();
898 tracker_horiz_label.setText(get_tracker_horiz_label());
899 tracker_vert_label.setText(get_tracker_vert_label());
900 set_tracker_horiz_values();
901 set_tracker_vert_values();
903 (int) (AltosConvert.height.parse(th, !imperial_units) + 0.5),
904 (int) (AltosConvert.height.parse(tv, !imperial_units) + 0.5)
906 set_tracker_distances(t);
910 public void set_apogee_delay(int new_apogee_delay) {
911 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
912 apogee_delay_value.setEnabled(new_apogee_delay >= 0);
915 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
918 v = s.split("\\s+")[0];
920 return Integer.parseInt(v);
921 } catch (NumberFormatException ne) {
922 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
926 public int apogee_delay() throws AltosConfigDataException {
927 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
930 public void set_apogee_lockout(int new_apogee_lockout) {
931 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
932 apogee_lockout_value.setEnabled(new_apogee_lockout >= 0);
935 public int apogee_lockout() throws AltosConfigDataException {
936 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
939 public void set_radio_frequency(double new_radio_frequency) {
940 radio_frequency_value.set_frequency(new_radio_frequency);
943 public double radio_frequency() {
944 return radio_frequency_value.frequency();
947 public void set_radio_calibration(int new_radio_calibration) {
948 radio_calibration_value.setVisible(new_radio_calibration >= 0);
949 if (new_radio_calibration < 0)
950 radio_calibration_value.setText("Disabled");
952 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
955 public int radio_calibration() throws AltosConfigDataException {
956 return parse_int("radio calibration", radio_calibration_value.getText(), false);
959 public void set_radio_enable(int new_radio_enable) {
960 if (new_radio_enable >= 0) {
961 radio_enable_value.setSelected(new_radio_enable > 0);
962 radio_enable_value.setEnabled(true);
964 radio_enable_value.setSelected(true);
965 radio_enable_value.setVisible(radio_frequency() > 0);
966 radio_enable_value.setEnabled(false);
968 set_radio_enable_tool_tip();
971 public int radio_enable() {
972 if (radio_enable_value.isEnabled())
973 return radio_enable_value.isSelected() ? 1 : 0;
978 public void set_callsign(String new_callsign) {
979 callsign_value.setVisible(new_callsign != null);
980 callsign_value.setText(new_callsign);
983 public String callsign() {
984 return callsign_value.getText();
987 int flight_log_max_limit;
990 public String flight_log_max_label(int flight_log_max) {
991 if (flight_log_max_limit != 0) {
992 int nflight = flight_log_max_limit / flight_log_max;
993 String plural = nflight > 1 ? "s" : "";
995 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
997 return String.format("%d", flight_log_max);
1000 public void set_flight_log_max(int new_flight_log_max) {
1001 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1002 flight_log_max = new_flight_log_max;
1003 set_flight_log_max_tool_tip();
1006 public void set_flight_log_max_enabled(boolean enable) {
1007 flight_log_max_value.setEnabled(enable);
1008 set_flight_log_max_tool_tip();
1011 public int flight_log_max() throws AltosConfigDataException {
1012 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1015 public void set_flight_log_max_limit(int new_flight_log_max_limit) {
1016 flight_log_max_limit = new_flight_log_max_limit;
1017 flight_log_max_value.removeAllItems();
1018 for (int i = 8; i >= 1; i--) {
1019 int size = flight_log_max_limit / i;
1020 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1022 if (flight_log_max != 0)
1023 set_flight_log_max(flight_log_max);
1026 public void set_ignite_mode(int new_ignite_mode) {
1027 if (new_ignite_mode >= ignite_mode_values.length)
1028 new_ignite_mode = 0;
1029 if (new_ignite_mode < 0) {
1030 ignite_mode_value.setEnabled(false);
1031 new_ignite_mode = 0;
1033 ignite_mode_value.setEnabled(true);
1035 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1036 set_ignite_mode_tool_tip();
1039 public int ignite_mode() {
1040 if (ignite_mode_value.isEnabled())
1041 return ignite_mode_value.getSelectedIndex();
1047 public void set_pad_orientation(int new_pad_orientation) {
1048 if (new_pad_orientation >= pad_orientation_values.length)
1049 new_pad_orientation = 0;
1050 if (new_pad_orientation < 0) {
1051 pad_orientation_value.setVisible(false);
1052 new_pad_orientation = 0;
1054 pad_orientation_value.setVisible(true);
1056 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1057 set_pad_orientation_tool_tip();
1060 public int pad_orientation() {
1061 if (pad_orientation_value.isEnabled())
1062 return pad_orientation_value.getSelectedIndex();
1067 public void set_beep(int new_beep) {
1068 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1069 for (int i = 0; i < beep_values.length; i++)
1070 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1071 beep_value.setSelectedIndex(i);
1072 set_beep_tool_tip();
1075 beep_value.setSelectedItem(String.format("%d", new_freq));
1076 beep_value.setEnabled(new_beep >= 0);
1077 set_beep_tool_tip();
1081 if (beep_value.isEnabled())
1082 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1087 String[] tracker_horiz_values() {
1088 if (AltosConvert.imperial_units)
1089 return tracker_horiz_values_ft;
1091 return tracker_horiz_values_m;
1094 void set_tracker_horiz_values() {
1095 String[] v = tracker_horiz_values();
1096 while (tracker_horiz_value.getItemCount() > 0)
1097 tracker_horiz_value.removeItemAt(0);
1098 for (int i = 0; i < v.length; i++)
1099 tracker_horiz_value.addItem(v[i]);
1100 tracker_horiz_value.setMaximumRowCount(v.length);
1103 String get_tracker_horiz_label() {
1104 return String.format("Logging Trigger Horizontal (%s):", AltosConvert.height.show_units());
1107 String[] tracker_vert_values() {
1108 if (AltosConvert.imperial_units)
1109 return tracker_vert_values_ft;
1111 return tracker_vert_values_m;
1114 void set_tracker_vert_values() {
1115 String[] v = tracker_vert_values();
1116 while (tracker_vert_value.getItemCount() > 0)
1117 tracker_vert_value.removeItemAt(0);
1118 for (int i = 0; i < v.length; i++)
1119 tracker_vert_value.addItem(v[i]);
1120 tracker_vert_value.setMaximumRowCount(v.length);
1123 void set_tracker_tool_tip() {
1124 if (tracker_horiz_value.isEnabled())
1125 tracker_horiz_value.setToolTipText("How far the device must move before logging is enabled");
1127 tracker_horiz_value.setToolTipText("This device doesn't disable logging before motion");
1128 if (tracker_vert_value.isEnabled())
1129 tracker_vert_value.setToolTipText("How far the device must move before logging is enabled");
1131 tracker_vert_value.setToolTipText("This device doesn't disable logging before motion");
1134 String get_tracker_vert_label() {
1135 return String.format("Logging Trigger Vertical (%s):", AltosConvert.height.show_units());
1138 public void set_tracker_distances(int[] tracker_distances) {
1139 if (tracker_distances != null) {
1140 tracker_horiz_value.setSelectedItem(AltosConvert.height.say(tracker_distances[0]));
1141 tracker_vert_value.setSelectedItem(AltosConvert.height.say(tracker_distances[1]));
1142 tracker_horiz_value.setEnabled(true);
1143 tracker_vert_value.setEnabled(true);
1145 tracker_horiz_value.setEnabled(false);
1146 tracker_vert_value.setEnabled(false);
1150 public int[] tracker_distances() {
1151 if (tracker_horiz_value.isEnabled() && tracker_vert_value.isEnabled()) {
1153 (int) (AltosConvert.height.parse(tracker_horiz_value.getSelectedItem().toString()) + 0.5),
1154 (int) (AltosConvert.height.parse(tracker_vert_value.getSelectedItem().toString()) + 0.5),
1161 public void set_pyros(AltosPyro[] new_pyros) {
1163 pyro.setVisible(pyros != null);
1164 if (pyros != null && pyro_ui != null)
1165 pyro_ui.set_pyros(pyros);
1168 public AltosPyro[] pyros() throws AltosConfigDataException {
1169 if (pyro_ui != null)
1170 pyros = pyro_ui.get_pyros();
1174 public void set_aprs_interval(int new_aprs_interval) {
1177 if (new_aprs_interval <= 0)
1180 s = Integer.toString(new_aprs_interval);
1181 aprs_interval_value.setSelectedItem(s);
1182 aprs_interval_value.setVisible(new_aprs_interval >= 0);
1183 set_aprs_interval_tool_tip();
1186 public int aprs_interval() throws AltosConfigDataException {
1187 String s = aprs_interval_value.getSelectedItem().toString();
1189 if (s.equals("Disabled"))
1191 return parse_int("aprs interval", s, false);