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