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