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