altos/easymega-v2.0: Change binary to easymega-v2.0 instead of easymega-v1.0
[fw/altos] / altosui / AltosConfigFCUI.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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
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.
13  *
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.
17  */
18
19 package altosui;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import javax.swing.*;
24 import javax.swing.event.*;
25 import java.text.*;
26 import org.altusmetrum.altoslib_13.*;
27 import org.altusmetrum.altosuilib_13.*;
28
29 public class AltosConfigFCUI
30         extends AltosUIDialog
31         implements ActionListener, ItemListener, DocumentListener, AltosConfigValues, AltosUnitsListener
32 {
33
34         Container               pane;
35         JLabel                  product_label;
36         JLabel                  version_label;
37         JLabel                  serial_label;
38         JLabel                  main_deploy_label;
39         JLabel                  apogee_delay_label;
40         JLabel                  apogee_lockout_label;
41         JLabel                  frequency_label;
42         JLabel                  radio_calibration_label;
43         JLabel                  radio_frequency_label;
44         JLabel                  radio_enable_label;
45         JLabel                  rate_label;
46         JLabel                  aprs_interval_label;
47         JLabel                  aprs_ssid_label;
48         JLabel                  aprs_format_label;
49         JLabel                  flight_log_max_label;
50         JLabel                  ignite_mode_label;
51         JLabel                  pad_orientation_label;
52         JLabel                  accel_plus_label;
53         JLabel                  accel_minus_label;
54         JLabel                  callsign_label;
55         JLabel                  beep_label;
56         JLabel                  tracker_motion_label;
57         JLabel                  tracker_interval_label;
58
59         public boolean          dirty;
60
61         JFrame                  owner;
62         JLabel                  product_value;
63         JLabel                  version_value;
64         JLabel                  serial_value;
65         JComboBox<String>       main_deploy_value;
66         JComboBox<String>       apogee_delay_value;
67         JComboBox<String>       apogee_lockout_value;
68         AltosUIFreqList         radio_frequency_value;
69         JLabel                  radio_calibration_value;
70         JRadioButton            radio_enable_value;
71         AltosUIRateList         rate_value;
72         JComboBox<String>       aprs_interval_value;
73         JComboBox<Integer>      aprs_ssid_value;
74         JComboBox<String>       aprs_format_value;
75         JComboBox<String>       flight_log_max_value;
76         JComboBox<String>       ignite_mode_value;
77         JComboBox<String>       pad_orientation_value;
78         JTextField              accel_plus_value;
79         JTextField              accel_minus_value;
80         JTextField              callsign_value;
81         JComboBox<String>       beep_value;
82         JComboBox<String>       tracker_motion_value;
83         JComboBox<String>       tracker_interval_value;
84
85         JButton                 pyro;
86         JButton                 accel_cal;
87
88         JButton                 save;
89         JButton                 reset;
90         JButton                 reboot;
91         JButton                 close;
92
93         AltosPyro[]             pyros;
94         double                  pyro_firing_time;
95
96         ActionListener          listener;
97
98         static String[]         main_deploy_values_m = {
99                 "100", "150", "200", "250", "300", "350",
100                 "400", "450", "500"
101         };
102
103         static String[]         main_deploy_values_ft = {
104                 "250", "500", "750", "1000", "1250", "1500",
105                 "1750", "2000"
106         };
107
108         static String[]         apogee_delay_values = {
109                 "0", "1", "2", "3", "4", "5"
110         };
111
112         static String[]         apogee_lockout_values = {
113                 "0", "5", "10", "15", "20"
114         };
115
116         static String[]         ignite_mode_values = {
117                 "Dual Deploy",
118                 "Redundant Apogee",
119                 "Redundant Main",
120         };
121
122         static String[]         aprs_interval_values = {
123                 "Disabled",
124                 "2",
125                 "5",
126                 "10"
127         };
128
129         static Integer[]        aprs_ssid_values = {
130                 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
131         };
132
133         static String[]         beep_values = {
134                 "3750",
135                 "4000",
136                 "4250",
137         };
138
139         static String[]         pad_orientation_values = {
140                 "Antenna Up",
141                 "Antenna Down",
142         };
143
144         static String[]         tracker_motion_values_m = {
145                 "2",
146                 "5",
147                 "10",
148                 "25",
149         };
150
151         static String[]         tracker_motion_values_ft = {
152                 "5",
153                 "20",
154                 "50",
155                 "100"
156         };
157
158         static String[]         tracker_interval_values = {
159                 "1",
160                 "2",
161                 "5",
162                 "10"
163         };
164
165         /* A window listener to catch closing events and tell the config code */
166         class ConfigListener extends WindowAdapter {
167                 AltosConfigFCUI ui;
168
169                 public ConfigListener(AltosConfigFCUI this_ui) {
170                         ui = this_ui;
171                 }
172
173                 public void windowClosing(WindowEvent e) {
174                         ui.actionPerformed(new ActionEvent(e.getSource(),
175                                                            ActionEvent.ACTION_PERFORMED,
176                                                            "Close"));
177                 }
178         }
179
180         boolean is_telemini_v1() {
181                 String  product = product_value.getText();
182                 return product != null && product.startsWith("TeleMini-v1");
183         }
184
185         boolean is_telemini() {
186                 String  product = product_value.getText();
187                 return product != null && product.startsWith("TeleMini");
188         }
189
190         boolean is_easymini() {
191                 String  product = product_value.getText();
192                 return product != null && product.startsWith("EasyMini");
193         }
194
195         boolean is_telemetrum() {
196                 String  product = product_value.getText();
197                 return product != null && product.startsWith("TeleMetrum");
198         }
199
200         void set_radio_enable_tool_tip() {
201                 if (radio_enable_value.isVisible())
202                         radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
203                 else
204                         radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
205         }
206
207         void set_rate_tool_tip() {
208                 if (rate_value.isVisible())
209                         rate_value.setToolTipText("Select telemetry baud rate");
210                 else
211                         rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
212         }
213
214         void set_aprs_interval_tool_tip() {
215                 if (aprs_interval_value.isVisible())
216                         aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
217                 else
218                         aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
219         }
220
221         void set_aprs_ssid_tool_tip() {
222                 if (aprs_ssid_value.isVisible())
223                         aprs_ssid_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
224                 else if (aprs_ssid_value.isVisible())
225                         aprs_ssid_value.setToolTipText("Software version doesn't support setting the APRS SSID");
226                 else
227                         aprs_ssid_value.setToolTipText("Hardware doesn't support APRS");
228         }
229
230         void set_aprs_format_tool_tip() {
231                 if (aprs_format_value.isVisible())
232                         aprs_format_value.setToolTipText("Set the APRS format (compressed/uncompressed)");
233                 else if (aprs_format_value.isVisible())
234                         aprs_format_value.setToolTipText("Software version doesn't support setting the APRS format");
235                 else
236                         aprs_format_value.setToolTipText("Hardware doesn't support APRS");
237         }
238
239         void set_flight_log_max_tool_tip() {
240                 if (flight_log_max_value.isVisible())
241                         flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
242                 else {
243                         if (is_telemini_v1())
244                                 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
245                         else
246                                 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
247                 }
248         }
249
250         void set_ignite_mode_tool_tip() {
251                 if (ignite_mode_value.isVisible())
252                         ignite_mode_value.setToolTipText("Select when igniters will be fired");
253                 else
254                         ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
255         }
256
257         void set_pad_orientation_tool_tip() {
258                 if (pad_orientation_value.isVisible()) {
259                         pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
260                 } else {
261                         if (is_telemetrum())
262                                 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
263                         else if (is_telemini() || is_easymini())
264                                 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
265                         else
266                                 pad_orientation_value.setToolTipText("Can't select orientation");
267                 }
268         }
269
270         void set_accel_tool_tips() {
271                 if (accel_plus_value.isVisible()) {
272                         accel_plus_value.setToolTipText("Pad acceleration value in flight orientation");
273                         accel_minus_value.setToolTipText("Upside-down acceleration value");
274                 } else {
275                         accel_plus_value.setToolTipText("No accelerometer");
276                         accel_minus_value.setToolTipText("No accelerometer");
277                 }
278         }
279
280         void set_beep_tool_tip() {
281                 if (beep_value.isVisible())
282                         beep_value.setToolTipText("What frequency the beeper will sound at");
283                 else
284                         beep_value.setToolTipText("Older firmware could not select beeper frequency");
285         }
286
287         /* Build the UI using a grid bag */
288         public AltosConfigFCUI(JFrame in_owner, boolean remote) {
289                 super (in_owner, "Configure Flight Computer", false);
290
291                 owner = in_owner;
292                 GridBagConstraints c;
293                 int row = 0;
294
295                 Insets il = new Insets(4,4,4,4);
296                 Insets ir = new Insets(4,4,4,4);
297
298                 pane = getContentPane();
299                 pane.setLayout(new GridBagLayout());
300
301                 /* Product */
302                 c = new GridBagConstraints();
303                 c.gridx = 0; c.gridy = row;
304                 c.gridwidth = 4;
305                 c.fill = GridBagConstraints.NONE;
306                 c.anchor = GridBagConstraints.LINE_START;
307                 c.insets = il;
308                 product_label = new JLabel("Product:");
309                 pane.add(product_label, c);
310
311                 c = new GridBagConstraints();
312                 c.gridx = 4; c.gridy = row;
313                 c.gridwidth = 4;
314                 c.fill = GridBagConstraints.HORIZONTAL;
315                 c.weightx = 1;
316                 c.anchor = GridBagConstraints.LINE_START;
317                 c.insets = ir;
318                 product_value = new JLabel("");
319                 pane.add(product_value, c);
320                 row++;
321
322                 /* Version */
323                 c = new GridBagConstraints();
324                 c.gridx = 0; c.gridy = row;
325                 c.gridwidth = 4;
326                 c.fill = GridBagConstraints.NONE;
327                 c.anchor = GridBagConstraints.LINE_START;
328                 c.insets = il;
329                 c.ipady = 5;
330                 version_label = new JLabel("Software version:");
331                 pane.add(version_label, c);
332
333                 c = new GridBagConstraints();
334                 c.gridx = 4; c.gridy = row;
335                 c.gridwidth = 4;
336                 c.fill = GridBagConstraints.HORIZONTAL;
337                 c.weightx = 1;
338                 c.anchor = GridBagConstraints.LINE_START;
339                 c.insets = ir;
340                 c.ipady = 5;
341                 version_value = new JLabel("");
342                 pane.add(version_value, c);
343                 row++;
344
345                 /* Serial */
346                 c = new GridBagConstraints();
347                 c.gridx = 0; c.gridy = row;
348                 c.gridwidth = 4;
349                 c.fill = GridBagConstraints.NONE;
350                 c.anchor = GridBagConstraints.LINE_START;
351                 c.insets = il;
352                 c.ipady = 5;
353                 serial_label = new JLabel("Serial:");
354                 pane.add(serial_label, c);
355
356                 c = new GridBagConstraints();
357                 c.gridx = 4; c.gridy = row;
358                 c.gridwidth = 4;
359                 c.fill = GridBagConstraints.HORIZONTAL;
360                 c.weightx = 1;
361                 c.anchor = GridBagConstraints.LINE_START;
362                 c.insets = ir;
363                 c.ipady = 5;
364                 serial_value = new JLabel("");
365                 pane.add(serial_value, c);
366                 row++;
367
368                 /* Main deploy */
369                 c = new GridBagConstraints();
370                 c.gridx = 0; c.gridy = row;
371                 c.gridwidth = 4;
372                 c.fill = GridBagConstraints.NONE;
373                 c.anchor = GridBagConstraints.LINE_START;
374                 c.insets = il;
375                 c.ipady = 5;
376                 main_deploy_label = new JLabel(get_main_deploy_label());
377                 pane.add(main_deploy_label, c);
378
379                 c = new GridBagConstraints();
380                 c.gridx = 4; c.gridy = row;
381                 c.gridwidth = 4;
382                 c.fill = GridBagConstraints.HORIZONTAL;
383                 c.weightx = 1;
384                 c.anchor = GridBagConstraints.LINE_START;
385                 c.insets = ir;
386                 c.ipady = 5;
387                 main_deploy_value = new JComboBox<String>(main_deploy_values());
388                 main_deploy_value.setEditable(true);
389                 main_deploy_value.addItemListener(this);
390                 pane.add(main_deploy_value, c);
391                 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
392                 row++;
393
394                 /* Apogee delay */
395                 c = new GridBagConstraints();
396                 c.gridx = 0; c.gridy = row;
397                 c.gridwidth = 4;
398                 c.fill = GridBagConstraints.NONE;
399                 c.anchor = GridBagConstraints.LINE_START;
400                 c.insets = il;
401                 c.ipady = 5;
402                 apogee_delay_label = new JLabel("Apogee Delay(s):");
403                 pane.add(apogee_delay_label, c);
404
405                 c = new GridBagConstraints();
406                 c.gridx = 4; c.gridy = row;
407                 c.gridwidth = 4;
408                 c.fill = GridBagConstraints.HORIZONTAL;
409                 c.weightx = 1;
410                 c.anchor = GridBagConstraints.LINE_START;
411                 c.insets = ir;
412                 c.ipady = 5;
413                 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
414                 apogee_delay_value.setEditable(true);
415                 apogee_delay_value.addItemListener(this);
416                 pane.add(apogee_delay_value, c);
417                 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
418                 row++;
419
420                 /* Apogee lockout */
421                 c = new GridBagConstraints();
422                 c.gridx = 0; c.gridy = row;
423                 c.gridwidth = 4;
424                 c.fill = GridBagConstraints.NONE;
425                 c.anchor = GridBagConstraints.LINE_START;
426                 c.insets = il;
427                 c.ipady = 5;
428                 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
429                 pane.add(apogee_lockout_label, c);
430
431                 c = new GridBagConstraints();
432                 c.gridx = 4; c.gridy = row;
433                 c.gridwidth = 4;
434                 c.fill = GridBagConstraints.HORIZONTAL;
435                 c.weightx = 1;
436                 c.anchor = GridBagConstraints.LINE_START;
437                 c.insets = ir;
438                 c.ipady = 5;
439                 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
440                 apogee_lockout_value.setEditable(true);
441                 apogee_lockout_value.addItemListener(this);
442                 pane.add(apogee_lockout_value, c);
443                 apogee_lockout_value.setToolTipText("Time after launch while apogee detection is locked out");
444                 row++;
445
446                 /* Frequency */
447                 c = new GridBagConstraints();
448                 c.gridx = 0; c.gridy = row;
449                 c.gridwidth = 4;
450                 c.fill = GridBagConstraints.NONE;
451                 c.anchor = GridBagConstraints.LINE_START;
452                 c.insets = il;
453                 c.ipady = 5;
454                 radio_frequency_label = new JLabel("Frequency:");
455                 pane.add(radio_frequency_label, c);
456
457                 c = new GridBagConstraints();
458                 c.gridx = 4; c.gridy = row;
459                 c.gridwidth = 4;
460                 c.fill = GridBagConstraints.HORIZONTAL;
461                 c.weightx = 1;
462                 c.anchor = GridBagConstraints.LINE_START;
463                 c.insets = ir;
464                 c.ipady = 5;
465                 radio_frequency_value = new AltosUIFreqList();
466                 radio_frequency_value.addItemListener(this);
467                 pane.add(radio_frequency_value, c);
468                 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
469                 row++;
470
471                 /* Radio Calibration */
472                 c = new GridBagConstraints();
473                 c.gridx = 0; c.gridy = row;
474                 c.gridwidth = 4;
475                 c.fill = GridBagConstraints.NONE;
476                 c.anchor = GridBagConstraints.LINE_START;
477                 c.insets = il;
478                 c.ipady = 5;
479                 radio_calibration_label = new JLabel("RF Calibration:");
480                 pane.add(radio_calibration_label, c);
481
482                 c = new GridBagConstraints();
483                 c.gridx = 4; c.gridy = row;
484                 c.gridwidth = 4;
485                 c.fill = GridBagConstraints.HORIZONTAL;
486                 c.weightx = 1;
487                 c.anchor = GridBagConstraints.LINE_START;
488                 c.insets = ir;
489                 c.ipady = 5;
490                 radio_calibration_value = new JLabel(String.format("%d", 1186611));
491                 pane.add(radio_calibration_value, c);
492                 row++;
493
494                 /* Radio Enable */
495                 c = new GridBagConstraints();
496                 c.gridx = 0; c.gridy = row;
497                 c.gridwidth = 4;
498                 c.fill = GridBagConstraints.NONE;
499                 c.anchor = GridBagConstraints.LINE_START;
500                 c.insets = il;
501                 c.ipady = 5;
502                 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
503                 pane.add(radio_enable_label, c);
504
505                 c = new GridBagConstraints();
506                 c.gridx = 4; c.gridy = row;
507                 c.gridwidth = 4;
508                 c.fill = GridBagConstraints.HORIZONTAL;
509                 c.weightx = 1;
510                 c.anchor = GridBagConstraints.LINE_START;
511                 c.insets = ir;
512                 c.ipady = 5;
513                 radio_enable_value = new JRadioButton("Enabled");
514                 radio_enable_value.addItemListener(this);
515                 pane.add(radio_enable_value, c);
516                 set_radio_enable_tool_tip();
517                 row++;
518
519                 /* Telemetry Rate */
520                 c = new GridBagConstraints();
521                 c.gridx = 0; c.gridy = row;
522                 c.gridwidth = 4;
523                 c.fill = GridBagConstraints.NONE;
524                 c.anchor = GridBagConstraints.LINE_START;
525                 c.insets = il;
526                 c.ipady = 5;
527                 rate_label = new JLabel("Telemetry baud rate:");
528                 pane.add(rate_label, c);
529
530                 c = new GridBagConstraints();
531                 c.gridx = 4; c.gridy = row;
532                 c.gridwidth = 4;
533                 c.fill = GridBagConstraints.HORIZONTAL;
534                 c.weightx = 1;
535                 c.anchor = GridBagConstraints.LINE_START;
536                 c.insets = ir;
537                 c.ipady = 5;
538                 rate_value = new AltosUIRateList();
539                 rate_value.addItemListener(this);
540                 pane.add(rate_value, c);
541                 set_rate_tool_tip();
542                 row++;
543
544                 /* APRS interval */
545                 c = new GridBagConstraints();
546                 c.gridx = 0; c.gridy = row;
547                 c.gridwidth = 4;
548                 c.fill = GridBagConstraints.NONE;
549                 c.anchor = GridBagConstraints.LINE_START;
550                 c.insets = il;
551                 c.ipady = 5;
552                 aprs_interval_label = new JLabel("APRS Interval(s):");
553                 pane.add(aprs_interval_label, c);
554
555                 c = new GridBagConstraints();
556                 c.gridx = 4; c.gridy = row;
557                 c.gridwidth = 4;
558                 c.fill = GridBagConstraints.HORIZONTAL;
559                 c.weightx = 1;
560                 c.anchor = GridBagConstraints.LINE_START;
561                 c.insets = ir;
562                 c.ipady = 5;
563                 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
564                 aprs_interval_value.setEditable(true);
565                 aprs_interval_value.addItemListener(this);
566                 pane.add(aprs_interval_value, c);
567                 set_aprs_interval_tool_tip();
568                 row++;
569
570                 /* APRS SSID */
571                 c = new GridBagConstraints();
572                 c.gridx = 0; c.gridy = row;
573                 c.gridwidth = 4;
574                 c.fill = GridBagConstraints.NONE;
575                 c.anchor = GridBagConstraints.LINE_START;
576                 c.insets = il;
577                 c.ipady = 5;
578                 aprs_ssid_label = new JLabel("APRS SSID:");
579                 pane.add(aprs_ssid_label, c);
580
581                 c = new GridBagConstraints();
582                 c.gridx = 4; c.gridy = row;
583                 c.gridwidth = 4;
584                 c.fill = GridBagConstraints.HORIZONTAL;
585                 c.weightx = 1;
586                 c.anchor = GridBagConstraints.LINE_START;
587                 c.insets = ir;
588                 c.ipady = 5;
589                 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
590                 aprs_ssid_value.setEditable(false);
591                 aprs_ssid_value.addItemListener(this);
592                 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
593                 pane.add(aprs_ssid_value, c);
594                 set_aprs_ssid_tool_tip();
595                 row++;
596
597                 /* APRS format */
598                 c = new GridBagConstraints();
599                 c.gridx = 0; c.gridy = row;
600                 c.gridwidth = 4;
601                 c.fill = GridBagConstraints.NONE;
602                 c.anchor = GridBagConstraints.LINE_START;
603                 c.insets = il;
604                 c.ipady = 5;
605                 aprs_format_label = new JLabel("APRS format:");
606                 pane.add(aprs_format_label, c);
607
608                 c = new GridBagConstraints();
609                 c.gridx = 4; c.gridy = row;
610                 c.gridwidth = 4;
611                 c.fill = GridBagConstraints.HORIZONTAL;
612                 c.weightx = 1;
613                 c.anchor = GridBagConstraints.LINE_START;
614                 c.insets = ir;
615                 c.ipady = 5;
616                 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
617                 aprs_format_value.setEditable(false);
618                 aprs_format_value.addItemListener(this);
619                 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
620                 pane.add(aprs_format_value, c);
621                 set_aprs_format_tool_tip();
622                 row++;
623
624                 /* Callsign */
625                 c = new GridBagConstraints();
626                 c.gridx = 0; c.gridy = row;
627                 c.gridwidth = 4;
628                 c.fill = GridBagConstraints.NONE;
629                 c.anchor = GridBagConstraints.LINE_START;
630                 c.insets = il;
631                 c.ipady = 5;
632                 callsign_label = new JLabel("Callsign:");
633                 pane.add(callsign_label, c);
634
635                 c = new GridBagConstraints();
636                 c.gridx = 4; c.gridy = row;
637                 c.gridwidth = 4;
638                 c.fill = GridBagConstraints.HORIZONTAL;
639                 c.weightx = 1;
640                 c.anchor = GridBagConstraints.LINE_START;
641                 c.insets = ir;
642                 c.ipady = 5;
643                 callsign_value = new JTextField(AltosUIPreferences.callsign());
644                 callsign_value.getDocument().addDocumentListener(this);
645                 pane.add(callsign_value, c);
646                 callsign_value.setToolTipText("Callsign reported in telemetry data");
647                 row++;
648
649                 /* Flight log max */
650                 c = new GridBagConstraints();
651                 c.gridx = 0; c.gridy = row;
652                 c.gridwidth = 4;
653                 c.fill = GridBagConstraints.NONE;
654                 c.anchor = GridBagConstraints.LINE_START;
655                 c.insets = il;
656                 c.ipady = 5;
657                 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
658                 pane.add(flight_log_max_label, c);
659
660                 c = new GridBagConstraints();
661                 c.gridx = 4; c.gridy = row;
662                 c.gridwidth = 4;
663                 c.fill = GridBagConstraints.HORIZONTAL;
664                 c.weightx = 1;
665                 c.anchor = GridBagConstraints.LINE_START;
666                 c.insets = ir;
667                 c.ipady = 5;
668                 flight_log_max_value = new JComboBox<String>();
669                 flight_log_max_value.setEditable(true);
670                 flight_log_max_value.addItemListener(this);
671                 pane.add(flight_log_max_value, c);
672                 set_flight_log_max_tool_tip();
673                 row++;
674
675                 /* Ignite mode */
676                 c = new GridBagConstraints();
677                 c.gridx = 0; c.gridy = row;
678                 c.gridwidth = 4;
679                 c.fill = GridBagConstraints.NONE;
680                 c.anchor = GridBagConstraints.LINE_START;
681                 c.insets = il;
682                 c.ipady = 5;
683                 ignite_mode_label = new JLabel("Igniter Firing Mode:");
684                 pane.add(ignite_mode_label, c);
685
686                 c = new GridBagConstraints();
687                 c.gridx = 4; c.gridy = row;
688                 c.gridwidth = 4;
689                 c.fill = GridBagConstraints.HORIZONTAL;
690                 c.weightx = 1;
691                 c.anchor = GridBagConstraints.LINE_START;
692                 c.insets = ir;
693                 c.ipady = 5;
694                 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
695                 ignite_mode_value.setEditable(false);
696                 ignite_mode_value.addItemListener(this);
697                 pane.add(ignite_mode_value, c);
698                 set_ignite_mode_tool_tip();
699                 row++;
700
701                 /* Pad orientation */
702                 c = new GridBagConstraints();
703                 c.gridx = 0; c.gridy = row;
704                 c.gridwidth = 4;
705                 c.fill = GridBagConstraints.NONE;
706                 c.anchor = GridBagConstraints.LINE_START;
707                 c.insets = il;
708                 c.ipady = 5;
709                 pad_orientation_label = new JLabel("Pad Orientation:");
710                 pane.add(pad_orientation_label, c);
711
712                 c = new GridBagConstraints();
713                 c.gridx = 4; c.gridy = row;
714                 c.gridwidth = 4;
715                 c.fill = GridBagConstraints.HORIZONTAL;
716                 c.weightx = 1;
717                 c.anchor = GridBagConstraints.LINE_START;
718                 c.insets = ir;
719                 c.ipady = 5;
720                 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
721                 pad_orientation_value.setEditable(false);
722                 pad_orientation_value.addItemListener(this);
723                 pane.add(pad_orientation_value, c);
724                 set_pad_orientation_tool_tip();
725                 row++;
726
727                 /* Accel plus */
728                 c = new GridBagConstraints();
729                 c.gridx = 0; c.gridy = row;
730                 c.gridwidth = 4;
731                 c.fill = GridBagConstraints.NONE;
732                 c.anchor = GridBagConstraints.LINE_START;
733                 c.insets = il;
734                 c.ipady = 5;
735                 accel_plus_label = new JLabel("Accel Plus:");
736                 pane.add(accel_plus_label, c);
737
738                 c = new GridBagConstraints();
739                 c.gridx = 4; c.gridy = row;
740                 c.gridwidth = 4;
741                 c.fill = GridBagConstraints.HORIZONTAL;
742                 c.weightx = 1;
743                 c.anchor = GridBagConstraints.LINE_START;
744                 c.insets = ir;
745                 c.ipady = 5;
746                 accel_plus_value = new JTextField(10);
747                 accel_plus_value.setEditable(true);
748                 accel_plus_value.getDocument().addDocumentListener(this);
749                 pane.add(accel_plus_value, c);
750                 row++;
751
752                 /* Accel minus */
753                 c = new GridBagConstraints();
754                 c.gridx = 0; c.gridy = row;
755                 c.gridwidth = 4;
756                 c.fill = GridBagConstraints.NONE;
757                 c.anchor = GridBagConstraints.LINE_START;
758                 c.insets = il;
759                 c.ipady = 5;
760                 accel_minus_label = new JLabel("Accel Minus:");
761                 pane.add(accel_minus_label, c);
762
763                 c = new GridBagConstraints();
764                 c.gridx = 4; c.gridy = row;
765                 c.gridwidth = 4;
766                 c.fill = GridBagConstraints.HORIZONTAL;
767                 c.weightx = 1;
768                 c.anchor = GridBagConstraints.LINE_START;
769                 c.insets = ir;
770                 c.ipady = 5;
771                 accel_minus_value = new JTextField(10);
772                 accel_minus_value.setEditable(true);
773                 accel_minus_value.getDocument().addDocumentListener(this);
774                 pane.add(accel_minus_value, c);
775                 row++;
776                 set_accel_tool_tips();
777
778                 /* Beeper */
779                 c = new GridBagConstraints();
780                 c.gridx = 0; c.gridy = row;
781                 c.gridwidth = 4;
782                 c.fill = GridBagConstraints.NONE;
783                 c.anchor = GridBagConstraints.LINE_START;
784                 c.insets = il;
785                 c.ipady = 5;
786                 beep_label = new JLabel("Beeper Frequency:");
787                 pane.add(beep_label, c);
788
789                 c = new GridBagConstraints();
790                 c.gridx = 4; c.gridy = row;
791                 c.gridwidth = 4;
792                 c.fill = GridBagConstraints.HORIZONTAL;
793                 c.weightx = 1;
794                 c.anchor = GridBagConstraints.LINE_START;
795                 c.insets = ir;
796                 c.ipady = 5;
797                 beep_value = new JComboBox<String>(beep_values);
798                 beep_value.setEditable(true);
799                 beep_value.addItemListener(this);
800                 pane.add(beep_value, c);
801                 set_beep_tool_tip();
802                 row++;
803
804                 /* Tracker triger horiz distances */
805                 c = new GridBagConstraints();
806                 c.gridx = 0; c.gridy = row;
807                 c.gridwidth = 4;
808                 c.fill = GridBagConstraints.NONE;
809                 c.anchor = GridBagConstraints.LINE_START;
810                 c.insets = il;
811                 c.ipady = 5;
812                 tracker_motion_label = new JLabel(get_tracker_motion_label());
813                 pane.add(tracker_motion_label, c);
814
815                 c = new GridBagConstraints();
816                 c.gridx = 4; c.gridy = row;
817                 c.gridwidth = 4;
818                 c.fill = GridBagConstraints.HORIZONTAL;
819                 c.weightx = 1;
820                 c.anchor = GridBagConstraints.LINE_START;
821                 c.insets = ir;
822                 c.ipady = 5;
823                 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
824                 tracker_motion_value.setEditable(true);
825                 tracker_motion_value.addItemListener(this);
826                 pane.add(tracker_motion_value, c);
827                 row++;
828
829                 /* Tracker triger vert distances */
830                 c = new GridBagConstraints();
831                 c.gridx = 0; c.gridy = row;
832                 c.gridwidth = 4;
833                 c.fill = GridBagConstraints.NONE;
834                 c.anchor = GridBagConstraints.LINE_START;
835                 c.insets = il;
836                 c.ipady = 5;
837                 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
838                 pane.add(tracker_interval_label, c);
839
840                 c = new GridBagConstraints();
841                 c.gridx = 4; c.gridy = row;
842                 c.gridwidth = 4;
843                 c.fill = GridBagConstraints.HORIZONTAL;
844                 c.weightx = 1;
845                 c.anchor = GridBagConstraints.LINE_START;
846                 c.insets = ir;
847                 c.ipady = 5;
848                 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
849                 tracker_interval_value.setEditable(true);
850                 tracker_interval_value.addItemListener(this);
851                 pane.add(tracker_interval_value, c);
852                 set_tracker_tool_tip();
853                 row++;
854
855                 /* Pyro channels */
856                 c = new GridBagConstraints();
857                 c.gridx = 4; c.gridy = row;
858                 c.gridwidth = 4;
859                 c.fill = GridBagConstraints.HORIZONTAL;
860                 c.anchor = GridBagConstraints.LINE_START;
861                 c.insets = il;
862                 c.ipady = 5;
863                 pyro = new JButton("Configure Pyro Channels");
864                 pane.add(pyro, c);
865                 pyro.addActionListener(this);
866                 pyro.setActionCommand("Pyro");
867                 row++;
868
869                 /* Accel cal */
870                 c = new GridBagConstraints();
871                 c.gridx = 5; c.gridy = row;
872                 c.gridwidth = 5;
873                 c.fill = GridBagConstraints.HORIZONTAL;
874                 c.anchor = GridBagConstraints.LINE_START;
875                 c.insets = il;
876                 c.ipady = 5;
877                 accel_cal = new JButton("Calibrate Accelerometer");
878                 pane.add(accel_cal, c);
879                 accel_cal.addActionListener(this);
880                 accel_cal.setActionCommand("Accel");
881                 row++;
882
883                 /* Buttons */
884                 c = new GridBagConstraints();
885                 c.gridx = 0; c.gridy = row;
886                 c.gridwidth = 2;
887                 c.fill = GridBagConstraints.NONE;
888                 c.anchor = GridBagConstraints.LINE_START;
889                 c.insets = il;
890                 save = new JButton("Save");
891                 pane.add(save, c);
892                 save.addActionListener(this);
893                 save.setActionCommand("Save");
894
895                 c = new GridBagConstraints();
896                 c.gridx = 2; c.gridy = row;
897                 c.gridwidth = 2;
898                 c.fill = GridBagConstraints.NONE;
899                 c.anchor = GridBagConstraints.CENTER;
900                 c.insets = il;
901                 reset = new JButton("Reset");
902                 pane.add(reset, c);
903                 reset.addActionListener(this);
904                 reset.setActionCommand("Reset");
905
906                 c = new GridBagConstraints();
907                 c.gridx = 4; c.gridy = row;
908                 c.gridwidth = 2;
909                 c.fill = GridBagConstraints.NONE;
910                 c.anchor = GridBagConstraints.CENTER;
911                 c.insets = il;
912                 reboot = new JButton("Reboot");
913                 pane.add(reboot, c);
914                 reboot.addActionListener(this);
915                 reboot.setActionCommand("Reboot");
916
917                 c = new GridBagConstraints();
918                 c.gridx = 6; c.gridy = row;
919                 c.gridwidth = 2;
920                 c.fill = GridBagConstraints.NONE;
921                 c.anchor = GridBagConstraints.LINE_END;
922                 c.insets = il;
923                 close = new JButton("Close");
924                 pane.add(close, c);
925                 close.addActionListener(this);
926                 close.setActionCommand("Close");
927
928                 addWindowListener(new ConfigListener(this));
929                 AltosPreferences.register_units_listener(this);
930         }
931
932         /* Once the initial values are set, the config code will show the dialog */
933         public void make_visible() {
934                 pack();
935                 setLocationRelativeTo(owner);
936                 setVisible(true);
937         }
938
939         /* If any values have been changed, confirm before closing */
940         public boolean check_dirty(String operation) {
941                 if (dirty) {
942                         Object[] options = { String.format("%s anyway", operation), "Keep editing" };
943                         int i;
944                         i = JOptionPane.showOptionDialog(this,
945                                                          String.format("Configuration modified. %s anyway?", operation),
946                                                          "Configuration Modified",
947                                                          JOptionPane.DEFAULT_OPTION,
948                                                          JOptionPane.WARNING_MESSAGE,
949                                                          null, options, options[1]);
950                         if (i != 0)
951                                 return false;
952                 }
953                 return true;
954         }
955
956         public void set_dirty() {
957                 dirty = true;
958                 save.setEnabled(true);
959         }
960
961         public void set_clean() {
962                 dirty = false;
963                 save.setEnabled(false);
964         }
965
966         AltosConfigPyroUI       pyro_ui;
967
968         public void dispose() {
969                 if (pyro_ui != null)
970                         pyro_ui.dispose();
971                 AltosPreferences.unregister_units_listener(this);
972                 super.dispose();
973         }
974
975         /* Listen for events from our buttons */
976         public void actionPerformed(ActionEvent e) {
977                 String  cmd = e.getActionCommand();
978
979                 if (cmd.equals("Pyro")) {
980                         if (pyro_ui == null && pyros != null)
981                                 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
982                         if (pyro_ui != null)
983                                 pyro_ui.make_visible();
984                         return;
985                 }
986
987                 if (cmd.equals("Close") || cmd.equals("Reboot"))
988                         if (!check_dirty(cmd))
989                                 return;
990                 listener.actionPerformed(e);
991                 if (cmd.equals("Close") || cmd.equals("Reboot")) {
992                         setVisible(false);
993                         dispose();
994                 }
995                 if (cmd.equals("Save") || cmd.equals("Reset"))
996                         set_clean();
997         }
998
999         /* ItemListener interface method */
1000         public void itemStateChanged(ItemEvent e) {
1001                 set_dirty();
1002         }
1003
1004         /* DocumentListener interface methods */
1005         public void changedUpdate(DocumentEvent e) {
1006                 set_dirty();
1007         }
1008
1009         public void insertUpdate(DocumentEvent e) {
1010                 set_dirty();
1011         }
1012
1013         public void removeUpdate(DocumentEvent e) {
1014                 set_dirty();
1015         }
1016
1017         /* Let the config code hook on a listener */
1018         public void addActionListener(ActionListener l) {
1019                 listener = l;
1020         }
1021
1022         /* set and get all of the dialog values */
1023         public void set_product(String product) {
1024                 radio_frequency_value.set_product(product);
1025                 product_value.setText(product);
1026                 set_pad_orientation_tool_tip();
1027                 set_accel_tool_tips();
1028                 set_flight_log_max_tool_tip();
1029         }
1030
1031         public void set_version(String version) {
1032                 version_value.setText(version);
1033         }
1034
1035         public void set_serial(int serial) {
1036                 radio_frequency_value.set_serial(serial);
1037                 serial_value.setText(String.format("%d", serial));
1038         }
1039
1040         public void set_altitude_32(int altitude_32) {
1041         }
1042
1043         public void set_main_deploy(int new_main_deploy) {
1044                 if (new_main_deploy != AltosLib.MISSING)
1045                         main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
1046                 main_deploy_value.setVisible(new_main_deploy != AltosLib.MISSING);
1047                 main_deploy_label.setVisible(new_main_deploy != AltosLib.MISSING);
1048         }
1049
1050         public int main_deploy() throws AltosConfigDataException {
1051                 String  str = main_deploy_value.getSelectedItem().toString();
1052                 try {
1053                         return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1054                 } catch (ParseException pe) {
1055                         throw new AltosConfigDataException("invalid main deploy height %s", str);
1056                 }
1057         }
1058
1059         String get_main_deploy_label() {
1060                 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.parse_units());
1061         }
1062
1063         String[] main_deploy_values() {
1064                 if (AltosConvert.imperial_units)
1065                         return main_deploy_values_ft;
1066                 else
1067                         return main_deploy_values_m;
1068         }
1069
1070         void set_main_deploy_values() {
1071                 String[]        v = main_deploy_values();
1072                 while (main_deploy_value.getItemCount() > 0)
1073                         main_deploy_value.removeItemAt(0);
1074                 for (int i = 0; i < v.length; i++)
1075                         main_deploy_value.addItem(v[i]);
1076                 main_deploy_value.setMaximumRowCount(v.length);
1077         }
1078
1079         public void units_changed(boolean imperial_units) {
1080                 boolean was_dirty = dirty;
1081
1082                 String v = main_deploy_value.getSelectedItem().toString();
1083                 main_deploy_label.setText(get_main_deploy_label());
1084                 set_main_deploy_values();
1085                 try {
1086                         int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1087                         set_main_deploy(m);
1088                 } catch (ParseException pe) {
1089                 }
1090
1091                 if (tracker_motion_value.isVisible()) {
1092                         String motion = tracker_motion_value.getSelectedItem().toString();
1093                         tracker_motion_label.setText(get_tracker_motion_label());
1094                         set_tracker_motion_values();
1095                         try {
1096                                 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1097                                 set_tracker_motion(m);
1098                         } catch (ParseException pe) {
1099                         }
1100                 }
1101
1102                 if (!was_dirty)
1103                         set_clean();
1104         }
1105
1106         public void set_apogee_delay(int new_apogee_delay) {
1107                 if (new_apogee_delay != AltosLib.MISSING)
1108                         apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1109                 apogee_delay_value.setVisible(new_apogee_delay != AltosLib.MISSING);
1110                 apogee_delay_label.setVisible(new_apogee_delay != AltosLib.MISSING);
1111         }
1112
1113         private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1114                 String v = s;
1115                 if (split)
1116                         v = s.split("\\s+")[0];
1117                 try {
1118                         return Integer.parseInt(v);
1119                 } catch (NumberFormatException ne) {
1120                         throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1121                 }
1122         }
1123
1124         public int apogee_delay() throws AltosConfigDataException {
1125                 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1126         }
1127
1128         public void set_apogee_lockout(int new_apogee_lockout) {
1129                 if (new_apogee_lockout != AltosLib.MISSING)
1130                         apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1131
1132                 apogee_lockout_value.setVisible(new_apogee_lockout != AltosLib.MISSING);
1133                 apogee_lockout_label.setVisible(new_apogee_lockout != AltosLib.MISSING);
1134         }
1135
1136         public int apogee_lockout() throws AltosConfigDataException {
1137                 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1138         }
1139
1140         public void set_radio_frequency(double new_radio_frequency) {
1141                 if (new_radio_frequency != AltosLib.MISSING)
1142                         radio_frequency_value.set_frequency(new_radio_frequency);
1143                 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
1144                 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
1145         }
1146
1147         public double radio_frequency() {
1148                 return radio_frequency_value.frequency();
1149         }
1150
1151         public void set_radio_calibration(int new_radio_calibration) {
1152                 if (new_radio_calibration != AltosLib.MISSING)
1153                         radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1154                 radio_calibration_value.setVisible(new_radio_calibration != AltosLib.MISSING);
1155                 radio_calibration_label.setVisible(new_radio_calibration != AltosLib.MISSING);
1156         }
1157
1158         public void set_radio_enable(int new_radio_enable) {
1159                 if (new_radio_enable != AltosLib.MISSING)
1160                         radio_enable_value.setSelected(new_radio_enable != 0);
1161                 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
1162                 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
1163                 set_radio_enable_tool_tip();
1164         }
1165
1166         public int radio_enable() {
1167                 if (radio_enable_value.isVisible())
1168                         return radio_enable_value.isSelected() ? 1 : 0;
1169                 else
1170                         return AltosLib.MISSING;
1171         }
1172
1173         public void set_telemetry_rate(int new_rate) {
1174                 if (new_rate != AltosLib.MISSING)
1175                         rate_value.set_rate(new_rate);
1176                 rate_label.setVisible(new_rate != AltosLib.MISSING);
1177                 rate_value.setVisible(new_rate != AltosLib.MISSING);
1178                 set_rate_tool_tip();
1179         }
1180
1181         public int telemetry_rate() {
1182                 return rate_value.rate();
1183         }
1184
1185         public void set_callsign(String new_callsign) {
1186                 if (new_callsign != null)
1187                         callsign_value.setText(new_callsign);
1188                 callsign_value.setVisible(new_callsign != null);
1189                 callsign_label.setVisible(new_callsign != null);
1190         }
1191
1192         public String callsign() {
1193                 if (callsign_value.isVisible())
1194                         return callsign_value.getText();
1195                 return null;
1196         }
1197
1198         int     flight_log_max_limit;
1199         int     flight_log_max;
1200
1201         public String flight_log_max_label(int flight_log_max) {
1202                 if (flight_log_max_limit != 0) {
1203                         int     nflight = flight_log_max_limit / flight_log_max;
1204                         String  plural = nflight > 1 ? "s" : "";
1205
1206                         return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1207                 }
1208                 return String.format("%d", flight_log_max);
1209         }
1210
1211         public void set_flight_log_max(int new_flight_log_max) {
1212                 if (new_flight_log_max != AltosLib.MISSING) {
1213                         flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1214                         flight_log_max = new_flight_log_max;
1215                 }
1216                 flight_log_max_value.setVisible(new_flight_log_max != AltosLib.MISSING);
1217                 flight_log_max_label.setVisible(new_flight_log_max != AltosLib.MISSING);
1218                 set_flight_log_max_tool_tip();
1219         }
1220
1221         public void set_flight_log_max_enabled(boolean enable) {
1222                 flight_log_max_value.setEnabled(enable);
1223                 set_flight_log_max_tool_tip();
1224         }
1225
1226         public int flight_log_max() throws AltosConfigDataException {
1227                 if (flight_log_max_value.isVisible())
1228                         return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1229                 return AltosLib.MISSING;
1230         }
1231
1232         public void set_flight_log_max_limit(int new_flight_log_max_limit) {
1233                 flight_log_max_limit = new_flight_log_max_limit;
1234                 if (new_flight_log_max_limit != AltosLib.MISSING) {
1235                         flight_log_max_value.removeAllItems();
1236                         for (int i = 8; i >= 1; i--) {
1237                                 int     size = flight_log_max_limit / i;
1238                                 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1239                         }
1240                 }
1241                 if (flight_log_max != 0)
1242                         set_flight_log_max(flight_log_max);
1243         }
1244
1245         public void set_ignite_mode(int new_ignite_mode) {
1246                 if (new_ignite_mode != AltosLib.MISSING) {
1247                         if (new_ignite_mode >= ignite_mode_values.length)
1248                                 new_ignite_mode = 0;
1249                         if (new_ignite_mode < 0) {
1250                                 ignite_mode_value.setEnabled(false);
1251                                 new_ignite_mode = 0;
1252                         } else {
1253                                 ignite_mode_value.setEnabled(true);
1254                         }
1255                         ignite_mode_value.setSelectedIndex(new_ignite_mode);
1256                 }
1257                 ignite_mode_value.setVisible(new_ignite_mode != AltosLib.MISSING);
1258                 ignite_mode_label.setVisible(new_ignite_mode != AltosLib.MISSING);
1259
1260                 set_ignite_mode_tool_tip();
1261         }
1262
1263         public int ignite_mode() {
1264                 if (ignite_mode_value.isVisible())
1265                         return ignite_mode_value.getSelectedIndex();
1266                 else
1267                         return AltosLib.MISSING;
1268         }
1269
1270
1271         public void set_pad_orientation(int new_pad_orientation) {
1272                 if (new_pad_orientation != AltosLib.MISSING) {
1273                         if (new_pad_orientation >= pad_orientation_values.length)
1274                                 new_pad_orientation = 0;
1275                         if (new_pad_orientation < 0)
1276                                 new_pad_orientation = 0;
1277                         pad_orientation_value.setSelectedIndex(new_pad_orientation);
1278                 }
1279                 pad_orientation_value.setVisible(new_pad_orientation != AltosLib.MISSING);
1280                 pad_orientation_label.setVisible(new_pad_orientation != AltosLib.MISSING);
1281                 accel_cal.setVisible(new_pad_orientation != AltosLib.MISSING);
1282
1283                 set_pad_orientation_tool_tip();
1284         }
1285
1286         public int pad_orientation() {
1287                 if (pad_orientation_value.isVisible())
1288                         return pad_orientation_value.getSelectedIndex();
1289                 else
1290                         return AltosLib.MISSING;
1291         }
1292
1293         public void set_accel_cal(int accel_plus, int accel_minus) {
1294                 if (accel_plus != AltosLib.MISSING) {
1295                         accel_plus_value.setText(String.format("%d", accel_plus));
1296                         accel_minus_value.setText(String.format("%d", accel_minus));
1297                 }
1298                 accel_plus_value.setVisible(accel_plus != AltosLib.MISSING);
1299                 accel_plus_label.setVisible(accel_plus != AltosLib.MISSING);
1300                 accel_minus_value.setVisible(accel_minus != AltosLib.MISSING);
1301                 accel_minus_label.setVisible(accel_minus != AltosLib.MISSING);
1302
1303                 set_accel_tool_tips();
1304         }
1305
1306         public int accel_cal_plus() {
1307                 if (accel_plus_value.isVisible())
1308                         return Integer.parseInt(accel_plus_value.getText());
1309                 return AltosLib.MISSING;
1310         }
1311
1312         public int accel_cal_minus() {
1313                 if (accel_minus_value.isVisible())
1314                         return Integer.parseInt(accel_minus_value.getText());
1315                 return AltosLib.MISSING;
1316         }
1317
1318         public void set_beep(int new_beep) {
1319                 if (new_beep != AltosLib.MISSING) {
1320                         int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1321                         for (int i = 0; i < beep_values.length; i++)
1322                                 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1323                                         beep_value.setSelectedIndex(i);
1324                                         set_beep_tool_tip();
1325                                         return;
1326                                 }
1327                         beep_value.setSelectedItem(String.format("%d", new_freq));
1328                 }
1329                 beep_value.setVisible(new_beep != AltosLib.MISSING);
1330                 beep_label.setVisible(new_beep != AltosLib.MISSING);
1331                 set_beep_tool_tip();
1332         }
1333
1334         public int beep() {
1335                 if (beep_value.isVisible())
1336                         return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1337                 else
1338                         return AltosLib.MISSING;
1339         }
1340
1341         String[] tracker_motion_values() {
1342                 if (AltosConvert.imperial_units)
1343                         return tracker_motion_values_ft;
1344                 else
1345                         return tracker_motion_values_m;
1346         }
1347
1348         void set_tracker_motion_values() {
1349                 String[]        v = tracker_motion_values();
1350                 while (tracker_motion_value.getItemCount() > 0)
1351                         tracker_motion_value.removeItemAt(0);
1352                 for (int i = 0; i < v.length; i++)
1353                         tracker_motion_value.addItem(v[i]);
1354                 tracker_motion_value.setMaximumRowCount(v.length);
1355         }
1356
1357         String get_tracker_motion_label() {
1358                 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1359         }
1360
1361         void set_tracker_tool_tip() {
1362                 if (tracker_motion_value.isVisible())
1363                         tracker_motion_value.setToolTipText("How far the device must move before logging");
1364                 else
1365                         tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1366                 if (tracker_interval_value.isVisible())
1367                         tracker_interval_value.setToolTipText("How often to report GPS position");
1368                 else
1369                         tracker_interval_value.setToolTipText("This device can't configure interval");
1370         }
1371
1372         public void set_tracker_motion(int tracker_motion) {
1373                 if (tracker_motion != AltosLib.MISSING)
1374                         tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1375                 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1376                 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1377         }
1378
1379         public int tracker_motion() throws AltosConfigDataException {
1380                 if (tracker_motion_value.isVisible()) {
1381                         String str = tracker_motion_value.getSelectedItem().toString();
1382                         try {
1383                                 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1384                         } catch (ParseException pe) {
1385                                 throw new AltosConfigDataException("invalid tracker motion %s", str);
1386                         }
1387                 }
1388                 return AltosLib.MISSING;
1389         }
1390
1391         public void set_tracker_interval(int tracker_interval) {
1392                 if (tracker_interval != AltosLib.MISSING)
1393                         tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1394                 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1395                 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1396         }
1397
1398         public int tracker_interval() throws AltosConfigDataException {
1399                 if (tracker_interval_value.isVisible())
1400                         return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1401                 return AltosLib.MISSING;
1402         }
1403
1404         public void set_pyros(AltosPyro[] new_pyros) {
1405                 pyros = new_pyros;
1406                 if (pyros != null && pyro_ui != null)
1407                         pyro_ui.set_pyros(pyros);
1408                 pyro.setVisible(pyros != null);
1409         }
1410
1411         public AltosPyro[] pyros() throws AltosConfigDataException {
1412                 if (pyro_ui != null)
1413                         pyros = pyro_ui.get_pyros();
1414                 return pyros;
1415         }
1416
1417         public void set_pyro_firing_time(double new_pyro_firing_time) {
1418                 pyro_firing_time = new_pyro_firing_time;
1419                 if (pyro_firing_time != AltosLib.MISSING && pyro_ui != null)
1420                         pyro_ui.set_pyro_firing_time(pyro_firing_time);
1421                 pyro.setVisible(pyro_firing_time != AltosLib.MISSING);
1422         }
1423
1424         public double pyro_firing_time() throws AltosConfigDataException {
1425                 if (pyro_ui != null)
1426                         pyro_firing_time = pyro_ui.get_pyro_firing_time();
1427                 return pyro_firing_time;
1428         }
1429
1430         public void set_aprs_interval(int new_aprs_interval) {
1431                 if (new_aprs_interval != AltosLib.MISSING)
1432                         aprs_interval_value.setSelectedItem(Integer.toString(new_aprs_interval));
1433                 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1434                 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1435                 set_aprs_interval_tool_tip();
1436         }
1437
1438         public int aprs_interval() throws AltosConfigDataException {
1439                 if (aprs_interval_value.isVisible()) {
1440                         String  s = aprs_interval_value.getSelectedItem().toString();
1441
1442                         return parse_int("aprs interval", s, false);
1443                 }
1444                 return AltosLib.MISSING;
1445         }
1446
1447         public void set_aprs_ssid(int new_aprs_ssid) {
1448                 if (new_aprs_ssid != AltosLib.MISSING)
1449                         aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1450                 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1451                 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1452                 set_aprs_ssid_tool_tip();
1453         }
1454
1455         public int aprs_ssid() throws AltosConfigDataException {
1456                 if (aprs_ssid_value.isVisible()) {
1457                         Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1458                         return i;
1459                 }
1460                 return AltosLib.MISSING;
1461         }
1462
1463         public void set_aprs_format(int new_aprs_format) {
1464                 if (new_aprs_format != AltosLib.MISSING)
1465                         aprs_format_value.setSelectedIndex(new_aprs_format);
1466                 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1467                 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1468                 set_aprs_format_tool_tip();
1469         }
1470
1471         public int aprs_format() throws AltosConfigDataException {
1472                 if (aprs_format_value.isVisible())
1473                         return aprs_format_value.getSelectedIndex();
1474                 return AltosLib.MISSING;
1475         }
1476 }