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 public boolean has_radio() { return true; }
253 /* Build the UI using a grid bag */
254 public TeleGPSConfigUI(JFrame in_owner) {
255 super (in_owner, "Configure Device", false);
258 GridBagConstraints c;
261 Insets il = new Insets(4,4,4,4);
262 Insets ir = new Insets(4,4,4,4);
264 pane = getScrollablePane();
265 pane.setLayout(new GridBagLayout());
268 c = new GridBagConstraints();
269 c.gridx = 0; c.gridy = row;
271 c.fill = GridBagConstraints.NONE;
272 c.anchor = GridBagConstraints.LINE_START;
274 product_label = new JLabel("Product:");
275 pane.add(product_label, c);
277 c = new GridBagConstraints();
278 c.gridx = 4; c.gridy = row;
280 c.fill = GridBagConstraints.HORIZONTAL;
282 c.anchor = GridBagConstraints.LINE_START;
284 product_value = new JLabel("");
285 pane.add(product_value, c);
289 c = new GridBagConstraints();
290 c.gridx = 0; c.gridy = row;
292 c.fill = GridBagConstraints.NONE;
293 c.anchor = GridBagConstraints.LINE_START;
296 version_label = new JLabel("Software version:");
297 pane.add(version_label, c);
299 c = new GridBagConstraints();
300 c.gridx = 4; c.gridy = row;
302 c.fill = GridBagConstraints.HORIZONTAL;
304 c.anchor = GridBagConstraints.LINE_START;
307 version_value = new JLabel("");
308 pane.add(version_value, c);
312 c = new GridBagConstraints();
313 c.gridx = 0; c.gridy = row;
315 c.fill = GridBagConstraints.NONE;
316 c.anchor = GridBagConstraints.LINE_START;
319 serial_label = new JLabel("Serial:");
320 pane.add(serial_label, c);
322 c = new GridBagConstraints();
323 c.gridx = 4; c.gridy = row;
325 c.fill = GridBagConstraints.HORIZONTAL;
327 c.anchor = GridBagConstraints.LINE_START;
330 serial_value = new JLabel("");
331 pane.add(serial_value, c);
335 c = new GridBagConstraints();
336 c.gridx = 0; c.gridy = row;
338 c.fill = GridBagConstraints.NONE;
339 c.anchor = GridBagConstraints.LINE_START;
342 radio_frequency_label = new JLabel("Frequency:");
343 pane.add(radio_frequency_label, c);
345 c = new GridBagConstraints();
346 c.gridx = 4; c.gridy = row;
348 c.fill = GridBagConstraints.HORIZONTAL;
350 c.anchor = GridBagConstraints.LINE_START;
353 radio_frequency_value = new AltosUIFreqList();
354 radio_frequency_value.addItemListener(this);
355 pane.add(radio_frequency_value, c);
356 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
359 /* Radio Calibration */
360 c = new GridBagConstraints();
361 c.gridx = 0; c.gridy = row;
363 c.fill = GridBagConstraints.NONE;
364 c.anchor = GridBagConstraints.LINE_START;
367 radio_calibration_label = new JLabel("RF Calibration:");
368 pane.add(radio_calibration_label, c);
370 c = new GridBagConstraints();
371 c.gridx = 4; c.gridy = row;
373 c.fill = GridBagConstraints.HORIZONTAL;
375 c.anchor = GridBagConstraints.LINE_START;
378 radio_calibration_value = new JLabel(String.format("%d", 1186611));
379 pane.add(radio_calibration_value, c);
383 c = new GridBagConstraints();
384 c.gridx = 0; c.gridy = row;
386 c.fill = GridBagConstraints.NONE;
387 c.anchor = GridBagConstraints.LINE_START;
390 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
391 pane.add(radio_enable_label, c);
393 c = new GridBagConstraints();
394 c.gridx = 4; c.gridy = row;
396 c.fill = GridBagConstraints.HORIZONTAL;
398 c.anchor = GridBagConstraints.LINE_START;
401 radio_enable_value = new JRadioButton("Enabled");
402 radio_enable_value.addItemListener(this);
403 pane.add(radio_enable_value, c);
404 set_radio_enable_tool_tip();
408 c = new GridBagConstraints();
409 c.gridx = 0; c.gridy = row;
411 c.fill = GridBagConstraints.NONE;
412 c.anchor = GridBagConstraints.LINE_START;
415 report_feet_label = new JLabel("Beep max height in:");
416 pane.add(report_feet_label, c);
418 c = new GridBagConstraints();
419 c.gridx = 4; c.gridy = row;
421 c.fill = GridBagConstraints.HORIZONTAL;
423 c.anchor = GridBagConstraints.LINE_START;
426 report_feet_value = new JComboBox<String>(report_feet_values);
427 report_feet_value.setEditable(false);
428 report_feet_value.addItemListener(this);
429 pane.add(report_feet_value, c);
430 set_report_feet_tool_tip();
433 /* Radio 10mW limit */
434 c = new GridBagConstraints();
435 c.gridx = 0; c.gridy = row;
437 c.fill = GridBagConstraints.NONE;
438 c.anchor = GridBagConstraints.LINE_START;
441 radio_10mw_label = new JLabel("Limit transmit to 10mW:");
442 pane.add(radio_10mw_label, c);
444 c = new GridBagConstraints();
445 c.gridx = 4; c.gridy = row;
447 c.fill = GridBagConstraints.HORIZONTAL;
449 c.anchor = GridBagConstraints.LINE_START;
452 radio_10mw_value = new JRadioButton("Limited");
453 radio_10mw_value.addItemListener(this);
454 pane.add(radio_10mw_value, c);
455 set_radio_10mw_tool_tip();
459 c = new GridBagConstraints();
460 c.gridx = 0; c.gridy = row;
462 c.fill = GridBagConstraints.NONE;
463 c.anchor = GridBagConstraints.LINE_START;
466 rate_label = new JLabel("Telemetry baud rate:");
467 pane.add(rate_label, c);
469 c = new GridBagConstraints();
470 c.gridx = 4; c.gridy = row;
472 c.fill = GridBagConstraints.HORIZONTAL;
474 c.anchor = GridBagConstraints.LINE_START;
477 rate_value = new AltosUIRateList();
478 rate_value.addItemListener(this);
479 pane.add(rate_value, c);
484 c = new GridBagConstraints();
485 c.gridx = 0; c.gridy = row;
487 c.fill = GridBagConstraints.NONE;
488 c.anchor = GridBagConstraints.LINE_START;
491 aprs_interval_label = new JLabel("APRS Interval(s):");
492 pane.add(aprs_interval_label, c);
494 c = new GridBagConstraints();
495 c.gridx = 4; c.gridy = row;
497 c.fill = GridBagConstraints.HORIZONTAL;
499 c.anchor = GridBagConstraints.LINE_START;
502 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
503 aprs_interval_value.setEditable(true);
504 aprs_interval_value.addItemListener(this);
505 pane.add(aprs_interval_value, c);
506 set_aprs_interval_tool_tip();
510 c = new GridBagConstraints();
511 c.gridx = 0; c.gridy = row;
513 c.fill = GridBagConstraints.NONE;
514 c.anchor = GridBagConstraints.LINE_START;
517 aprs_ssid_label = new JLabel("APRS SSID:");
518 pane.add(aprs_ssid_label, c);
520 c = new GridBagConstraints();
521 c.gridx = 4; c.gridy = row;
523 c.fill = GridBagConstraints.HORIZONTAL;
525 c.anchor = GridBagConstraints.LINE_START;
528 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
529 aprs_ssid_value.setEditable(false);
530 aprs_ssid_value.addItemListener(this);
531 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
532 pane.add(aprs_ssid_value, c);
533 set_aprs_ssid_tool_tip();
537 c = new GridBagConstraints();
538 c.gridx = 0; c.gridy = row;
540 c.fill = GridBagConstraints.NONE;
541 c.anchor = GridBagConstraints.LINE_START;
544 aprs_format_label = new JLabel("APRS format:");
545 pane.add(aprs_format_label, c);
547 c = new GridBagConstraints();
548 c.gridx = 4; c.gridy = row;
550 c.fill = GridBagConstraints.HORIZONTAL;
552 c.anchor = GridBagConstraints.LINE_START;
555 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
556 aprs_format_value.setEditable(false);
557 aprs_format_value.addItemListener(this);
558 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
559 pane.add(aprs_format_value, c);
560 set_aprs_format_tool_tip();
564 c = new GridBagConstraints();
565 c.gridx = 0; c.gridy = row;
567 c.fill = GridBagConstraints.NONE;
568 c.anchor = GridBagConstraints.LINE_START;
571 aprs_offset_label = new JLabel("APRS offset:");
572 pane.add(aprs_offset_label, c);
574 c = new GridBagConstraints();
575 c.gridx = 4; c.gridy = row;
577 c.fill = GridBagConstraints.HORIZONTAL;
579 c.anchor = GridBagConstraints.LINE_START;
582 aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
583 aprs_offset_value.setEditable(false);
584 aprs_offset_value.addItemListener(this);
585 aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
586 pane.add(aprs_offset_value, c);
587 set_aprs_offset_tool_tip();
591 c = new GridBagConstraints();
592 c.gridx = 0; c.gridy = row;
594 c.fill = GridBagConstraints.NONE;
595 c.anchor = GridBagConstraints.LINE_START;
598 callsign_label = new JLabel("Callsign:");
599 pane.add(callsign_label, c);
601 c = new GridBagConstraints();
602 c.gridx = 4; c.gridy = row;
604 c.fill = GridBagConstraints.HORIZONTAL;
606 c.anchor = GridBagConstraints.LINE_START;
609 callsign_value = new JTextField(AltosUIPreferences.callsign());
610 callsign_value.getDocument().addDocumentListener(this);
611 pane.add(callsign_value, c);
612 callsign_value.setToolTipText("Callsign reported in telemetry data");
616 c = new GridBagConstraints();
617 c.gridx = 0; c.gridy = row;
619 c.fill = GridBagConstraints.NONE;
620 c.anchor = GridBagConstraints.LINE_START;
623 flight_log_max_label = new JLabel("Maximum Log Size (kB):");
624 pane.add(flight_log_max_label, c);
626 c = new GridBagConstraints();
627 c.gridx = 4; c.gridy = row;
629 c.fill = GridBagConstraints.HORIZONTAL;
631 c.anchor = GridBagConstraints.LINE_START;
634 flight_log_max_value = new JComboBox<String>();
635 flight_log_max_value.setEditable(true);
636 flight_log_max_value.addItemListener(this);
637 pane.add(flight_log_max_value, c);
638 set_flight_log_max_tool_tip();
641 /* Tracker triger horiz distances */
642 c = new GridBagConstraints();
643 c.gridx = 0; c.gridy = row;
645 c.fill = GridBagConstraints.NONE;
646 c.anchor = GridBagConstraints.LINE_START;
649 tracker_motion_label = new JLabel(get_tracker_motion_label());
650 pane.add(tracker_motion_label, c);
652 c = new GridBagConstraints();
653 c.gridx = 4; c.gridy = row;
655 c.fill = GridBagConstraints.HORIZONTAL;
657 c.anchor = GridBagConstraints.LINE_START;
660 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
661 tracker_motion_value.setEditable(true);
662 tracker_motion_value.addItemListener(this);
663 pane.add(tracker_motion_value, c);
666 /* Tracker triger vert distances */
667 c = new GridBagConstraints();
668 c.gridx = 0; c.gridy = row;
670 c.fill = GridBagConstraints.NONE;
671 c.anchor = GridBagConstraints.LINE_START;
674 tracker_interval_label = new JLabel("Position Reporting Interval (s):");
675 pane.add(tracker_interval_label, c);
677 c = new GridBagConstraints();
678 c.gridx = 4; c.gridy = row;
680 c.fill = GridBagConstraints.HORIZONTAL;
682 c.anchor = GridBagConstraints.LINE_START;
685 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
686 tracker_interval_value.setEditable(true);
687 tracker_interval_value.addItemListener(this);
688 pane.add(tracker_interval_value, c);
689 set_tracker_tool_tip();
693 c = new GridBagConstraints();
694 c.gridx = 0; c.gridy = row;
696 c.fill = GridBagConstraints.NONE;
697 c.anchor = GridBagConstraints.LINE_START;
699 save = new JButton("Save");
701 save.addActionListener(this);
702 save.setActionCommand("Save");
704 c = new GridBagConstraints();
705 c.gridx = 2; c.gridy = row;
707 c.fill = GridBagConstraints.NONE;
708 c.anchor = GridBagConstraints.CENTER;
710 reset = new JButton("Reset");
712 reset.addActionListener(this);
713 reset.setActionCommand("Reset");
715 c = new GridBagConstraints();
716 c.gridx = 4; c.gridy = row;
718 c.fill = GridBagConstraints.NONE;
719 c.anchor = GridBagConstraints.CENTER;
721 reboot = new JButton("Reboot");
723 reboot.addActionListener(this);
724 reboot.setActionCommand("Reboot");
726 c = new GridBagConstraints();
727 c.gridx = 6; c.gridy = row;
729 c.fill = GridBagConstraints.NONE;
730 c.anchor = GridBagConstraints.LINE_END;
732 close = new JButton("Close");
734 close.addActionListener(this);
735 close.setActionCommand("Close");
737 addWindowListener(new ConfigListener(this));
738 AltosPreferences.register_units_listener(this);
741 /* Once the initial values are set, the config code will show the dialog */
742 public void make_visible() {
744 setLocationRelativeTo(owner);
748 /* If any values have been changed, confirm before closing */
749 public boolean check_dirty(String operation) {
751 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
753 i = JOptionPane.showOptionDialog(this,
754 String.format("Configuration modified. %s anyway?", operation),
755 "Configuration Modified",
756 JOptionPane.DEFAULT_OPTION,
757 JOptionPane.WARNING_MESSAGE,
758 null, options, options[1]);
765 public void set_dirty() {
767 save.setEnabled(true);
770 public void set_clean() {
772 save.setEnabled(false);
775 public void dispose() {
776 AltosPreferences.unregister_units_listener(this);
780 public int accel_cal_plus() {
781 return AltosLib.MISSING;
784 public int accel_cal_minus() {
785 return AltosLib.MISSING;
788 public void set_accel_cal(int accel_plus, int accel_minus) {
791 /* Listen for events from our buttons */
792 public void actionPerformed(ActionEvent e) {
793 String cmd = e.getActionCommand();
795 if (cmd.equals("Close") || cmd.equals("Reboot"))
796 if (!check_dirty(cmd))
798 listener.actionPerformed(e);
799 if (cmd.equals("Close") || cmd.equals("Reboot")) {
806 /* ItemListener interface method */
807 public void itemStateChanged(ItemEvent e) {
811 /* DocumentListener interface methods */
812 public void changedUpdate(DocumentEvent e) {
816 public void insertUpdate(DocumentEvent e) {
820 public void removeUpdate(DocumentEvent e) {
824 /* Let the config code hook on a listener */
825 public void addActionListener(ActionListener l) {
829 public void units_changed(boolean imperial_units) {
830 boolean was_dirty = dirty;
832 if (tracker_motion_value.isVisible()) {
833 String motion = tracker_motion_value.getSelectedItem().toString();
834 tracker_motion_label.setText(get_tracker_motion_label());
835 set_tracker_motion_values();
837 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
838 set_tracker_motion(m);
839 } catch (ParseException pe) {
846 /* set and get all of the dialog values */
847 public void set_product(String product) {
848 radio_frequency_value.set_product(product);
849 product_value.setText(product);
850 set_flight_log_max_tool_tip();
853 public void set_version(String version) {
854 version_value.setText(version);
857 public void set_serial(int serial) {
858 radio_frequency_value.set_serial(serial);
859 serial_value.setText(String.format("%d", serial));
862 public void set_altitude_32(int altitude_32) {
865 public void set_main_deploy(int new_main_deploy) {
868 public int main_deploy() {
869 return AltosLib.MISSING;
872 public void set_apogee_delay(int new_apogee_delay) { }
874 public int apogee_delay() {
875 return AltosLib.MISSING;
878 public void set_apogee_lockout(int new_apogee_lockout) { }
880 public int apogee_lockout() { return AltosLib.MISSING; }
882 public void set_radio_frequency(double new_radio_frequency) {
883 if (new_radio_frequency != AltosLib.MISSING)
884 radio_frequency_value.set_frequency(new_radio_frequency);
885 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
886 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
889 public double radio_frequency() {
890 return radio_frequency_value.frequency();
893 public void set_radio_calibration(int new_radio_calibration) {
894 if (new_radio_calibration != AltosLib.MISSING)
895 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
896 radio_calibration_value.setVisible(new_radio_calibration == AltosLib.MISSING);
897 radio_calibration_label.setVisible(new_radio_calibration == AltosLib.MISSING);
900 public void set_radio_enable(int new_radio_enable) {
901 if (new_radio_enable != AltosLib.MISSING)
902 radio_enable_value.setSelected(new_radio_enable != 0);
903 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
904 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
905 set_radio_enable_tool_tip();
908 public int radio_enable() {
909 if (radio_enable_value.isVisible())
910 return radio_enable_value.isSelected() ? 1 : 0;
912 return AltosLib.MISSING;
915 public void set_radio_10mw(int new_radio_10mw) {
916 if (new_radio_10mw != AltosLib.MISSING) {
917 radio_10mw_value.setSelected(new_radio_10mw != 0);
919 radio_10mw_value.setVisible(new_radio_10mw != AltosLib.MISSING);
920 radio_10mw_label.setVisible(new_radio_10mw != AltosLib.MISSING);
921 set_radio_10mw_tool_tip();
924 public int radio_10mw() {
925 if (radio_10mw_value.isVisible())
926 return radio_10mw_value.isSelected() ? 1 : 0;
928 return AltosLib.MISSING;
931 public void set_telemetry_rate(int new_rate) {
932 if (new_rate != AltosLib.MISSING)
933 rate_value.set_rate(new_rate);
934 rate_label.setVisible(new_rate != AltosLib.MISSING);
935 rate_value.setVisible(new_rate != AltosLib.MISSING);
938 public int telemetry_rate() {
939 return rate_value.rate();
942 public void set_callsign(String new_callsign) {
943 if (new_callsign != null)
944 callsign_value.setText(new_callsign);
945 callsign_value.setVisible(new_callsign != null);
946 callsign_label.setVisible(new_callsign != null);
949 public String callsign() {
950 if (callsign_value.isVisible())
951 return callsign_value.getText();
955 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
958 v = s.split("\\s+")[0];
960 return Integer.parseInt(v);
961 } catch (NumberFormatException ne) {
962 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
966 int flight_log_max_limit;
969 public String flight_log_max_label(int flight_log_max) {
970 if (flight_log_max_limit != 0) {
971 int nflight = flight_log_max_limit / flight_log_max;
972 String plural = nflight > 1 ? "s" : "";
974 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
976 return String.format("%d", flight_log_max);
979 public void set_flight_log_max(int new_flight_log_max) {
980 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
981 flight_log_max = new_flight_log_max;
982 set_flight_log_max_tool_tip();
985 public void set_flight_log_max_enabled(boolean enable) {
986 flight_log_max_value.setEnabled(enable);
987 set_flight_log_max_tool_tip();
990 public int flight_log_max() throws AltosConfigDataException {
991 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
994 public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
995 flight_log_max_limit = new_flight_log_max_limit;
996 if (new_flight_log_max_limit != AltosLib.MISSING) {
997 flight_log_max_value.removeAllItems();
998 for (int i = 8; i >= 1; i--) {
999 int size = flight_log_max_limit / i;
1000 if (new_storage_erase_unit != 0)
1001 size &= ~(new_storage_erase_unit - 1);
1002 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1005 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
1006 set_flight_log_max(flight_log_max);
1009 public void set_ignite_mode(int new_ignite_mode) { }
1010 public int ignite_mode() { return AltosLib.MISSING; }
1013 public void set_pad_orientation(int new_pad_orientation) { }
1014 public int pad_orientation() { return AltosLib.MISSING; }
1016 public void set_beep(int new_beep) { }
1018 public int beep() { return AltosLib.MISSING; }
1020 String[] tracker_motion_values() {
1021 if (AltosConvert.imperial_units)
1022 return tracker_motion_values_ft;
1024 return tracker_motion_values_m;
1027 void set_tracker_motion_values() {
1028 String[] v = tracker_motion_values();
1029 while (tracker_motion_value.getItemCount() > 0)
1030 tracker_motion_value.removeItemAt(0);
1031 for (int i = 0; i < v.length; i++)
1032 tracker_motion_value.addItem(v[i]);
1033 tracker_motion_value.setMaximumRowCount(v.length);
1036 String get_tracker_motion_label() {
1037 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1040 void set_tracker_tool_tip() {
1041 if (tracker_motion_value.isVisible())
1042 tracker_motion_value.setToolTipText("How far the device must move before logging");
1044 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1045 if (tracker_interval_value.isVisible())
1046 tracker_interval_value.setToolTipText("How often to report GPS position");
1048 tracker_interval_value.setToolTipText("This device can't configure interval");
1051 public void set_tracker_motion(int tracker_motion) {
1052 if (tracker_motion != AltosLib.MISSING)
1053 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1054 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1055 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1058 public int tracker_motion() throws AltosConfigDataException {
1059 if (tracker_motion_value.isVisible()) {
1060 String str = tracker_motion_value.getSelectedItem().toString();
1062 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1063 } catch (ParseException pe) {
1064 throw new AltosConfigDataException("invalid tracker motion %s", str);
1067 return AltosLib.MISSING;
1070 public void set_tracker_interval(int tracker_interval) {
1071 if (tracker_interval != AltosLib.MISSING)
1072 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1073 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1074 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1077 public int tracker_interval() throws AltosConfigDataException {
1078 if (tracker_interval_value.isVisible())
1079 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1080 return AltosLib.MISSING;
1083 public void set_aprs_interval(int new_aprs_interval) {
1084 if (new_aprs_interval != AltosLib.MISSING)
1085 aprs_interval_value.setSelectedItem(Integer.toString(new_aprs_interval));
1086 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1087 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1088 set_aprs_interval_tool_tip();
1091 public int aprs_interval() throws AltosConfigDataException {
1092 if (aprs_interval_value.isVisible()) {
1093 String s = aprs_interval_value.getSelectedItem().toString();
1095 return parse_int("aprs interval", s, false);
1097 return AltosLib.MISSING;
1100 public void set_aprs_ssid(int new_aprs_ssid) {
1101 if (new_aprs_ssid != AltosLib.MISSING)
1102 aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1103 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1104 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1105 set_aprs_ssid_tool_tip();
1108 public int aprs_ssid() throws AltosConfigDataException {
1109 if (aprs_ssid_value.isVisible()) {
1110 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1113 return AltosLib.MISSING;
1116 public void set_aprs_format(int new_aprs_format) {
1117 if (new_aprs_format != AltosLib.MISSING)
1118 aprs_format_value.setSelectedIndex(new_aprs_format);
1119 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1120 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1121 set_aprs_format_tool_tip();
1124 public int aprs_format() throws AltosConfigDataException {
1125 if (aprs_format_value.isVisible())
1126 return aprs_format_value.getSelectedIndex();
1127 return AltosLib.MISSING;
1129 public void set_aprs_offset(int new_aprs_offset) {
1130 if (new_aprs_offset != AltosLib.MISSING)
1131 aprs_offset_value.setSelectedItem(new_aprs_offset);
1132 aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
1133 aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
1134 set_aprs_offset_tool_tip();
1137 public int aprs_offset() throws AltosConfigDataException {
1138 if (aprs_offset_value.isVisible()) {
1139 Integer i = (Integer) aprs_offset_value.getSelectedItem();
1142 return AltosLib.MISSING;