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