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;
44 JLabel aprs_interval_label;
45 JLabel aprs_ssid_label;
46 JLabel flight_log_max_label;
47 JLabel ignite_mode_label;
48 JLabel pad_orientation_label;
49 JLabel callsign_label;
51 JLabel tracker_motion_label;
52 JLabel tracker_interval_label;
60 JComboBox<String> main_deploy_value;
61 JComboBox<String> apogee_delay_value;
62 JComboBox<String> apogee_lockout_value;
63 AltosUIFreqList radio_frequency_value;
64 JTextField radio_calibration_value;
65 JRadioButton radio_enable_value;
66 AltosUIRateList rate_value;
67 JComboBox<String> aprs_interval_value;
68 JComboBox<Integer> aprs_ssid_value;
69 JComboBox<String> flight_log_max_value;
70 JComboBox<String> ignite_mode_value;
71 JComboBox<String> pad_orientation_value;
72 JTextField callsign_value;
73 JComboBox<String> beep_value;
74 JComboBox<String> tracker_motion_value;
75 JComboBox<String> tracker_interval_value;
85 double pyro_firing_time;
87 ActionListener listener;
89 static String[] main_deploy_values_m = {
90 "100", "150", "200", "250", "300", "350",
94 static String[] main_deploy_values_ft = {
95 "250", "500", "750", "1000", "1250", "1500",
99 static String[] apogee_delay_values = {
100 "0", "1", "2", "3", "4", "5"
103 static String[] apogee_lockout_values = {
104 "0", "5", "10", "15", "20"
107 static String[] ignite_mode_values = {
113 static String[] aprs_interval_values = {
120 static Integer[] aprs_ssid_values = {
121 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
124 static String[] beep_values = {
130 static String[] pad_orientation_values = {
135 static String[] tracker_motion_values_m = {
142 static String[] tracker_motion_values_ft = {
149 static String[] tracker_interval_values = {
156 /* A window listener to catch closing events and tell the config code */
157 class ConfigListener extends WindowAdapter {
160 public ConfigListener(AltosConfigUI this_ui) {
164 public void windowClosing(WindowEvent e) {
165 ui.actionPerformed(new ActionEvent(e.getSource(),
166 ActionEvent.ACTION_PERFORMED,
171 boolean is_telemini_v1() {
172 String product = product_value.getText();
173 return product != null && product.startsWith("TeleMini-v1");
176 boolean is_telemini() {
177 String product = product_value.getText();
178 return product != null && product.startsWith("TeleMini");
181 boolean is_easymini() {
182 String product = product_value.getText();
183 return product != null && product.startsWith("EasyMini");
186 boolean is_telemetrum() {
187 String product = product_value.getText();
188 return product != null && product.startsWith("TeleMetrum");
191 void set_radio_calibration_tool_tip() {
192 if (radio_calibration_value.isEnabled())
193 radio_calibration_value.setToolTipText("Tune radio output to match desired frequency");
195 radio_calibration_value.setToolTipText("Cannot tune radio while connected over packet mode");
198 void set_radio_enable_tool_tip() {
199 if (radio_enable_value.isEnabled())
200 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
202 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
205 void set_rate_tool_tip() {
206 if (rate_value.isEnabled())
207 rate_value.setToolTipText("Select telemetry baud rate");
209 rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
212 void set_aprs_interval_tool_tip() {
213 if (aprs_interval_value.isEnabled())
214 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
216 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
219 void set_aprs_ssid_tool_tip() {
220 if (aprs_ssid_value.isEnabled())
221 aprs_interval_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
222 else if (aprs_interval_value.isEnabled())
223 aprs_interval_value.setToolTipText("Software version doesn't support setting the APRS SSID");
225 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
228 void set_flight_log_max_tool_tip() {
229 if (flight_log_max_value.isEnabled())
230 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
232 if (is_telemini_v1())
233 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
235 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
239 void set_ignite_mode_tool_tip() {
240 if (ignite_mode_value.isEnabled())
241 ignite_mode_value.setToolTipText("Select when igniters will be fired");
243 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
246 void set_pad_orientation_tool_tip() {
247 if (pad_orientation_value.isEnabled())
248 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
251 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
252 else if (is_telemini() || is_easymini())
253 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
255 pad_orientation_value.setToolTipText("Can't select orientation");
259 void set_beep_tool_tip() {
260 if (beep_value.isEnabled())
261 beep_value.setToolTipText("What frequency the beeper will sound at");
263 beep_value.setToolTipText("Older firmware could not select beeper frequency");
266 /* Build the UI using a grid bag */
267 public AltosConfigUI(JFrame in_owner, boolean remote) {
268 super (in_owner, "Configure Flight Computer", false);
271 GridBagConstraints c;
274 Insets il = new Insets(4,4,4,4);
275 Insets ir = new Insets(4,4,4,4);
277 pane = getContentPane();
278 pane.setLayout(new GridBagLayout());
281 c = new GridBagConstraints();
282 c.gridx = 0; c.gridy = row;
284 c.fill = GridBagConstraints.NONE;
285 c.anchor = GridBagConstraints.LINE_START;
287 product_label = new JLabel("Product:");
288 pane.add(product_label, c);
290 c = new GridBagConstraints();
291 c.gridx = 4; c.gridy = row;
293 c.fill = GridBagConstraints.HORIZONTAL;
295 c.anchor = GridBagConstraints.LINE_START;
297 product_value = new JLabel("");
298 pane.add(product_value, c);
302 c = new GridBagConstraints();
303 c.gridx = 0; c.gridy = row;
305 c.fill = GridBagConstraints.NONE;
306 c.anchor = GridBagConstraints.LINE_START;
309 version_label = new JLabel("Software version:");
310 pane.add(version_label, c);
312 c = new GridBagConstraints();
313 c.gridx = 4; c.gridy = row;
315 c.fill = GridBagConstraints.HORIZONTAL;
317 c.anchor = GridBagConstraints.LINE_START;
320 version_value = new JLabel("");
321 pane.add(version_value, c);
325 c = new GridBagConstraints();
326 c.gridx = 0; c.gridy = row;
328 c.fill = GridBagConstraints.NONE;
329 c.anchor = GridBagConstraints.LINE_START;
332 serial_label = new JLabel("Serial:");
333 pane.add(serial_label, c);
335 c = new GridBagConstraints();
336 c.gridx = 4; c.gridy = row;
338 c.fill = GridBagConstraints.HORIZONTAL;
340 c.anchor = GridBagConstraints.LINE_START;
343 serial_value = new JLabel("");
344 pane.add(serial_value, c);
348 c = new GridBagConstraints();
349 c.gridx = 0; c.gridy = row;
351 c.fill = GridBagConstraints.NONE;
352 c.anchor = GridBagConstraints.LINE_START;
355 main_deploy_label = new JLabel(get_main_deploy_label());
356 pane.add(main_deploy_label, c);
358 c = new GridBagConstraints();
359 c.gridx = 4; c.gridy = row;
361 c.fill = GridBagConstraints.HORIZONTAL;
363 c.anchor = GridBagConstraints.LINE_START;
366 main_deploy_value = new JComboBox<String>(main_deploy_values());
367 main_deploy_value.setEditable(true);
368 main_deploy_value.addItemListener(this);
369 pane.add(main_deploy_value, c);
370 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
374 c = new GridBagConstraints();
375 c.gridx = 0; c.gridy = row;
377 c.fill = GridBagConstraints.NONE;
378 c.anchor = GridBagConstraints.LINE_START;
381 apogee_delay_label = new JLabel("Apogee Delay(s):");
382 pane.add(apogee_delay_label, c);
384 c = new GridBagConstraints();
385 c.gridx = 4; c.gridy = row;
387 c.fill = GridBagConstraints.HORIZONTAL;
389 c.anchor = GridBagConstraints.LINE_START;
392 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
393 apogee_delay_value.setEditable(true);
394 apogee_delay_value.addItemListener(this);
395 pane.add(apogee_delay_value, c);
396 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
400 c = new GridBagConstraints();
401 c.gridx = 0; c.gridy = row;
403 c.fill = GridBagConstraints.NONE;
404 c.anchor = GridBagConstraints.LINE_START;
407 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
408 pane.add(apogee_lockout_label, c);
410 c = new GridBagConstraints();
411 c.gridx = 4; c.gridy = row;
413 c.fill = GridBagConstraints.HORIZONTAL;
415 c.anchor = GridBagConstraints.LINE_START;
418 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
419 apogee_lockout_value.setEditable(true);
420 apogee_lockout_value.addItemListener(this);
421 pane.add(apogee_lockout_value, c);
422 apogee_lockout_value.setToolTipText("Time after boost while apogee detection is locked out");
426 c = new GridBagConstraints();
427 c.gridx = 0; c.gridy = row;
429 c.fill = GridBagConstraints.NONE;
430 c.anchor = GridBagConstraints.LINE_START;
433 radio_frequency_label = new JLabel("Frequency:");
434 pane.add(radio_frequency_label, c);
436 c = new GridBagConstraints();
437 c.gridx = 4; c.gridy = row;
439 c.fill = GridBagConstraints.HORIZONTAL;
441 c.anchor = GridBagConstraints.LINE_START;
444 radio_frequency_value = new AltosUIFreqList();
445 radio_frequency_value.addItemListener(this);
446 pane.add(radio_frequency_value, c);
447 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
450 /* Radio Calibration */
451 c = new GridBagConstraints();
452 c.gridx = 0; c.gridy = row;
454 c.fill = GridBagConstraints.NONE;
455 c.anchor = GridBagConstraints.LINE_START;
458 radio_calibration_label = new JLabel("RF Calibration:");
459 pane.add(radio_calibration_label, c);
461 c = new GridBagConstraints();
462 c.gridx = 4; c.gridy = row;
464 c.fill = GridBagConstraints.HORIZONTAL;
466 c.anchor = GridBagConstraints.LINE_START;
469 radio_calibration_value = new JTextField(String.format("%d", 1186611));
470 radio_calibration_value.getDocument().addDocumentListener(this);
472 radio_calibration_value.setEnabled(false);
473 pane.add(radio_calibration_value, c);
474 set_radio_calibration_tool_tip();
478 c = new GridBagConstraints();
479 c.gridx = 0; c.gridy = row;
481 c.fill = GridBagConstraints.NONE;
482 c.anchor = GridBagConstraints.LINE_START;
485 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
486 pane.add(radio_enable_label, c);
488 c = new GridBagConstraints();
489 c.gridx = 4; c.gridy = row;
491 c.fill = GridBagConstraints.HORIZONTAL;
493 c.anchor = GridBagConstraints.LINE_START;
496 radio_enable_value = new JRadioButton("Enabled");
497 radio_enable_value.addItemListener(this);
498 pane.add(radio_enable_value, c);
499 set_radio_enable_tool_tip();
503 c = new GridBagConstraints();
504 c.gridx = 0; c.gridy = row;
506 c.fill = GridBagConstraints.NONE;
507 c.anchor = GridBagConstraints.LINE_START;
510 rate_label = new JLabel("Telemetry baud rate:");
511 pane.add(rate_label, c);
513 c = new GridBagConstraints();
514 c.gridx = 4; c.gridy = row;
516 c.fill = GridBagConstraints.HORIZONTAL;
518 c.anchor = GridBagConstraints.LINE_START;
521 rate_value = new AltosUIRateList();
522 rate_value.addItemListener(this);
523 pane.add(rate_value, c);
528 c = new GridBagConstraints();
529 c.gridx = 0; c.gridy = row;
531 c.fill = GridBagConstraints.NONE;
532 c.anchor = GridBagConstraints.LINE_START;
535 aprs_interval_label = new JLabel("APRS Interval(s):");
536 pane.add(aprs_interval_label, c);
538 c = new GridBagConstraints();
539 c.gridx = 4; c.gridy = row;
541 c.fill = GridBagConstraints.HORIZONTAL;
543 c.anchor = GridBagConstraints.LINE_START;
546 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
547 aprs_interval_value.setEditable(true);
548 aprs_interval_value.addItemListener(this);
549 pane.add(aprs_interval_value, c);
550 set_aprs_interval_tool_tip();
554 c = new GridBagConstraints();
555 c.gridx = 0; c.gridy = row;
557 c.fill = GridBagConstraints.NONE;
558 c.anchor = GridBagConstraints.LINE_START;
561 aprs_ssid_label = new JLabel("APRS SSID:");
562 pane.add(aprs_ssid_label, c);
564 c = new GridBagConstraints();
565 c.gridx = 4; c.gridy = row;
567 c.fill = GridBagConstraints.HORIZONTAL;
569 c.anchor = GridBagConstraints.LINE_START;
572 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
573 aprs_ssid_value.setEditable(false);
574 aprs_ssid_value.addItemListener(this);
575 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
576 pane.add(aprs_ssid_value, c);
577 set_aprs_ssid_tool_tip();
581 c = new GridBagConstraints();
582 c.gridx = 0; c.gridy = row;
584 c.fill = GridBagConstraints.NONE;
585 c.anchor = GridBagConstraints.LINE_START;
588 callsign_label = new JLabel("Callsign:");
589 pane.add(callsign_label, c);
591 c = new GridBagConstraints();
592 c.gridx = 4; c.gridy = row;
594 c.fill = GridBagConstraints.HORIZONTAL;
596 c.anchor = GridBagConstraints.LINE_START;
599 callsign_value = new JTextField(AltosUIPreferences.callsign());
600 callsign_value.getDocument().addDocumentListener(this);
601 pane.add(callsign_value, c);
602 callsign_value.setToolTipText("Callsign reported in telemetry data");
606 c = new GridBagConstraints();
607 c.gridx = 0; c.gridy = row;
609 c.fill = GridBagConstraints.NONE;
610 c.anchor = GridBagConstraints.LINE_START;
613 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
614 pane.add(flight_log_max_label, c);
616 c = new GridBagConstraints();
617 c.gridx = 4; c.gridy = row;
619 c.fill = GridBagConstraints.HORIZONTAL;
621 c.anchor = GridBagConstraints.LINE_START;
624 flight_log_max_value = new JComboBox<String>();
625 flight_log_max_value.setEditable(true);
626 flight_log_max_value.addItemListener(this);
627 pane.add(flight_log_max_value, c);
628 set_flight_log_max_tool_tip();
632 c = new GridBagConstraints();
633 c.gridx = 0; c.gridy = row;
635 c.fill = GridBagConstraints.NONE;
636 c.anchor = GridBagConstraints.LINE_START;
639 ignite_mode_label = new JLabel("Igniter Firing Mode:");
640 pane.add(ignite_mode_label, c);
642 c = new GridBagConstraints();
643 c.gridx = 4; c.gridy = row;
645 c.fill = GridBagConstraints.HORIZONTAL;
647 c.anchor = GridBagConstraints.LINE_START;
650 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
651 ignite_mode_value.setEditable(false);
652 ignite_mode_value.addItemListener(this);
653 pane.add(ignite_mode_value, c);
654 set_ignite_mode_tool_tip();
657 /* Pad orientation */
658 c = new GridBagConstraints();
659 c.gridx = 0; c.gridy = row;
661 c.fill = GridBagConstraints.NONE;
662 c.anchor = GridBagConstraints.LINE_START;
665 pad_orientation_label = new JLabel("Pad Orientation:");
666 pane.add(pad_orientation_label, c);
668 c = new GridBagConstraints();
669 c.gridx = 4; c.gridy = row;
671 c.fill = GridBagConstraints.HORIZONTAL;
673 c.anchor = GridBagConstraints.LINE_START;
676 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
677 pad_orientation_value.setEditable(false);
678 pad_orientation_value.addItemListener(this);
679 pane.add(pad_orientation_value, c);
680 set_pad_orientation_tool_tip();
684 c = new GridBagConstraints();
685 c.gridx = 0; c.gridy = row;
687 c.fill = GridBagConstraints.NONE;
688 c.anchor = GridBagConstraints.LINE_START;
691 beep_label = new JLabel("Beeper Frequency:");
692 pane.add(beep_label, c);
694 c = new GridBagConstraints();
695 c.gridx = 4; c.gridy = row;
697 c.fill = GridBagConstraints.HORIZONTAL;
699 c.anchor = GridBagConstraints.LINE_START;
702 beep_value = new JComboBox<String>(beep_values);
703 beep_value.setEditable(true);
704 beep_value.addItemListener(this);
705 pane.add(beep_value, c);
709 /* Tracker triger horiz distances */
710 c = new GridBagConstraints();
711 c.gridx = 0; c.gridy = row;
713 c.fill = GridBagConstraints.NONE;
714 c.anchor = GridBagConstraints.LINE_START;
717 tracker_motion_label = new JLabel(get_tracker_motion_label());
718 pane.add(tracker_motion_label, c);
720 c = new GridBagConstraints();
721 c.gridx = 4; c.gridy = row;
723 c.fill = GridBagConstraints.HORIZONTAL;
725 c.anchor = GridBagConstraints.LINE_START;
728 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
729 tracker_motion_value.setEditable(true);
730 tracker_motion_value.addItemListener(this);
731 pane.add(tracker_motion_value, c);
734 /* Tracker triger vert distances */
735 c = new GridBagConstraints();
736 c.gridx = 0; c.gridy = row;
738 c.fill = GridBagConstraints.NONE;
739 c.anchor = GridBagConstraints.LINE_START;
742 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
743 pane.add(tracker_interval_label, c);
745 c = new GridBagConstraints();
746 c.gridx = 4; c.gridy = row;
748 c.fill = GridBagConstraints.HORIZONTAL;
750 c.anchor = GridBagConstraints.LINE_START;
753 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
754 tracker_interval_value.setEditable(true);
755 tracker_interval_value.addItemListener(this);
756 pane.add(tracker_interval_value, c);
757 set_tracker_tool_tip();
761 c = new GridBagConstraints();
762 c.gridx = 4; c.gridy = row;
764 c.fill = GridBagConstraints.HORIZONTAL;
765 c.anchor = GridBagConstraints.LINE_START;
768 pyro = new JButton("Configure Pyro Channels");
770 pyro.addActionListener(this);
771 pyro.setActionCommand("Pyro");
775 c = new GridBagConstraints();
776 c.gridx = 0; c.gridy = row;
778 c.fill = GridBagConstraints.NONE;
779 c.anchor = GridBagConstraints.LINE_START;
781 save = new JButton("Save");
783 save.addActionListener(this);
784 save.setActionCommand("Save");
786 c = new GridBagConstraints();
787 c.gridx = 2; c.gridy = row;
789 c.fill = GridBagConstraints.NONE;
790 c.anchor = GridBagConstraints.CENTER;
792 reset = new JButton("Reset");
794 reset.addActionListener(this);
795 reset.setActionCommand("Reset");
797 c = new GridBagConstraints();
798 c.gridx = 4; c.gridy = row;
800 c.fill = GridBagConstraints.NONE;
801 c.anchor = GridBagConstraints.CENTER;
803 reboot = new JButton("Reboot");
805 reboot.addActionListener(this);
806 reboot.setActionCommand("Reboot");
808 c = new GridBagConstraints();
809 c.gridx = 6; c.gridy = row;
811 c.fill = GridBagConstraints.NONE;
812 c.anchor = GridBagConstraints.LINE_END;
814 close = new JButton("Close");
816 close.addActionListener(this);
817 close.setActionCommand("Close");
819 addWindowListener(new ConfigListener(this));
820 AltosPreferences.register_units_listener(this);
823 /* Once the initial values are set, the config code will show the dialog */
824 public void make_visible() {
826 setLocationRelativeTo(owner);
830 /* If any values have been changed, confirm before closing */
831 public boolean check_dirty(String operation) {
833 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
835 i = JOptionPane.showOptionDialog(this,
836 String.format("Configuration modified. %s anyway?", operation),
837 "Configuration Modified",
838 JOptionPane.DEFAULT_OPTION,
839 JOptionPane.WARNING_MESSAGE,
840 null, options, options[1]);
849 save.setEnabled(true);
852 public void set_clean() {
854 save.setEnabled(false);
857 AltosConfigPyroUI pyro_ui;
859 public void dispose() {
862 AltosPreferences.unregister_units_listener(this);
866 /* Listen for events from our buttons */
867 public void actionPerformed(ActionEvent e) {
868 String cmd = e.getActionCommand();
870 if (cmd.equals("Pyro")) {
871 if (pyro_ui == null && pyros != null)
872 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
874 pyro_ui.make_visible();
878 if (cmd.equals("Close") || cmd.equals("Reboot"))
879 if (!check_dirty(cmd))
881 listener.actionPerformed(e);
882 if (cmd.equals("Close") || cmd.equals("Reboot")) {
889 /* ItemListener interface method */
890 public void itemStateChanged(ItemEvent e) {
894 /* DocumentListener interface methods */
895 public void changedUpdate(DocumentEvent e) {
899 public void insertUpdate(DocumentEvent e) {
903 public void removeUpdate(DocumentEvent e) {
907 /* Let the config code hook on a listener */
908 public void addActionListener(ActionListener l) {
912 /* set and get all of the dialog values */
913 public void set_product(String product) {
914 radio_frequency_value.set_product(product);
915 product_value.setText(product);
916 set_pad_orientation_tool_tip();
917 set_flight_log_max_tool_tip();
920 public void set_version(String version) {
921 version_value.setText(version);
924 public void set_serial(int serial) {
925 radio_frequency_value.set_serial(serial);
926 serial_value.setText(String.format("%d", serial));
929 public void set_main_deploy(int new_main_deploy) {
930 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
931 main_deploy_value.setEnabled(new_main_deploy >= 0);
933 main_deploy_value.setVisible(new_main_deploy >= 0);
934 main_deploy_label.setVisible(new_main_deploy >= 0);
938 public int main_deploy() {
939 return (int) (AltosConvert.height.parse(main_deploy_value.getSelectedItem().toString()) + 0.5);
942 String get_main_deploy_label() {
943 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.show_units());
946 String[] main_deploy_values() {
947 if (AltosConvert.imperial_units)
948 return main_deploy_values_ft;
950 return main_deploy_values_m;
953 void set_main_deploy_values() {
954 String[] v = main_deploy_values();
955 while (main_deploy_value.getItemCount() > 0)
956 main_deploy_value.removeItemAt(0);
957 for (int i = 0; i < v.length; i++)
958 main_deploy_value.addItem(v[i]);
959 main_deploy_value.setMaximumRowCount(v.length);
962 public void units_changed(boolean imperial_units) {
963 boolean was_dirty = dirty;
965 String v = main_deploy_value.getSelectedItem().toString();
966 main_deploy_label.setText(get_main_deploy_label());
967 set_main_deploy_values();
968 int m = (int) (AltosConvert.height.parse(v, !imperial_units) + 0.5);
971 if (tracker_motion_value.isEnabled()) {
972 String motion = tracker_motion_value.getSelectedItem().toString();
973 tracker_motion_label.setText(get_tracker_motion_label());
974 set_tracker_motion_values();
975 set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5));
982 public void set_apogee_delay(int new_apogee_delay) {
983 apogee_delay_value.setVisible(new_apogee_delay >= 0);
984 apogee_delay_label.setVisible(new_apogee_delay >= 0);
986 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
987 apogee_delay_value.setEnabled(new_apogee_delay >= 0);
990 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
993 v = s.split("\\s+")[0];
995 return Integer.parseInt(v);
996 } catch (NumberFormatException ne) {
997 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1001 public int apogee_delay() throws AltosConfigDataException {
1002 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1005 public void set_apogee_lockout(int new_apogee_lockout) {
1006 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1007 apogee_lockout_value.setEnabled(new_apogee_lockout >= 0);
1009 apogee_lockout_value.setVisible(new_apogee_lockout >= 0);
1010 apogee_lockout_label.setVisible(new_apogee_lockout >= 0);
1013 public int apogee_lockout() throws AltosConfigDataException {
1014 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1017 public void set_radio_frequency(double new_radio_frequency) {
1018 radio_frequency_label.setVisible(new_radio_frequency >= 0);
1019 radio_frequency_value.set_frequency(new_radio_frequency);
1022 public double radio_frequency() {
1023 return radio_frequency_value.frequency();
1026 public void set_radio_calibration(int new_radio_calibration) {
1027 radio_calibration_value.setVisible(new_radio_calibration >= 0);
1028 radio_calibration_label.setVisible(new_radio_calibration >= 0);
1030 if (new_radio_calibration < 0)
1031 radio_calibration_value.setText("Disabled");
1033 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1036 public int radio_calibration() throws AltosConfigDataException {
1037 return parse_int("radio calibration", radio_calibration_value.getText(), false);
1040 public void set_radio_enable(int new_radio_enable) {
1041 radio_enable_label.setVisible(new_radio_enable >= 0);
1042 radio_enable_value.setVisible(new_radio_enable >= 0);
1044 if (new_radio_enable >= 0) {
1045 radio_enable_value.setSelected(new_radio_enable > 0);
1046 radio_enable_value.setEnabled(true);
1048 radio_enable_value.setSelected(true);
1049 radio_enable_value.setEnabled(false);
1051 set_radio_enable_tool_tip();
1054 public int radio_enable() {
1055 if (radio_enable_value.isEnabled())
1056 return radio_enable_value.isSelected() ? 1 : 0;
1061 public void set_telemetry_rate(int new_rate) {
1062 rate_label.setVisible(new_rate >= 0);
1064 rate_value.set_rate(new_rate);
1067 public int telemetry_rate() {
1068 return rate_value.rate();
1071 public void set_callsign(String new_callsign) {
1072 callsign_value.setVisible(new_callsign != null);
1073 callsign_label.setVisible(new_callsign != null);
1075 callsign_value.setText(new_callsign);
1078 public String callsign() {
1079 return callsign_value.getText();
1082 int flight_log_max_limit;
1085 public String flight_log_max_label(int flight_log_max) {
1086 if (flight_log_max_limit != 0) {
1087 int nflight = flight_log_max_limit / flight_log_max;
1088 String plural = nflight > 1 ? "s" : "";
1090 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1092 return String.format("%d", flight_log_max);
1095 public void set_flight_log_max(int new_flight_log_max) {
1096 flight_log_max_value.setVisible(new_flight_log_max >= 0);
1097 flight_log_max_label.setVisible(new_flight_log_max >= 0);
1099 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1100 flight_log_max = new_flight_log_max;
1101 set_flight_log_max_tool_tip();
1104 public void set_flight_log_max_enabled(boolean enable) {
1105 flight_log_max_value.setEnabled(enable);
1106 set_flight_log_max_tool_tip();
1109 public int flight_log_max() throws AltosConfigDataException {
1110 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1113 public void set_flight_log_max_limit(int new_flight_log_max_limit) {
1114 flight_log_max_limit = new_flight_log_max_limit;
1115 flight_log_max_value.removeAllItems();
1116 for (int i = 8; i >= 1; i--) {
1117 int size = flight_log_max_limit / i;
1118 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1120 if (flight_log_max != 0)
1121 set_flight_log_max(flight_log_max);
1124 public void set_ignite_mode(int new_ignite_mode) {
1125 ignite_mode_value.setVisible(new_ignite_mode >= 0);
1126 ignite_mode_label.setVisible(new_ignite_mode >= 0);
1128 if (new_ignite_mode >= ignite_mode_values.length)
1129 new_ignite_mode = 0;
1130 if (new_ignite_mode < 0) {
1131 ignite_mode_value.setEnabled(false);
1132 new_ignite_mode = 0;
1134 ignite_mode_value.setEnabled(true);
1136 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1137 set_ignite_mode_tool_tip();
1140 public int ignite_mode() {
1141 if (ignite_mode_value.isEnabled())
1142 return ignite_mode_value.getSelectedIndex();
1148 public void set_pad_orientation(int new_pad_orientation) {
1149 pad_orientation_value.setVisible(new_pad_orientation >= 0);
1150 pad_orientation_label.setVisible(new_pad_orientation >= 0);
1152 if (new_pad_orientation >= pad_orientation_values.length)
1153 new_pad_orientation = 0;
1154 if (new_pad_orientation < 0)
1155 new_pad_orientation = 0;
1156 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1157 set_pad_orientation_tool_tip();
1160 public int pad_orientation() {
1161 if (pad_orientation_value.isEnabled())
1162 return pad_orientation_value.getSelectedIndex();
1167 public void set_beep(int new_beep) {
1168 beep_value.setVisible(new_beep >= 0);
1169 beep_label.setVisible(new_beep >= 0);
1171 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1172 for (int i = 0; i < beep_values.length; i++)
1173 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1174 beep_value.setSelectedIndex(i);
1175 set_beep_tool_tip();
1178 beep_value.setSelectedItem(String.format("%d", new_freq));
1179 beep_value.setEnabled(new_beep >= 0);
1180 set_beep_tool_tip();
1184 if (beep_value.isEnabled())
1185 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1190 String[] tracker_motion_values() {
1191 if (AltosConvert.imperial_units)
1192 return tracker_motion_values_ft;
1194 return tracker_motion_values_m;
1197 void set_tracker_motion_values() {
1198 String[] v = tracker_motion_values();
1199 while (tracker_motion_value.getItemCount() > 0)
1200 tracker_motion_value.removeItemAt(0);
1201 for (int i = 0; i < v.length; i++)
1202 tracker_motion_value.addItem(v[i]);
1203 tracker_motion_value.setMaximumRowCount(v.length);
1206 String get_tracker_motion_label() {
1207 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.show_units());
1210 void set_tracker_tool_tip() {
1211 if (tracker_motion_value.isEnabled())
1212 tracker_motion_value.setToolTipText("How far the device must move before logging");
1214 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1215 if (tracker_interval_value.isEnabled())
1216 tracker_interval_value.setToolTipText("How often to report GPS position");
1218 tracker_interval_value.setToolTipText("This device can't configure interval");
1221 public void set_tracker_motion(int tracker_motion) {
1222 tracker_motion_label.setVisible(tracker_motion >= 0);
1223 tracker_motion_value.setVisible(tracker_motion >= 0);
1225 if (tracker_motion < 0) {
1226 tracker_motion_value.setEnabled(false);
1228 tracker_motion_value.setEnabled(true);
1229 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1233 public int tracker_motion() throws AltosConfigDataException {
1234 return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString());
1237 public void set_tracker_interval(int tracker_interval) {
1238 tracker_interval_label.setVisible(tracker_interval >= 0);
1239 tracker_interval_value.setVisible(tracker_interval >= 0);
1241 if (tracker_interval< 0) {
1242 tracker_interval_value.setEnabled(false);
1244 tracker_interval_value.setEnabled(true);
1245 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1249 public int tracker_interval() throws AltosConfigDataException {
1250 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1253 public void set_pyros(AltosPyro[] new_pyros) {
1255 pyro.setVisible(pyros != null);
1256 if (pyros != null && pyro_ui != null)
1257 pyro_ui.set_pyros(pyros);
1260 public AltosPyro[] pyros() throws AltosConfigDataException {
1261 if (pyro_ui != null)
1262 pyros = pyro_ui.get_pyros();
1266 public void set_pyro_firing_time(double new_pyro_firing_time) {
1267 pyro_firing_time = new_pyro_firing_time;
1268 pyro.setVisible(pyro_firing_time >= 0);
1269 if (pyro_firing_time >= 0 && pyro_ui != null)
1270 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1273 public double pyro_firing_time() throws AltosConfigDataException {
1274 if (pyro_ui != null)
1275 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1276 return pyro_firing_time;
1279 public void set_aprs_interval(int new_aprs_interval) {
1280 aprs_interval_value.setVisible(new_aprs_interval >= 0);
1281 aprs_interval_label.setVisible(new_aprs_interval >= 0);
1285 if (new_aprs_interval <= 0)
1288 s = Integer.toString(new_aprs_interval);
1289 aprs_interval_value.setSelectedItem(s);
1290 set_aprs_interval_tool_tip();
1293 public int aprs_interval() throws AltosConfigDataException {
1294 String s = aprs_interval_value.getSelectedItem().toString();
1296 if (s.equals("Disabled"))
1298 return parse_int("aprs interval", s, false);
1301 public void set_aprs_ssid(int new_aprs_ssid) {
1302 aprs_ssid_value.setVisible(new_aprs_ssid >= 0);
1303 aprs_ssid_label.setVisible(new_aprs_ssid >= 0);
1305 aprs_ssid_value.setSelectedItem(Math.max(0,new_aprs_ssid));
1306 set_aprs_ssid_tool_tip();
1309 public int aprs_ssid() throws AltosConfigDataException {
1310 Integer i = (Integer) aprs_ssid_value.getSelectedItem();