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();
406 c = new GridBagConstraints();
407 c.gridx = 0; c.gridy = row;
409 c.fill = GridBagConstraints.NONE;
410 c.anchor = GridBagConstraints.LINE_START;
413 report_feet_label = new JLabel("Beep max height in:");
414 pane.add(report_feet_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 report_feet_value = new JComboBox<String>(report_feet_values);
425 report_feet_value.setEditable(false);
426 report_feet_value.addItemListener(this);
427 pane.add(report_feet_value, c);
428 set_report_feet_tool_tip();
431 /* Radio 10mW limit */
432 c = new GridBagConstraints();
433 c.gridx = 0; c.gridy = row;
435 c.fill = GridBagConstraints.NONE;
436 c.anchor = GridBagConstraints.LINE_START;
439 radio_10mw_label = new JLabel("Limit transmit to 10mW:");
440 pane.add(radio_10mw_label, c);
442 c = new GridBagConstraints();
443 c.gridx = 4; c.gridy = row;
445 c.fill = GridBagConstraints.HORIZONTAL;
447 c.anchor = GridBagConstraints.LINE_START;
450 radio_10mw_value = new JRadioButton("Limited");
451 radio_10mw_value.addItemListener(this);
452 pane.add(radio_10mw_value, c);
453 set_radio_10mw_tool_tip();
457 c = new GridBagConstraints();
458 c.gridx = 0; c.gridy = row;
460 c.fill = GridBagConstraints.NONE;
461 c.anchor = GridBagConstraints.LINE_START;
464 rate_label = new JLabel("Telemetry baud rate:");
465 pane.add(rate_label, c);
467 c = new GridBagConstraints();
468 c.gridx = 4; c.gridy = row;
470 c.fill = GridBagConstraints.HORIZONTAL;
472 c.anchor = GridBagConstraints.LINE_START;
475 rate_value = new AltosUIRateList();
476 rate_value.addItemListener(this);
477 pane.add(rate_value, c);
482 c = new GridBagConstraints();
483 c.gridx = 0; c.gridy = row;
485 c.fill = GridBagConstraints.NONE;
486 c.anchor = GridBagConstraints.LINE_START;
489 aprs_interval_label = new JLabel("APRS Interval(s):");
490 pane.add(aprs_interval_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_interval_value = new JComboBox<String>(aprs_interval_values);
501 aprs_interval_value.setEditable(true);
502 aprs_interval_value.addItemListener(this);
503 pane.add(aprs_interval_value, c);
504 set_aprs_interval_tool_tip();
508 c = new GridBagConstraints();
509 c.gridx = 0; c.gridy = row;
511 c.fill = GridBagConstraints.NONE;
512 c.anchor = GridBagConstraints.LINE_START;
515 aprs_ssid_label = new JLabel("APRS SSID:");
516 pane.add(aprs_ssid_label, c);
518 c = new GridBagConstraints();
519 c.gridx = 4; c.gridy = row;
521 c.fill = GridBagConstraints.HORIZONTAL;
523 c.anchor = GridBagConstraints.LINE_START;
526 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
527 aprs_ssid_value.setEditable(false);
528 aprs_ssid_value.addItemListener(this);
529 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
530 pane.add(aprs_ssid_value, c);
531 set_aprs_ssid_tool_tip();
535 c = new GridBagConstraints();
536 c.gridx = 0; c.gridy = row;
538 c.fill = GridBagConstraints.NONE;
539 c.anchor = GridBagConstraints.LINE_START;
542 aprs_format_label = new JLabel("APRS format:");
543 pane.add(aprs_format_label, c);
545 c = new GridBagConstraints();
546 c.gridx = 4; c.gridy = row;
548 c.fill = GridBagConstraints.HORIZONTAL;
550 c.anchor = GridBagConstraints.LINE_START;
553 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
554 aprs_format_value.setEditable(false);
555 aprs_format_value.addItemListener(this);
556 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
557 pane.add(aprs_format_value, c);
558 set_aprs_format_tool_tip();
562 c = new GridBagConstraints();
563 c.gridx = 0; c.gridy = row;
565 c.fill = GridBagConstraints.NONE;
566 c.anchor = GridBagConstraints.LINE_START;
569 aprs_offset_label = new JLabel("APRS offset:");
570 pane.add(aprs_offset_label, c);
572 c = new GridBagConstraints();
573 c.gridx = 4; c.gridy = row;
575 c.fill = GridBagConstraints.HORIZONTAL;
577 c.anchor = GridBagConstraints.LINE_START;
580 aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
581 aprs_offset_value.setEditable(false);
582 aprs_offset_value.addItemListener(this);
583 aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
584 pane.add(aprs_offset_value, c);
585 set_aprs_offset_tool_tip();
589 c = new GridBagConstraints();
590 c.gridx = 0; c.gridy = row;
592 c.fill = GridBagConstraints.NONE;
593 c.anchor = GridBagConstraints.LINE_START;
596 callsign_label = new JLabel("Callsign:");
597 pane.add(callsign_label, c);
599 c = new GridBagConstraints();
600 c.gridx = 4; c.gridy = row;
602 c.fill = GridBagConstraints.HORIZONTAL;
604 c.anchor = GridBagConstraints.LINE_START;
607 callsign_value = new JTextField(AltosUIPreferences.callsign());
608 callsign_value.getDocument().addDocumentListener(this);
609 pane.add(callsign_value, c);
610 callsign_value.setToolTipText("Callsign reported in telemetry data");
614 c = new GridBagConstraints();
615 c.gridx = 0; c.gridy = row;
617 c.fill = GridBagConstraints.NONE;
618 c.anchor = GridBagConstraints.LINE_START;
621 flight_log_max_label = new JLabel("Maximum Log Size (kB):");
622 pane.add(flight_log_max_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 flight_log_max_value = new JComboBox<String>();
633 flight_log_max_value.setEditable(true);
634 flight_log_max_value.addItemListener(this);
635 pane.add(flight_log_max_value, c);
636 set_flight_log_max_tool_tip();
639 /* Tracker triger horiz distances */
640 c = new GridBagConstraints();
641 c.gridx = 0; c.gridy = row;
643 c.fill = GridBagConstraints.NONE;
644 c.anchor = GridBagConstraints.LINE_START;
647 tracker_motion_label = new JLabel(get_tracker_motion_label());
648 pane.add(tracker_motion_label, c);
650 c = new GridBagConstraints();
651 c.gridx = 4; c.gridy = row;
653 c.fill = GridBagConstraints.HORIZONTAL;
655 c.anchor = GridBagConstraints.LINE_START;
658 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
659 tracker_motion_value.setEditable(true);
660 tracker_motion_value.addItemListener(this);
661 pane.add(tracker_motion_value, c);
664 /* Tracker triger vert distances */
665 c = new GridBagConstraints();
666 c.gridx = 0; c.gridy = row;
668 c.fill = GridBagConstraints.NONE;
669 c.anchor = GridBagConstraints.LINE_START;
672 tracker_interval_label = new JLabel("Position Reporting Interval (s):");
673 pane.add(tracker_interval_label, c);
675 c = new GridBagConstraints();
676 c.gridx = 4; c.gridy = row;
678 c.fill = GridBagConstraints.HORIZONTAL;
680 c.anchor = GridBagConstraints.LINE_START;
683 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
684 tracker_interval_value.setEditable(true);
685 tracker_interval_value.addItemListener(this);
686 pane.add(tracker_interval_value, c);
687 set_tracker_tool_tip();
691 c = new GridBagConstraints();
692 c.gridx = 0; c.gridy = row;
694 c.fill = GridBagConstraints.NONE;
695 c.anchor = GridBagConstraints.LINE_START;
697 save = new JButton("Save");
699 save.addActionListener(this);
700 save.setActionCommand("Save");
702 c = new GridBagConstraints();
703 c.gridx = 2; c.gridy = row;
705 c.fill = GridBagConstraints.NONE;
706 c.anchor = GridBagConstraints.CENTER;
708 reset = new JButton("Reset");
710 reset.addActionListener(this);
711 reset.setActionCommand("Reset");
713 c = new GridBagConstraints();
714 c.gridx = 4; c.gridy = row;
716 c.fill = GridBagConstraints.NONE;
717 c.anchor = GridBagConstraints.CENTER;
719 reboot = new JButton("Reboot");
721 reboot.addActionListener(this);
722 reboot.setActionCommand("Reboot");
724 c = new GridBagConstraints();
725 c.gridx = 6; c.gridy = row;
727 c.fill = GridBagConstraints.NONE;
728 c.anchor = GridBagConstraints.LINE_END;
730 close = new JButton("Close");
732 close.addActionListener(this);
733 close.setActionCommand("Close");
735 addWindowListener(new ConfigListener(this));
736 AltosPreferences.register_units_listener(this);
739 /* Once the initial values are set, the config code will show the dialog */
740 public void make_visible() {
742 setLocationRelativeTo(owner);
746 /* If any values have been changed, confirm before closing */
747 public boolean check_dirty(String operation) {
749 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
751 i = JOptionPane.showOptionDialog(this,
752 String.format("Configuration modified. %s anyway?", operation),
753 "Configuration Modified",
754 JOptionPane.DEFAULT_OPTION,
755 JOptionPane.WARNING_MESSAGE,
756 null, options, options[1]);
763 public void set_dirty() {
765 save.setEnabled(true);
768 public void set_clean() {
770 save.setEnabled(false);
773 public void dispose() {
774 AltosPreferences.unregister_units_listener(this);
778 public int accel_cal_plus() {
779 return AltosLib.MISSING;
782 public int accel_cal_minus() {
783 return AltosLib.MISSING;
786 public void set_accel_cal(int accel_plus, int accel_minus) {
789 /* Listen for events from our buttons */
790 public void actionPerformed(ActionEvent e) {
791 String cmd = e.getActionCommand();
793 if (cmd.equals("Close") || cmd.equals("Reboot"))
794 if (!check_dirty(cmd))
796 listener.actionPerformed(e);
797 if (cmd.equals("Close") || cmd.equals("Reboot")) {
804 /* ItemListener interface method */
805 public void itemStateChanged(ItemEvent e) {
809 /* DocumentListener interface methods */
810 public void changedUpdate(DocumentEvent e) {
814 public void insertUpdate(DocumentEvent e) {
818 public void removeUpdate(DocumentEvent e) {
822 /* Let the config code hook on a listener */
823 public void addActionListener(ActionListener l) {
827 public void units_changed(boolean imperial_units) {
828 boolean was_dirty = dirty;
830 if (tracker_motion_value.isVisible()) {
831 String motion = tracker_motion_value.getSelectedItem().toString();
832 tracker_motion_label.setText(get_tracker_motion_label());
833 set_tracker_motion_values();
835 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
836 set_tracker_motion(m);
837 } catch (ParseException pe) {
844 /* set and get all of the dialog values */
845 public void set_product(String product) {
846 radio_frequency_value.set_product(product);
847 product_value.setText(product);
848 set_flight_log_max_tool_tip();
851 public void set_version(String version) {
852 version_value.setText(version);
855 public void set_serial(int serial) {
856 radio_frequency_value.set_serial(serial);
857 serial_value.setText(String.format("%d", serial));
860 public void set_altitude_32(int altitude_32) {
863 public void set_main_deploy(int new_main_deploy) {
866 public int main_deploy() {
867 return AltosLib.MISSING;
870 public void set_apogee_delay(int new_apogee_delay) { }
872 public int apogee_delay() {
873 return AltosLib.MISSING;
876 public void set_apogee_lockout(int new_apogee_lockout) { }
878 public int apogee_lockout() { return AltosLib.MISSING; }
880 public void set_radio_frequency(double new_radio_frequency) {
881 if (new_radio_frequency != AltosLib.MISSING)
882 radio_frequency_value.set_frequency(new_radio_frequency);
883 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
884 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
887 public double radio_frequency() {
888 return radio_frequency_value.frequency();
891 public void set_radio_calibration(int new_radio_calibration) {
892 if (new_radio_calibration != AltosLib.MISSING)
893 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
894 radio_calibration_value.setVisible(new_radio_calibration == AltosLib.MISSING);
895 radio_calibration_label.setVisible(new_radio_calibration == AltosLib.MISSING);
898 public void set_radio_enable(int new_radio_enable) {
899 if (new_radio_enable != AltosLib.MISSING)
900 radio_enable_value.setSelected(new_radio_enable != 0);
901 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
902 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
903 set_radio_enable_tool_tip();
906 public int radio_enable() {
907 if (radio_enable_value.isVisible())
908 return radio_enable_value.isSelected() ? 1 : 0;
910 return AltosLib.MISSING;
913 public void set_radio_10mw(int new_radio_10mw) {
914 if (new_radio_10mw != AltosLib.MISSING) {
915 radio_10mw_value.setSelected(new_radio_10mw != 0);
917 radio_10mw_value.setVisible(new_radio_10mw != AltosLib.MISSING);
918 radio_10mw_label.setVisible(new_radio_10mw != AltosLib.MISSING);
919 set_radio_10mw_tool_tip();
922 public int radio_10mw() {
923 if (radio_10mw_value.isVisible())
924 return radio_10mw_value.isSelected() ? 1 : 0;
926 return AltosLib.MISSING;
929 public void set_telemetry_rate(int new_rate) {
930 if (new_rate != AltosLib.MISSING)
931 rate_value.set_rate(new_rate);
932 rate_label.setVisible(new_rate != AltosLib.MISSING);
933 rate_value.setVisible(new_rate != AltosLib.MISSING);
936 public int telemetry_rate() {
937 return rate_value.rate();
940 public void set_callsign(String new_callsign) {
941 if (new_callsign != null)
942 callsign_value.setText(new_callsign);
943 callsign_value.setVisible(new_callsign != null);
944 callsign_label.setVisible(new_callsign != null);
947 public String callsign() {
948 if (callsign_value.isVisible())
949 return callsign_value.getText();
953 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
956 v = s.split("\\s+")[0];
958 return Integer.parseInt(v);
959 } catch (NumberFormatException ne) {
960 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
964 int flight_log_max_limit;
967 public String flight_log_max_label(int flight_log_max) {
968 if (flight_log_max_limit != 0) {
969 int nflight = flight_log_max_limit / flight_log_max;
970 String plural = nflight > 1 ? "s" : "";
972 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
974 return String.format("%d", flight_log_max);
977 public void set_flight_log_max(int new_flight_log_max) {
978 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
979 flight_log_max = new_flight_log_max;
980 set_flight_log_max_tool_tip();
983 public void set_flight_log_max_enabled(boolean enable) {
984 flight_log_max_value.setEnabled(enable);
985 set_flight_log_max_tool_tip();
988 public int flight_log_max() throws AltosConfigDataException {
989 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
992 public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
993 flight_log_max_limit = new_flight_log_max_limit;
994 if (new_flight_log_max_limit != AltosLib.MISSING) {
995 flight_log_max_value.removeAllItems();
996 for (int i = 8; i >= 1; i--) {
997 int size = flight_log_max_limit / i;
998 if (new_storage_erase_unit != 0)
999 size &= ~(new_storage_erase_unit - 1);
1000 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1003 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
1004 set_flight_log_max(flight_log_max);
1007 public void set_ignite_mode(int new_ignite_mode) { }
1008 public int ignite_mode() { return AltosLib.MISSING; }
1011 public void set_pad_orientation(int new_pad_orientation) { }
1012 public int pad_orientation() { return AltosLib.MISSING; }
1014 public void set_beep(int new_beep) { }
1016 public int beep() { return AltosLib.MISSING; }
1018 String[] tracker_motion_values() {
1019 if (AltosConvert.imperial_units)
1020 return tracker_motion_values_ft;
1022 return tracker_motion_values_m;
1025 void set_tracker_motion_values() {
1026 String[] v = tracker_motion_values();
1027 while (tracker_motion_value.getItemCount() > 0)
1028 tracker_motion_value.removeItemAt(0);
1029 for (int i = 0; i < v.length; i++)
1030 tracker_motion_value.addItem(v[i]);
1031 tracker_motion_value.setMaximumRowCount(v.length);
1034 String get_tracker_motion_label() {
1035 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1038 void set_tracker_tool_tip() {
1039 if (tracker_motion_value.isVisible())
1040 tracker_motion_value.setToolTipText("How far the device must move before logging");
1042 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1043 if (tracker_interval_value.isVisible())
1044 tracker_interval_value.setToolTipText("How often to report GPS position");
1046 tracker_interval_value.setToolTipText("This device can't configure interval");
1049 public void set_tracker_motion(int tracker_motion) {
1050 if (tracker_motion != AltosLib.MISSING)
1051 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1052 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1053 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1056 public int tracker_motion() throws AltosConfigDataException {
1057 if (tracker_motion_value.isVisible()) {
1058 String str = tracker_motion_value.getSelectedItem().toString();
1060 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1061 } catch (ParseException pe) {
1062 throw new AltosConfigDataException("invalid tracker motion %s", str);
1065 return AltosLib.MISSING;
1068 public void set_tracker_interval(int tracker_interval) {
1069 if (tracker_interval != AltosLib.MISSING)
1070 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1071 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1072 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1075 public int tracker_interval() throws AltosConfigDataException {
1076 if (tracker_interval_value.isVisible())
1077 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1078 return AltosLib.MISSING;
1081 public void set_aprs_interval(int new_aprs_interval) {
1082 if (new_aprs_interval != AltosLib.MISSING)
1083 aprs_interval_value.setSelectedItem(Integer.toString(new_aprs_interval));
1084 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1085 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1086 set_aprs_interval_tool_tip();
1089 public int aprs_interval() throws AltosConfigDataException {
1090 if (aprs_interval_value.isVisible()) {
1091 String s = aprs_interval_value.getSelectedItem().toString();
1093 return parse_int("aprs interval", s, false);
1095 return AltosLib.MISSING;
1098 public void set_aprs_ssid(int new_aprs_ssid) {
1099 if (new_aprs_ssid != AltosLib.MISSING)
1100 aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1101 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1102 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1103 set_aprs_ssid_tool_tip();
1106 public int aprs_ssid() throws AltosConfigDataException {
1107 if (aprs_ssid_value.isVisible()) {
1108 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1111 return AltosLib.MISSING;
1114 public void set_aprs_format(int new_aprs_format) {
1115 if (new_aprs_format != AltosLib.MISSING)
1116 aprs_format_value.setSelectedIndex(new_aprs_format);
1117 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1118 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1119 set_aprs_format_tool_tip();
1122 public int aprs_format() throws AltosConfigDataException {
1123 if (aprs_format_value.isVisible())
1124 return aprs_format_value.getSelectedIndex();
1125 return AltosLib.MISSING;
1127 public void set_aprs_offset(int new_aprs_offset) {
1128 if (new_aprs_offset != AltosLib.MISSING)
1129 aprs_offset_value.setSelectedItem(new_aprs_offset);
1130 aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
1131 aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
1132 set_aprs_offset_tool_tip();
1135 public int aprs_offset() throws AltosConfigDataException {
1136 if (aprs_offset_value.isVisible()) {
1137 Integer i = (Integer) aprs_offset_value.getSelectedItem();
1140 return AltosLib.MISSING;