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