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