altosui: Improve configuration save feedback
[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 = getContentPane();
361                 pane.setLayout(new GridBagLayout());
362
363                 /* Product */
364                 c = new GridBagConstraints();
365                 c.gridx = 0; c.gridy = row;
366                 c.gridwidth = 4;
367                 c.fill = GridBagConstraints.NONE;
368                 c.anchor = GridBagConstraints.LINE_START;
369                 c.insets = il;
370                 product_label = new JLabel("Product:");
371                 pane.add(product_label, c);
372
373                 c = new GridBagConstraints();
374                 c.gridx = 4; c.gridy = row;
375                 c.gridwidth = 4;
376                 c.fill = GridBagConstraints.HORIZONTAL;
377                 c.weightx = 1;
378                 c.anchor = GridBagConstraints.LINE_START;
379                 c.insets = ir;
380                 product_value = new JLabel("");
381                 pane.add(product_value, c);
382                 row++;
383
384                 /* Version */
385                 c = new GridBagConstraints();
386                 c.gridx = 0; c.gridy = row;
387                 c.gridwidth = 4;
388                 c.fill = GridBagConstraints.NONE;
389                 c.anchor = GridBagConstraints.LINE_START;
390                 c.insets = il;
391                 c.ipady = 5;
392                 version_label = new JLabel("Software version:");
393                 pane.add(version_label, c);
394
395                 c = new GridBagConstraints();
396                 c.gridx = 4; c.gridy = row;
397                 c.gridwidth = 4;
398                 c.fill = GridBagConstraints.HORIZONTAL;
399                 c.weightx = 1;
400                 c.anchor = GridBagConstraints.LINE_START;
401                 c.insets = ir;
402                 c.ipady = 5;
403                 version_value = new JLabel("");
404                 pane.add(version_value, c);
405                 row++;
406
407                 /* Serial */
408                 c = new GridBagConstraints();
409                 c.gridx = 0; c.gridy = row;
410                 c.gridwidth = 4;
411                 c.fill = GridBagConstraints.NONE;
412                 c.anchor = GridBagConstraints.LINE_START;
413                 c.insets = il;
414                 c.ipady = 5;
415                 serial_label = new JLabel("Serial:");
416                 pane.add(serial_label, c);
417
418                 c = new GridBagConstraints();
419                 c.gridx = 4; c.gridy = row;
420                 c.gridwidth = 4;
421                 c.fill = GridBagConstraints.HORIZONTAL;
422                 c.weightx = 1;
423                 c.anchor = GridBagConstraints.LINE_START;
424                 c.insets = ir;
425                 c.ipady = 5;
426                 serial_value = new JLabel("");
427                 pane.add(serial_value, c);
428                 row++;
429
430                 /* Main deploy */
431                 c = new GridBagConstraints();
432                 c.gridx = 0; c.gridy = row;
433                 c.gridwidth = 4;
434                 c.fill = GridBagConstraints.NONE;
435                 c.anchor = GridBagConstraints.LINE_START;
436                 c.insets = il;
437                 c.ipady = 5;
438                 main_deploy_label = new JLabel(get_main_deploy_label());
439                 pane.add(main_deploy_label, c);
440
441                 c = new GridBagConstraints();
442                 c.gridx = 4; c.gridy = row;
443                 c.gridwidth = 4;
444                 c.fill = GridBagConstraints.HORIZONTAL;
445                 c.weightx = 1;
446                 c.anchor = GridBagConstraints.LINE_START;
447                 c.insets = ir;
448                 c.ipady = 5;
449                 main_deploy_value = new JComboBox<String>(main_deploy_values());
450                 main_deploy_value.setEditable(true);
451                 main_deploy_value.addItemListener(this);
452                 pane.add(main_deploy_value, c);
453                 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
454                 row++;
455
456                 /* Apogee delay */
457                 c = new GridBagConstraints();
458                 c.gridx = 0; c.gridy = row;
459                 c.gridwidth = 4;
460                 c.fill = GridBagConstraints.NONE;
461                 c.anchor = GridBagConstraints.LINE_START;
462                 c.insets = il;
463                 c.ipady = 5;
464                 apogee_delay_label = new JLabel("Apogee Delay(s):");
465                 pane.add(apogee_delay_label, c);
466
467                 c = new GridBagConstraints();
468                 c.gridx = 4; c.gridy = row;
469                 c.gridwidth = 4;
470                 c.fill = GridBagConstraints.HORIZONTAL;
471                 c.weightx = 1;
472                 c.anchor = GridBagConstraints.LINE_START;
473                 c.insets = ir;
474                 c.ipady = 5;
475                 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
476                 apogee_delay_value.setEditable(true);
477                 apogee_delay_value.addItemListener(this);
478                 pane.add(apogee_delay_value, c);
479                 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
480                 row++;
481
482                 /* Apogee lockout */
483                 c = new GridBagConstraints();
484                 c.gridx = 0; c.gridy = row;
485                 c.gridwidth = 4;
486                 c.fill = GridBagConstraints.NONE;
487                 c.anchor = GridBagConstraints.LINE_START;
488                 c.insets = il;
489                 c.ipady = 5;
490                 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
491                 pane.add(apogee_lockout_label, c);
492
493                 c = new GridBagConstraints();
494                 c.gridx = 4; c.gridy = row;
495                 c.gridwidth = 4;
496                 c.fill = GridBagConstraints.HORIZONTAL;
497                 c.weightx = 1;
498                 c.anchor = GridBagConstraints.LINE_START;
499                 c.insets = ir;
500                 c.ipady = 5;
501                 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
502                 apogee_lockout_value.setEditable(true);
503                 apogee_lockout_value.addItemListener(this);
504                 pane.add(apogee_lockout_value, c);
505                 apogee_lockout_value.setToolTipText("Time after launch while apogee detection is locked out");
506                 row++;
507
508                 /* Frequency */
509                 c = new GridBagConstraints();
510                 c.gridx = 0; c.gridy = row;
511                 c.gridwidth = 4;
512                 c.fill = GridBagConstraints.NONE;
513                 c.anchor = GridBagConstraints.LINE_START;
514                 c.insets = il;
515                 c.ipady = 5;
516                 radio_frequency_label = new JLabel("Frequency:");
517                 pane.add(radio_frequency_label, c);
518
519                 c = new GridBagConstraints();
520                 c.gridx = 4; c.gridy = row;
521                 c.gridwidth = 4;
522                 c.fill = GridBagConstraints.HORIZONTAL;
523                 c.weightx = 1;
524                 c.anchor = GridBagConstraints.LINE_START;
525                 c.insets = ir;
526                 c.ipady = 5;
527                 radio_frequency_value = new AltosUIFreqList();
528                 radio_frequency_value.addItemListener(this);
529                 pane.add(radio_frequency_value, c);
530                 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
531                 row++;
532
533                 /* Radio Calibration */
534                 c = new GridBagConstraints();
535                 c.gridx = 0; c.gridy = row;
536                 c.gridwidth = 4;
537                 c.fill = GridBagConstraints.NONE;
538                 c.anchor = GridBagConstraints.LINE_START;
539                 c.insets = il;
540                 c.ipady = 5;
541                 radio_calibration_label = new JLabel("RF Calibration:");
542                 pane.add(radio_calibration_label, c);
543
544                 c = new GridBagConstraints();
545                 c.gridx = 4; c.gridy = row;
546                 c.gridwidth = 4;
547                 c.fill = GridBagConstraints.HORIZONTAL;
548                 c.weightx = 1;
549                 c.anchor = GridBagConstraints.LINE_START;
550                 c.insets = ir;
551                 c.ipady = 5;
552                 radio_calibration_value = new JLabel(String.format("%d", 1186611));
553                 pane.add(radio_calibration_value, c);
554                 row++;
555
556                 /* Radio Enable */
557                 c = new GridBagConstraints();
558                 c.gridx = 0; c.gridy = row;
559                 c.gridwidth = 4;
560                 c.fill = GridBagConstraints.NONE;
561                 c.anchor = GridBagConstraints.LINE_START;
562                 c.insets = il;
563                 c.ipady = 5;
564                 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
565                 pane.add(radio_enable_label, c);
566
567                 c = new GridBagConstraints();
568                 c.gridx = 4; c.gridy = row;
569                 c.gridwidth = 4;
570                 c.fill = GridBagConstraints.HORIZONTAL;
571                 c.weightx = 1;
572                 c.anchor = GridBagConstraints.LINE_START;
573                 c.insets = ir;
574                 c.ipady = 5;
575                 radio_enable_value = new JRadioButton("Enabled");
576                 radio_enable_value.addItemListener(this);
577                 pane.add(radio_enable_value, c);
578                 set_radio_enable_tool_tip();
579                 row++;
580
581                 /* Telemetry Rate */
582                 c = new GridBagConstraints();
583                 c.gridx = 0; c.gridy = row;
584                 c.gridwidth = 4;
585                 c.fill = GridBagConstraints.NONE;
586                 c.anchor = GridBagConstraints.LINE_START;
587                 c.insets = il;
588                 c.ipady = 5;
589                 rate_label = new JLabel("Telemetry baud rate:");
590                 pane.add(rate_label, c);
591
592                 c = new GridBagConstraints();
593                 c.gridx = 4; c.gridy = row;
594                 c.gridwidth = 4;
595                 c.fill = GridBagConstraints.HORIZONTAL;
596                 c.weightx = 1;
597                 c.anchor = GridBagConstraints.LINE_START;
598                 c.insets = ir;
599                 c.ipady = 5;
600                 rate_value = new AltosUIRateList();
601                 rate_value.addItemListener(this);
602                 pane.add(rate_value, c);
603                 set_rate_tool_tip();
604                 row++;
605
606                 /* APRS interval */
607                 c = new GridBagConstraints();
608                 c.gridx = 0; c.gridy = row;
609                 c.gridwidth = 4;
610                 c.fill = GridBagConstraints.NONE;
611                 c.anchor = GridBagConstraints.LINE_START;
612                 c.insets = il;
613                 c.ipady = 5;
614                 aprs_interval_label = new JLabel("APRS Interval(s):");
615                 pane.add(aprs_interval_label, c);
616
617                 c = new GridBagConstraints();
618                 c.gridx = 4; c.gridy = row;
619                 c.gridwidth = 4;
620                 c.fill = GridBagConstraints.HORIZONTAL;
621                 c.weightx = 1;
622                 c.anchor = GridBagConstraints.LINE_START;
623                 c.insets = ir;
624                 c.ipady = 5;
625                 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
626                 aprs_interval_value.setEditable(true);
627                 aprs_interval_value.addItemListener(this);
628                 pane.add(aprs_interval_value, c);
629                 set_aprs_interval_tool_tip();
630                 row++;
631
632                 /* APRS SSID */
633                 c = new GridBagConstraints();
634                 c.gridx = 0; c.gridy = row;
635                 c.gridwidth = 4;
636                 c.fill = GridBagConstraints.NONE;
637                 c.anchor = GridBagConstraints.LINE_START;
638                 c.insets = il;
639                 c.ipady = 5;
640                 aprs_ssid_label = new JLabel("APRS SSID:");
641                 pane.add(aprs_ssid_label, c);
642
643                 c = new GridBagConstraints();
644                 c.gridx = 4; c.gridy = row;
645                 c.gridwidth = 4;
646                 c.fill = GridBagConstraints.HORIZONTAL;
647                 c.weightx = 1;
648                 c.anchor = GridBagConstraints.LINE_START;
649                 c.insets = ir;
650                 c.ipady = 5;
651                 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
652                 aprs_ssid_value.setEditable(false);
653                 aprs_ssid_value.addItemListener(this);
654                 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
655                 pane.add(aprs_ssid_value, c);
656                 set_aprs_ssid_tool_tip();
657                 row++;
658
659                 /* APRS format */
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                 aprs_format_label = new JLabel("APRS format:");
668                 pane.add(aprs_format_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                 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
679                 aprs_format_value.setEditable(false);
680                 aprs_format_value.addItemListener(this);
681                 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
682                 pane.add(aprs_format_value, c);
683                 set_aprs_format_tool_tip();
684                 row++;
685
686                 /* APRS offset */
687                 c = new GridBagConstraints();
688                 c.gridx = 0; c.gridy = row;
689                 c.gridwidth = 4;
690                 c.fill = GridBagConstraints.NONE;
691                 c.anchor = GridBagConstraints.LINE_START;
692                 c.insets = il;
693                 c.ipady = 5;
694                 aprs_offset_label = new JLabel("APRS offset:");
695                 pane.add(aprs_offset_label, c);
696
697                 c = new GridBagConstraints();
698                 c.gridx = 4; c.gridy = row;
699                 c.gridwidth = 4;
700                 c.fill = GridBagConstraints.HORIZONTAL;
701                 c.weightx = 1;
702                 c.anchor = GridBagConstraints.LINE_START;
703                 c.insets = ir;
704                 c.ipady = 5;
705                 aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
706                 aprs_offset_value.setEditable(false);
707                 aprs_offset_value.addItemListener(this);
708                 aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
709                 pane.add(aprs_offset_value, c);
710                 set_aprs_offset_tool_tip();
711                 row++;
712
713                 /* Callsign */
714                 c = new GridBagConstraints();
715                 c.gridx = 0; c.gridy = row;
716                 c.gridwidth = 4;
717                 c.fill = GridBagConstraints.NONE;
718                 c.anchor = GridBagConstraints.LINE_START;
719                 c.insets = il;
720                 c.ipady = 5;
721                 callsign_label = new JLabel("Callsign:");
722                 pane.add(callsign_label, c);
723
724                 c = new GridBagConstraints();
725                 c.gridx = 4; c.gridy = row;
726                 c.gridwidth = 4;
727                 c.fill = GridBagConstraints.HORIZONTAL;
728                 c.weightx = 1;
729                 c.anchor = GridBagConstraints.LINE_START;
730                 c.insets = ir;
731                 c.ipady = 5;
732                 callsign_value = new JTextField(AltosUIPreferences.callsign());
733                 callsign_value.getDocument().addDocumentListener(this);
734                 pane.add(callsign_value, c);
735                 callsign_value.setToolTipText("Callsign reported in telemetry data");
736                 row++;
737
738                 /* Flight log max */
739                 c = new GridBagConstraints();
740                 c.gridx = 0; c.gridy = row;
741                 c.gridwidth = 4;
742                 c.fill = GridBagConstraints.NONE;
743                 c.anchor = GridBagConstraints.LINE_START;
744                 c.insets = il;
745                 c.ipady = 5;
746                 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
747                 pane.add(flight_log_max_label, c);
748
749                 c = new GridBagConstraints();
750                 c.gridx = 4; c.gridy = row;
751                 c.gridwidth = 4;
752                 c.fill = GridBagConstraints.HORIZONTAL;
753                 c.weightx = 1;
754                 c.anchor = GridBagConstraints.LINE_START;
755                 c.insets = ir;
756                 c.ipady = 5;
757                 flight_log_max_value = new JComboBox<String>();
758                 flight_log_max_value.setEditable(true);
759                 flight_log_max_value.addItemListener(this);
760                 pane.add(flight_log_max_value, c);
761                 set_flight_log_max_tool_tip();
762                 row++;
763
764                 /* Ignite mode */
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                 ignite_mode_label = new JLabel("Igniter Firing Mode:");
773                 pane.add(ignite_mode_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                 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
784                 ignite_mode_value.setEditable(false);
785                 ignite_mode_value.addItemListener(this);
786                 pane.add(ignite_mode_value, c);
787                 set_ignite_mode_tool_tip();
788                 row++;
789
790                 /* Pad orientation */
791                 c = new GridBagConstraints();
792                 c.gridx = 0; c.gridy = row;
793                 c.gridwidth = 4;
794                 c.fill = GridBagConstraints.NONE;
795                 c.anchor = GridBagConstraints.LINE_START;
796                 c.insets = il;
797                 c.ipady = 5;
798                 pad_orientation_label = new JLabel("Pad Orientation:");
799                 pane.add(pad_orientation_label, c);
800
801                 c = new GridBagConstraints();
802                 c.gridx = 4; c.gridy = row;
803                 c.gridwidth = 4;
804                 c.fill = GridBagConstraints.HORIZONTAL;
805                 c.weightx = 1;
806                 c.anchor = GridBagConstraints.LINE_START;
807                 c.insets = ir;
808                 c.ipady = 5;
809                 pad_orientation_values = pad_orientation_values_no_radio;
810
811                 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
812                 pad_orientation_value.setEditable(false);
813                 pad_orientation_value.addItemListener(this);
814                 pane.add(pad_orientation_value, c);
815                 set_pad_orientation_tool_tip();
816                 row++;
817
818                 /* Accel plus */
819                 c = new GridBagConstraints();
820                 c.gridx = 0; c.gridy = row;
821                 c.gridwidth = 4;
822                 c.fill = GridBagConstraints.NONE;
823                 c.anchor = GridBagConstraints.LINE_START;
824                 c.insets = il;
825                 c.ipady = 5;
826                 accel_plus_label = new JLabel("Accel Plus:");
827                 pane.add(accel_plus_label, c);
828
829                 c = new GridBagConstraints();
830                 c.gridx = 4; c.gridy = row;
831                 c.gridwidth = 4;
832                 c.fill = GridBagConstraints.HORIZONTAL;
833                 c.weightx = 1;
834                 c.anchor = GridBagConstraints.LINE_START;
835                 c.insets = ir;
836                 c.ipady = 5;
837                 accel_plus_value = new JTextField(10);
838                 accel_plus_value.setEditable(true);
839                 accel_plus_value.getDocument().addDocumentListener(this);
840                 pane.add(accel_plus_value, c);
841                 row++;
842
843                 /* Accel minus */
844                 c = new GridBagConstraints();
845                 c.gridx = 0; c.gridy = row;
846                 c.gridwidth = 4;
847                 c.fill = GridBagConstraints.NONE;
848                 c.anchor = GridBagConstraints.LINE_START;
849                 c.insets = il;
850                 c.ipady = 5;
851                 accel_minus_label = new JLabel("Accel Minus:");
852                 pane.add(accel_minus_label, c);
853
854                 c = new GridBagConstraints();
855                 c.gridx = 4; c.gridy = row;
856                 c.gridwidth = 4;
857                 c.fill = GridBagConstraints.HORIZONTAL;
858                 c.weightx = 1;
859                 c.anchor = GridBagConstraints.LINE_START;
860                 c.insets = ir;
861                 c.ipady = 5;
862                 accel_minus_value = new JTextField(10);
863                 accel_minus_value.setEditable(true);
864                 accel_minus_value.getDocument().addDocumentListener(this);
865                 pane.add(accel_minus_value, c);
866                 row++;
867                 set_accel_tool_tips();
868
869                 /* Beeper */
870                 c = new GridBagConstraints();
871                 c.gridx = 0; c.gridy = row;
872                 c.gridwidth = 4;
873                 c.fill = GridBagConstraints.NONE;
874                 c.anchor = GridBagConstraints.LINE_START;
875                 c.insets = il;
876                 c.ipady = 5;
877                 beep_label = new JLabel("Beeper Frequency:");
878                 pane.add(beep_label, c);
879
880                 c = new GridBagConstraints();
881                 c.gridx = 4; c.gridy = row;
882                 c.gridwidth = 4;
883                 c.fill = GridBagConstraints.HORIZONTAL;
884                 c.weightx = 1;
885                 c.anchor = GridBagConstraints.LINE_START;
886                 c.insets = ir;
887                 c.ipady = 5;
888                 beep_value = new JComboBox<String>(beep_values);
889                 beep_value.setEditable(true);
890                 beep_value.addItemListener(this);
891                 pane.add(beep_value, c);
892                 set_beep_tool_tip();
893                 row++;
894
895                 /* Tracker triger horiz distances */
896                 c = new GridBagConstraints();
897                 c.gridx = 0; c.gridy = row;
898                 c.gridwidth = 4;
899                 c.fill = GridBagConstraints.NONE;
900                 c.anchor = GridBagConstraints.LINE_START;
901                 c.insets = il;
902                 c.ipady = 5;
903                 tracker_motion_label = new JLabel(get_tracker_motion_label());
904                 pane.add(tracker_motion_label, c);
905
906                 c = new GridBagConstraints();
907                 c.gridx = 4; c.gridy = row;
908                 c.gridwidth = 4;
909                 c.fill = GridBagConstraints.HORIZONTAL;
910                 c.weightx = 1;
911                 c.anchor = GridBagConstraints.LINE_START;
912                 c.insets = ir;
913                 c.ipady = 5;
914                 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
915                 tracker_motion_value.setEditable(true);
916                 tracker_motion_value.addItemListener(this);
917                 pane.add(tracker_motion_value, c);
918                 row++;
919
920                 /* Tracker triger vert distances */
921                 c = new GridBagConstraints();
922                 c.gridx = 0; c.gridy = row;
923                 c.gridwidth = 4;
924                 c.fill = GridBagConstraints.NONE;
925                 c.anchor = GridBagConstraints.LINE_START;
926                 c.insets = il;
927                 c.ipady = 5;
928                 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
929                 pane.add(tracker_interval_label, c);
930
931                 c = new GridBagConstraints();
932                 c.gridx = 4; c.gridy = row;
933                 c.gridwidth = 4;
934                 c.fill = GridBagConstraints.HORIZONTAL;
935                 c.weightx = 1;
936                 c.anchor = GridBagConstraints.LINE_START;
937                 c.insets = ir;
938                 c.ipady = 5;
939                 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
940                 tracker_interval_value.setEditable(true);
941                 tracker_interval_value.addItemListener(this);
942                 pane.add(tracker_interval_value, c);
943                 set_tracker_tool_tip();
944                 row++;
945
946                 /* Pyro channels */
947                 c = new GridBagConstraints();
948                 c.gridx = 4; c.gridy = row;
949                 c.gridwidth = 4;
950                 c.fill = GridBagConstraints.HORIZONTAL;
951                 c.anchor = GridBagConstraints.LINE_START;
952                 c.insets = il;
953                 c.ipady = 5;
954                 pyro = new JButton("Configure Pyro Channels");
955                 pane.add(pyro, c);
956                 pyro.addActionListener(this);
957                 pyro.setActionCommand("Pyro");
958                 row++;
959
960                 /* Accel cal */
961                 c = new GridBagConstraints();
962                 c.gridx = 5; c.gridy = row;
963                 c.gridwidth = 5;
964                 c.fill = GridBagConstraints.HORIZONTAL;
965                 c.anchor = GridBagConstraints.LINE_START;
966                 c.insets = il;
967                 c.ipady = 5;
968                 accel_cal = new JButton("Calibrate Accelerometer");
969                 pane.add(accel_cal, c);
970                 accel_cal.addActionListener(this);
971                 accel_cal.setActionCommand("Accel");
972                 row++;
973
974                 /* Buttons */
975                 c = new GridBagConstraints();
976                 c.gridx = 0; c.gridy = row;
977                 c.gridwidth = 2;
978                 c.fill = GridBagConstraints.NONE;
979                 c.anchor = GridBagConstraints.LINE_START;
980                 c.insets = il;
981                 save = new JButton("Save");
982                 pane.add(save, c);
983                 save.addActionListener(this);
984                 save.setActionCommand("Save");
985
986                 c = new GridBagConstraints();
987                 c.gridx = 2; c.gridy = row;
988                 c.gridwidth = 2;
989                 c.fill = GridBagConstraints.NONE;
990                 c.anchor = GridBagConstraints.CENTER;
991                 c.insets = il;
992                 reset = new JButton("Reset");
993                 pane.add(reset, c);
994                 reset.addActionListener(this);
995                 reset.setActionCommand("Reset");
996
997                 c = new GridBagConstraints();
998                 c.gridx = 4; c.gridy = row;
999                 c.gridwidth = 2;
1000                 c.fill = GridBagConstraints.NONE;
1001                 c.anchor = GridBagConstraints.CENTER;
1002                 c.insets = il;
1003                 reboot = new JButton("Reboot");
1004                 pane.add(reboot, c);
1005                 reboot.addActionListener(this);
1006                 reboot.setActionCommand("Reboot");
1007
1008                 c = new GridBagConstraints();
1009                 c.gridx = 6; c.gridy = row;
1010                 c.gridwidth = 2;
1011                 c.fill = GridBagConstraints.NONE;
1012                 c.anchor = GridBagConstraints.LINE_END;
1013                 c.insets = il;
1014                 close = new JButton("Close");
1015                 pane.add(close, c);
1016                 close.addActionListener(this);
1017                 close.setActionCommand("Close");
1018
1019                 addWindowListener(new ConfigListener(this));
1020                 AltosPreferences.register_units_listener(this);
1021         }
1022
1023         /* Once the initial values are set, the config code will show the dialog */
1024         public void make_visible() {
1025                 pack();
1026                 setLocationRelativeTo(owner);
1027                 setVisible(true);
1028         }
1029
1030         /* If any values have been changed, confirm before closing */
1031         public boolean check_dirty(String operation) {
1032                 if (dirty) {
1033                         Object[] options = { String.format("%s anyway", operation), "Keep editing" };
1034                         int i;
1035                         i = JOptionPane.showOptionDialog(this,
1036                                                          String.format("Configuration modified. %s anyway?", operation),
1037                                                          "Configuration Modified",
1038                                                          JOptionPane.DEFAULT_OPTION,
1039                                                          JOptionPane.WARNING_MESSAGE,
1040                                                          null, options, options[1]);
1041                         if (i != 0)
1042                                 return false;
1043                 }
1044                 return true;
1045         }
1046
1047         public void set_dirty() {
1048                 dirty = true;
1049                 setTitle(title + " (modified)");
1050                 save.setEnabled(true);
1051         }
1052
1053         public void set_clean() {
1054                 dirty = false;
1055                 setTitle(title);
1056                 save.setEnabled(false);
1057         }
1058
1059         AltosConfigPyroUI       pyro_ui;
1060
1061         public void dispose() {
1062                 if (pyro_ui != null)
1063                         pyro_ui.dispose();
1064                 AltosPreferences.unregister_units_listener(this);
1065                 super.dispose();
1066         }
1067
1068         /* Listen for events from our buttons */
1069         public void actionPerformed(ActionEvent e) {
1070                 String  cmd = e.getActionCommand();
1071
1072                 if (cmd.equals("Pyro")) {
1073                         if (pyro_ui == null && pyros != null)
1074                                 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
1075                         if (pyro_ui != null)
1076                                 pyro_ui.make_visible();
1077                         return;
1078                 }
1079
1080                 if (cmd.equals("Close") || cmd.equals("Reboot"))
1081                         if (!check_dirty(cmd))
1082                                 return;
1083                 if (cmd.equals("Save"))
1084                         save.setEnabled(false);
1085                 listener.actionPerformed(e);
1086                 if (cmd.equals("Close") || cmd.equals("Reboot")) {
1087                         setVisible(false);
1088                         dispose();
1089                 }
1090         }
1091
1092         /* ItemListener interface method */
1093         public void itemStateChanged(ItemEvent e) {
1094                 set_dirty();
1095         }
1096
1097         /* DocumentListener interface methods */
1098         public void changedUpdate(DocumentEvent e) {
1099                 set_dirty();
1100         }
1101
1102         public void insertUpdate(DocumentEvent e) {
1103                 set_dirty();
1104         }
1105
1106         public void removeUpdate(DocumentEvent e) {
1107                 set_dirty();
1108         }
1109
1110         /* Let the config code hook on a listener */
1111         public void addActionListener(ActionListener l) {
1112                 listener = l;
1113         }
1114
1115         /* set and get all of the dialog values */
1116         public void set_product(String product) {
1117                 radio_frequency_value.set_product(product);
1118                 product_value.setText(product);
1119                 set_pad_orientation_tool_tip();
1120                 set_accel_tool_tips();
1121                 set_flight_log_max_tool_tip();
1122                 set_pad_orientation_values();
1123         }
1124
1125         public void set_version(String version) {
1126                 version_value.setText(version);
1127         }
1128
1129         public void set_serial(int serial) {
1130                 radio_frequency_value.set_serial(serial);
1131                 serial_value.setText(String.format("%d", serial));
1132         }
1133
1134         public void set_altitude_32(int altitude_32) {
1135         }
1136
1137         public void set_main_deploy(int new_main_deploy) {
1138                 if (new_main_deploy != AltosLib.MISSING)
1139                         main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
1140                 main_deploy_value.setVisible(new_main_deploy != AltosLib.MISSING);
1141                 main_deploy_label.setVisible(new_main_deploy != AltosLib.MISSING);
1142         }
1143
1144         public int main_deploy() throws AltosConfigDataException {
1145                 String  str = main_deploy_value.getSelectedItem().toString();
1146                 try {
1147                         return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1148                 } catch (ParseException pe) {
1149                         throw new AltosConfigDataException("invalid main deploy height %s", str);
1150                 }
1151         }
1152
1153         String get_main_deploy_label() {
1154                 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.parse_units());
1155         }
1156
1157         String[] main_deploy_values() {
1158                 if (AltosConvert.imperial_units)
1159                         return main_deploy_values_ft;
1160                 else
1161                         return main_deploy_values_m;
1162         }
1163
1164         void set_main_deploy_values() {
1165                 String[]        v = main_deploy_values();
1166                 while (main_deploy_value.getItemCount() > 0)
1167                         main_deploy_value.removeItemAt(0);
1168                 for (int i = 0; i < v.length; i++)
1169                         main_deploy_value.addItem(v[i]);
1170                 main_deploy_value.setMaximumRowCount(v.length);
1171         }
1172
1173         public void units_changed(boolean imperial_units) {
1174                 boolean was_dirty = dirty;
1175
1176                 String v = main_deploy_value.getSelectedItem().toString();
1177                 main_deploy_label.setText(get_main_deploy_label());
1178                 set_main_deploy_values();
1179                 try {
1180                         int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1181                         set_main_deploy(m);
1182                 } catch (ParseException pe) {
1183                 }
1184
1185                 if (tracker_motion_value.isVisible()) {
1186                         String motion = tracker_motion_value.getSelectedItem().toString();
1187                         tracker_motion_label.setText(get_tracker_motion_label());
1188                         set_tracker_motion_values();
1189                         try {
1190                                 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1191                                 set_tracker_motion(m);
1192                         } catch (ParseException pe) {
1193                         }
1194                 }
1195
1196                 if (!was_dirty)
1197                         set_clean();
1198         }
1199
1200         public void set_apogee_delay(int new_apogee_delay) {
1201                 if (new_apogee_delay != AltosLib.MISSING)
1202                         apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1203                 apogee_delay_value.setVisible(new_apogee_delay != AltosLib.MISSING);
1204                 apogee_delay_label.setVisible(new_apogee_delay != AltosLib.MISSING);
1205         }
1206
1207         private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1208                 String v = s;
1209                 if (split)
1210                         v = s.split("\\s+")[0];
1211                 try {
1212                         return Integer.parseInt(v);
1213                 } catch (NumberFormatException ne) {
1214                         throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1215                 }
1216         }
1217
1218         public int apogee_delay() throws AltosConfigDataException {
1219                 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1220         }
1221
1222         public void set_apogee_lockout(int new_apogee_lockout) {
1223                 if (new_apogee_lockout != AltosLib.MISSING)
1224                         apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1225
1226                 apogee_lockout_value.setVisible(new_apogee_lockout != AltosLib.MISSING);
1227                 apogee_lockout_label.setVisible(new_apogee_lockout != AltosLib.MISSING);
1228         }
1229
1230         public int apogee_lockout() throws AltosConfigDataException {
1231                 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1232         }
1233
1234         public void set_radio_frequency(double new_radio_frequency) {
1235                 if (new_radio_frequency != AltosLib.MISSING)
1236                         radio_frequency_value.set_frequency(new_radio_frequency);
1237                 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
1238                 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
1239         }
1240
1241         public double radio_frequency() {
1242                 return radio_frequency_value.frequency();
1243         }
1244
1245         public void set_radio_calibration(int new_radio_calibration) {
1246                 if (new_radio_calibration != AltosLib.MISSING)
1247                         radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1248                 radio_calibration_value.setVisible(new_radio_calibration != AltosLib.MISSING);
1249                 radio_calibration_label.setVisible(new_radio_calibration != AltosLib.MISSING);
1250         }
1251
1252         public void set_radio_enable(int new_radio_enable) {
1253                 if (new_radio_enable != AltosLib.MISSING)
1254                         radio_enable_value.setSelected(new_radio_enable != 0);
1255                 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
1256                 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
1257                 set_radio_enable_tool_tip();
1258         }
1259
1260         public int radio_enable() {
1261                 if (radio_enable_value.isVisible())
1262                         return radio_enable_value.isSelected() ? 1 : 0;
1263                 else
1264                         return AltosLib.MISSING;
1265         }
1266
1267         public void set_telemetry_rate(int new_rate) {
1268                 if (new_rate != AltosLib.MISSING)
1269                         rate_value.set_rate(new_rate);
1270                 rate_label.setVisible(new_rate != AltosLib.MISSING);
1271                 rate_value.setVisible(new_rate != AltosLib.MISSING);
1272                 set_rate_tool_tip();
1273         }
1274
1275         public int telemetry_rate() {
1276                 return rate_value.rate();
1277         }
1278
1279         public void set_callsign(String new_callsign) {
1280                 if (new_callsign != null)
1281                         callsign_value.setText(new_callsign);
1282                 callsign_value.setVisible(new_callsign != null);
1283                 callsign_label.setVisible(new_callsign != null);
1284         }
1285
1286         public String callsign() {
1287                 if (callsign_value.isVisible())
1288                         return callsign_value.getText();
1289                 return null;
1290         }
1291
1292         int     flight_log_max_limit;
1293         int     flight_log_max;
1294
1295         public String flight_log_max_label(int flight_log_max) {
1296                 if (flight_log_max_limit != 0) {
1297                         int     nflight = flight_log_max_limit / flight_log_max;
1298                         String  plural = nflight > 1 ? "s" : "";
1299
1300                         return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1301                 }
1302                 return String.format("%d", flight_log_max);
1303         }
1304
1305         public void set_flight_log_max(int new_flight_log_max) {
1306                 if (new_flight_log_max != AltosLib.MISSING) {
1307                         flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1308                         flight_log_max = new_flight_log_max;
1309                 }
1310                 flight_log_max_value.setVisible(new_flight_log_max != AltosLib.MISSING);
1311                 flight_log_max_label.setVisible(new_flight_log_max != AltosLib.MISSING);
1312                 set_flight_log_max_tool_tip();
1313         }
1314
1315         public void set_flight_log_max_enabled(boolean enable) {
1316                 flight_log_max_value.setEnabled(enable);
1317                 set_flight_log_max_tool_tip();
1318         }
1319
1320         public int flight_log_max() throws AltosConfigDataException {
1321                 if (flight_log_max_value.isVisible())
1322                         return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1323                 return AltosLib.MISSING;
1324         }
1325
1326         public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
1327                 flight_log_max_limit = new_flight_log_max_limit;
1328                 if (new_flight_log_max_limit != AltosLib.MISSING) {
1329                         flight_log_max_value.removeAllItems();
1330                         for (int i = 8; i >= 1; i--) {
1331                                 int     size = flight_log_max_limit / i;
1332                                 if (new_storage_erase_unit != 0)
1333                                         size &= ~(new_storage_erase_unit - 1);
1334                                 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1335                         }
1336                 }
1337                 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
1338                         set_flight_log_max(flight_log_max);
1339         }
1340
1341         public void set_ignite_mode(int new_ignite_mode) {
1342                 if (new_ignite_mode != AltosLib.MISSING) {
1343                         if (new_ignite_mode >= ignite_mode_values.length)
1344                                 new_ignite_mode = 0;
1345                         if (new_ignite_mode < 0) {
1346                                 ignite_mode_value.setEnabled(false);
1347                                 new_ignite_mode = 0;
1348                         } else {
1349                                 ignite_mode_value.setEnabled(true);
1350                         }
1351                         ignite_mode_value.setSelectedIndex(new_ignite_mode);
1352                 }
1353                 ignite_mode_value.setVisible(new_ignite_mode != AltosLib.MISSING);
1354                 ignite_mode_label.setVisible(new_ignite_mode != AltosLib.MISSING);
1355
1356                 set_ignite_mode_tool_tip();
1357         }
1358
1359         public int ignite_mode() {
1360                 if (ignite_mode_value.isVisible())
1361                         return ignite_mode_value.getSelectedIndex();
1362                 else
1363                         return AltosLib.MISSING;
1364         }
1365
1366
1367         public void set_pad_orientation(int new_pad_orientation) {
1368                 if (new_pad_orientation != AltosLib.MISSING) {
1369                         if (new_pad_orientation >= pad_orientation_values.length)
1370                                 new_pad_orientation = 0;
1371                         if (new_pad_orientation < 0)
1372                                 new_pad_orientation = 0;
1373                         pad_orientation_value.setSelectedIndex(new_pad_orientation);
1374                 }
1375                 pad_orientation_value.setVisible(new_pad_orientation != AltosLib.MISSING);
1376                 pad_orientation_label.setVisible(new_pad_orientation != AltosLib.MISSING);
1377                 accel_cal.setVisible(new_pad_orientation != AltosLib.MISSING);
1378
1379                 set_pad_orientation_tool_tip();
1380         }
1381
1382         public int pad_orientation() {
1383                 if (pad_orientation_value.isVisible())
1384                         return pad_orientation_value.getSelectedIndex();
1385                 else
1386                         return AltosLib.MISSING;
1387         }
1388
1389         public void set_accel_cal(int accel_plus, int accel_minus) {
1390                 if (accel_plus != AltosLib.MISSING) {
1391                         accel_plus_value.setText(String.format("%d", accel_plus));
1392                         accel_minus_value.setText(String.format("%d", accel_minus));
1393                 }
1394                 accel_plus_value.setVisible(accel_plus != AltosLib.MISSING);
1395                 accel_plus_label.setVisible(accel_plus != AltosLib.MISSING);
1396                 accel_minus_value.setVisible(accel_minus != AltosLib.MISSING);
1397                 accel_minus_label.setVisible(accel_minus != AltosLib.MISSING);
1398
1399                 set_accel_tool_tips();
1400         }
1401
1402         public int accel_cal_plus() {
1403                 if (accel_plus_value.isVisible())
1404                         return Integer.parseInt(accel_plus_value.getText());
1405                 return AltosLib.MISSING;
1406         }
1407
1408         public int accel_cal_minus() {
1409                 if (accel_minus_value.isVisible())
1410                         return Integer.parseInt(accel_minus_value.getText());
1411                 return AltosLib.MISSING;
1412         }
1413
1414         public void set_beep(int new_beep) {
1415                 if (new_beep != AltosLib.MISSING) {
1416                         int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1417                         for (int i = 0; i < beep_values.length; i++)
1418                                 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1419                                         beep_value.setSelectedIndex(i);
1420                                         set_beep_tool_tip();
1421                                         return;
1422                                 }
1423                         beep_value.setSelectedItem(String.format("%d", new_freq));
1424                 }
1425                 beep_value.setVisible(new_beep != AltosLib.MISSING);
1426                 beep_label.setVisible(new_beep != AltosLib.MISSING);
1427                 set_beep_tool_tip();
1428         }
1429
1430         public int beep() {
1431                 if (beep_value.isVisible())
1432                         return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1433                 else
1434                         return AltosLib.MISSING;
1435         }
1436
1437         String[] tracker_motion_values() {
1438                 if (AltosConvert.imperial_units)
1439                         return tracker_motion_values_ft;
1440                 else
1441                         return tracker_motion_values_m;
1442         }
1443
1444         void set_tracker_motion_values() {
1445                 String[]        v = tracker_motion_values();
1446                 while (tracker_motion_value.getItemCount() > 0)
1447                         tracker_motion_value.removeItemAt(0);
1448                 for (int i = 0; i < v.length; i++)
1449                         tracker_motion_value.addItem(v[i]);
1450                 tracker_motion_value.setMaximumRowCount(v.length);
1451         }
1452
1453         String get_tracker_motion_label() {
1454                 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1455         }
1456
1457         void set_tracker_tool_tip() {
1458                 if (tracker_motion_value.isVisible())
1459                         tracker_motion_value.setToolTipText("How far the device must move before logging");
1460                 else
1461                         tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1462                 if (tracker_interval_value.isVisible())
1463                         tracker_interval_value.setToolTipText("How often to report GPS position");
1464                 else
1465                         tracker_interval_value.setToolTipText("This device can't configure interval");
1466         }
1467
1468         public void set_tracker_motion(int tracker_motion) {
1469                 if (tracker_motion != AltosLib.MISSING)
1470                         tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1471                 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1472                 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1473         }
1474
1475         public int tracker_motion() throws AltosConfigDataException {
1476                 if (tracker_motion_value.isVisible()) {
1477                         String str = tracker_motion_value.getSelectedItem().toString();
1478                         try {
1479                                 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1480                         } catch (ParseException pe) {
1481                                 throw new AltosConfigDataException("invalid tracker motion %s", str);
1482                         }
1483                 }
1484                 return AltosLib.MISSING;
1485         }
1486
1487         public void set_tracker_interval(int tracker_interval) {
1488                 if (tracker_interval != AltosLib.MISSING)
1489                         tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1490                 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1491                 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1492         }
1493
1494         public int tracker_interval() throws AltosConfigDataException {
1495                 if (tracker_interval_value.isVisible())
1496                         return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1497                 return AltosLib.MISSING;
1498         }
1499
1500         public void set_pyros(AltosPyro[] new_pyros) {
1501                 pyros = new_pyros;
1502                 if (pyros != null && pyro_ui != null)
1503                         pyro_ui.set_pyros(pyros);
1504                 pyro.setVisible(pyros != null);
1505         }
1506
1507         public AltosPyro[] pyros() throws AltosConfigDataException {
1508                 if (pyro_ui != null)
1509                         pyros = pyro_ui.get_pyros();
1510                 return pyros;
1511         }
1512
1513         public void set_pyro_firing_time(double new_pyro_firing_time) {
1514                 pyro_firing_time = new_pyro_firing_time;
1515                 if (pyro_firing_time != AltosLib.MISSING && pyro_ui != null)
1516                         pyro_ui.set_pyro_firing_time(pyro_firing_time);
1517                 pyro.setVisible(pyro_firing_time != AltosLib.MISSING);
1518         }
1519
1520         public double pyro_firing_time() throws AltosConfigDataException {
1521                 if (pyro_ui != null)
1522                         pyro_firing_time = pyro_ui.get_pyro_firing_time();
1523                 return pyro_firing_time;
1524         }
1525
1526         private String aprs_interval_string(int interval) {
1527                 if (interval == 0)
1528                         return "Disabled";
1529                 return Integer.toString(interval);
1530         }
1531
1532         private int aprs_interval_value(String interval) throws AltosConfigDataException {
1533                 if (interval.equalsIgnoreCase("Disabled"))
1534                         return 0;
1535                 return parse_int("aprs interval", interval, false);
1536         }
1537
1538         public void set_aprs_interval(int new_aprs_interval) {
1539                 if (new_aprs_interval != AltosLib.MISSING)
1540                         aprs_interval_value.setSelectedItem(aprs_interval_string(new_aprs_interval));
1541                 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1542                 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1543                 set_aprs_interval_tool_tip();
1544         }
1545
1546         public int aprs_interval() throws AltosConfigDataException {
1547                 if (aprs_interval_value.isVisible())
1548                         return aprs_interval_value(aprs_interval_value.getSelectedItem().toString());
1549                 return AltosLib.MISSING;
1550         }
1551
1552         public void set_aprs_ssid(int new_aprs_ssid) {
1553                 if (new_aprs_ssid != AltosLib.MISSING)
1554                         aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1555                 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1556                 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1557                 set_aprs_ssid_tool_tip();
1558         }
1559
1560         public int aprs_ssid() throws AltosConfigDataException {
1561                 if (aprs_ssid_value.isVisible()) {
1562                         Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1563                         return i;
1564                 }
1565                 return AltosLib.MISSING;
1566         }
1567
1568         public void set_aprs_format(int new_aprs_format) {
1569                 if (new_aprs_format != AltosLib.MISSING)
1570                         aprs_format_value.setSelectedIndex(new_aprs_format);
1571                 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1572                 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1573                 set_aprs_format_tool_tip();
1574         }
1575
1576         public int aprs_format() throws AltosConfigDataException {
1577                 if (aprs_format_value.isVisible())
1578                         return aprs_format_value.getSelectedIndex();
1579                 return AltosLib.MISSING;
1580         }
1581
1582         public void set_aprs_offset(int new_aprs_offset) {
1583                 if (new_aprs_offset != AltosLib.MISSING)
1584                         aprs_offset_value.setSelectedItem(new_aprs_offset);
1585                 aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
1586                 aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
1587                 set_aprs_offset_tool_tip();
1588         }
1589
1590         public int aprs_offset() throws AltosConfigDataException {
1591                 if (aprs_offset_value.isVisible()) {
1592                         Integer i = (Integer) aprs_offset_value.getSelectedItem();
1593                         return i;
1594                 }
1595                 return AltosLib.MISSING;
1596         }
1597 }