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;
45 JLabel aprs_interval_label;
46 JLabel aprs_ssid_label;
47 JLabel aprs_format_label;
48 JLabel aprs_offset_label;
49 JLabel flight_log_max_label;
50 JLabel callsign_label;
51 JLabel tracker_motion_label;
52 JLabel tracker_interval_label;
60 AltosUIFreqList radio_frequency_value;
61 JLabel radio_calibration_value;
62 JRadioButton radio_enable_value;
63 JRadioButton radio_10mw_value;
64 JComboBox<String> report_feet_value;
65 AltosUIRateList rate_value;
66 JComboBox<String> aprs_interval_value;
67 JComboBox<Integer> aprs_ssid_value;
68 JComboBox<String> aprs_format_value;
69 JComboBox<Integer> aprs_offset_value;
70 JComboBox<String> flight_log_max_value;
71 JTextField callsign_value;
72 JComboBox<String> tracker_motion_value;
73 JComboBox<String> tracker_interval_value;
80 ActionListener listener;
82 static String[] aprs_interval_values = {
89 static Integer[] aprs_ssid_values = {
90 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
93 static Integer[] aprs_offset_values = {
94 0, 2, 4, 6, 8, 10, 12, 14, 16, 18
97 static String[] tracker_motion_values_m = {
104 static String[] tracker_motion_values_ft = {
111 static String[] tracker_interval_values = {
118 static String[] report_feet_values = {
123 /* A window listener to catch closing events and tell the config code */
124 class ConfigListener extends WindowAdapter {
127 public ConfigListener(TeleGPSConfigUI this_ui) {
131 public void windowClosing(WindowEvent e) {
132 ui.actionPerformed(new ActionEvent(e.getSource(),
133 ActionEvent.ACTION_PERFORMED,
138 public void set_pyros(AltosPyro[] new_pyros) {
141 public AltosPyro[] pyros() {
145 public void set_pyro_firing_time(double new_pyro_firing_time) {
148 public double pyro_firing_time() {
149 return AltosLib.MISSING;
152 boolean is_telemetrum() {
153 String product = product_value.getText();
154 return product != null && product.startsWith("TeleGPS");
157 void set_radio_enable_tool_tip() {
158 if (radio_enable_value.isVisible())
159 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
161 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
164 void set_radio_10mw_tool_tip() {
165 if (radio_10mw_value.isVisible())
166 radio_10mw_value.setToolTipText("Should transmitter power be limited to 10mW");
168 radio_10mw_value.setToolTipText("Older firmware could not limit radio power");
171 void set_report_feet_tool_tip() {
172 if (report_feet_value.isVisible())
173 report_feet_value.setToolTipText("Units used after landing to beep max height");
175 report_feet_value.setToolTipText("Older firmware always beeps max height in meters");
178 public void set_report_feet(int new_report_feet) {
179 if (new_report_feet != AltosLib.MISSING) {
180 if (new_report_feet >= report_feet_values.length)
182 if (new_report_feet < 0) {
183 report_feet_value.setEnabled(false);
186 report_feet_value.setEnabled(true);
188 report_feet_value.setSelectedIndex(new_report_feet);
190 report_feet_value.setVisible(new_report_feet != AltosLib.MISSING);
191 report_feet_label.setVisible(new_report_feet != AltosLib.MISSING);
193 set_report_feet_tool_tip();
196 public int report_feet() {
197 if (report_feet_value.isVisible())
198 return report_feet_value.getSelectedIndex();
200 return AltosLib.MISSING;
203 void set_rate_tool_tip() {
204 if (rate_value.isVisible())
205 rate_value.setToolTipText("Select telemetry baud rate");
207 rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
210 void set_aprs_interval_tool_tip() {
211 if (aprs_interval_value.isVisible())
212 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
214 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
217 void set_aprs_ssid_tool_tip() {
218 if (aprs_ssid_value.isVisible())
219 aprs_ssid_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
220 else if (aprs_ssid_value.isVisible())
221 aprs_ssid_value.setToolTipText("Software version doesn't support setting the APRS SSID");
223 aprs_ssid_value.setToolTipText("Hardware doesn't support APRS");
226 void set_aprs_format_tool_tip() {
227 if (aprs_format_value.isVisible())
228 aprs_format_value.setToolTipText("Set the APRS format (compressed/uncompressed)");
229 else if (aprs_format_value.isVisible())
230 aprs_format_value.setToolTipText("Software version doesn't support setting the APRS format");
232 aprs_format_value.setToolTipText("Hardware doesn't support APRS");
235 void set_aprs_offset_tool_tip() {
236 if (aprs_offset_value.isVisible())
237 aprs_offset_value.setToolTipText("Set the APRS offset from top of minute");
238 else if (aprs_offset_value.isVisible())
239 aprs_offset_value.setToolTipText("Software version doesn't support setting the APRS offset");
241 aprs_offset_value.setToolTipText("Hardware doesn't support APRS");
244 void set_flight_log_max_tool_tip() {
245 if (flight_log_max_value.isVisible())
246 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
248 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
251 /* Build the UI using a grid bag */
252 public TeleGPSConfigUI(JFrame in_owner) {
253 super (in_owner, "Configure Device", false);
256 GridBagConstraints c;
259 Insets il = new Insets(4,4,4,4);
260 Insets ir = new Insets(4,4,4,4);
262 pane = getScrollablePane();
263 pane.setLayout(new GridBagLayout());
266 c = new GridBagConstraints();
267 c.gridx = 0; c.gridy = row;
269 c.fill = GridBagConstraints.NONE;
270 c.anchor = GridBagConstraints.LINE_START;
272 product_label = new JLabel("Product:");
273 pane.add(product_label, c);
275 c = new GridBagConstraints();
276 c.gridx = 4; c.gridy = row;
278 c.fill = GridBagConstraints.HORIZONTAL;
280 c.anchor = GridBagConstraints.LINE_START;
282 product_value = new JLabel("");
283 pane.add(product_value, c);
287 c = new GridBagConstraints();
288 c.gridx = 0; c.gridy = row;
290 c.fill = GridBagConstraints.NONE;
291 c.anchor = GridBagConstraints.LINE_START;
294 version_label = new JLabel("Software version:");
295 pane.add(version_label, c);
297 c = new GridBagConstraints();
298 c.gridx = 4; c.gridy = row;
300 c.fill = GridBagConstraints.HORIZONTAL;
302 c.anchor = GridBagConstraints.LINE_START;
305 version_value = new JLabel("");
306 pane.add(version_value, c);
310 c = new GridBagConstraints();
311 c.gridx = 0; c.gridy = row;
313 c.fill = GridBagConstraints.NONE;
314 c.anchor = GridBagConstraints.LINE_START;
317 serial_label = new JLabel("Serial:");
318 pane.add(serial_label, c);
320 c = new GridBagConstraints();
321 c.gridx = 4; c.gridy = row;
323 c.fill = GridBagConstraints.HORIZONTAL;
325 c.anchor = GridBagConstraints.LINE_START;
328 serial_value = new JLabel("");
329 pane.add(serial_value, c);
333 c = new GridBagConstraints();
334 c.gridx = 0; c.gridy = row;
336 c.fill = GridBagConstraints.NONE;
337 c.anchor = GridBagConstraints.LINE_START;
340 radio_frequency_label = new JLabel("Frequency:");
341 pane.add(radio_frequency_label, c);
343 c = new GridBagConstraints();
344 c.gridx = 4; c.gridy = row;
346 c.fill = GridBagConstraints.HORIZONTAL;
348 c.anchor = GridBagConstraints.LINE_START;
351 radio_frequency_value = new AltosUIFreqList();
352 radio_frequency_value.addItemListener(this);
353 pane.add(radio_frequency_value, c);
354 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
357 /* Radio Calibration */
358 c = new GridBagConstraints();
359 c.gridx = 0; c.gridy = row;
361 c.fill = GridBagConstraints.NONE;
362 c.anchor = GridBagConstraints.LINE_START;
365 radio_calibration_label = new JLabel("RF Calibration:");
366 pane.add(radio_calibration_label, c);
368 c = new GridBagConstraints();
369 c.gridx = 4; c.gridy = row;
371 c.fill = GridBagConstraints.HORIZONTAL;
373 c.anchor = GridBagConstraints.LINE_START;
376 radio_calibration_value = new JLabel(String.format("%d", 1186611));
377 pane.add(radio_calibration_value, c);
381 c = new GridBagConstraints();
382 c.gridx = 0; c.gridy = row;
384 c.fill = GridBagConstraints.NONE;
385 c.anchor = GridBagConstraints.LINE_START;
388 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
389 pane.add(radio_enable_label, c);
391 c = new GridBagConstraints();
392 c.gridx = 4; c.gridy = row;
394 c.fill = GridBagConstraints.HORIZONTAL;
396 c.anchor = GridBagConstraints.LINE_START;
399 radio_enable_value = new JRadioButton("Enabled");
400 radio_enable_value.addItemListener(this);
401 pane.add(radio_enable_value, c);
402 set_radio_enable_tool_tip();
405 /* Radio 10mW limit */
406 c = new GridBagConstraints();
407 c.gridx = 0; c.gridy = row;
409 c.fill = GridBagConstraints.NONE;
410 c.anchor = GridBagConstraints.LINE_START;
413 radio_10mw_label = new JLabel("Limit transmit to 10mW:");
414 pane.add(radio_10mw_label, c);
416 c = new GridBagConstraints();
417 c.gridx = 4; c.gridy = row;
419 c.fill = GridBagConstraints.HORIZONTAL;
421 c.anchor = GridBagConstraints.LINE_START;
424 radio_10mw_value = new JRadioButton("Limited");
425 radio_10mw_value.addItemListener(this);
426 pane.add(radio_10mw_value, c);
427 set_radio_10mw_tool_tip();
431 c = new GridBagConstraints();
432 c.gridx = 0; c.gridy = row;
434 c.fill = GridBagConstraints.NONE;
435 c.anchor = GridBagConstraints.LINE_START;
438 rate_label = new JLabel("Telemetry baud rate:");
439 pane.add(rate_label, c);
441 c = new GridBagConstraints();
442 c.gridx = 4; c.gridy = row;
444 c.fill = GridBagConstraints.HORIZONTAL;
446 c.anchor = GridBagConstraints.LINE_START;
449 rate_value = new AltosUIRateList();
450 rate_value.addItemListener(this);
451 pane.add(rate_value, c);
456 c = new GridBagConstraints();
457 c.gridx = 0; c.gridy = row;
459 c.fill = GridBagConstraints.NONE;
460 c.anchor = GridBagConstraints.LINE_START;
463 aprs_interval_label = new JLabel("APRS Interval(s):");
464 pane.add(aprs_interval_label, c);
466 c = new GridBagConstraints();
467 c.gridx = 4; c.gridy = row;
469 c.fill = GridBagConstraints.HORIZONTAL;
471 c.anchor = GridBagConstraints.LINE_START;
474 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
475 aprs_interval_value.setEditable(true);
476 aprs_interval_value.addItemListener(this);
477 pane.add(aprs_interval_value, c);
478 set_aprs_interval_tool_tip();
482 c = new GridBagConstraints();
483 c.gridx = 0; c.gridy = row;
485 c.fill = GridBagConstraints.NONE;
486 c.anchor = GridBagConstraints.LINE_START;
489 aprs_ssid_label = new JLabel("APRS SSID:");
490 pane.add(aprs_ssid_label, c);
492 c = new GridBagConstraints();
493 c.gridx = 4; c.gridy = row;
495 c.fill = GridBagConstraints.HORIZONTAL;
497 c.anchor = GridBagConstraints.LINE_START;
500 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
501 aprs_ssid_value.setEditable(false);
502 aprs_ssid_value.addItemListener(this);
503 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
504 pane.add(aprs_ssid_value, c);
505 set_aprs_ssid_tool_tip();
509 c = new GridBagConstraints();
510 c.gridx = 0; c.gridy = row;
512 c.fill = GridBagConstraints.NONE;
513 c.anchor = GridBagConstraints.LINE_START;
516 aprs_format_label = new JLabel("APRS format:");
517 pane.add(aprs_format_label, c);
519 c = new GridBagConstraints();
520 c.gridx = 4; c.gridy = row;
522 c.fill = GridBagConstraints.HORIZONTAL;
524 c.anchor = GridBagConstraints.LINE_START;
527 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
528 aprs_format_value.setEditable(false);
529 aprs_format_value.addItemListener(this);
530 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
531 pane.add(aprs_format_value, c);
532 set_aprs_format_tool_tip();
536 c = new GridBagConstraints();
537 c.gridx = 0; c.gridy = row;
539 c.fill = GridBagConstraints.NONE;
540 c.anchor = GridBagConstraints.LINE_START;
543 aprs_offset_label = new JLabel("APRS offset:");
544 pane.add(aprs_offset_label, c);
546 c = new GridBagConstraints();
547 c.gridx = 4; c.gridy = row;
549 c.fill = GridBagConstraints.HORIZONTAL;
551 c.anchor = GridBagConstraints.LINE_START;
554 aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
555 aprs_offset_value.setEditable(false);
556 aprs_offset_value.addItemListener(this);
557 aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
558 pane.add(aprs_offset_value, c);
559 set_aprs_offset_tool_tip();
563 c = new GridBagConstraints();
564 c.gridx = 0; c.gridy = row;
566 c.fill = GridBagConstraints.NONE;
567 c.anchor = GridBagConstraints.LINE_START;
570 callsign_label = new JLabel("Callsign:");
571 pane.add(callsign_label, c);
573 c = new GridBagConstraints();
574 c.gridx = 4; c.gridy = row;
576 c.fill = GridBagConstraints.HORIZONTAL;
578 c.anchor = GridBagConstraints.LINE_START;
581 callsign_value = new JTextField(AltosUIPreferences.callsign());
582 callsign_value.getDocument().addDocumentListener(this);
583 pane.add(callsign_value, c);
584 callsign_value.setToolTipText("Callsign reported in telemetry data");
588 c = new GridBagConstraints();
589 c.gridx = 0; c.gridy = row;
591 c.fill = GridBagConstraints.NONE;
592 c.anchor = GridBagConstraints.LINE_START;
595 flight_log_max_label = new JLabel("Maximum Log Size (kB):");
596 pane.add(flight_log_max_label, c);
598 c = new GridBagConstraints();
599 c.gridx = 4; c.gridy = row;
601 c.fill = GridBagConstraints.HORIZONTAL;
603 c.anchor = GridBagConstraints.LINE_START;
606 flight_log_max_value = new JComboBox<String>();
607 flight_log_max_value.setEditable(true);
608 flight_log_max_value.addItemListener(this);
609 pane.add(flight_log_max_value, c);
610 set_flight_log_max_tool_tip();
613 /* Tracker triger horiz distances */
614 c = new GridBagConstraints();
615 c.gridx = 0; c.gridy = row;
617 c.fill = GridBagConstraints.NONE;
618 c.anchor = GridBagConstraints.LINE_START;
621 tracker_motion_label = new JLabel(get_tracker_motion_label());
622 pane.add(tracker_motion_label, c);
624 c = new GridBagConstraints();
625 c.gridx = 4; c.gridy = row;
627 c.fill = GridBagConstraints.HORIZONTAL;
629 c.anchor = GridBagConstraints.LINE_START;
632 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
633 tracker_motion_value.setEditable(true);
634 tracker_motion_value.addItemListener(this);
635 pane.add(tracker_motion_value, c);
638 /* Tracker triger vert distances */
639 c = new GridBagConstraints();
640 c.gridx = 0; c.gridy = row;
642 c.fill = GridBagConstraints.NONE;
643 c.anchor = GridBagConstraints.LINE_START;
646 tracker_interval_label = new JLabel("Position Reporting Interval (s):");
647 pane.add(tracker_interval_label, c);
649 c = new GridBagConstraints();
650 c.gridx = 4; c.gridy = row;
652 c.fill = GridBagConstraints.HORIZONTAL;
654 c.anchor = GridBagConstraints.LINE_START;
657 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
658 tracker_interval_value.setEditable(true);
659 tracker_interval_value.addItemListener(this);
660 pane.add(tracker_interval_value, c);
661 set_tracker_tool_tip();
665 c = new GridBagConstraints();
666 c.gridx = 0; c.gridy = row;
668 c.fill = GridBagConstraints.NONE;
669 c.anchor = GridBagConstraints.LINE_START;
671 save = new JButton("Save");
673 save.addActionListener(this);
674 save.setActionCommand("Save");
676 c = new GridBagConstraints();
677 c.gridx = 2; c.gridy = row;
679 c.fill = GridBagConstraints.NONE;
680 c.anchor = GridBagConstraints.CENTER;
682 reset = new JButton("Reset");
684 reset.addActionListener(this);
685 reset.setActionCommand("Reset");
687 c = new GridBagConstraints();
688 c.gridx = 4; c.gridy = row;
690 c.fill = GridBagConstraints.NONE;
691 c.anchor = GridBagConstraints.CENTER;
693 reboot = new JButton("Reboot");
695 reboot.addActionListener(this);
696 reboot.setActionCommand("Reboot");
698 c = new GridBagConstraints();
699 c.gridx = 6; c.gridy = row;
701 c.fill = GridBagConstraints.NONE;
702 c.anchor = GridBagConstraints.LINE_END;
704 close = new JButton("Close");
706 close.addActionListener(this);
707 close.setActionCommand("Close");
709 addWindowListener(new ConfigListener(this));
710 AltosPreferences.register_units_listener(this);
713 /* Once the initial values are set, the config code will show the dialog */
714 public void make_visible() {
716 setLocationRelativeTo(owner);
720 /* If any values have been changed, confirm before closing */
721 public boolean check_dirty(String operation) {
723 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
725 i = JOptionPane.showOptionDialog(this,
726 String.format("Configuration modified. %s anyway?", operation),
727 "Configuration Modified",
728 JOptionPane.DEFAULT_OPTION,
729 JOptionPane.WARNING_MESSAGE,
730 null, options, options[1]);
737 public void set_dirty() {
739 save.setEnabled(true);
742 public void set_clean() {
744 save.setEnabled(false);
747 public void dispose() {
748 AltosPreferences.unregister_units_listener(this);
752 public int accel_cal_plus() {
753 return AltosLib.MISSING;
756 public int accel_cal_minus() {
757 return AltosLib.MISSING;
760 public void set_accel_cal(int accel_plus, int accel_minus) {
763 /* Listen for events from our buttons */
764 public void actionPerformed(ActionEvent e) {
765 String cmd = e.getActionCommand();
767 if (cmd.equals("Close") || cmd.equals("Reboot"))
768 if (!check_dirty(cmd))
770 listener.actionPerformed(e);
771 if (cmd.equals("Close") || cmd.equals("Reboot")) {
778 /* ItemListener interface method */
779 public void itemStateChanged(ItemEvent e) {
783 /* DocumentListener interface methods */
784 public void changedUpdate(DocumentEvent e) {
788 public void insertUpdate(DocumentEvent e) {
792 public void removeUpdate(DocumentEvent e) {
796 /* Let the config code hook on a listener */
797 public void addActionListener(ActionListener l) {
801 public void units_changed(boolean imperial_units) {
802 boolean was_dirty = dirty;
804 if (tracker_motion_value.isVisible()) {
805 String motion = tracker_motion_value.getSelectedItem().toString();
806 tracker_motion_label.setText(get_tracker_motion_label());
807 set_tracker_motion_values();
809 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
810 set_tracker_motion(m);
811 } catch (ParseException pe) {
818 /* set and get all of the dialog values */
819 public void set_product(String product) {
820 radio_frequency_value.set_product(product);
821 product_value.setText(product);
822 set_flight_log_max_tool_tip();
825 public void set_version(String version) {
826 version_value.setText(version);
829 public void set_serial(int serial) {
830 radio_frequency_value.set_serial(serial);
831 serial_value.setText(String.format("%d", serial));
834 public void set_altitude_32(int altitude_32) {
837 public void set_main_deploy(int new_main_deploy) {
840 public int main_deploy() {
841 return AltosLib.MISSING;
844 public void set_apogee_delay(int new_apogee_delay) { }
846 public int apogee_delay() {
847 return AltosLib.MISSING;
850 public void set_apogee_lockout(int new_apogee_lockout) { }
852 public int apogee_lockout() { return AltosLib.MISSING; }
854 public void set_radio_frequency(double new_radio_frequency) {
855 if (new_radio_frequency != AltosLib.MISSING)
856 radio_frequency_value.set_frequency(new_radio_frequency);
857 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
858 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
861 public double radio_frequency() {
862 return radio_frequency_value.frequency();
865 public void set_radio_calibration(int new_radio_calibration) {
866 if (new_radio_calibration != AltosLib.MISSING)
867 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
868 radio_calibration_value.setVisible(new_radio_calibration == AltosLib.MISSING);
869 radio_calibration_label.setVisible(new_radio_calibration == AltosLib.MISSING);
872 public void set_radio_enable(int new_radio_enable) {
873 if (new_radio_enable != AltosLib.MISSING)
874 radio_enable_value.setSelected(new_radio_enable != 0);
875 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
876 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
877 set_radio_enable_tool_tip();
880 public int radio_enable() {
881 if (radio_enable_value.isVisible())
882 return radio_enable_value.isSelected() ? 1 : 0;
884 return AltosLib.MISSING;
887 public void set_radio_10mw(int new_radio_10mw) {
888 if (new_radio_10mw != AltosLib.MISSING) {
889 radio_10mw_value.setSelected(new_radio_10mw != 0);
891 radio_10mw_value.setVisible(new_radio_10mw != AltosLib.MISSING);
892 radio_10mw_label.setVisible(new_radio_10mw != AltosLib.MISSING);
893 set_radio_10mw_tool_tip();
896 public int radio_10mw() {
897 if (radio_10mw_value.isVisible())
898 return radio_10mw_value.isSelected() ? 1 : 0;
900 return AltosLib.MISSING;
903 public void set_telemetry_rate(int new_rate) {
904 if (new_rate != AltosLib.MISSING)
905 rate_value.set_rate(new_rate);
906 rate_label.setVisible(new_rate != AltosLib.MISSING);
907 rate_value.setVisible(new_rate != AltosLib.MISSING);
910 public int telemetry_rate() {
911 return rate_value.rate();
914 public void set_callsign(String new_callsign) {
915 if (new_callsign != null)
916 callsign_value.setText(new_callsign);
917 callsign_value.setVisible(new_callsign != null);
918 callsign_label.setVisible(new_callsign != null);
921 public String callsign() {
922 if (callsign_value.isVisible())
923 return callsign_value.getText();
927 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
930 v = s.split("\\s+")[0];
932 return Integer.parseInt(v);
933 } catch (NumberFormatException ne) {
934 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
938 int flight_log_max_limit;
941 public String flight_log_max_label(int flight_log_max) {
942 if (flight_log_max_limit != 0) {
943 int nflight = flight_log_max_limit / flight_log_max;
944 String plural = nflight > 1 ? "s" : "";
946 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
948 return String.format("%d", flight_log_max);
951 public void set_flight_log_max(int new_flight_log_max) {
952 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
953 flight_log_max = new_flight_log_max;
954 set_flight_log_max_tool_tip();
957 public void set_flight_log_max_enabled(boolean enable) {
958 flight_log_max_value.setEnabled(enable);
959 set_flight_log_max_tool_tip();
962 public int flight_log_max() throws AltosConfigDataException {
963 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
966 public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
967 flight_log_max_limit = new_flight_log_max_limit;
968 if (new_flight_log_max_limit != AltosLib.MISSING) {
969 flight_log_max_value.removeAllItems();
970 for (int i = 8; i >= 1; i--) {
971 int size = flight_log_max_limit / i;
972 if (new_storage_erase_unit != 0)
973 size &= ~(new_storage_erase_unit - 1);
974 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
977 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
978 set_flight_log_max(flight_log_max);
981 public void set_ignite_mode(int new_ignite_mode) { }
982 public int ignite_mode() { return AltosLib.MISSING; }
985 public void set_pad_orientation(int new_pad_orientation) { }
986 public int pad_orientation() { return AltosLib.MISSING; }
988 public void set_beep(int new_beep) { }
990 public int beep() { return AltosLib.MISSING; }
992 String[] tracker_motion_values() {
993 if (AltosConvert.imperial_units)
994 return tracker_motion_values_ft;
996 return tracker_motion_values_m;
999 void set_tracker_motion_values() {
1000 String[] v = tracker_motion_values();
1001 while (tracker_motion_value.getItemCount() > 0)
1002 tracker_motion_value.removeItemAt(0);
1003 for (int i = 0; i < v.length; i++)
1004 tracker_motion_value.addItem(v[i]);
1005 tracker_motion_value.setMaximumRowCount(v.length);
1008 String get_tracker_motion_label() {
1009 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1012 void set_tracker_tool_tip() {
1013 if (tracker_motion_value.isVisible())
1014 tracker_motion_value.setToolTipText("How far the device must move before logging");
1016 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1017 if (tracker_interval_value.isVisible())
1018 tracker_interval_value.setToolTipText("How often to report GPS position");
1020 tracker_interval_value.setToolTipText("This device can't configure interval");
1023 public void set_tracker_motion(int tracker_motion) {
1024 if (tracker_motion != AltosLib.MISSING)
1025 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1026 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1027 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1030 public int tracker_motion() throws AltosConfigDataException {
1031 if (tracker_motion_value.isVisible()) {
1032 String str = tracker_motion_value.getSelectedItem().toString();
1034 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1035 } catch (ParseException pe) {
1036 throw new AltosConfigDataException("invalid tracker motion %s", str);
1039 return AltosLib.MISSING;
1042 public void set_tracker_interval(int tracker_interval) {
1043 if (tracker_interval != AltosLib.MISSING)
1044 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1045 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1046 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1049 public int tracker_interval() throws AltosConfigDataException {
1050 if (tracker_interval_value.isVisible())
1051 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1052 return AltosLib.MISSING;
1055 public void set_aprs_interval(int new_aprs_interval) {
1056 if (new_aprs_interval != AltosLib.MISSING)
1057 aprs_interval_value.setSelectedItem(Integer.toString(new_aprs_interval));
1058 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1059 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1060 set_aprs_interval_tool_tip();
1063 public int aprs_interval() throws AltosConfigDataException {
1064 if (aprs_interval_value.isVisible()) {
1065 String s = aprs_interval_value.getSelectedItem().toString();
1067 return parse_int("aprs interval", s, false);
1069 return AltosLib.MISSING;
1072 public void set_aprs_ssid(int new_aprs_ssid) {
1073 if (new_aprs_ssid != AltosLib.MISSING)
1074 aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1075 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1076 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1077 set_aprs_ssid_tool_tip();
1080 public int aprs_ssid() throws AltosConfigDataException {
1081 if (aprs_ssid_value.isVisible()) {
1082 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1085 return AltosLib.MISSING;
1088 public void set_aprs_format(int new_aprs_format) {
1089 if (new_aprs_format != AltosLib.MISSING)
1090 aprs_format_value.setSelectedIndex(new_aprs_format);
1091 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1092 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1093 set_aprs_format_tool_tip();
1096 public int aprs_format() throws AltosConfigDataException {
1097 if (aprs_format_value.isVisible())
1098 return aprs_format_value.getSelectedIndex();
1099 return AltosLib.MISSING;
1101 public void set_aprs_offset(int new_aprs_offset) {
1102 if (new_aprs_offset != AltosLib.MISSING)
1103 aprs_offset_value.setSelectedItem(new_aprs_offset);
1104 aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
1105 aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
1106 set_aprs_offset_tool_tip();
1109 public int aprs_offset() throws AltosConfigDataException {
1110 if (aprs_offset_value.isVisible()) {
1111 Integer i = (Integer) aprs_offset_value.getSelectedItem();
1114 return AltosLib.MISSING;