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