telegps: Disable tracker config when not available
[fw/altos] / telegps / TeleGPSConfigUI.java
1 /*
2  * Copyright © 2010 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package org.altusmetrum.telegps;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import javax.swing.event.*;
24 import org.altusmetrum.altoslib_5.*;
25 import org.altusmetrum.altosuilib_3.*;
26
27 public class TeleGPSConfigUI
28         extends AltosUIDialog
29         implements ActionListener, ItemListener, DocumentListener, AltosConfigValues, AltosUnitsListener
30 {
31
32         Container               pane;
33         JLabel                  product_label;
34         JLabel                  version_label;
35         JLabel                  serial_label;
36         JLabel                  frequency_label;
37         JLabel                  radio_calibration_label;
38         JLabel                  radio_frequency_label;
39         JLabel                  radio_enable_label;
40         JLabel                  aprs_interval_label;
41         JLabel                  aprs_ssid_label;
42         JLabel                  flight_log_max_label;
43         JLabel                  callsign_label;
44         JLabel                  tracker_motion_label;
45         JLabel                  tracker_interval_label;
46
47         public boolean          dirty;
48
49         JFrame                  owner;
50         JLabel                  product_value;
51         JLabel                  version_value;
52         JLabel                  serial_value;
53         AltosFreqList           radio_frequency_value;
54         JTextField              radio_calibration_value;
55         JRadioButton            radio_enable_value;
56         JComboBox<String>       aprs_interval_value;
57         JComboBox<Integer>      aprs_ssid_value;
58         JComboBox<String>       flight_log_max_value;
59         JTextField              callsign_value;
60         JComboBox<String>       tracker_motion_value;
61         JComboBox<String>       tracker_interval_value;
62
63         JButton                 save;
64         JButton                 reset;
65         JButton                 reboot;
66         JButton                 close;
67
68         ActionListener          listener;
69
70         static String[]         aprs_interval_values = {
71                 "Disabled",
72                 "2",
73                 "5",
74                 "10"
75         };
76
77         static Integer[]        aprs_ssid_values = {
78                 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
79         };
80
81         static String[]         tracker_motion_values_m = {
82                 "2",
83                 "5",
84                 "10",
85                 "25",
86         };
87
88         static String[]         tracker_motion_values_ft = {
89                 "5",
90                 "20",
91                 "50",
92                 "100"
93         };
94
95         static String[]         tracker_interval_values = {
96                 "1",
97                 "2",
98                 "5",
99                 "10"
100         };
101
102         /* A window listener to catch closing events and tell the config code */
103         class ConfigListener extends WindowAdapter {
104                 TeleGPSConfigUI ui;
105
106                 public ConfigListener(TeleGPSConfigUI this_ui) {
107                         ui = this_ui;
108                 }
109
110                 public void windowClosing(WindowEvent e) {
111                         ui.actionPerformed(new ActionEvent(e.getSource(),
112                                                            ActionEvent.ACTION_PERFORMED,
113                                                            "Close"));
114                 }
115         }
116
117         public void set_pyros(AltosPyro[] new_pyros) {
118         }
119
120         public AltosPyro[] pyros() {
121                 return null;
122         }
123
124         public void set_pyro_firing_time(double new_pyro_firing_time) {
125         }
126
127         public double pyro_firing_time() {
128                 return -1;
129         }
130
131         boolean is_telemetrum() {
132                 String  product = product_value.getText();
133                 return product != null && product.startsWith("TeleGPS");
134         }
135
136         void set_radio_calibration_tool_tip() {
137                 if (radio_calibration_value.isEnabled())
138                         radio_calibration_value.setToolTipText("Tune radio output to match desired frequency");
139                 else
140                         radio_calibration_value.setToolTipText("Cannot tune radio while connected over packet mode");
141         }
142
143         void set_radio_enable_tool_tip() {
144                 if (radio_enable_value.isEnabled())
145                         radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
146                 else
147                         radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
148         }
149
150         void set_aprs_interval_tool_tip() {
151                 if (aprs_interval_value.isEnabled())
152                         aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
153                 else
154                         aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
155         }
156
157         void set_aprs_ssid_tool_tip() {
158                 if (aprs_ssid_value.isEnabled())
159                         aprs_interval_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
160                 else if (aprs_interval_value.isEnabled())
161                         aprs_interval_value.setToolTipText("Software version doesn't support setting the APRS SSID");
162                 else
163                         aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
164         }
165
166         void set_flight_log_max_tool_tip() {
167                 if (flight_log_max_value.isEnabled())
168                         flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
169                 else
170                         flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
171         }
172
173         /* Build the UI using a grid bag */
174         public TeleGPSConfigUI(JFrame in_owner) {
175                 super (in_owner, "Configure Device", false);
176
177                 owner = in_owner;
178                 GridBagConstraints c;
179                 int row = 0;
180
181                 Insets il = new Insets(4,4,4,4);
182                 Insets ir = new Insets(4,4,4,4);
183
184                 pane = getContentPane();
185                 pane.setLayout(new GridBagLayout());
186
187                 /* Product */
188                 c = new GridBagConstraints();
189                 c.gridx = 0; c.gridy = row;
190                 c.gridwidth = 4;
191                 c.fill = GridBagConstraints.NONE;
192                 c.anchor = GridBagConstraints.LINE_START;
193                 c.insets = il;
194                 product_label = new JLabel("Product:");
195                 pane.add(product_label, c);
196
197                 c = new GridBagConstraints();
198                 c.gridx = 4; c.gridy = row;
199                 c.gridwidth = 4;
200                 c.fill = GridBagConstraints.HORIZONTAL;
201                 c.weightx = 1;
202                 c.anchor = GridBagConstraints.LINE_START;
203                 c.insets = ir;
204                 product_value = new JLabel("");
205                 pane.add(product_value, c);
206                 row++;
207
208                 /* Version */
209                 c = new GridBagConstraints();
210                 c.gridx = 0; c.gridy = row;
211                 c.gridwidth = 4;
212                 c.fill = GridBagConstraints.NONE;
213                 c.anchor = GridBagConstraints.LINE_START;
214                 c.insets = il;
215                 c.ipady = 5;
216                 version_label = new JLabel("Software version:");
217                 pane.add(version_label, c);
218
219                 c = new GridBagConstraints();
220                 c.gridx = 4; c.gridy = row;
221                 c.gridwidth = 4;
222                 c.fill = GridBagConstraints.HORIZONTAL;
223                 c.weightx = 1;
224                 c.anchor = GridBagConstraints.LINE_START;
225                 c.insets = ir;
226                 c.ipady = 5;
227                 version_value = new JLabel("");
228                 pane.add(version_value, c);
229                 row++;
230
231                 /* Serial */
232                 c = new GridBagConstraints();
233                 c.gridx = 0; c.gridy = row;
234                 c.gridwidth = 4;
235                 c.fill = GridBagConstraints.NONE;
236                 c.anchor = GridBagConstraints.LINE_START;
237                 c.insets = il;
238                 c.ipady = 5;
239                 serial_label = new JLabel("Serial:");
240                 pane.add(serial_label, c);
241
242                 c = new GridBagConstraints();
243                 c.gridx = 4; c.gridy = row;
244                 c.gridwidth = 4;
245                 c.fill = GridBagConstraints.HORIZONTAL;
246                 c.weightx = 1;
247                 c.anchor = GridBagConstraints.LINE_START;
248                 c.insets = ir;
249                 c.ipady = 5;
250                 serial_value = new JLabel("");
251                 pane.add(serial_value, c);
252                 row++;
253
254                 /* Frequency */
255                 c = new GridBagConstraints();
256                 c.gridx = 0; c.gridy = row;
257                 c.gridwidth = 4;
258                 c.fill = GridBagConstraints.NONE;
259                 c.anchor = GridBagConstraints.LINE_START;
260                 c.insets = il;
261                 c.ipady = 5;
262                 radio_frequency_label = new JLabel("Frequency:");
263                 pane.add(radio_frequency_label, c);
264
265                 c = new GridBagConstraints();
266                 c.gridx = 4; c.gridy = row;
267                 c.gridwidth = 4;
268                 c.fill = GridBagConstraints.HORIZONTAL;
269                 c.weightx = 1;
270                 c.anchor = GridBagConstraints.LINE_START;
271                 c.insets = ir;
272                 c.ipady = 5;
273                 radio_frequency_value = new AltosFreqList();
274                 radio_frequency_value.addItemListener(this);
275
276                 JMenuBar menu_bar = new JMenuBar();
277                 menu_bar.add(radio_frequency_value);
278
279                 pane.add(menu_bar, c);
280                 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
281                 row++;
282
283                 /* Radio Calibration */
284                 c = new GridBagConstraints();
285                 c.gridx = 0; c.gridy = row;
286                 c.gridwidth = 4;
287                 c.fill = GridBagConstraints.NONE;
288                 c.anchor = GridBagConstraints.LINE_START;
289                 c.insets = il;
290                 c.ipady = 5;
291                 radio_calibration_label = new JLabel("RF Calibration:");
292                 pane.add(radio_calibration_label, c);
293
294                 c = new GridBagConstraints();
295                 c.gridx = 4; c.gridy = row;
296                 c.gridwidth = 4;
297                 c.fill = GridBagConstraints.HORIZONTAL;
298                 c.weightx = 1;
299                 c.anchor = GridBagConstraints.LINE_START;
300                 c.insets = ir;
301                 c.ipady = 5;
302                 radio_calibration_value = new JTextField(String.format("%d", 1186611));
303                 radio_calibration_value.getDocument().addDocumentListener(this);
304                 pane.add(radio_calibration_value, c);
305                 set_radio_calibration_tool_tip();
306                 row++;
307
308                 /* Radio Enable */
309                 c = new GridBagConstraints();
310                 c.gridx = 0; c.gridy = row;
311                 c.gridwidth = 4;
312                 c.fill = GridBagConstraints.NONE;
313                 c.anchor = GridBagConstraints.LINE_START;
314                 c.insets = il;
315                 c.ipady = 5;
316                 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
317                 pane.add(radio_enable_label, c);
318
319                 c = new GridBagConstraints();
320                 c.gridx = 4; c.gridy = row;
321                 c.gridwidth = 4;
322                 c.fill = GridBagConstraints.HORIZONTAL;
323                 c.weightx = 1;
324                 c.anchor = GridBagConstraints.LINE_START;
325                 c.insets = ir;
326                 c.ipady = 5;
327                 radio_enable_value = new JRadioButton("Enabled");
328                 radio_enable_value.addItemListener(this);
329                 pane.add(radio_enable_value, c);
330                 set_radio_enable_tool_tip();
331                 row++;
332
333                 /* APRS interval */
334                 c = new GridBagConstraints();
335                 c.gridx = 0; c.gridy = row;
336                 c.gridwidth = 4;
337                 c.fill = GridBagConstraints.NONE;
338                 c.anchor = GridBagConstraints.LINE_START;
339                 c.insets = il;
340                 c.ipady = 5;
341                 aprs_interval_label = new JLabel("APRS Interval(s):");
342                 pane.add(aprs_interval_label, c);
343
344                 c = new GridBagConstraints();
345                 c.gridx = 4; c.gridy = row;
346                 c.gridwidth = 4;
347                 c.fill = GridBagConstraints.HORIZONTAL;
348                 c.weightx = 1;
349                 c.anchor = GridBagConstraints.LINE_START;
350                 c.insets = ir;
351                 c.ipady = 5;
352                 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
353                 aprs_interval_value.setEditable(true);
354                 aprs_interval_value.addItemListener(this);
355                 pane.add(aprs_interval_value, c);
356                 set_aprs_interval_tool_tip();
357                 row++;
358
359                 /* APRS SSID */
360                 c = new GridBagConstraints();
361                 c.gridx = 0; c.gridy = row;
362                 c.gridwidth = 4;
363                 c.fill = GridBagConstraints.NONE;
364                 c.anchor = GridBagConstraints.LINE_START;
365                 c.insets = il;
366                 c.ipady = 5;
367                 aprs_ssid_label = new JLabel("APRS SSID:");
368                 pane.add(aprs_ssid_label, c);
369
370                 c = new GridBagConstraints();
371                 c.gridx = 4; c.gridy = row;
372                 c.gridwidth = 4;
373                 c.fill = GridBagConstraints.HORIZONTAL;
374                 c.weightx = 1;
375                 c.anchor = GridBagConstraints.LINE_START;
376                 c.insets = ir;
377                 c.ipady = 5;
378                 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
379                 aprs_ssid_value.setEditable(false);
380                 aprs_ssid_value.addItemListener(this);
381                 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
382                 pane.add(aprs_ssid_value, c);
383                 set_aprs_ssid_tool_tip();
384                 row++;
385
386                 /* Callsign */
387                 c = new GridBagConstraints();
388                 c.gridx = 0; c.gridy = row;
389                 c.gridwidth = 4;
390                 c.fill = GridBagConstraints.NONE;
391                 c.anchor = GridBagConstraints.LINE_START;
392                 c.insets = il;
393                 c.ipady = 5;
394                 callsign_label = new JLabel("Callsign:");
395                 pane.add(callsign_label, c);
396
397                 c = new GridBagConstraints();
398                 c.gridx = 4; c.gridy = row;
399                 c.gridwidth = 4;
400                 c.fill = GridBagConstraints.HORIZONTAL;
401                 c.weightx = 1;
402                 c.anchor = GridBagConstraints.LINE_START;
403                 c.insets = ir;
404                 c.ipady = 5;
405                 callsign_value = new JTextField(AltosUIPreferences.callsign());
406                 callsign_value.getDocument().addDocumentListener(this);
407                 pane.add(callsign_value, c);
408                 callsign_value.setToolTipText("Callsign reported in telemetry data");
409                 row++;
410
411                 /* Flight log max */
412                 c = new GridBagConstraints();
413                 c.gridx = 0; c.gridy = row;
414                 c.gridwidth = 4;
415                 c.fill = GridBagConstraints.NONE;
416                 c.anchor = GridBagConstraints.LINE_START;
417                 c.insets = il;
418                 c.ipady = 5;
419                 flight_log_max_label = new JLabel("Maximum Log Size (kB):");
420                 pane.add(flight_log_max_label, c);
421
422                 c = new GridBagConstraints();
423                 c.gridx = 4; c.gridy = row;
424                 c.gridwidth = 4;
425                 c.fill = GridBagConstraints.HORIZONTAL;
426                 c.weightx = 1;
427                 c.anchor = GridBagConstraints.LINE_START;
428                 c.insets = ir;
429                 c.ipady = 5;
430                 flight_log_max_value = new JComboBox<String>();
431                 flight_log_max_value.setEditable(true);
432                 flight_log_max_value.addItemListener(this);
433                 pane.add(flight_log_max_value, c);
434                 set_flight_log_max_tool_tip();
435                 row++;
436
437                 /* Tracker triger horiz distances */
438                 c = new GridBagConstraints();
439                 c.gridx = 0; c.gridy = row;
440                 c.gridwidth = 4;
441                 c.fill = GridBagConstraints.NONE;
442                 c.anchor = GridBagConstraints.LINE_START;
443                 c.insets = il;
444                 c.ipady = 5;
445                 tracker_motion_label = new JLabel(get_tracker_motion_label());
446                 pane.add(tracker_motion_label, c);
447
448                 c = new GridBagConstraints();
449                 c.gridx = 4; c.gridy = row;
450                 c.gridwidth = 4;
451                 c.fill = GridBagConstraints.HORIZONTAL;
452                 c.weightx = 1;
453                 c.anchor = GridBagConstraints.LINE_START;
454                 c.insets = ir;
455                 c.ipady = 5;
456                 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
457                 tracker_motion_value.setEditable(true);
458                 tracker_motion_value.addItemListener(this);
459                 pane.add(tracker_motion_value, c);
460                 row++;
461
462                 /* Tracker triger vert distances */
463                 c = new GridBagConstraints();
464                 c.gridx = 0; c.gridy = row;
465                 c.gridwidth = 4;
466                 c.fill = GridBagConstraints.NONE;
467                 c.anchor = GridBagConstraints.LINE_START;
468                 c.insets = il;
469                 c.ipady = 5;
470                 tracker_interval_label = new JLabel("Position Reporting Interval (s):");
471                 pane.add(tracker_interval_label, c);
472
473                 c = new GridBagConstraints();
474                 c.gridx = 4; c.gridy = row;
475                 c.gridwidth = 4;
476                 c.fill = GridBagConstraints.HORIZONTAL;
477                 c.weightx = 1;
478                 c.anchor = GridBagConstraints.LINE_START;
479                 c.insets = ir;
480                 c.ipady = 5;
481                 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
482                 tracker_interval_value.setEditable(true);
483                 tracker_interval_value.addItemListener(this);
484                 pane.add(tracker_interval_value, c);
485                 set_tracker_tool_tip();
486                 row++;
487
488                 /* Buttons */
489                 c = new GridBagConstraints();
490                 c.gridx = 0; c.gridy = row;
491                 c.gridwidth = 2;
492                 c.fill = GridBagConstraints.NONE;
493                 c.anchor = GridBagConstraints.LINE_START;
494                 c.insets = il;
495                 save = new JButton("Save");
496                 pane.add(save, c);
497                 save.addActionListener(this);
498                 save.setActionCommand("Save");
499
500                 c = new GridBagConstraints();
501                 c.gridx = 2; c.gridy = row;
502                 c.gridwidth = 2;
503                 c.fill = GridBagConstraints.NONE;
504                 c.anchor = GridBagConstraints.CENTER;
505                 c.insets = il;
506                 reset = new JButton("Reset");
507                 pane.add(reset, c);
508                 reset.addActionListener(this);
509                 reset.setActionCommand("Reset");
510
511                 c = new GridBagConstraints();
512                 c.gridx = 4; c.gridy = row;
513                 c.gridwidth = 2;
514                 c.fill = GridBagConstraints.NONE;
515                 c.anchor = GridBagConstraints.CENTER;
516                 c.insets = il;
517                 reboot = new JButton("Reboot");
518                 pane.add(reboot, c);
519                 reboot.addActionListener(this);
520                 reboot.setActionCommand("Reboot");
521
522                 c = new GridBagConstraints();
523                 c.gridx = 6; c.gridy = row;
524                 c.gridwidth = 2;
525                 c.fill = GridBagConstraints.NONE;
526                 c.anchor = GridBagConstraints.LINE_END;
527                 c.insets = il;
528                 close = new JButton("Close");
529                 pane.add(close, c);
530                 close.addActionListener(this);
531                 close.setActionCommand("Close");
532
533                 addWindowListener(new ConfigListener(this));
534                 AltosPreferences.register_units_listener(this);
535         }
536
537         /* Once the initial values are set, the config code will show the dialog */
538         public void make_visible() {
539                 pack();
540                 setLocationRelativeTo(owner);
541                 setVisible(true);
542         }
543
544         /* If any values have been changed, confirm before closing */
545         public boolean check_dirty(String operation) {
546                 if (dirty) {
547                         Object[] options = { String.format("%s anyway", operation), "Keep editing" };
548                         int i;
549                         i = JOptionPane.showOptionDialog(this,
550                                                          String.format("Configuration modified. %s anyway?", operation),
551                                                          "Configuration Modified",
552                                                          JOptionPane.DEFAULT_OPTION,
553                                                          JOptionPane.WARNING_MESSAGE,
554                                                          null, options, options[1]);
555                         if (i != 0)
556                                 return false;
557                 }
558                 return true;
559         }
560
561         void set_dirty() {
562                 dirty = true;
563                 save.setEnabled(true);
564         }
565
566         public void set_clean() {
567                 dirty = false;
568                 save.setEnabled(false);
569         }
570
571         public void dispose() {
572                 AltosPreferences.unregister_units_listener(this);
573                 super.dispose();
574         }
575
576         /* Listen for events from our buttons */
577         public void actionPerformed(ActionEvent e) {
578                 String  cmd = e.getActionCommand();
579
580                 if (cmd.equals("Close") || cmd.equals("Reboot"))
581                         if (!check_dirty(cmd))
582                                 return;
583                 listener.actionPerformed(e);
584                 if (cmd.equals("Close") || cmd.equals("Reboot")) {
585                         setVisible(false);
586                         dispose();
587                 }
588                 set_clean();
589         }
590
591         /* ItemListener interface method */
592         public void itemStateChanged(ItemEvent e) {
593                 set_dirty();
594         }
595
596         /* DocumentListener interface methods */
597         public void changedUpdate(DocumentEvent e) {
598                 set_dirty();
599         }
600
601         public void insertUpdate(DocumentEvent e) {
602                 set_dirty();
603         }
604
605         public void removeUpdate(DocumentEvent e) {
606                 set_dirty();
607         }
608
609         /* Let the config code hook on a listener */
610         public void addActionListener(ActionListener l) {
611                 listener = l;
612         }
613
614         public void units_changed(boolean imperial_units) {
615                 boolean was_dirty = dirty;
616
617                 if (tracker_motion_value.isEnabled()) {
618                         String motion = tracker_motion_value.getSelectedItem().toString();
619                         tracker_motion_label.setText(get_tracker_motion_label());
620                         set_tracker_motion_values();
621                         set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5));
622                 }
623                 if (!was_dirty)
624                         set_clean();
625         }
626
627         /* set and get all of the dialog values */
628         public void set_product(String product) {
629                 radio_frequency_value.set_product(product);
630                 product_value.setText(product);
631                 set_flight_log_max_tool_tip();
632         }
633
634         public void set_version(String version) {
635                 version_value.setText(version);
636         }
637
638         public void set_serial(int serial) {
639                 radio_frequency_value.set_serial(serial);
640                 serial_value.setText(String.format("%d", serial));
641         }
642
643         public void set_main_deploy(int new_main_deploy) {
644         }
645
646         public int main_deploy() {
647                 return -1;
648         }
649
650         public void set_apogee_delay(int new_apogee_delay) { }
651
652         public int apogee_delay() {
653                 return -1;
654         }
655
656         public void set_apogee_lockout(int new_apogee_lockout) { }
657
658         public int apogee_lockout() { return -1; }
659
660         public void set_radio_frequency(double new_radio_frequency) {
661                 radio_frequency_value.set_frequency(new_radio_frequency);
662         }
663
664         public double radio_frequency() {
665                 return radio_frequency_value.frequency();
666         }
667
668         public void set_radio_calibration(int new_radio_calibration) {
669                 radio_calibration_value.setVisible(new_radio_calibration >= 0);
670                 if (new_radio_calibration < 0)
671                         radio_calibration_value.setText("Disabled");
672                 else
673                         radio_calibration_value.setText(String.format("%d", new_radio_calibration));
674         }
675
676         private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
677                 String v = s;
678                 if (split)
679                         v = s.split("\\s+")[0];
680                 try {
681                         return Integer.parseInt(v);
682                 } catch (NumberFormatException ne) {
683                         throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
684                 }
685         }
686
687         public int radio_calibration() throws AltosConfigDataException {
688                 return parse_int("radio calibration", radio_calibration_value.getText(), false);
689         }
690
691         public void set_radio_enable(int new_radio_enable) {
692                 if (new_radio_enable >= 0) {
693                         radio_enable_value.setSelected(new_radio_enable > 0);
694                         radio_enable_value.setEnabled(true);
695                 } else {
696                         radio_enable_value.setSelected(true);
697                         radio_enable_value.setVisible(radio_frequency() > 0);
698                         radio_enable_value.setEnabled(false);
699                 }
700                 set_radio_enable_tool_tip();
701         }
702
703         public int radio_enable() {
704                 if (radio_enable_value.isEnabled())
705                         return radio_enable_value.isSelected() ? 1 : 0;
706                 else
707                         return -1;
708         }
709
710         public void set_callsign(String new_callsign) {
711                 callsign_value.setVisible(new_callsign != null);
712                 callsign_value.setText(new_callsign);
713         }
714
715         public String callsign() {
716                 return callsign_value.getText();
717         }
718
719         int     flight_log_max_limit;
720         int     flight_log_max;
721
722         public String flight_log_max_label(int flight_log_max) {
723                 if (flight_log_max_limit != 0) {
724                         int     nflight = flight_log_max_limit / flight_log_max;
725                         String  plural = nflight > 1 ? "s" : "";
726
727                         return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
728                 }
729                 return String.format("%d", flight_log_max);
730         }
731
732         public void set_flight_log_max(int new_flight_log_max) {
733                 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
734                 flight_log_max = new_flight_log_max;
735                 set_flight_log_max_tool_tip();
736         }
737
738         public void set_flight_log_max_enabled(boolean enable) {
739                 flight_log_max_value.setEnabled(enable);
740                 set_flight_log_max_tool_tip();
741         }
742
743         public int flight_log_max() throws AltosConfigDataException {
744                 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
745         }
746
747         public void set_flight_log_max_limit(int new_flight_log_max_limit) {
748                 flight_log_max_limit = new_flight_log_max_limit;
749                 flight_log_max_value.removeAllItems();
750                 for (int i = 8; i >= 1; i--) {
751                         int     size = flight_log_max_limit / i;
752                         flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
753                 }
754                 if (flight_log_max != 0)
755                         set_flight_log_max(flight_log_max);
756         }
757
758         public void set_ignite_mode(int new_ignite_mode) { }
759         public int ignite_mode() { return -1; }
760
761
762         public void set_pad_orientation(int new_pad_orientation) { }
763         public int pad_orientation() { return -1; }
764
765         public void set_beep(int new_beep) { }
766
767         public int beep() { return -1; }
768
769         String[] tracker_motion_values() {
770                 if (AltosConvert.imperial_units)
771                         return tracker_motion_values_ft;
772                 else
773                         return tracker_motion_values_m;
774         }
775
776         void set_tracker_motion_values() {
777                 String[]        v = tracker_motion_values();
778                 while (tracker_motion_value.getItemCount() > 0)
779                         tracker_motion_value.removeItemAt(0);
780                 for (int i = 0; i < v.length; i++)
781                         tracker_motion_value.addItem(v[i]);
782                 tracker_motion_value.setMaximumRowCount(v.length);
783         }
784
785         String get_tracker_motion_label() {
786                 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.show_units());
787         }
788
789         void set_tracker_tool_tip() {
790                 if (tracker_motion_value.isEnabled())
791                         tracker_motion_value.setToolTipText("How far the device must move before logging");
792                 else
793                         tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
794                 if (tracker_interval_value.isEnabled())
795                         tracker_interval_value.setToolTipText("How often to report GPS position");
796                 else
797                         tracker_interval_value.setToolTipText("This device can't configure interval");
798         }
799
800         public void set_tracker_motion(int tracker_motion) {
801                 if (tracker_motion < 0) {
802                         tracker_motion_value.setEnabled(false);
803                 } else {
804                         tracker_motion_value.setEnabled(true);
805                         tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
806                 }
807         }
808
809         public int tracker_motion() throws AltosConfigDataException {
810                 return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString());
811         }
812
813         public void set_tracker_interval(int tracker_interval) {
814                 if (tracker_interval< 0) {
815                         tracker_interval_value.setEnabled(false);
816                 } else {
817                         tracker_interval_value.setEnabled(true);
818                         tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
819                 }
820         }
821
822         public int tracker_interval() throws AltosConfigDataException {
823                 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
824         }
825
826         public void set_aprs_interval(int new_aprs_interval) {
827                 String  s;
828
829                 if (new_aprs_interval <= 0)
830                         s = "Disabled";
831                 else
832                         s = Integer.toString(new_aprs_interval);
833                 aprs_interval_value.setSelectedItem(s);
834                 aprs_interval_value.setVisible(new_aprs_interval >= 0);
835                 set_aprs_interval_tool_tip();
836         }
837
838         public int aprs_interval() throws AltosConfigDataException {
839                 String  s = aprs_interval_value.getSelectedItem().toString();
840
841                 if (s.equals("Disabled"))
842                         return 0;
843                 return parse_int("aprs interval", s, false);
844         }
845
846         public void set_aprs_ssid(int new_aprs_ssid) {
847                 aprs_ssid_value.setSelectedItem(Math.max(0,new_aprs_ssid));
848                 aprs_ssid_value.setVisible(new_aprs_ssid >= 0);
849                 set_aprs_ssid_tool_tip();
850         }
851
852         public int aprs_ssid() throws AltosConfigDataException {
853                 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
854                 return i;
855         }
856 }