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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.telegps;
23 import java.awt.event.*;
25 import javax.swing.event.*;
26 import org.altusmetrum.altoslib_14.*;
27 import org.altusmetrum.altosuilib_14.*;
29 public class TeleGPSConfigUI
31 implements ActionListener, ItemListener, DocumentListener, AltosConfigValues, AltosUnitsListener
38 JLabel frequency_label;
39 JLabel radio_calibration_label;
40 JLabel radio_frequency_label;
41 JLabel radio_enable_label;
42 JLabel radio_10mw_label;
43 JLabel report_feet_label;
44 JLabel gps_receiver_label;
46 JLabel aprs_interval_label;
47 JLabel aprs_ssid_label;
48 JLabel aprs_format_label;
49 JLabel aprs_offset_label;
50 JLabel flight_log_max_label;
51 JLabel callsign_label;
52 JLabel tracker_motion_label;
53 JLabel tracker_interval_label;
61 AltosUIFreqList radio_frequency_value;
62 JLabel radio_calibration_value;
63 JRadioButton radio_enable_value;
64 JRadioButton radio_10mw_value;
65 JComboBox<String> report_feet_value;
66 JComboBox<String> gps_receiver_value;
67 AltosUIRateList rate_value;
68 JComboBox<String> aprs_interval_value;
69 JComboBox<Integer> aprs_ssid_value;
70 JComboBox<String> aprs_format_value;
71 JComboBox<Integer> aprs_offset_value;
72 JComboBox<String> flight_log_max_value;
73 JTextField callsign_value;
74 JComboBox<String> tracker_motion_value;
75 JComboBox<String> tracker_interval_value;
82 ActionListener listener;
84 static String[] aprs_interval_values = {
91 static Integer[] aprs_ssid_values = {
92 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
95 static Integer[] aprs_offset_values = {
96 0, 2, 4, 6, 8, 10, 12, 14, 16, 18
99 static String[] tracker_motion_values_m = {
106 static String[] tracker_motion_values_ft = {
113 static String[] tracker_interval_values = {
120 static String[] report_feet_values = {
125 /* A window listener to catch closing events and tell the config code */
126 class ConfigListener extends WindowAdapter {
129 public ConfigListener(TeleGPSConfigUI this_ui) {
133 public void windowClosing(WindowEvent e) {
134 ui.actionPerformed(new ActionEvent(e.getSource(),
135 ActionEvent.ACTION_PERFORMED,
140 public void set_pyros(AltosPyro[] new_pyros) {
143 public AltosPyro[] pyros() {
147 public void set_pyro_firing_time(double new_pyro_firing_time) {
150 public double pyro_firing_time() {
151 return AltosLib.MISSING;
154 boolean is_telemetrum() {
155 String product = product_value.getText();
156 return product != null && product.startsWith("TeleGPS");
159 void set_radio_enable_tool_tip() {
160 if (radio_enable_value.isVisible())
161 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
163 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
166 void set_radio_10mw_tool_tip() {
167 if (radio_10mw_value.isVisible())
168 radio_10mw_value.setToolTipText("Should transmitter power be limited to 10mW");
170 radio_10mw_value.setToolTipText("Older firmware could not limit radio power");
173 void set_report_feet_tool_tip() {
174 if (report_feet_value.isVisible())
175 report_feet_value.setToolTipText("Units used after landing to beep max height");
177 report_feet_value.setToolTipText("Older firmware always beeps max height in meters");
180 public void set_report_feet(int new_report_feet) {
181 if (new_report_feet != AltosLib.MISSING) {
182 if (new_report_feet >= report_feet_values.length)
184 if (new_report_feet < 0) {
185 report_feet_value.setEnabled(false);
188 report_feet_value.setEnabled(true);
190 report_feet_value.setSelectedIndex(new_report_feet);
192 report_feet_value.setVisible(new_report_feet != AltosLib.MISSING);
193 report_feet_label.setVisible(new_report_feet != AltosLib.MISSING);
195 set_report_feet_tool_tip();
198 public int report_feet() {
199 if (report_feet_value.isVisible())
200 return report_feet_value.getSelectedIndex();
202 return AltosLib.MISSING;
205 void set_gps_receiver_tool_tip() {
206 if (gps_receiver_value.isVisible())
207 gps_receiver_value.setToolTipText("GPS receiver selection");
209 gps_receiver_value.setToolTipText("Only TeleMega with new firmware supports alternate GPS receivers");
212 public void set_gps_receiver(int new_gps_receiver) {
213 System.out.printf("set_gps_receiver %d\n", new_gps_receiver);
214 if (new_gps_receiver != AltosLib.MISSING) {
215 if (new_gps_receiver >= AltosLib.gps_receiver_names.length)
216 new_gps_receiver = 0;
217 if (new_gps_receiver < 0) {
218 gps_receiver_value.setEnabled(false);
219 new_gps_receiver = 0;
221 gps_receiver_value.setEnabled(true);
223 gps_receiver_value.setSelectedIndex(new_gps_receiver);
225 gps_receiver_value.setVisible(new_gps_receiver != AltosLib.MISSING);
226 gps_receiver_label.setVisible(new_gps_receiver != AltosLib.MISSING);
228 set_gps_receiver_tool_tip();
231 public int gps_receiver() {
232 if (gps_receiver_value.isVisible())
233 return gps_receiver_value.getSelectedIndex();
235 return AltosLib.MISSING;
238 void set_rate_tool_tip() {
239 if (rate_value.isVisible())
240 rate_value.setToolTipText("Select telemetry baud rate");
242 rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
245 void set_aprs_interval_tool_tip() {
246 if (aprs_interval_value.isVisible())
247 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
249 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
252 void set_aprs_ssid_tool_tip() {
253 if (aprs_ssid_value.isVisible())
254 aprs_ssid_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
255 else if (aprs_ssid_value.isVisible())
256 aprs_ssid_value.setToolTipText("Software version doesn't support setting the APRS SSID");
258 aprs_ssid_value.setToolTipText("Hardware doesn't support APRS");
261 void set_aprs_format_tool_tip() {
262 if (aprs_format_value.isVisible())
263 aprs_format_value.setToolTipText("Set the APRS format (compressed/uncompressed)");
264 else if (aprs_format_value.isVisible())
265 aprs_format_value.setToolTipText("Software version doesn't support setting the APRS format");
267 aprs_format_value.setToolTipText("Hardware doesn't support APRS");
270 void set_aprs_offset_tool_tip() {
271 if (aprs_offset_value.isVisible())
272 aprs_offset_value.setToolTipText("Set the APRS offset from top of minute");
273 else if (aprs_offset_value.isVisible())
274 aprs_offset_value.setToolTipText("Software version doesn't support setting the APRS offset");
276 aprs_offset_value.setToolTipText("Hardware doesn't support APRS");
279 void set_flight_log_max_tool_tip() {
280 if (flight_log_max_value.isVisible())
281 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
283 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
286 public boolean has_radio() { return true; }
288 /* Build the UI using a grid bag */
289 public TeleGPSConfigUI(JFrame in_owner) {
290 super (in_owner, "Configure Device", false);
293 GridBagConstraints c;
296 Insets il = new Insets(4,4,4,4);
297 Insets ir = new Insets(4,4,4,4);
299 pane = getScrollablePane();
300 pane.setLayout(new GridBagLayout());
303 c = new GridBagConstraints();
304 c.gridx = 0; c.gridy = row;
306 c.fill = GridBagConstraints.NONE;
307 c.anchor = GridBagConstraints.LINE_START;
309 product_label = new JLabel("Product:");
310 pane.add(product_label, c);
312 c = new GridBagConstraints();
313 c.gridx = 4; c.gridy = row;
315 c.fill = GridBagConstraints.HORIZONTAL;
317 c.anchor = GridBagConstraints.LINE_START;
319 product_value = new JLabel("");
320 pane.add(product_value, c);
324 c = new GridBagConstraints();
325 c.gridx = 0; c.gridy = row;
327 c.fill = GridBagConstraints.NONE;
328 c.anchor = GridBagConstraints.LINE_START;
331 version_label = new JLabel("Software version:");
332 pane.add(version_label, c);
334 c = new GridBagConstraints();
335 c.gridx = 4; c.gridy = row;
337 c.fill = GridBagConstraints.HORIZONTAL;
339 c.anchor = GridBagConstraints.LINE_START;
342 version_value = new JLabel("");
343 pane.add(version_value, c);
347 c = new GridBagConstraints();
348 c.gridx = 0; c.gridy = row;
350 c.fill = GridBagConstraints.NONE;
351 c.anchor = GridBagConstraints.LINE_START;
354 serial_label = new JLabel("Serial:");
355 pane.add(serial_label, c);
357 c = new GridBagConstraints();
358 c.gridx = 4; c.gridy = row;
360 c.fill = GridBagConstraints.HORIZONTAL;
362 c.anchor = GridBagConstraints.LINE_START;
365 serial_value = new JLabel("");
366 pane.add(serial_value, c);
370 c = new GridBagConstraints();
371 c.gridx = 0; c.gridy = row;
373 c.fill = GridBagConstraints.NONE;
374 c.anchor = GridBagConstraints.LINE_START;
377 radio_frequency_label = new JLabel("Frequency:");
378 pane.add(radio_frequency_label, c);
380 c = new GridBagConstraints();
381 c.gridx = 4; c.gridy = row;
383 c.fill = GridBagConstraints.HORIZONTAL;
385 c.anchor = GridBagConstraints.LINE_START;
388 radio_frequency_value = new AltosUIFreqList();
389 radio_frequency_value.addItemListener(this);
390 pane.add(radio_frequency_value, c);
391 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
394 /* Radio Calibration */
395 c = new GridBagConstraints();
396 c.gridx = 0; c.gridy = row;
398 c.fill = GridBagConstraints.NONE;
399 c.anchor = GridBagConstraints.LINE_START;
402 radio_calibration_label = new JLabel("RF Calibration:");
403 pane.add(radio_calibration_label, c);
405 c = new GridBagConstraints();
406 c.gridx = 4; c.gridy = row;
408 c.fill = GridBagConstraints.HORIZONTAL;
410 c.anchor = GridBagConstraints.LINE_START;
413 radio_calibration_value = new JLabel(String.format("%d", 1186611));
414 pane.add(radio_calibration_value, c);
418 c = new GridBagConstraints();
419 c.gridx = 0; c.gridy = row;
421 c.fill = GridBagConstraints.NONE;
422 c.anchor = GridBagConstraints.LINE_START;
425 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
426 pane.add(radio_enable_label, c);
428 c = new GridBagConstraints();
429 c.gridx = 4; c.gridy = row;
431 c.fill = GridBagConstraints.HORIZONTAL;
433 c.anchor = GridBagConstraints.LINE_START;
436 radio_enable_value = new JRadioButton("Enabled");
437 radio_enable_value.addItemListener(this);
438 pane.add(radio_enable_value, c);
439 set_radio_enable_tool_tip();
443 c = new GridBagConstraints();
444 c.gridx = 0; c.gridy = row;
446 c.fill = GridBagConstraints.NONE;
447 c.anchor = GridBagConstraints.LINE_START;
450 report_feet_label = new JLabel("Beep max height in:");
451 pane.add(report_feet_label, c);
453 c = new GridBagConstraints();
454 c.gridx = 4; c.gridy = row;
456 c.fill = GridBagConstraints.HORIZONTAL;
458 c.anchor = GridBagConstraints.LINE_START;
461 report_feet_value = new JComboBox<String>(report_feet_values);
462 report_feet_value.setEditable(false);
463 report_feet_value.addItemListener(this);
464 pane.add(report_feet_value, c);
465 set_report_feet_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 gps_receiver_label = new JLabel("GPS Receiver:");
477 pane.add(gps_receiver_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 gps_receiver_value = new JComboBox<String>(AltosLib.gps_receiver_names);
488 gps_receiver_value.setEditable(false);
489 gps_receiver_value.addItemListener(this);
490 pane.add(gps_receiver_value, c);
491 set_gps_receiver_tool_tip();
494 /* Radio 10mW limit */
495 c = new GridBagConstraints();
496 c.gridx = 0; c.gridy = row;
498 c.fill = GridBagConstraints.NONE;
499 c.anchor = GridBagConstraints.LINE_START;
502 radio_10mw_label = new JLabel("Limit transmit to 10mW:");
503 pane.add(radio_10mw_label, c);
505 c = new GridBagConstraints();
506 c.gridx = 4; c.gridy = row;
508 c.fill = GridBagConstraints.HORIZONTAL;
510 c.anchor = GridBagConstraints.LINE_START;
513 radio_10mw_value = new JRadioButton("Limited");
514 radio_10mw_value.addItemListener(this);
515 pane.add(radio_10mw_value, c);
516 set_radio_10mw_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 rate_label = new JLabel("Telemetry baud rate:");
528 pane.add(rate_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 rate_value = new AltosUIRateList();
539 rate_value.addItemListener(this);
540 pane.add(rate_value, c);
545 c = new GridBagConstraints();
546 c.gridx = 0; c.gridy = row;
548 c.fill = GridBagConstraints.NONE;
549 c.anchor = GridBagConstraints.LINE_START;
552 aprs_interval_label = new JLabel("APRS Interval(s):");
553 pane.add(aprs_interval_label, c);
555 c = new GridBagConstraints();
556 c.gridx = 4; c.gridy = row;
558 c.fill = GridBagConstraints.HORIZONTAL;
560 c.anchor = GridBagConstraints.LINE_START;
563 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
564 aprs_interval_value.setEditable(true);
565 aprs_interval_value.addItemListener(this);
566 pane.add(aprs_interval_value, c);
567 set_aprs_interval_tool_tip();
571 c = new GridBagConstraints();
572 c.gridx = 0; c.gridy = row;
574 c.fill = GridBagConstraints.NONE;
575 c.anchor = GridBagConstraints.LINE_START;
578 aprs_ssid_label = new JLabel("APRS SSID:");
579 pane.add(aprs_ssid_label, c);
581 c = new GridBagConstraints();
582 c.gridx = 4; c.gridy = row;
584 c.fill = GridBagConstraints.HORIZONTAL;
586 c.anchor = GridBagConstraints.LINE_START;
589 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
590 aprs_ssid_value.setEditable(false);
591 aprs_ssid_value.addItemListener(this);
592 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
593 pane.add(aprs_ssid_value, c);
594 set_aprs_ssid_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 aprs_format_label = new JLabel("APRS format:");
606 pane.add(aprs_format_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 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
617 aprs_format_value.setEditable(false);
618 aprs_format_value.addItemListener(this);
619 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
620 pane.add(aprs_format_value, c);
621 set_aprs_format_tool_tip();
625 c = new GridBagConstraints();
626 c.gridx = 0; c.gridy = row;
628 c.fill = GridBagConstraints.NONE;
629 c.anchor = GridBagConstraints.LINE_START;
632 aprs_offset_label = new JLabel("APRS offset:");
633 pane.add(aprs_offset_label, c);
635 c = new GridBagConstraints();
636 c.gridx = 4; c.gridy = row;
638 c.fill = GridBagConstraints.HORIZONTAL;
640 c.anchor = GridBagConstraints.LINE_START;
643 aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
644 aprs_offset_value.setEditable(false);
645 aprs_offset_value.addItemListener(this);
646 aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
647 pane.add(aprs_offset_value, c);
648 set_aprs_offset_tool_tip();
652 c = new GridBagConstraints();
653 c.gridx = 0; c.gridy = row;
655 c.fill = GridBagConstraints.NONE;
656 c.anchor = GridBagConstraints.LINE_START;
659 callsign_label = new JLabel("Callsign:");
660 pane.add(callsign_label, c);
662 c = new GridBagConstraints();
663 c.gridx = 4; c.gridy = row;
665 c.fill = GridBagConstraints.HORIZONTAL;
667 c.anchor = GridBagConstraints.LINE_START;
670 callsign_value = new JTextField(AltosUIPreferences.callsign());
671 callsign_value.getDocument().addDocumentListener(this);
672 pane.add(callsign_value, c);
673 callsign_value.setToolTipText("Callsign reported in telemetry data");
677 c = new GridBagConstraints();
678 c.gridx = 0; c.gridy = row;
680 c.fill = GridBagConstraints.NONE;
681 c.anchor = GridBagConstraints.LINE_START;
684 flight_log_max_label = new JLabel("Maximum Log Size (kB):");
685 pane.add(flight_log_max_label, c);
687 c = new GridBagConstraints();
688 c.gridx = 4; c.gridy = row;
690 c.fill = GridBagConstraints.HORIZONTAL;
692 c.anchor = GridBagConstraints.LINE_START;
695 flight_log_max_value = new JComboBox<String>();
696 flight_log_max_value.setEditable(true);
697 flight_log_max_value.addItemListener(this);
698 pane.add(flight_log_max_value, c);
699 set_flight_log_max_tool_tip();
702 /* Tracker triger horiz distances */
703 c = new GridBagConstraints();
704 c.gridx = 0; c.gridy = row;
706 c.fill = GridBagConstraints.NONE;
707 c.anchor = GridBagConstraints.LINE_START;
710 tracker_motion_label = new JLabel(get_tracker_motion_label());
711 pane.add(tracker_motion_label, c);
713 c = new GridBagConstraints();
714 c.gridx = 4; c.gridy = row;
716 c.fill = GridBagConstraints.HORIZONTAL;
718 c.anchor = GridBagConstraints.LINE_START;
721 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
722 tracker_motion_value.setEditable(true);
723 tracker_motion_value.addItemListener(this);
724 pane.add(tracker_motion_value, c);
727 /* Tracker triger vert distances */
728 c = new GridBagConstraints();
729 c.gridx = 0; c.gridy = row;
731 c.fill = GridBagConstraints.NONE;
732 c.anchor = GridBagConstraints.LINE_START;
735 tracker_interval_label = new JLabel("Position Reporting Interval (s):");
736 pane.add(tracker_interval_label, c);
738 c = new GridBagConstraints();
739 c.gridx = 4; c.gridy = row;
741 c.fill = GridBagConstraints.HORIZONTAL;
743 c.anchor = GridBagConstraints.LINE_START;
746 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
747 tracker_interval_value.setEditable(true);
748 tracker_interval_value.addItemListener(this);
749 pane.add(tracker_interval_value, c);
750 set_tracker_tool_tip();
754 c = new GridBagConstraints();
755 c.gridx = 0; c.gridy = row;
757 c.fill = GridBagConstraints.NONE;
758 c.anchor = GridBagConstraints.LINE_START;
760 save = new JButton("Save");
762 save.addActionListener(this);
763 save.setActionCommand("Save");
765 c = new GridBagConstraints();
766 c.gridx = 2; c.gridy = row;
768 c.fill = GridBagConstraints.NONE;
769 c.anchor = GridBagConstraints.CENTER;
771 reset = new JButton("Reset");
773 reset.addActionListener(this);
774 reset.setActionCommand("Reset");
776 c = new GridBagConstraints();
777 c.gridx = 4; c.gridy = row;
779 c.fill = GridBagConstraints.NONE;
780 c.anchor = GridBagConstraints.CENTER;
782 reboot = new JButton("Reboot");
784 reboot.addActionListener(this);
785 reboot.setActionCommand("Reboot");
787 c = new GridBagConstraints();
788 c.gridx = 6; c.gridy = row;
790 c.fill = GridBagConstraints.NONE;
791 c.anchor = GridBagConstraints.LINE_END;
793 close = new JButton("Close");
795 close.addActionListener(this);
796 close.setActionCommand("Close");
798 addWindowListener(new ConfigListener(this));
799 AltosPreferences.register_units_listener(this);
802 /* Once the initial values are set, the config code will show the dialog */
803 public void make_visible() {
805 setLocationRelativeTo(owner);
809 /* If any values have been changed, confirm before closing */
810 public boolean check_dirty(String operation) {
812 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
814 i = JOptionPane.showOptionDialog(this,
815 String.format("Configuration modified. %s anyway?", operation),
816 "Configuration Modified",
817 JOptionPane.DEFAULT_OPTION,
818 JOptionPane.WARNING_MESSAGE,
819 null, options, options[1]);
826 public void set_dirty() {
828 save.setEnabled(true);
831 public void set_clean() {
833 save.setEnabled(false);
836 public void dispose() {
837 AltosPreferences.unregister_units_listener(this);
841 public int accel_cal_plus() {
842 return AltosLib.MISSING;
845 public int accel_cal_minus() {
846 return AltosLib.MISSING;
849 public void set_accel_cal(int accel_plus, int accel_minus) {
852 /* Listen for events from our buttons */
853 public void actionPerformed(ActionEvent e) {
854 String cmd = e.getActionCommand();
856 if (cmd.equals("Close") || cmd.equals("Reboot"))
857 if (!check_dirty(cmd))
859 listener.actionPerformed(e);
860 if (cmd.equals("Close") || cmd.equals("Reboot")) {
867 /* ItemListener interface method */
868 public void itemStateChanged(ItemEvent e) {
872 /* DocumentListener interface methods */
873 public void changedUpdate(DocumentEvent e) {
877 public void insertUpdate(DocumentEvent e) {
881 public void removeUpdate(DocumentEvent e) {
885 /* Let the config code hook on a listener */
886 public void addActionListener(ActionListener l) {
890 public void units_changed(boolean imperial_units) {
891 boolean was_dirty = dirty;
893 if (tracker_motion_value.isVisible()) {
894 String motion = tracker_motion_value.getSelectedItem().toString();
895 tracker_motion_label.setText(get_tracker_motion_label());
896 set_tracker_motion_values();
898 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
899 set_tracker_motion(m);
900 } catch (ParseException pe) {
907 /* set and get all of the dialog values */
908 public void set_product(String product) {
909 radio_frequency_value.set_product(product);
910 product_value.setText(product);
911 set_flight_log_max_tool_tip();
914 public void set_version(String version) {
915 version_value.setText(version);
918 public void set_serial(int serial) {
919 radio_frequency_value.set_serial(serial);
920 serial_value.setText(String.format("%d", serial));
923 public void set_altitude_32(int altitude_32) {
926 public void set_main_deploy(int new_main_deploy) {
929 public int main_deploy() {
930 return AltosLib.MISSING;
933 public void set_apogee_delay(int new_apogee_delay) { }
935 public int apogee_delay() {
936 return AltosLib.MISSING;
939 public void set_apogee_lockout(int new_apogee_lockout) { }
941 public int apogee_lockout() { return AltosLib.MISSING; }
943 public void set_radio_frequency(double new_radio_frequency) {
944 if (new_radio_frequency != AltosLib.MISSING)
945 radio_frequency_value.set_frequency(new_radio_frequency);
946 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
947 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
950 public double radio_frequency() {
951 return radio_frequency_value.frequency();
954 public void set_radio_calibration(int new_radio_calibration) {
955 if (new_radio_calibration != AltosLib.MISSING)
956 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
957 radio_calibration_value.setVisible(new_radio_calibration == AltosLib.MISSING);
958 radio_calibration_label.setVisible(new_radio_calibration == AltosLib.MISSING);
961 public void set_radio_enable(int new_radio_enable) {
962 if (new_radio_enable != AltosLib.MISSING)
963 radio_enable_value.setSelected(new_radio_enable != 0);
964 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
965 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
966 set_radio_enable_tool_tip();
969 public int radio_enable() {
970 if (radio_enable_value.isVisible())
971 return radio_enable_value.isSelected() ? 1 : 0;
973 return AltosLib.MISSING;
976 public void set_radio_10mw(int new_radio_10mw) {
977 if (new_radio_10mw != AltosLib.MISSING) {
978 radio_10mw_value.setSelected(new_radio_10mw != 0);
980 radio_10mw_value.setVisible(new_radio_10mw != AltosLib.MISSING);
981 radio_10mw_label.setVisible(new_radio_10mw != AltosLib.MISSING);
982 set_radio_10mw_tool_tip();
985 public int radio_10mw() {
986 if (radio_10mw_value.isVisible())
987 return radio_10mw_value.isSelected() ? 1 : 0;
989 return AltosLib.MISSING;
992 public void set_telemetry_rate(int new_rate) {
993 if (new_rate != AltosLib.MISSING)
994 rate_value.set_rate(new_rate);
995 rate_label.setVisible(new_rate != AltosLib.MISSING);
996 rate_value.setVisible(new_rate != AltosLib.MISSING);
999 public int telemetry_rate() {
1000 return rate_value.rate();
1003 public void set_callsign(String new_callsign) {
1004 if (new_callsign != null)
1005 callsign_value.setText(new_callsign);
1006 callsign_value.setVisible(new_callsign != null);
1007 callsign_label.setVisible(new_callsign != null);
1010 public String callsign() {
1011 if (callsign_value.isVisible())
1012 return callsign_value.getText();
1016 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1019 v = s.split("\\s+")[0];
1021 return Integer.parseInt(v);
1022 } catch (NumberFormatException ne) {
1023 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1027 int flight_log_max_limit;
1030 public String flight_log_max_label(int flight_log_max) {
1031 if (flight_log_max_limit != 0) {
1032 int nflight = flight_log_max_limit / flight_log_max;
1033 String plural = nflight > 1 ? "s" : "";
1035 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1037 return String.format("%d", flight_log_max);
1040 public void set_flight_log_max(int new_flight_log_max) {
1041 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1042 flight_log_max = new_flight_log_max;
1043 set_flight_log_max_tool_tip();
1046 public void set_flight_log_max_enabled(boolean enable) {
1047 flight_log_max_value.setEnabled(enable);
1048 set_flight_log_max_tool_tip();
1051 public int flight_log_max() throws AltosConfigDataException {
1052 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1055 public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
1056 flight_log_max_limit = new_flight_log_max_limit;
1057 if (new_flight_log_max_limit != AltosLib.MISSING) {
1058 flight_log_max_value.removeAllItems();
1059 for (int i = 8; i >= 1; i--) {
1060 int size = flight_log_max_limit / i;
1061 if (new_storage_erase_unit != 0)
1062 size &= ~(new_storage_erase_unit - 1);
1063 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1066 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
1067 set_flight_log_max(flight_log_max);
1070 public void set_ignite_mode(int new_ignite_mode) { }
1071 public int ignite_mode() { return AltosLib.MISSING; }
1074 public void set_pad_orientation(int new_pad_orientation) { }
1075 public int pad_orientation() { return AltosLib.MISSING; }
1077 public void set_beep(int new_beep) { }
1079 public int beep() { return AltosLib.MISSING; }
1081 String[] tracker_motion_values() {
1082 if (AltosConvert.imperial_units)
1083 return tracker_motion_values_ft;
1085 return tracker_motion_values_m;
1088 void set_tracker_motion_values() {
1089 String[] v = tracker_motion_values();
1090 while (tracker_motion_value.getItemCount() > 0)
1091 tracker_motion_value.removeItemAt(0);
1092 for (int i = 0; i < v.length; i++)
1093 tracker_motion_value.addItem(v[i]);
1094 tracker_motion_value.setMaximumRowCount(v.length);
1097 String get_tracker_motion_label() {
1098 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1101 void set_tracker_tool_tip() {
1102 if (tracker_motion_value.isVisible())
1103 tracker_motion_value.setToolTipText("How far the device must move before logging");
1105 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1106 if (tracker_interval_value.isVisible())
1107 tracker_interval_value.setToolTipText("How often to report GPS position");
1109 tracker_interval_value.setToolTipText("This device can't configure interval");
1112 public void set_tracker_motion(int tracker_motion) {
1113 if (tracker_motion != AltosLib.MISSING)
1114 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1115 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1116 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1119 public int tracker_motion() throws AltosConfigDataException {
1120 if (tracker_motion_value.isVisible()) {
1121 String str = tracker_motion_value.getSelectedItem().toString();
1123 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1124 } catch (ParseException pe) {
1125 throw new AltosConfigDataException("invalid tracker motion %s", str);
1128 return AltosLib.MISSING;
1131 public void set_tracker_interval(int tracker_interval) {
1132 if (tracker_interval != AltosLib.MISSING)
1133 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1134 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1135 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1138 public int tracker_interval() throws AltosConfigDataException {
1139 if (tracker_interval_value.isVisible())
1140 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1141 return AltosLib.MISSING;
1144 public void set_aprs_interval(int new_aprs_interval) {
1145 if (new_aprs_interval != AltosLib.MISSING)
1146 aprs_interval_value.setSelectedItem(Integer.toString(new_aprs_interval));
1147 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1148 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1149 set_aprs_interval_tool_tip();
1152 public int aprs_interval() throws AltosConfigDataException {
1153 if (aprs_interval_value.isVisible()) {
1154 String s = aprs_interval_value.getSelectedItem().toString();
1156 return parse_int("aprs interval", s, false);
1158 return AltosLib.MISSING;
1161 public void set_aprs_ssid(int new_aprs_ssid) {
1162 if (new_aprs_ssid != AltosLib.MISSING)
1163 aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1164 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1165 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1166 set_aprs_ssid_tool_tip();
1169 public int aprs_ssid() throws AltosConfigDataException {
1170 if (aprs_ssid_value.isVisible()) {
1171 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1174 return AltosLib.MISSING;
1177 public void set_aprs_format(int new_aprs_format) {
1178 if (new_aprs_format != AltosLib.MISSING)
1179 aprs_format_value.setSelectedIndex(new_aprs_format);
1180 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1181 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1182 set_aprs_format_tool_tip();
1185 public int aprs_format() throws AltosConfigDataException {
1186 if (aprs_format_value.isVisible())
1187 return aprs_format_value.getSelectedIndex();
1188 return AltosLib.MISSING;
1190 public void set_aprs_offset(int new_aprs_offset) {
1191 if (new_aprs_offset != AltosLib.MISSING)
1192 aprs_offset_value.setSelectedItem(new_aprs_offset);
1193 aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
1194 aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
1195 set_aprs_offset_tool_tip();
1198 public int aprs_offset() throws AltosConfigDataException {
1199 if (aprs_offset_value.isVisible()) {
1200 Integer i = (Integer) aprs_offset_value.getSelectedItem();
1203 return AltosLib.MISSING;