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