2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 import java.awt.event.*;
23 import javax.swing.event.*;
24 import org.altusmetrum.altoslib_5.*;
25 import org.altusmetrum.altosuilib_3.*;
27 public class AltosConfigUI
29 implements ActionListener, ItemListener, DocumentListener, AltosConfigValues, AltosUnitsListener
36 JLabel main_deploy_label;
37 JLabel apogee_delay_label;
38 JLabel apogee_lockout_label;
39 JLabel frequency_label;
40 JLabel radio_calibration_label;
41 JLabel radio_frequency_label;
42 JLabel radio_enable_label;
43 JLabel aprs_interval_label;
44 JLabel aprs_ssid_label;
45 JLabel flight_log_max_label;
46 JLabel ignite_mode_label;
47 JLabel pad_orientation_label;
48 JLabel callsign_label;
50 JLabel tracker_motion_label;
51 JLabel tracker_interval_label;
59 JComboBox<String> main_deploy_value;
60 JComboBox<String> apogee_delay_value;
61 JComboBox<String> apogee_lockout_value;
62 AltosUIFreqList radio_frequency_value;
63 JTextField radio_calibration_value;
64 JRadioButton radio_enable_value;
65 JComboBox<String> aprs_interval_value;
66 JComboBox<Integer> aprs_ssid_value;
67 JComboBox<String> flight_log_max_value;
68 JComboBox<String> ignite_mode_value;
69 JComboBox<String> pad_orientation_value;
70 JTextField callsign_value;
71 JComboBox<String> beep_value;
72 JComboBox<String> tracker_motion_value;
73 JComboBox<String> tracker_interval_value;
83 double pyro_firing_time;
85 ActionListener listener;
87 static String[] main_deploy_values_m = {
88 "100", "150", "200", "250", "300", "350",
92 static String[] main_deploy_values_ft = {
93 "250", "500", "750", "1000", "1250", "1500",
97 static String[] apogee_delay_values = {
98 "0", "1", "2", "3", "4", "5"
101 static String[] apogee_lockout_values = {
102 "0", "5", "10", "15", "20"
105 static String[] ignite_mode_values = {
111 static String[] aprs_interval_values = {
118 static Integer[] aprs_ssid_values = {
119 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
122 static String[] beep_values = {
128 static String[] pad_orientation_values = {
133 static String[] tracker_motion_values_m = {
140 static String[] tracker_motion_values_ft = {
147 static String[] tracker_interval_values = {
154 /* A window listener to catch closing events and tell the config code */
155 class ConfigListener extends WindowAdapter {
158 public ConfigListener(AltosConfigUI this_ui) {
162 public void windowClosing(WindowEvent e) {
163 ui.actionPerformed(new ActionEvent(e.getSource(),
164 ActionEvent.ACTION_PERFORMED,
169 boolean is_telemini_v1() {
170 String product = product_value.getText();
171 return product != null && product.startsWith("TeleMini-v1");
174 boolean is_telemini() {
175 String product = product_value.getText();
176 return product != null && product.startsWith("TeleMini");
179 boolean is_easymini() {
180 String product = product_value.getText();
181 return product != null && product.startsWith("EasyMini");
184 boolean is_telemetrum() {
185 String product = product_value.getText();
186 return product != null && product.startsWith("TeleMetrum");
189 void set_radio_calibration_tool_tip() {
190 if (radio_calibration_value.isEnabled())
191 radio_calibration_value.setToolTipText("Tune radio output to match desired frequency");
193 radio_calibration_value.setToolTipText("Cannot tune radio while connected over packet mode");
196 void set_radio_enable_tool_tip() {
197 if (radio_enable_value.isEnabled())
198 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
200 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
203 void set_aprs_interval_tool_tip() {
204 if (aprs_interval_value.isEnabled())
205 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
207 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
210 void set_aprs_ssid_tool_tip() {
211 if (aprs_ssid_value.isEnabled())
212 aprs_interval_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
213 else if (aprs_interval_value.isEnabled())
214 aprs_interval_value.setToolTipText("Software version doesn't support setting the APRS SSID");
216 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
219 void set_flight_log_max_tool_tip() {
220 if (flight_log_max_value.isEnabled())
221 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
223 if (is_telemini_v1())
224 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
226 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
230 void set_ignite_mode_tool_tip() {
231 if (ignite_mode_value.isEnabled())
232 ignite_mode_value.setToolTipText("Select when igniters will be fired");
234 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
237 void set_pad_orientation_tool_tip() {
238 if (pad_orientation_value.isEnabled())
239 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
242 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
243 else if (is_telemini() || is_easymini())
244 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
246 pad_orientation_value.setToolTipText("Can't select orientation");
250 void set_beep_tool_tip() {
251 if (beep_value.isEnabled())
252 beep_value.setToolTipText("What frequency the beeper will sound at");
254 beep_value.setToolTipText("Older firmware could not select beeper frequency");
257 /* Build the UI using a grid bag */
258 public AltosConfigUI(JFrame in_owner, boolean remote) {
259 super (in_owner, "Configure Flight Computer", false);
262 GridBagConstraints c;
265 Insets il = new Insets(4,4,4,4);
266 Insets ir = new Insets(4,4,4,4);
268 pane = getContentPane();
269 pane.setLayout(new GridBagLayout());
272 c = new GridBagConstraints();
273 c.gridx = 0; c.gridy = row;
275 c.fill = GridBagConstraints.NONE;
276 c.anchor = GridBagConstraints.LINE_START;
278 product_label = new JLabel("Product:");
279 pane.add(product_label, c);
281 c = new GridBagConstraints();
282 c.gridx = 4; c.gridy = row;
284 c.fill = GridBagConstraints.HORIZONTAL;
286 c.anchor = GridBagConstraints.LINE_START;
288 product_value = new JLabel("");
289 pane.add(product_value, c);
293 c = new GridBagConstraints();
294 c.gridx = 0; c.gridy = row;
296 c.fill = GridBagConstraints.NONE;
297 c.anchor = GridBagConstraints.LINE_START;
300 version_label = new JLabel("Software version:");
301 pane.add(version_label, c);
303 c = new GridBagConstraints();
304 c.gridx = 4; c.gridy = row;
306 c.fill = GridBagConstraints.HORIZONTAL;
308 c.anchor = GridBagConstraints.LINE_START;
311 version_value = new JLabel("");
312 pane.add(version_value, c);
316 c = new GridBagConstraints();
317 c.gridx = 0; c.gridy = row;
319 c.fill = GridBagConstraints.NONE;
320 c.anchor = GridBagConstraints.LINE_START;
323 serial_label = new JLabel("Serial:");
324 pane.add(serial_label, c);
326 c = new GridBagConstraints();
327 c.gridx = 4; c.gridy = row;
329 c.fill = GridBagConstraints.HORIZONTAL;
331 c.anchor = GridBagConstraints.LINE_START;
334 serial_value = new JLabel("");
335 pane.add(serial_value, c);
339 c = new GridBagConstraints();
340 c.gridx = 0; c.gridy = row;
342 c.fill = GridBagConstraints.NONE;
343 c.anchor = GridBagConstraints.LINE_START;
346 main_deploy_label = new JLabel(get_main_deploy_label());
347 pane.add(main_deploy_label, c);
349 c = new GridBagConstraints();
350 c.gridx = 4; c.gridy = row;
352 c.fill = GridBagConstraints.HORIZONTAL;
354 c.anchor = GridBagConstraints.LINE_START;
357 main_deploy_value = new JComboBox<String>(main_deploy_values());
358 main_deploy_value.setEditable(true);
359 main_deploy_value.addItemListener(this);
360 pane.add(main_deploy_value, c);
361 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
365 c = new GridBagConstraints();
366 c.gridx = 0; c.gridy = row;
368 c.fill = GridBagConstraints.NONE;
369 c.anchor = GridBagConstraints.LINE_START;
372 apogee_delay_label = new JLabel("Apogee Delay(s):");
373 pane.add(apogee_delay_label, c);
375 c = new GridBagConstraints();
376 c.gridx = 4; c.gridy = row;
378 c.fill = GridBagConstraints.HORIZONTAL;
380 c.anchor = GridBagConstraints.LINE_START;
383 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
384 apogee_delay_value.setEditable(true);
385 apogee_delay_value.addItemListener(this);
386 pane.add(apogee_delay_value, c);
387 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
391 c = new GridBagConstraints();
392 c.gridx = 0; c.gridy = row;
394 c.fill = GridBagConstraints.NONE;
395 c.anchor = GridBagConstraints.LINE_START;
398 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
399 pane.add(apogee_lockout_label, c);
401 c = new GridBagConstraints();
402 c.gridx = 4; c.gridy = row;
404 c.fill = GridBagConstraints.HORIZONTAL;
406 c.anchor = GridBagConstraints.LINE_START;
409 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
410 apogee_lockout_value.setEditable(true);
411 apogee_lockout_value.addItemListener(this);
412 pane.add(apogee_lockout_value, c);
413 apogee_lockout_value.setToolTipText("Time after boost while apogee detection is locked out");
417 c = new GridBagConstraints();
418 c.gridx = 0; c.gridy = row;
420 c.fill = GridBagConstraints.NONE;
421 c.anchor = GridBagConstraints.LINE_START;
424 radio_frequency_label = new JLabel("Frequency:");
425 pane.add(radio_frequency_label, c);
427 c = new GridBagConstraints();
428 c.gridx = 4; c.gridy = row;
430 c.fill = GridBagConstraints.HORIZONTAL;
432 c.anchor = GridBagConstraints.LINE_START;
435 radio_frequency_value = new AltosUIFreqList();
436 radio_frequency_value.addItemListener(this);
437 pane.add(radio_frequency_value, c);
438 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
441 /* Radio Calibration */
442 c = new GridBagConstraints();
443 c.gridx = 0; c.gridy = row;
445 c.fill = GridBagConstraints.NONE;
446 c.anchor = GridBagConstraints.LINE_START;
449 radio_calibration_label = new JLabel("RF Calibration:");
450 pane.add(radio_calibration_label, c);
452 c = new GridBagConstraints();
453 c.gridx = 4; c.gridy = row;
455 c.fill = GridBagConstraints.HORIZONTAL;
457 c.anchor = GridBagConstraints.LINE_START;
460 radio_calibration_value = new JTextField(String.format("%d", 1186611));
461 radio_calibration_value.getDocument().addDocumentListener(this);
463 radio_calibration_value.setEnabled(false);
464 pane.add(radio_calibration_value, c);
465 set_radio_calibration_tool_tip();
469 c = new GridBagConstraints();
470 c.gridx = 0; c.gridy = row;
472 c.fill = GridBagConstraints.NONE;
473 c.anchor = GridBagConstraints.LINE_START;
476 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
477 pane.add(radio_enable_label, c);
479 c = new GridBagConstraints();
480 c.gridx = 4; c.gridy = row;
482 c.fill = GridBagConstraints.HORIZONTAL;
484 c.anchor = GridBagConstraints.LINE_START;
487 radio_enable_value = new JRadioButton("Enabled");
488 radio_enable_value.addItemListener(this);
489 pane.add(radio_enable_value, c);
490 set_radio_enable_tool_tip();
494 c = new GridBagConstraints();
495 c.gridx = 0; c.gridy = row;
497 c.fill = GridBagConstraints.NONE;
498 c.anchor = GridBagConstraints.LINE_START;
501 aprs_interval_label = new JLabel("APRS Interval(s):");
502 pane.add(aprs_interval_label, c);
504 c = new GridBagConstraints();
505 c.gridx = 4; c.gridy = row;
507 c.fill = GridBagConstraints.HORIZONTAL;
509 c.anchor = GridBagConstraints.LINE_START;
512 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
513 aprs_interval_value.setEditable(true);
514 aprs_interval_value.addItemListener(this);
515 pane.add(aprs_interval_value, c);
516 set_aprs_interval_tool_tip();
520 c = new GridBagConstraints();
521 c.gridx = 0; c.gridy = row;
523 c.fill = GridBagConstraints.NONE;
524 c.anchor = GridBagConstraints.LINE_START;
527 aprs_ssid_label = new JLabel("APRS SSID:");
528 pane.add(aprs_ssid_label, c);
530 c = new GridBagConstraints();
531 c.gridx = 4; c.gridy = row;
533 c.fill = GridBagConstraints.HORIZONTAL;
535 c.anchor = GridBagConstraints.LINE_START;
538 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
539 aprs_ssid_value.setEditable(false);
540 aprs_ssid_value.addItemListener(this);
541 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
542 pane.add(aprs_ssid_value, c);
543 set_aprs_ssid_tool_tip();
547 c = new GridBagConstraints();
548 c.gridx = 0; c.gridy = row;
550 c.fill = GridBagConstraints.NONE;
551 c.anchor = GridBagConstraints.LINE_START;
554 callsign_label = new JLabel("Callsign:");
555 pane.add(callsign_label, c);
557 c = new GridBagConstraints();
558 c.gridx = 4; c.gridy = row;
560 c.fill = GridBagConstraints.HORIZONTAL;
562 c.anchor = GridBagConstraints.LINE_START;
565 callsign_value = new JTextField(AltosUIPreferences.callsign());
566 callsign_value.getDocument().addDocumentListener(this);
567 pane.add(callsign_value, c);
568 callsign_value.setToolTipText("Callsign reported in telemetry data");
572 c = new GridBagConstraints();
573 c.gridx = 0; c.gridy = row;
575 c.fill = GridBagConstraints.NONE;
576 c.anchor = GridBagConstraints.LINE_START;
579 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
580 pane.add(flight_log_max_label, c);
582 c = new GridBagConstraints();
583 c.gridx = 4; c.gridy = row;
585 c.fill = GridBagConstraints.HORIZONTAL;
587 c.anchor = GridBagConstraints.LINE_START;
590 flight_log_max_value = new JComboBox<String>();
591 flight_log_max_value.setEditable(true);
592 flight_log_max_value.addItemListener(this);
593 pane.add(flight_log_max_value, c);
594 set_flight_log_max_tool_tip();
598 c = new GridBagConstraints();
599 c.gridx = 0; c.gridy = row;
601 c.fill = GridBagConstraints.NONE;
602 c.anchor = GridBagConstraints.LINE_START;
605 ignite_mode_label = new JLabel("Igniter Firing Mode:");
606 pane.add(ignite_mode_label, c);
608 c = new GridBagConstraints();
609 c.gridx = 4; c.gridy = row;
611 c.fill = GridBagConstraints.HORIZONTAL;
613 c.anchor = GridBagConstraints.LINE_START;
616 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
617 ignite_mode_value.setEditable(false);
618 ignite_mode_value.addItemListener(this);
619 pane.add(ignite_mode_value, c);
620 set_ignite_mode_tool_tip();
623 /* Pad orientation */
624 c = new GridBagConstraints();
625 c.gridx = 0; c.gridy = row;
627 c.fill = GridBagConstraints.NONE;
628 c.anchor = GridBagConstraints.LINE_START;
631 pad_orientation_label = new JLabel("Pad Orientation:");
632 pane.add(pad_orientation_label, c);
634 c = new GridBagConstraints();
635 c.gridx = 4; c.gridy = row;
637 c.fill = GridBagConstraints.HORIZONTAL;
639 c.anchor = GridBagConstraints.LINE_START;
642 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
643 pad_orientation_value.setEditable(false);
644 pad_orientation_value.addItemListener(this);
645 pane.add(pad_orientation_value, c);
646 set_pad_orientation_tool_tip();
650 c = new GridBagConstraints();
651 c.gridx = 0; c.gridy = row;
653 c.fill = GridBagConstraints.NONE;
654 c.anchor = GridBagConstraints.LINE_START;
657 beep_label = new JLabel("Beeper Frequency:");
658 pane.add(beep_label, c);
660 c = new GridBagConstraints();
661 c.gridx = 4; c.gridy = row;
663 c.fill = GridBagConstraints.HORIZONTAL;
665 c.anchor = GridBagConstraints.LINE_START;
668 beep_value = new JComboBox<String>(beep_values);
669 beep_value.setEditable(true);
670 beep_value.addItemListener(this);
671 pane.add(beep_value, c);
675 /* Tracker triger horiz distances */
676 c = new GridBagConstraints();
677 c.gridx = 0; c.gridy = row;
679 c.fill = GridBagConstraints.NONE;
680 c.anchor = GridBagConstraints.LINE_START;
683 tracker_motion_label = new JLabel(get_tracker_motion_label());
684 pane.add(tracker_motion_label, c);
686 c = new GridBagConstraints();
687 c.gridx = 4; c.gridy = row;
689 c.fill = GridBagConstraints.HORIZONTAL;
691 c.anchor = GridBagConstraints.LINE_START;
694 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
695 tracker_motion_value.setEditable(true);
696 tracker_motion_value.addItemListener(this);
697 pane.add(tracker_motion_value, c);
700 /* Tracker triger vert distances */
701 c = new GridBagConstraints();
702 c.gridx = 0; c.gridy = row;
704 c.fill = GridBagConstraints.NONE;
705 c.anchor = GridBagConstraints.LINE_START;
708 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
709 pane.add(tracker_interval_label, c);
711 c = new GridBagConstraints();
712 c.gridx = 4; c.gridy = row;
714 c.fill = GridBagConstraints.HORIZONTAL;
716 c.anchor = GridBagConstraints.LINE_START;
719 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
720 tracker_interval_value.setEditable(true);
721 tracker_interval_value.addItemListener(this);
722 pane.add(tracker_interval_value, c);
723 set_tracker_tool_tip();
727 c = new GridBagConstraints();
728 c.gridx = 4; c.gridy = row;
730 c.fill = GridBagConstraints.HORIZONTAL;
731 c.anchor = GridBagConstraints.LINE_START;
734 pyro = new JButton("Configure Pyro Channels");
736 pyro.addActionListener(this);
737 pyro.setActionCommand("Pyro");
741 c = new GridBagConstraints();
742 c.gridx = 0; c.gridy = row;
744 c.fill = GridBagConstraints.NONE;
745 c.anchor = GridBagConstraints.LINE_START;
747 save = new JButton("Save");
749 save.addActionListener(this);
750 save.setActionCommand("Save");
752 c = new GridBagConstraints();
753 c.gridx = 2; c.gridy = row;
755 c.fill = GridBagConstraints.NONE;
756 c.anchor = GridBagConstraints.CENTER;
758 reset = new JButton("Reset");
760 reset.addActionListener(this);
761 reset.setActionCommand("Reset");
763 c = new GridBagConstraints();
764 c.gridx = 4; c.gridy = row;
766 c.fill = GridBagConstraints.NONE;
767 c.anchor = GridBagConstraints.CENTER;
769 reboot = new JButton("Reboot");
771 reboot.addActionListener(this);
772 reboot.setActionCommand("Reboot");
774 c = new GridBagConstraints();
775 c.gridx = 6; c.gridy = row;
777 c.fill = GridBagConstraints.NONE;
778 c.anchor = GridBagConstraints.LINE_END;
780 close = new JButton("Close");
782 close.addActionListener(this);
783 close.setActionCommand("Close");
785 addWindowListener(new ConfigListener(this));
786 AltosPreferences.register_units_listener(this);
789 /* Once the initial values are set, the config code will show the dialog */
790 public void make_visible() {
792 setLocationRelativeTo(owner);
796 /* If any values have been changed, confirm before closing */
797 public boolean check_dirty(String operation) {
799 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
801 i = JOptionPane.showOptionDialog(this,
802 String.format("Configuration modified. %s anyway?", operation),
803 "Configuration Modified",
804 JOptionPane.DEFAULT_OPTION,
805 JOptionPane.WARNING_MESSAGE,
806 null, options, options[1]);
815 save.setEnabled(true);
818 public void set_clean() {
820 save.setEnabled(false);
823 AltosConfigPyroUI pyro_ui;
825 public void dispose() {
828 AltosPreferences.unregister_units_listener(this);
832 /* Listen for events from our buttons */
833 public void actionPerformed(ActionEvent e) {
834 String cmd = e.getActionCommand();
836 if (cmd.equals("Pyro")) {
837 if (pyro_ui == null && pyros != null)
838 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
840 pyro_ui.make_visible();
844 if (cmd.equals("Close") || cmd.equals("Reboot"))
845 if (!check_dirty(cmd))
847 listener.actionPerformed(e);
848 if (cmd.equals("Close") || cmd.equals("Reboot")) {
855 /* ItemListener interface method */
856 public void itemStateChanged(ItemEvent e) {
860 /* DocumentListener interface methods */
861 public void changedUpdate(DocumentEvent e) {
865 public void insertUpdate(DocumentEvent e) {
869 public void removeUpdate(DocumentEvent e) {
873 /* Let the config code hook on a listener */
874 public void addActionListener(ActionListener l) {
878 /* set and get all of the dialog values */
879 public void set_product(String product) {
880 radio_frequency_value.set_product(product);
881 product_value.setText(product);
882 set_pad_orientation_tool_tip();
883 set_flight_log_max_tool_tip();
886 public void set_version(String version) {
887 version_value.setText(version);
890 public void set_serial(int serial) {
891 radio_frequency_value.set_serial(serial);
892 serial_value.setText(String.format("%d", serial));
895 public void set_main_deploy(int new_main_deploy) {
896 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
897 main_deploy_value.setEnabled(new_main_deploy >= 0);
900 public int main_deploy() {
901 return (int) (AltosConvert.height.parse(main_deploy_value.getSelectedItem().toString()) + 0.5);
904 String get_main_deploy_label() {
905 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.show_units());
908 String[] main_deploy_values() {
909 if (AltosConvert.imperial_units)
910 return main_deploy_values_ft;
912 return main_deploy_values_m;
915 void set_main_deploy_values() {
916 String[] v = main_deploy_values();
917 while (main_deploy_value.getItemCount() > 0)
918 main_deploy_value.removeItemAt(0);
919 for (int i = 0; i < v.length; i++)
920 main_deploy_value.addItem(v[i]);
921 main_deploy_value.setMaximumRowCount(v.length);
924 public void units_changed(boolean imperial_units) {
925 boolean was_dirty = dirty;
927 String v = main_deploy_value.getSelectedItem().toString();
928 main_deploy_label.setText(get_main_deploy_label());
929 set_main_deploy_values();
930 int m = (int) (AltosConvert.height.parse(v, !imperial_units) + 0.5);
933 if (tracker_motion_value.isEnabled()) {
934 String motion = tracker_motion_value.getSelectedItem().toString();
935 tracker_motion_label.setText(get_tracker_motion_label());
936 set_tracker_motion_values();
937 set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5));
944 public void set_apogee_delay(int new_apogee_delay) {
945 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
946 apogee_delay_value.setEnabled(new_apogee_delay >= 0);
949 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
952 v = s.split("\\s+")[0];
954 return Integer.parseInt(v);
955 } catch (NumberFormatException ne) {
956 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
960 public int apogee_delay() throws AltosConfigDataException {
961 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
964 public void set_apogee_lockout(int new_apogee_lockout) {
965 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
966 apogee_lockout_value.setEnabled(new_apogee_lockout >= 0);
969 public int apogee_lockout() throws AltosConfigDataException {
970 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
973 public void set_radio_frequency(double new_radio_frequency) {
974 radio_frequency_value.set_frequency(new_radio_frequency);
977 public double radio_frequency() {
978 return radio_frequency_value.frequency();
981 public void set_radio_calibration(int new_radio_calibration) {
982 radio_calibration_value.setVisible(new_radio_calibration >= 0);
983 if (new_radio_calibration < 0)
984 radio_calibration_value.setText("Disabled");
986 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
989 public int radio_calibration() throws AltosConfigDataException {
990 return parse_int("radio calibration", radio_calibration_value.getText(), false);
993 public void set_radio_enable(int new_radio_enable) {
994 if (new_radio_enable >= 0) {
995 radio_enable_value.setSelected(new_radio_enable > 0);
996 radio_enable_value.setEnabled(true);
998 radio_enable_value.setSelected(true);
999 radio_enable_value.setVisible(radio_frequency() > 0);
1000 radio_enable_value.setEnabled(false);
1002 set_radio_enable_tool_tip();
1005 public int radio_enable() {
1006 if (radio_enable_value.isEnabled())
1007 return radio_enable_value.isSelected() ? 1 : 0;
1012 public void set_callsign(String new_callsign) {
1013 callsign_value.setVisible(new_callsign != null);
1014 callsign_value.setText(new_callsign);
1017 public String callsign() {
1018 return callsign_value.getText();
1021 int flight_log_max_limit;
1024 public String flight_log_max_label(int flight_log_max) {
1025 if (flight_log_max_limit != 0) {
1026 int nflight = flight_log_max_limit / flight_log_max;
1027 String plural = nflight > 1 ? "s" : "";
1029 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1031 return String.format("%d", flight_log_max);
1034 public void set_flight_log_max(int new_flight_log_max) {
1035 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1036 flight_log_max = new_flight_log_max;
1037 set_flight_log_max_tool_tip();
1040 public void set_flight_log_max_enabled(boolean enable) {
1041 flight_log_max_value.setEnabled(enable);
1042 set_flight_log_max_tool_tip();
1045 public int flight_log_max() throws AltosConfigDataException {
1046 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1049 public void set_flight_log_max_limit(int new_flight_log_max_limit) {
1050 flight_log_max_limit = new_flight_log_max_limit;
1051 flight_log_max_value.removeAllItems();
1052 for (int i = 8; i >= 1; i--) {
1053 int size = flight_log_max_limit / i;
1054 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1056 if (flight_log_max != 0)
1057 set_flight_log_max(flight_log_max);
1060 public void set_ignite_mode(int new_ignite_mode) {
1061 if (new_ignite_mode >= ignite_mode_values.length)
1062 new_ignite_mode = 0;
1063 if (new_ignite_mode < 0) {
1064 ignite_mode_value.setEnabled(false);
1065 new_ignite_mode = 0;
1067 ignite_mode_value.setEnabled(true);
1069 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1070 set_ignite_mode_tool_tip();
1073 public int ignite_mode() {
1074 if (ignite_mode_value.isEnabled())
1075 return ignite_mode_value.getSelectedIndex();
1081 public void set_pad_orientation(int new_pad_orientation) {
1082 if (new_pad_orientation >= pad_orientation_values.length)
1083 new_pad_orientation = 0;
1084 if (new_pad_orientation < 0) {
1085 pad_orientation_value.setVisible(false);
1086 new_pad_orientation = 0;
1088 pad_orientation_value.setVisible(true);
1090 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1091 set_pad_orientation_tool_tip();
1094 public int pad_orientation() {
1095 if (pad_orientation_value.isEnabled())
1096 return pad_orientation_value.getSelectedIndex();
1101 public void set_beep(int new_beep) {
1102 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1103 for (int i = 0; i < beep_values.length; i++)
1104 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1105 beep_value.setSelectedIndex(i);
1106 set_beep_tool_tip();
1109 beep_value.setSelectedItem(String.format("%d", new_freq));
1110 beep_value.setEnabled(new_beep >= 0);
1111 set_beep_tool_tip();
1115 if (beep_value.isEnabled())
1116 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1121 String[] tracker_motion_values() {
1122 if (AltosConvert.imperial_units)
1123 return tracker_motion_values_ft;
1125 return tracker_motion_values_m;
1128 void set_tracker_motion_values() {
1129 String[] v = tracker_motion_values();
1130 while (tracker_motion_value.getItemCount() > 0)
1131 tracker_motion_value.removeItemAt(0);
1132 for (int i = 0; i < v.length; i++)
1133 tracker_motion_value.addItem(v[i]);
1134 tracker_motion_value.setMaximumRowCount(v.length);
1137 String get_tracker_motion_label() {
1138 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.show_units());
1141 void set_tracker_tool_tip() {
1142 if (tracker_motion_value.isEnabled())
1143 tracker_motion_value.setToolTipText("How far the device must move before logging");
1145 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1146 if (tracker_interval_value.isEnabled())
1147 tracker_interval_value.setToolTipText("How often to report GPS position");
1149 tracker_interval_value.setToolTipText("This device can't configure interval");
1152 public void set_tracker_motion(int tracker_motion) {
1153 if (tracker_motion < 0) {
1154 tracker_motion_label.setVisible(false);
1155 tracker_motion_value.setVisible(false);
1156 tracker_motion_value.setEnabled(false);
1158 tracker_motion_label.setVisible(true);
1159 tracker_motion_value.setVisible(true);
1160 tracker_motion_value.setEnabled(true);
1161 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1165 public int tracker_motion() throws AltosConfigDataException {
1166 return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString());
1169 public void set_tracker_interval(int tracker_interval) {
1170 if (tracker_interval< 0) {
1171 tracker_interval_label.setVisible(false);
1172 tracker_interval_value.setVisible(false);
1173 tracker_interval_value.setEnabled(false);
1175 tracker_interval_label.setVisible(true);
1176 tracker_interval_value.setVisible(true);
1177 tracker_interval_value.setEnabled(true);
1178 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1182 public int tracker_interval() throws AltosConfigDataException {
1183 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1186 public void set_pyros(AltosPyro[] new_pyros) {
1188 pyro.setVisible(pyros != null);
1189 if (pyros != null && pyro_ui != null)
1190 pyro_ui.set_pyros(pyros);
1193 public AltosPyro[] pyros() throws AltosConfigDataException {
1194 if (pyro_ui != null)
1195 pyros = pyro_ui.get_pyros();
1199 public void set_pyro_firing_time(double new_pyro_firing_time) {
1200 pyro_firing_time = new_pyro_firing_time;
1201 pyro.setVisible(pyro_firing_time >= 0);
1202 if (pyro_firing_time >= 0 && pyro_ui != null)
1203 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1206 public double pyro_firing_time() throws AltosConfigDataException {
1207 if (pyro_ui != null)
1208 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1209 return pyro_firing_time;
1212 public void set_aprs_interval(int new_aprs_interval) {
1215 if (new_aprs_interval <= 0)
1218 s = Integer.toString(new_aprs_interval);
1219 aprs_interval_value.setSelectedItem(s);
1220 aprs_interval_value.setVisible(new_aprs_interval >= 0);
1221 set_aprs_interval_tool_tip();
1224 public int aprs_interval() throws AltosConfigDataException {
1225 String s = aprs_interval_value.getSelectedItem().toString();
1227 if (s.equals("Disabled"))
1229 return parse_int("aprs interval", s, false);
1232 public void set_aprs_ssid(int new_aprs_ssid) {
1233 aprs_ssid_value.setSelectedItem(Math.max(0,new_aprs_ssid));
1234 aprs_ssid_value.setVisible(new_aprs_ssid >= 0);
1235 set_aprs_ssid_tool_tip();
1238 public int aprs_ssid() throws AltosConfigDataException {
1239 Integer i = (Integer) aprs_ssid_value.getSelectedItem();