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