altosui: Accel calibration UI
[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_12.*;
27 import org.altusmetrum.altosuilib_12.*;
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 boost 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                 System.out.printf("set dirty\n");
958                 dirty = true;
959                 save.setEnabled(true);
960         }
961
962         public void set_clean() {
963                 System.out.printf("set clean\n");
964                 dirty = false;
965                 save.setEnabled(false);
966         }
967
968         AltosConfigPyroUI       pyro_ui;
969
970         public void dispose() {
971                 if (pyro_ui != null)
972                         pyro_ui.dispose();
973                 AltosPreferences.unregister_units_listener(this);
974                 super.dispose();
975         }
976
977         /* Listen for events from our buttons */
978         public void actionPerformed(ActionEvent e) {
979                 String  cmd = e.getActionCommand();
980
981                 if (cmd.equals("Pyro")) {
982                         if (pyro_ui == null && pyros != null)
983                                 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
984                         if (pyro_ui != null)
985                                 pyro_ui.make_visible();
986                         return;
987                 }
988
989                 if (cmd.equals("Close") || cmd.equals("Reboot"))
990                         if (!check_dirty(cmd))
991                                 return;
992                 listener.actionPerformed(e);
993                 if (cmd.equals("Close") || cmd.equals("Reboot")) {
994                         setVisible(false);
995                         dispose();
996                 }
997                 if (cmd.equals("Save") || cmd.equals("Reset"))
998                         set_clean();
999         }
1000
1001         /* ItemListener interface method */
1002         public void itemStateChanged(ItemEvent e) {
1003                 set_dirty();
1004         }
1005
1006         /* DocumentListener interface methods */
1007         public void changedUpdate(DocumentEvent e) {
1008                 set_dirty();
1009         }
1010
1011         public void insertUpdate(DocumentEvent e) {
1012                 set_dirty();
1013         }
1014
1015         public void removeUpdate(DocumentEvent e) {
1016                 set_dirty();
1017         }
1018
1019         /* Let the config code hook on a listener */
1020         public void addActionListener(ActionListener l) {
1021                 listener = l;
1022         }
1023
1024         /* set and get all of the dialog values */
1025         public void set_product(String product) {
1026                 radio_frequency_value.set_product(product);
1027                 product_value.setText(product);
1028                 set_pad_orientation_tool_tip();
1029                 set_accel_tool_tips();
1030                 set_flight_log_max_tool_tip();
1031         }
1032
1033         public void set_version(String version) {
1034                 version_value.setText(version);
1035         }
1036
1037         public void set_serial(int serial) {
1038                 radio_frequency_value.set_serial(serial);
1039                 serial_value.setText(String.format("%d", serial));
1040         }
1041
1042         public void set_altitude_32(int altitude_32) {
1043         }
1044
1045         public void set_main_deploy(int new_main_deploy) {
1046                 if (new_main_deploy != AltosLib.MISSING)
1047                         main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
1048                 main_deploy_value.setVisible(new_main_deploy != AltosLib.MISSING);
1049                 main_deploy_label.setVisible(new_main_deploy != AltosLib.MISSING);
1050         }
1051
1052         public int main_deploy() throws AltosConfigDataException {
1053                 String  str = main_deploy_value.getSelectedItem().toString();
1054                 try {
1055                         return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1056                 } catch (ParseException pe) {
1057                         throw new AltosConfigDataException("invalid main deploy height %s", str);
1058                 }
1059         }
1060
1061         String get_main_deploy_label() {
1062                 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.parse_units());
1063         }
1064
1065         String[] main_deploy_values() {
1066                 if (AltosConvert.imperial_units)
1067                         return main_deploy_values_ft;
1068                 else
1069                         return main_deploy_values_m;
1070         }
1071
1072         void set_main_deploy_values() {
1073                 String[]        v = main_deploy_values();
1074                 while (main_deploy_value.getItemCount() > 0)
1075                         main_deploy_value.removeItemAt(0);
1076                 for (int i = 0; i < v.length; i++)
1077                         main_deploy_value.addItem(v[i]);
1078                 main_deploy_value.setMaximumRowCount(v.length);
1079         }
1080
1081         public void units_changed(boolean imperial_units) {
1082                 boolean was_dirty = dirty;
1083
1084                 String v = main_deploy_value.getSelectedItem().toString();
1085                 main_deploy_label.setText(get_main_deploy_label());
1086                 set_main_deploy_values();
1087                 try {
1088                         int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1089                         set_main_deploy(m);
1090                 } catch (ParseException pe) {
1091                 }
1092
1093                 if (tracker_motion_value.isVisible()) {
1094                         String motion = tracker_motion_value.getSelectedItem().toString();
1095                         tracker_motion_label.setText(get_tracker_motion_label());
1096                         set_tracker_motion_values();
1097                         try {
1098                                 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1099                                 set_tracker_motion(m);
1100                         } catch (ParseException pe) {
1101                         }
1102                 }
1103
1104                 if (!was_dirty)
1105                         set_clean();
1106         }
1107
1108         public void set_apogee_delay(int new_apogee_delay) {
1109                 if (new_apogee_delay != AltosLib.MISSING)
1110                         apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1111                 apogee_delay_value.setVisible(new_apogee_delay != AltosLib.MISSING);
1112                 apogee_delay_label.setVisible(new_apogee_delay != AltosLib.MISSING);
1113         }
1114
1115         private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1116                 String v = s;
1117                 if (split)
1118                         v = s.split("\\s+")[0];
1119                 try {
1120                         return Integer.parseInt(v);
1121                 } catch (NumberFormatException ne) {
1122                         throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1123                 }
1124         }
1125
1126         public int apogee_delay() throws AltosConfigDataException {
1127                 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1128         }
1129
1130         public void set_apogee_lockout(int new_apogee_lockout) {
1131                 if (new_apogee_lockout != AltosLib.MISSING)
1132                         apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1133
1134                 apogee_lockout_value.setVisible(new_apogee_lockout != AltosLib.MISSING);
1135                 apogee_lockout_label.setVisible(new_apogee_lockout != AltosLib.MISSING);
1136         }
1137
1138         public int apogee_lockout() throws AltosConfigDataException {
1139                 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1140         }
1141
1142         public void set_radio_frequency(double new_radio_frequency) {
1143                 if (new_radio_frequency != AltosLib.MISSING)
1144                         radio_frequency_value.set_frequency(new_radio_frequency);
1145                 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
1146                 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
1147         }
1148
1149         public double radio_frequency() {
1150                 return radio_frequency_value.frequency();
1151         }
1152
1153         public void set_radio_calibration(int new_radio_calibration) {
1154                 if (new_radio_calibration != AltosLib.MISSING)
1155                         radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1156                 radio_calibration_value.setVisible(new_radio_calibration != AltosLib.MISSING);
1157                 radio_calibration_label.setVisible(new_radio_calibration != AltosLib.MISSING);
1158         }
1159
1160         public void set_radio_enable(int new_radio_enable) {
1161                 if (new_radio_enable != AltosLib.MISSING)
1162                         radio_enable_value.setSelected(new_radio_enable != 0);
1163                 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
1164                 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
1165                 set_radio_enable_tool_tip();
1166         }
1167
1168         public int radio_enable() {
1169                 if (radio_enable_value.isVisible())
1170                         return radio_enable_value.isSelected() ? 1 : 0;
1171                 else
1172                         return AltosLib.MISSING;
1173         }
1174
1175         public void set_telemetry_rate(int new_rate) {
1176                 if (new_rate != AltosLib.MISSING)
1177                         rate_value.set_rate(new_rate);
1178                 rate_label.setVisible(new_rate != AltosLib.MISSING);
1179                 rate_value.setVisible(new_rate != AltosLib.MISSING);
1180                 set_rate_tool_tip();
1181         }
1182
1183         public int telemetry_rate() {
1184                 return rate_value.rate();
1185         }
1186
1187         public void set_callsign(String new_callsign) {
1188                 if (new_callsign != null)
1189                         callsign_value.setText(new_callsign);
1190                 callsign_value.setVisible(new_callsign != null);
1191                 callsign_label.setVisible(new_callsign != null);
1192         }
1193
1194         public String callsign() {
1195                 if (callsign_value.isVisible())
1196                         return callsign_value.getText();
1197                 return null;
1198         }
1199
1200         int     flight_log_max_limit;
1201         int     flight_log_max;
1202
1203         public String flight_log_max_label(int flight_log_max) {
1204                 if (flight_log_max_limit != 0) {
1205                         int     nflight = flight_log_max_limit / flight_log_max;
1206                         String  plural = nflight > 1 ? "s" : "";
1207
1208                         return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1209                 }
1210                 return String.format("%d", flight_log_max);
1211         }
1212
1213         public void set_flight_log_max(int new_flight_log_max) {
1214                 if (new_flight_log_max != AltosLib.MISSING) {
1215                         flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1216                         flight_log_max = new_flight_log_max;
1217                 }
1218                 flight_log_max_value.setVisible(new_flight_log_max != AltosLib.MISSING);
1219                 flight_log_max_label.setVisible(new_flight_log_max != AltosLib.MISSING);
1220                 set_flight_log_max_tool_tip();
1221         }
1222
1223         public void set_flight_log_max_enabled(boolean enable) {
1224                 flight_log_max_value.setEnabled(enable);
1225                 set_flight_log_max_tool_tip();
1226         }
1227
1228         public int flight_log_max() throws AltosConfigDataException {
1229                 if (flight_log_max_value.isVisible())
1230                         return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1231                 return AltosLib.MISSING;
1232         }
1233
1234         public void set_flight_log_max_limit(int new_flight_log_max_limit) {
1235                 flight_log_max_limit = new_flight_log_max_limit;
1236                 if (new_flight_log_max_limit != AltosLib.MISSING) {
1237                         flight_log_max_value.removeAllItems();
1238                         for (int i = 8; i >= 1; i--) {
1239                                 int     size = flight_log_max_limit / i;
1240                                 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1241                         }
1242                 }
1243                 if (flight_log_max != 0)
1244                         set_flight_log_max(flight_log_max);
1245         }
1246
1247         public void set_ignite_mode(int new_ignite_mode) {
1248                 if (new_ignite_mode != AltosLib.MISSING) {
1249                         if (new_ignite_mode >= ignite_mode_values.length)
1250                                 new_ignite_mode = 0;
1251                         if (new_ignite_mode < 0) {
1252                                 ignite_mode_value.setEnabled(false);
1253                                 new_ignite_mode = 0;
1254                         } else {
1255                                 ignite_mode_value.setEnabled(true);
1256                         }
1257                         ignite_mode_value.setSelectedIndex(new_ignite_mode);
1258                 }
1259                 ignite_mode_value.setVisible(new_ignite_mode != AltosLib.MISSING);
1260                 ignite_mode_label.setVisible(new_ignite_mode != AltosLib.MISSING);
1261
1262                 set_ignite_mode_tool_tip();
1263         }
1264
1265         public int ignite_mode() {
1266                 if (ignite_mode_value.isVisible())
1267                         return ignite_mode_value.getSelectedIndex();
1268                 else
1269                         return AltosLib.MISSING;
1270         }
1271
1272
1273         public void set_pad_orientation(int new_pad_orientation) {
1274                 if (new_pad_orientation != AltosLib.MISSING) {
1275                         if (new_pad_orientation >= pad_orientation_values.length)
1276                                 new_pad_orientation = 0;
1277                         if (new_pad_orientation < 0)
1278                                 new_pad_orientation = 0;
1279                         pad_orientation_value.setSelectedIndex(new_pad_orientation);
1280                 }
1281                 pad_orientation_value.setVisible(new_pad_orientation != AltosLib.MISSING);
1282                 pad_orientation_label.setVisible(new_pad_orientation != AltosLib.MISSING);
1283                 accel_cal.setVisible(new_pad_orientation != AltosLib.MISSING);
1284
1285                 set_pad_orientation_tool_tip();
1286         }
1287
1288         public int pad_orientation() {
1289                 if (pad_orientation_value.isVisible())
1290                         return pad_orientation_value.getSelectedIndex();
1291                 else
1292                         return AltosLib.MISSING;
1293         }
1294
1295         public void set_accel_cal(int accel_plus, int accel_minus) {
1296                 if (accel_plus != AltosLib.MISSING) {
1297                         accel_plus_value.setText(String.format("%d", accel_plus));
1298                         accel_minus_value.setText(String.format("%d", accel_minus));
1299                 }
1300                 accel_plus_value.setVisible(accel_plus != AltosLib.MISSING);
1301                 accel_plus_label.setVisible(accel_plus != AltosLib.MISSING);
1302                 accel_minus_value.setVisible(accel_minus != AltosLib.MISSING);
1303                 accel_minus_label.setVisible(accel_minus != AltosLib.MISSING);
1304
1305                 set_accel_tool_tips();
1306         }
1307
1308         public int accel_cal_plus() {
1309                 if (accel_plus_value.isVisible())
1310                         return Integer.parseInt(accel_plus_value.getText());
1311                 return AltosLib.MISSING;
1312         }
1313
1314         public int accel_cal_minus() {
1315                 if (accel_minus_value.isVisible())
1316                         return Integer.parseInt(accel_minus_value.getText());
1317                 return AltosLib.MISSING;
1318         }
1319
1320         public void set_beep(int new_beep) {
1321                 if (new_beep != AltosLib.MISSING) {
1322                         int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1323                         for (int i = 0; i < beep_values.length; i++)
1324                                 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1325                                         beep_value.setSelectedIndex(i);
1326                                         set_beep_tool_tip();
1327                                         return;
1328                                 }
1329                         beep_value.setSelectedItem(String.format("%d", new_freq));
1330                 }
1331                 beep_value.setVisible(new_beep != AltosLib.MISSING);
1332                 beep_label.setVisible(new_beep != AltosLib.MISSING);
1333                 set_beep_tool_tip();
1334         }
1335
1336         public int beep() {
1337                 if (beep_value.isVisible())
1338                         return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1339                 else
1340                         return AltosLib.MISSING;
1341         }
1342
1343         String[] tracker_motion_values() {
1344                 if (AltosConvert.imperial_units)
1345                         return tracker_motion_values_ft;
1346                 else
1347                         return tracker_motion_values_m;
1348         }
1349
1350         void set_tracker_motion_values() {
1351                 String[]        v = tracker_motion_values();
1352                 while (tracker_motion_value.getItemCount() > 0)
1353                         tracker_motion_value.removeItemAt(0);
1354                 for (int i = 0; i < v.length; i++)
1355                         tracker_motion_value.addItem(v[i]);
1356                 tracker_motion_value.setMaximumRowCount(v.length);
1357         }
1358
1359         String get_tracker_motion_label() {
1360                 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1361         }
1362
1363         void set_tracker_tool_tip() {
1364                 if (tracker_motion_value.isVisible())
1365                         tracker_motion_value.setToolTipText("How far the device must move before logging");
1366                 else
1367                         tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1368                 if (tracker_interval_value.isVisible())
1369                         tracker_interval_value.setToolTipText("How often to report GPS position");
1370                 else
1371                         tracker_interval_value.setToolTipText("This device can't configure interval");
1372         }
1373
1374         public void set_tracker_motion(int tracker_motion) {
1375                 if (tracker_motion != AltosLib.MISSING)
1376                         tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1377                 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1378                 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1379         }
1380
1381         public int tracker_motion() throws AltosConfigDataException {
1382                 if (tracker_motion_value.isVisible()) {
1383                         String str = tracker_motion_value.getSelectedItem().toString();
1384                         try {
1385                                 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1386                         } catch (ParseException pe) {
1387                                 throw new AltosConfigDataException("invalid tracker motion %s", str);
1388                         }
1389                 }
1390                 return AltosLib.MISSING;
1391         }
1392
1393         public void set_tracker_interval(int tracker_interval) {
1394                 if (tracker_interval != AltosLib.MISSING)
1395                         tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1396                 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1397                 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1398         }
1399
1400         public int tracker_interval() throws AltosConfigDataException {
1401                 if (tracker_interval_value.isVisible())
1402                         return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1403                 return AltosLib.MISSING;
1404         }
1405
1406         public void set_pyros(AltosPyro[] new_pyros) {
1407                 pyros = new_pyros;
1408                 if (pyros != null && pyro_ui != null)
1409                         pyro_ui.set_pyros(pyros);
1410                 pyro.setVisible(pyros != null);
1411         }
1412
1413         public AltosPyro[] pyros() throws AltosConfigDataException {
1414                 if (pyro_ui != null)
1415                         pyros = pyro_ui.get_pyros();
1416                 return pyros;
1417         }
1418
1419         public void set_pyro_firing_time(double new_pyro_firing_time) {
1420                 pyro_firing_time = new_pyro_firing_time;
1421                 if (pyro_firing_time != AltosLib.MISSING && pyro_ui != null)
1422                         pyro_ui.set_pyro_firing_time(pyro_firing_time);
1423                 pyro.setVisible(pyro_firing_time != AltosLib.MISSING);
1424         }
1425
1426         public double pyro_firing_time() throws AltosConfigDataException {
1427                 if (pyro_ui != null)
1428                         pyro_firing_time = pyro_ui.get_pyro_firing_time();
1429                 return pyro_firing_time;
1430         }
1431
1432         public void set_aprs_interval(int new_aprs_interval) {
1433                 if (new_aprs_interval != AltosLib.MISSING)
1434                         aprs_interval_value.setSelectedItem(Integer.toString(new_aprs_interval));
1435                 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1436                 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1437                 set_aprs_interval_tool_tip();
1438         }
1439
1440         public int aprs_interval() throws AltosConfigDataException {
1441                 if (aprs_interval_value.isVisible()) {
1442                         String  s = aprs_interval_value.getSelectedItem().toString();
1443
1444                         return parse_int("aprs interval", s, false);
1445                 }
1446                 return AltosLib.MISSING;
1447         }
1448
1449         public void set_aprs_ssid(int new_aprs_ssid) {
1450                 if (new_aprs_ssid != AltosLib.MISSING)
1451                         aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1452                 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1453                 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1454                 set_aprs_ssid_tool_tip();
1455         }
1456
1457         public int aprs_ssid() throws AltosConfigDataException {
1458                 if (aprs_ssid_value.isVisible()) {
1459                         Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1460                         return i;
1461                 }
1462                 return AltosLib.MISSING;
1463         }
1464
1465         public void set_aprs_format(int new_aprs_format) {
1466                 if (new_aprs_format != AltosLib.MISSING)
1467                         aprs_format_value.setSelectedIndex(new_aprs_format);
1468                 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1469                 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1470                 set_aprs_format_tool_tip();
1471         }
1472
1473         public int aprs_format() throws AltosConfigDataException {
1474                 if (aprs_format_value.isVisible())
1475                         return aprs_format_value.getSelectedIndex();
1476                 return AltosLib.MISSING;
1477         }
1478 }