telegps: Copy altosui 'beep feet' bits to telegps
[fw/altos] / telegps / TeleGPSConfigUI.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 org.altusmetrum.telegps;
20
21 import java.text.*;
22 import java.awt.*;
23 import java.awt.event.*;
24 import javax.swing.*;
25 import javax.swing.event.*;
26 import org.altusmetrum.altoslib_14.*;
27 import org.altusmetrum.altosuilib_14.*;
28
29 public class TeleGPSConfigUI
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                  frequency_label;
39         JLabel                  radio_calibration_label;
40         JLabel                  radio_frequency_label;
41         JLabel                  radio_enable_label;
42         JLabel                  radio_10mw_label;
43         JLabel                  report_feet_label;
44         JLabel                  rate_label;
45         JLabel                  aprs_interval_label;
46         JLabel                  aprs_ssid_label;
47         JLabel                  aprs_format_label;
48         JLabel                  aprs_offset_label;
49         JLabel                  flight_log_max_label;
50         JLabel                  callsign_label;
51         JLabel                  tracker_motion_label;
52         JLabel                  tracker_interval_label;
53
54         public boolean          dirty;
55
56         JFrame                  owner;
57         JLabel                  product_value;
58         JLabel                  version_value;
59         JLabel                  serial_value;
60         AltosUIFreqList         radio_frequency_value;
61         JLabel                  radio_calibration_value;
62         JRadioButton            radio_enable_value;
63         JRadioButton            radio_10mw_value;
64         JComboBox<String>       report_feet_value;
65         AltosUIRateList         rate_value;
66         JComboBox<String>       aprs_interval_value;
67         JComboBox<Integer>      aprs_ssid_value;
68         JComboBox<String>       aprs_format_value;
69         JComboBox<Integer>      aprs_offset_value;
70         JComboBox<String>       flight_log_max_value;
71         JTextField              callsign_value;
72         JComboBox<String>       tracker_motion_value;
73         JComboBox<String>       tracker_interval_value;
74
75         JButton                 save;
76         JButton                 reset;
77         JButton                 reboot;
78         JButton                 close;
79
80         ActionListener          listener;
81
82         static String[]         aprs_interval_values = {
83                 "Disabled",
84                 "2",
85                 "5",
86                 "10"
87         };
88
89         static Integer[]        aprs_ssid_values = {
90                 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
91         };
92
93         static Integer[]        aprs_offset_values = {
94                 0, 2, 4, 6, 8, 10, 12, 14, 16, 18
95         };
96
97         static String[]         tracker_motion_values_m = {
98                 "2",
99                 "5",
100                 "10",
101                 "25",
102         };
103
104         static String[]         tracker_motion_values_ft = {
105                 "5",
106                 "20",
107                 "50",
108                 "100"
109         };
110
111         static String[]         tracker_interval_values = {
112                 "1",
113                 "2",
114                 "5",
115                 "10"
116         };
117
118         static String[]         report_feet_values = {
119                 "Meters",
120                 "Feet",
121         };
122
123         /* A window listener to catch closing events and tell the config code */
124         class ConfigListener extends WindowAdapter {
125                 TeleGPSConfigUI ui;
126
127                 public ConfigListener(TeleGPSConfigUI this_ui) {
128                         ui = this_ui;
129                 }
130
131                 public void windowClosing(WindowEvent e) {
132                         ui.actionPerformed(new ActionEvent(e.getSource(),
133                                                            ActionEvent.ACTION_PERFORMED,
134                                                            "Close"));
135                 }
136         }
137
138         public void set_pyros(AltosPyro[] new_pyros) {
139         }
140
141         public AltosPyro[] pyros() {
142                 return null;
143         }
144
145         public void set_pyro_firing_time(double new_pyro_firing_time) {
146         }
147
148         public double pyro_firing_time() {
149                 return AltosLib.MISSING;
150         }
151
152         boolean is_telemetrum() {
153                 String  product = product_value.getText();
154                 return product != null && product.startsWith("TeleGPS");
155         }
156
157         void set_radio_enable_tool_tip() {
158                 if (radio_enable_value.isVisible())
159                         radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
160                 else
161                         radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
162         }
163
164         void set_radio_10mw_tool_tip() {
165                 if (radio_10mw_value.isVisible())
166                         radio_10mw_value.setToolTipText("Should transmitter power be limited to 10mW");
167                 else
168                         radio_10mw_value.setToolTipText("Older firmware could not limit radio power");
169         }
170
171         void set_report_feet_tool_tip() {
172                 if (report_feet_value.isVisible())
173                         report_feet_value.setToolTipText("Units used after landing to beep max height");
174                 else
175                         report_feet_value.setToolTipText("Older firmware always beeps max height in meters");
176         }
177
178         public void set_report_feet(int new_report_feet) {
179                 if (new_report_feet != AltosLib.MISSING) {
180                         if (new_report_feet >= report_feet_values.length)
181                                 new_report_feet = 0;
182                         if (new_report_feet < 0) {
183                                 report_feet_value.setEnabled(false);
184                                 new_report_feet = 0;
185                         } else {
186                                 report_feet_value.setEnabled(true);
187                         }
188                         report_feet_value.setSelectedIndex(new_report_feet);
189                 }
190                 report_feet_value.setVisible(new_report_feet != AltosLib.MISSING);
191                 report_feet_label.setVisible(new_report_feet != AltosLib.MISSING);
192
193                 set_report_feet_tool_tip();
194         }
195
196         public int report_feet() {
197                 if (report_feet_value.isVisible())
198                         return report_feet_value.getSelectedIndex();
199                 else
200                         return AltosLib.MISSING;
201         }
202
203         void set_rate_tool_tip() {
204                 if (rate_value.isVisible())
205                         rate_value.setToolTipText("Select telemetry baud rate");
206                 else
207                         rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
208         }
209
210         void set_aprs_interval_tool_tip() {
211                 if (aprs_interval_value.isVisible())
212                         aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
213                 else
214                         aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
215         }
216
217         void set_aprs_ssid_tool_tip() {
218                 if (aprs_ssid_value.isVisible())
219                         aprs_ssid_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
220                 else if (aprs_ssid_value.isVisible())
221                         aprs_ssid_value.setToolTipText("Software version doesn't support setting the APRS SSID");
222                 else
223                         aprs_ssid_value.setToolTipText("Hardware doesn't support APRS");
224         }
225
226         void set_aprs_format_tool_tip() {
227                 if (aprs_format_value.isVisible())
228                         aprs_format_value.setToolTipText("Set the APRS format (compressed/uncompressed)");
229                 else if (aprs_format_value.isVisible())
230                         aprs_format_value.setToolTipText("Software version doesn't support setting the APRS format");
231                 else
232                         aprs_format_value.setToolTipText("Hardware doesn't support APRS");
233         }
234
235         void set_aprs_offset_tool_tip() {
236                 if (aprs_offset_value.isVisible())
237                         aprs_offset_value.setToolTipText("Set the APRS offset from top of minute");
238                 else if (aprs_offset_value.isVisible())
239                         aprs_offset_value.setToolTipText("Software version doesn't support setting the APRS offset");
240                 else
241                         aprs_offset_value.setToolTipText("Hardware doesn't support APRS");
242         }
243
244         void set_flight_log_max_tool_tip() {
245                 if (flight_log_max_value.isVisible())
246                         flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
247                 else
248                         flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
249         }
250
251         /* Build the UI using a grid bag */
252         public TeleGPSConfigUI(JFrame in_owner) {
253                 super (in_owner, "Configure Device", false);
254
255                 owner = in_owner;
256                 GridBagConstraints c;
257                 int row = 0;
258
259                 Insets il = new Insets(4,4,4,4);
260                 Insets ir = new Insets(4,4,4,4);
261
262                 pane = getScrollablePane();
263                 pane.setLayout(new GridBagLayout());
264
265                 /* Product */
266                 c = new GridBagConstraints();
267                 c.gridx = 0; c.gridy = row;
268                 c.gridwidth = 4;
269                 c.fill = GridBagConstraints.NONE;
270                 c.anchor = GridBagConstraints.LINE_START;
271                 c.insets = il;
272                 product_label = new JLabel("Product:");
273                 pane.add(product_label, c);
274
275                 c = new GridBagConstraints();
276                 c.gridx = 4; c.gridy = row;
277                 c.gridwidth = 4;
278                 c.fill = GridBagConstraints.HORIZONTAL;
279                 c.weightx = 1;
280                 c.anchor = GridBagConstraints.LINE_START;
281                 c.insets = ir;
282                 product_value = new JLabel("");
283                 pane.add(product_value, c);
284                 row++;
285
286                 /* Version */
287                 c = new GridBagConstraints();
288                 c.gridx = 0; c.gridy = row;
289                 c.gridwidth = 4;
290                 c.fill = GridBagConstraints.NONE;
291                 c.anchor = GridBagConstraints.LINE_START;
292                 c.insets = il;
293                 c.ipady = 5;
294                 version_label = new JLabel("Software version:");
295                 pane.add(version_label, c);
296
297                 c = new GridBagConstraints();
298                 c.gridx = 4; c.gridy = row;
299                 c.gridwidth = 4;
300                 c.fill = GridBagConstraints.HORIZONTAL;
301                 c.weightx = 1;
302                 c.anchor = GridBagConstraints.LINE_START;
303                 c.insets = ir;
304                 c.ipady = 5;
305                 version_value = new JLabel("");
306                 pane.add(version_value, c);
307                 row++;
308
309                 /* Serial */
310                 c = new GridBagConstraints();
311                 c.gridx = 0; c.gridy = row;
312                 c.gridwidth = 4;
313                 c.fill = GridBagConstraints.NONE;
314                 c.anchor = GridBagConstraints.LINE_START;
315                 c.insets = il;
316                 c.ipady = 5;
317                 serial_label = new JLabel("Serial:");
318                 pane.add(serial_label, c);
319
320                 c = new GridBagConstraints();
321                 c.gridx = 4; c.gridy = row;
322                 c.gridwidth = 4;
323                 c.fill = GridBagConstraints.HORIZONTAL;
324                 c.weightx = 1;
325                 c.anchor = GridBagConstraints.LINE_START;
326                 c.insets = ir;
327                 c.ipady = 5;
328                 serial_value = new JLabel("");
329                 pane.add(serial_value, c);
330                 row++;
331
332                 /* Frequency */
333                 c = new GridBagConstraints();
334                 c.gridx = 0; c.gridy = row;
335                 c.gridwidth = 4;
336                 c.fill = GridBagConstraints.NONE;
337                 c.anchor = GridBagConstraints.LINE_START;
338                 c.insets = il;
339                 c.ipady = 5;
340                 radio_frequency_label = new JLabel("Frequency:");
341                 pane.add(radio_frequency_label, c);
342
343                 c = new GridBagConstraints();
344                 c.gridx = 4; c.gridy = row;
345                 c.gridwidth = 4;
346                 c.fill = GridBagConstraints.HORIZONTAL;
347                 c.weightx = 1;
348                 c.anchor = GridBagConstraints.LINE_START;
349                 c.insets = ir;
350                 c.ipady = 5;
351                 radio_frequency_value = new AltosUIFreqList();
352                 radio_frequency_value.addItemListener(this);
353                 pane.add(radio_frequency_value, c);
354                 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
355                 row++;
356
357                 /* Radio Calibration */
358                 c = new GridBagConstraints();
359                 c.gridx = 0; c.gridy = row;
360                 c.gridwidth = 4;
361                 c.fill = GridBagConstraints.NONE;
362                 c.anchor = GridBagConstraints.LINE_START;
363                 c.insets = il;
364                 c.ipady = 5;
365                 radio_calibration_label = new JLabel("RF Calibration:");
366                 pane.add(radio_calibration_label, c);
367
368                 c = new GridBagConstraints();
369                 c.gridx = 4; c.gridy = row;
370                 c.gridwidth = 4;
371                 c.fill = GridBagConstraints.HORIZONTAL;
372                 c.weightx = 1;
373                 c.anchor = GridBagConstraints.LINE_START;
374                 c.insets = ir;
375                 c.ipady = 5;
376                 radio_calibration_value = new JLabel(String.format("%d", 1186611));
377                 pane.add(radio_calibration_value, c);
378                 row++;
379
380                 /* Radio Enable */
381                 c = new GridBagConstraints();
382                 c.gridx = 0; c.gridy = row;
383                 c.gridwidth = 4;
384                 c.fill = GridBagConstraints.NONE;
385                 c.anchor = GridBagConstraints.LINE_START;
386                 c.insets = il;
387                 c.ipady = 5;
388                 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
389                 pane.add(radio_enable_label, c);
390
391                 c = new GridBagConstraints();
392                 c.gridx = 4; c.gridy = row;
393                 c.gridwidth = 4;
394                 c.fill = GridBagConstraints.HORIZONTAL;
395                 c.weightx = 1;
396                 c.anchor = GridBagConstraints.LINE_START;
397                 c.insets = ir;
398                 c.ipady = 5;
399                 radio_enable_value = new JRadioButton("Enabled");
400                 radio_enable_value.addItemListener(this);
401                 pane.add(radio_enable_value, c);
402                 set_radio_enable_tool_tip();
403                 row++;
404
405                 /* Radio 10mW limit */
406                 c = new GridBagConstraints();
407                 c.gridx = 0; c.gridy = row;
408                 c.gridwidth = 4;
409                 c.fill = GridBagConstraints.NONE;
410                 c.anchor = GridBagConstraints.LINE_START;
411                 c.insets = il;
412                 c.ipady = 5;
413                 radio_10mw_label = new JLabel("Limit transmit to 10mW:");
414                 pane.add(radio_10mw_label, c);
415
416                 c = new GridBagConstraints();
417                 c.gridx = 4; c.gridy = row;
418                 c.gridwidth = 4;
419                 c.fill = GridBagConstraints.HORIZONTAL;
420                 c.weightx = 1;
421                 c.anchor = GridBagConstraints.LINE_START;
422                 c.insets = ir;
423                 c.ipady = 5;
424                 radio_10mw_value = new JRadioButton("Limited");
425                 radio_10mw_value.addItemListener(this);
426                 pane.add(radio_10mw_value, c);
427                 set_radio_10mw_tool_tip();
428                 row++;
429
430                 /* Telemetry Rate */
431                 c = new GridBagConstraints();
432                 c.gridx = 0; c.gridy = row;
433                 c.gridwidth = 4;
434                 c.fill = GridBagConstraints.NONE;
435                 c.anchor = GridBagConstraints.LINE_START;
436                 c.insets = il;
437                 c.ipady = 5;
438                 rate_label = new JLabel("Telemetry baud rate:");
439                 pane.add(rate_label, c);
440
441                 c = new GridBagConstraints();
442                 c.gridx = 4; c.gridy = row;
443                 c.gridwidth = 4;
444                 c.fill = GridBagConstraints.HORIZONTAL;
445                 c.weightx = 1;
446                 c.anchor = GridBagConstraints.LINE_START;
447                 c.insets = ir;
448                 c.ipady = 5;
449                 rate_value = new AltosUIRateList();
450                 rate_value.addItemListener(this);
451                 pane.add(rate_value, c);
452                 set_rate_tool_tip();
453                 row++;
454
455                 /* APRS interval */
456                 c = new GridBagConstraints();
457                 c.gridx = 0; c.gridy = row;
458                 c.gridwidth = 4;
459                 c.fill = GridBagConstraints.NONE;
460                 c.anchor = GridBagConstraints.LINE_START;
461                 c.insets = il;
462                 c.ipady = 5;
463                 aprs_interval_label = new JLabel("APRS Interval(s):");
464                 pane.add(aprs_interval_label, c);
465
466                 c = new GridBagConstraints();
467                 c.gridx = 4; c.gridy = row;
468                 c.gridwidth = 4;
469                 c.fill = GridBagConstraints.HORIZONTAL;
470                 c.weightx = 1;
471                 c.anchor = GridBagConstraints.LINE_START;
472                 c.insets = ir;
473                 c.ipady = 5;
474                 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
475                 aprs_interval_value.setEditable(true);
476                 aprs_interval_value.addItemListener(this);
477                 pane.add(aprs_interval_value, c);
478                 set_aprs_interval_tool_tip();
479                 row++;
480
481                 /* APRS SSID */
482                 c = new GridBagConstraints();
483                 c.gridx = 0; c.gridy = row;
484                 c.gridwidth = 4;
485                 c.fill = GridBagConstraints.NONE;
486                 c.anchor = GridBagConstraints.LINE_START;
487                 c.insets = il;
488                 c.ipady = 5;
489                 aprs_ssid_label = new JLabel("APRS SSID:");
490                 pane.add(aprs_ssid_label, c);
491
492                 c = new GridBagConstraints();
493                 c.gridx = 4; c.gridy = row;
494                 c.gridwidth = 4;
495                 c.fill = GridBagConstraints.HORIZONTAL;
496                 c.weightx = 1;
497                 c.anchor = GridBagConstraints.LINE_START;
498                 c.insets = ir;
499                 c.ipady = 5;
500                 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
501                 aprs_ssid_value.setEditable(false);
502                 aprs_ssid_value.addItemListener(this);
503                 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
504                 pane.add(aprs_ssid_value, c);
505                 set_aprs_ssid_tool_tip();
506                 row++;
507
508                 /* APRS format */
509                 c = new GridBagConstraints();
510                 c.gridx = 0; c.gridy = row;
511                 c.gridwidth = 4;
512                 c.fill = GridBagConstraints.NONE;
513                 c.anchor = GridBagConstraints.LINE_START;
514                 c.insets = il;
515                 c.ipady = 5;
516                 aprs_format_label = new JLabel("APRS format:");
517                 pane.add(aprs_format_label, c);
518
519                 c = new GridBagConstraints();
520                 c.gridx = 4; c.gridy = row;
521                 c.gridwidth = 4;
522                 c.fill = GridBagConstraints.HORIZONTAL;
523                 c.weightx = 1;
524                 c.anchor = GridBagConstraints.LINE_START;
525                 c.insets = ir;
526                 c.ipady = 5;
527                 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
528                 aprs_format_value.setEditable(false);
529                 aprs_format_value.addItemListener(this);
530                 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
531                 pane.add(aprs_format_value, c);
532                 set_aprs_format_tool_tip();
533                 row++;
534
535                 /* APRS offset */
536                 c = new GridBagConstraints();
537                 c.gridx = 0; c.gridy = row;
538                 c.gridwidth = 4;
539                 c.fill = GridBagConstraints.NONE;
540                 c.anchor = GridBagConstraints.LINE_START;
541                 c.insets = il;
542                 c.ipady = 5;
543                 aprs_offset_label = new JLabel("APRS offset:");
544                 pane.add(aprs_offset_label, c);
545
546                 c = new GridBagConstraints();
547                 c.gridx = 4; c.gridy = row;
548                 c.gridwidth = 4;
549                 c.fill = GridBagConstraints.HORIZONTAL;
550                 c.weightx = 1;
551                 c.anchor = GridBagConstraints.LINE_START;
552                 c.insets = ir;
553                 c.ipady = 5;
554                 aprs_offset_value = new JComboBox<Integer>(aprs_offset_values);
555                 aprs_offset_value.setEditable(false);
556                 aprs_offset_value.addItemListener(this);
557                 aprs_offset_value.setMaximumRowCount(aprs_offset_values.length);
558                 pane.add(aprs_offset_value, c);
559                 set_aprs_offset_tool_tip();
560                 row++;
561
562                 /* Callsign */
563                 c = new GridBagConstraints();
564                 c.gridx = 0; c.gridy = row;
565                 c.gridwidth = 4;
566                 c.fill = GridBagConstraints.NONE;
567                 c.anchor = GridBagConstraints.LINE_START;
568                 c.insets = il;
569                 c.ipady = 5;
570                 callsign_label = new JLabel("Callsign:");
571                 pane.add(callsign_label, c);
572
573                 c = new GridBagConstraints();
574                 c.gridx = 4; c.gridy = row;
575                 c.gridwidth = 4;
576                 c.fill = GridBagConstraints.HORIZONTAL;
577                 c.weightx = 1;
578                 c.anchor = GridBagConstraints.LINE_START;
579                 c.insets = ir;
580                 c.ipady = 5;
581                 callsign_value = new JTextField(AltosUIPreferences.callsign());
582                 callsign_value.getDocument().addDocumentListener(this);
583                 pane.add(callsign_value, c);
584                 callsign_value.setToolTipText("Callsign reported in telemetry data");
585                 row++;
586
587                 /* Flight log max */
588                 c = new GridBagConstraints();
589                 c.gridx = 0; c.gridy = row;
590                 c.gridwidth = 4;
591                 c.fill = GridBagConstraints.NONE;
592                 c.anchor = GridBagConstraints.LINE_START;
593                 c.insets = il;
594                 c.ipady = 5;
595                 flight_log_max_label = new JLabel("Maximum Log Size (kB):");
596                 pane.add(flight_log_max_label, c);
597
598                 c = new GridBagConstraints();
599                 c.gridx = 4; c.gridy = row;
600                 c.gridwidth = 4;
601                 c.fill = GridBagConstraints.HORIZONTAL;
602                 c.weightx = 1;
603                 c.anchor = GridBagConstraints.LINE_START;
604                 c.insets = ir;
605                 c.ipady = 5;
606                 flight_log_max_value = new JComboBox<String>();
607                 flight_log_max_value.setEditable(true);
608                 flight_log_max_value.addItemListener(this);
609                 pane.add(flight_log_max_value, c);
610                 set_flight_log_max_tool_tip();
611                 row++;
612
613                 /* Tracker triger horiz distances */
614                 c = new GridBagConstraints();
615                 c.gridx = 0; c.gridy = row;
616                 c.gridwidth = 4;
617                 c.fill = GridBagConstraints.NONE;
618                 c.anchor = GridBagConstraints.LINE_START;
619                 c.insets = il;
620                 c.ipady = 5;
621                 tracker_motion_label = new JLabel(get_tracker_motion_label());
622                 pane.add(tracker_motion_label, c);
623
624                 c = new GridBagConstraints();
625                 c.gridx = 4; c.gridy = row;
626                 c.gridwidth = 4;
627                 c.fill = GridBagConstraints.HORIZONTAL;
628                 c.weightx = 1;
629                 c.anchor = GridBagConstraints.LINE_START;
630                 c.insets = ir;
631                 c.ipady = 5;
632                 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
633                 tracker_motion_value.setEditable(true);
634                 tracker_motion_value.addItemListener(this);
635                 pane.add(tracker_motion_value, c);
636                 row++;
637
638                 /* Tracker triger vert distances */
639                 c = new GridBagConstraints();
640                 c.gridx = 0; c.gridy = row;
641                 c.gridwidth = 4;
642                 c.fill = GridBagConstraints.NONE;
643                 c.anchor = GridBagConstraints.LINE_START;
644                 c.insets = il;
645                 c.ipady = 5;
646                 tracker_interval_label = new JLabel("Position Reporting Interval (s):");
647                 pane.add(tracker_interval_label, c);
648
649                 c = new GridBagConstraints();
650                 c.gridx = 4; c.gridy = row;
651                 c.gridwidth = 4;
652                 c.fill = GridBagConstraints.HORIZONTAL;
653                 c.weightx = 1;
654                 c.anchor = GridBagConstraints.LINE_START;
655                 c.insets = ir;
656                 c.ipady = 5;
657                 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
658                 tracker_interval_value.setEditable(true);
659                 tracker_interval_value.addItemListener(this);
660                 pane.add(tracker_interval_value, c);
661                 set_tracker_tool_tip();
662                 row++;
663
664                 /* Buttons */
665                 c = new GridBagConstraints();
666                 c.gridx = 0; c.gridy = row;
667                 c.gridwidth = 2;
668                 c.fill = GridBagConstraints.NONE;
669                 c.anchor = GridBagConstraints.LINE_START;
670                 c.insets = il;
671                 save = new JButton("Save");
672                 pane.add(save, c);
673                 save.addActionListener(this);
674                 save.setActionCommand("Save");
675
676                 c = new GridBagConstraints();
677                 c.gridx = 2; c.gridy = row;
678                 c.gridwidth = 2;
679                 c.fill = GridBagConstraints.NONE;
680                 c.anchor = GridBagConstraints.CENTER;
681                 c.insets = il;
682                 reset = new JButton("Reset");
683                 pane.add(reset, c);
684                 reset.addActionListener(this);
685                 reset.setActionCommand("Reset");
686
687                 c = new GridBagConstraints();
688                 c.gridx = 4; c.gridy = row;
689                 c.gridwidth = 2;
690                 c.fill = GridBagConstraints.NONE;
691                 c.anchor = GridBagConstraints.CENTER;
692                 c.insets = il;
693                 reboot = new JButton("Reboot");
694                 pane.add(reboot, c);
695                 reboot.addActionListener(this);
696                 reboot.setActionCommand("Reboot");
697
698                 c = new GridBagConstraints();
699                 c.gridx = 6; c.gridy = row;
700                 c.gridwidth = 2;
701                 c.fill = GridBagConstraints.NONE;
702                 c.anchor = GridBagConstraints.LINE_END;
703                 c.insets = il;
704                 close = new JButton("Close");
705                 pane.add(close, c);
706                 close.addActionListener(this);
707                 close.setActionCommand("Close");
708
709                 addWindowListener(new ConfigListener(this));
710                 AltosPreferences.register_units_listener(this);
711         }
712
713         /* Once the initial values are set, the config code will show the dialog */
714         public void make_visible() {
715                 pack();
716                 setLocationRelativeTo(owner);
717                 setVisible(true);
718         }
719
720         /* If any values have been changed, confirm before closing */
721         public boolean check_dirty(String operation) {
722                 if (dirty) {
723                         Object[] options = { String.format("%s anyway", operation), "Keep editing" };
724                         int i;
725                         i = JOptionPane.showOptionDialog(this,
726                                                          String.format("Configuration modified. %s anyway?", operation),
727                                                          "Configuration Modified",
728                                                          JOptionPane.DEFAULT_OPTION,
729                                                          JOptionPane.WARNING_MESSAGE,
730                                                          null, options, options[1]);
731                         if (i != 0)
732                                 return false;
733                 }
734                 return true;
735         }
736
737         public void set_dirty() {
738                 dirty = true;
739                 save.setEnabled(true);
740         }
741
742         public void set_clean() {
743                 dirty = false;
744                 save.setEnabled(false);
745         }
746
747         public void dispose() {
748                 AltosPreferences.unregister_units_listener(this);
749                 super.dispose();
750         }
751
752         public int accel_cal_plus() {
753                 return AltosLib.MISSING;
754         }
755
756         public int accel_cal_minus() {
757                 return AltosLib.MISSING;
758         }
759
760         public void set_accel_cal(int accel_plus, int accel_minus) {
761         }
762
763         /* Listen for events from our buttons */
764         public void actionPerformed(ActionEvent e) {
765                 String  cmd = e.getActionCommand();
766
767                 if (cmd.equals("Close") || cmd.equals("Reboot"))
768                         if (!check_dirty(cmd))
769                                 return;
770                 listener.actionPerformed(e);
771                 if (cmd.equals("Close") || cmd.equals("Reboot")) {
772                         setVisible(false);
773                         dispose();
774                 }
775                 set_clean();
776         }
777
778         /* ItemListener interface method */
779         public void itemStateChanged(ItemEvent e) {
780                 set_dirty();
781         }
782
783         /* DocumentListener interface methods */
784         public void changedUpdate(DocumentEvent e) {
785                 set_dirty();
786         }
787
788         public void insertUpdate(DocumentEvent e) {
789                 set_dirty();
790         }
791
792         public void removeUpdate(DocumentEvent e) {
793                 set_dirty();
794         }
795
796         /* Let the config code hook on a listener */
797         public void addActionListener(ActionListener l) {
798                 listener = l;
799         }
800
801         public void units_changed(boolean imperial_units) {
802                 boolean was_dirty = dirty;
803
804                 if (tracker_motion_value.isVisible()) {
805                         String motion = tracker_motion_value.getSelectedItem().toString();
806                         tracker_motion_label.setText(get_tracker_motion_label());
807                         set_tracker_motion_values();
808                         try {
809                                 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
810                                 set_tracker_motion(m);
811                         } catch (ParseException pe) {
812                         }
813                 }
814                 if (!was_dirty)
815                         set_clean();
816         }
817
818         /* set and get all of the dialog values */
819         public void set_product(String product) {
820                 radio_frequency_value.set_product(product);
821                 product_value.setText(product);
822                 set_flight_log_max_tool_tip();
823         }
824
825         public void set_version(String version) {
826                 version_value.setText(version);
827         }
828
829         public void set_serial(int serial) {
830                 radio_frequency_value.set_serial(serial);
831                 serial_value.setText(String.format("%d", serial));
832         }
833
834         public void set_altitude_32(int altitude_32) {
835         }
836
837         public void set_main_deploy(int new_main_deploy) {
838         }
839
840         public int main_deploy() {
841                 return AltosLib.MISSING;
842         }
843
844         public void set_apogee_delay(int new_apogee_delay) { }
845
846         public int apogee_delay() {
847                 return AltosLib.MISSING;
848         }
849
850         public void set_apogee_lockout(int new_apogee_lockout) { }
851
852         public int apogee_lockout() { return AltosLib.MISSING; }
853
854         public void set_radio_frequency(double new_radio_frequency) {
855                 if (new_radio_frequency != AltosLib.MISSING)
856                         radio_frequency_value.set_frequency(new_radio_frequency);
857                 radio_frequency_label.setVisible(new_radio_frequency != AltosLib.MISSING);
858                 radio_frequency_value.setVisible(new_radio_frequency != AltosLib.MISSING);
859         }
860
861         public double radio_frequency() {
862                 return radio_frequency_value.frequency();
863         }
864
865         public void set_radio_calibration(int new_radio_calibration) {
866                 if (new_radio_calibration != AltosLib.MISSING)
867                         radio_calibration_value.setText(String.format("%d", new_radio_calibration));
868                 radio_calibration_value.setVisible(new_radio_calibration == AltosLib.MISSING);
869                 radio_calibration_label.setVisible(new_radio_calibration == AltosLib.MISSING);
870         }
871
872         public void set_radio_enable(int new_radio_enable) {
873                 if (new_radio_enable != AltosLib.MISSING)
874                         radio_enable_value.setSelected(new_radio_enable != 0);
875                 radio_enable_label.setVisible(new_radio_enable != AltosLib.MISSING);
876                 radio_enable_value.setVisible(new_radio_enable != AltosLib.MISSING);
877                 set_radio_enable_tool_tip();
878         }
879
880         public int radio_enable() {
881                 if (radio_enable_value.isVisible())
882                         return radio_enable_value.isSelected() ? 1 : 0;
883                 else
884                         return AltosLib.MISSING;
885         }
886
887         public void set_radio_10mw(int new_radio_10mw) {
888                 if (new_radio_10mw != AltosLib.MISSING) {
889                         radio_10mw_value.setSelected(new_radio_10mw != 0);
890                 }
891                 radio_10mw_value.setVisible(new_radio_10mw != AltosLib.MISSING);
892                 radio_10mw_label.setVisible(new_radio_10mw != AltosLib.MISSING);
893                 set_radio_10mw_tool_tip();
894         }
895
896         public int radio_10mw() {
897                 if (radio_10mw_value.isVisible())
898                         return radio_10mw_value.isSelected() ? 1 : 0;
899                 else
900                         return AltosLib.MISSING;
901         }
902
903         public void set_telemetry_rate(int new_rate) {
904                 if (new_rate != AltosLib.MISSING)
905                         rate_value.set_rate(new_rate);
906                 rate_label.setVisible(new_rate != AltosLib.MISSING);
907                 rate_value.setVisible(new_rate != AltosLib.MISSING);
908         }
909
910         public int telemetry_rate() {
911                 return rate_value.rate();
912         }
913
914         public void set_callsign(String new_callsign) {
915                 if (new_callsign != null)
916                         callsign_value.setText(new_callsign);
917                 callsign_value.setVisible(new_callsign != null);
918                 callsign_label.setVisible(new_callsign != null);
919         }
920
921         public String callsign() {
922                 if (callsign_value.isVisible())
923                         return callsign_value.getText();
924                 return null;
925         }
926
927         private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
928                 String v = s;
929                 if (split)
930                         v = s.split("\\s+")[0];
931                 try {
932                         return Integer.parseInt(v);
933                 } catch (NumberFormatException ne) {
934                         throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
935                 }
936         }
937
938         int     flight_log_max_limit;
939         int     flight_log_max;
940
941         public String flight_log_max_label(int flight_log_max) {
942                 if (flight_log_max_limit != 0) {
943                         int     nflight = flight_log_max_limit / flight_log_max;
944                         String  plural = nflight > 1 ? "s" : "";
945
946                         return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
947                 }
948                 return String.format("%d", flight_log_max);
949         }
950
951         public void set_flight_log_max(int new_flight_log_max) {
952                 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
953                 flight_log_max = new_flight_log_max;
954                 set_flight_log_max_tool_tip();
955         }
956
957         public void set_flight_log_max_enabled(boolean enable) {
958                 flight_log_max_value.setEnabled(enable);
959                 set_flight_log_max_tool_tip();
960         }
961
962         public int flight_log_max() throws AltosConfigDataException {
963                 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
964         }
965
966         public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
967                 flight_log_max_limit = new_flight_log_max_limit;
968                 if (new_flight_log_max_limit != AltosLib.MISSING) {
969                         flight_log_max_value.removeAllItems();
970                         for (int i = 8; i >= 1; i--) {
971                                 int     size = flight_log_max_limit / i;
972                                 if (new_storage_erase_unit != 0)
973                                         size &= ~(new_storage_erase_unit - 1);
974                                 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
975                         }
976                 }
977                 if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
978                         set_flight_log_max(flight_log_max);
979         }
980
981         public void set_ignite_mode(int new_ignite_mode) { }
982         public int ignite_mode() { return AltosLib.MISSING; }
983
984
985         public void set_pad_orientation(int new_pad_orientation) { }
986         public int pad_orientation() { return AltosLib.MISSING; }
987
988         public void set_beep(int new_beep) { }
989
990         public int beep() { return AltosLib.MISSING; }
991
992         String[] tracker_motion_values() {
993                 if (AltosConvert.imperial_units)
994                         return tracker_motion_values_ft;
995                 else
996                         return tracker_motion_values_m;
997         }
998
999         void set_tracker_motion_values() {
1000                 String[]        v = tracker_motion_values();
1001                 while (tracker_motion_value.getItemCount() > 0)
1002                         tracker_motion_value.removeItemAt(0);
1003                 for (int i = 0; i < v.length; i++)
1004                         tracker_motion_value.addItem(v[i]);
1005                 tracker_motion_value.setMaximumRowCount(v.length);
1006         }
1007
1008         String get_tracker_motion_label() {
1009                 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1010         }
1011
1012         void set_tracker_tool_tip() {
1013                 if (tracker_motion_value.isVisible())
1014                         tracker_motion_value.setToolTipText("How far the device must move before logging");
1015                 else
1016                         tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1017                 if (tracker_interval_value.isVisible())
1018                         tracker_interval_value.setToolTipText("How often to report GPS position");
1019                 else
1020                         tracker_interval_value.setToolTipText("This device can't configure interval");
1021         }
1022
1023         public void set_tracker_motion(int tracker_motion) {
1024                 if (tracker_motion != AltosLib.MISSING)
1025                         tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1026                 tracker_motion_label.setVisible(tracker_motion != AltosLib.MISSING);
1027                 tracker_motion_value.setVisible(tracker_motion != AltosLib.MISSING);
1028         }
1029
1030         public int tracker_motion() throws AltosConfigDataException {
1031                 if (tracker_motion_value.isVisible()) {
1032                         String str = tracker_motion_value.getSelectedItem().toString();
1033                         try {
1034                                 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1035                         } catch (ParseException pe) {
1036                                 throw new AltosConfigDataException("invalid tracker motion %s", str);
1037                         }
1038                 }
1039                 return AltosLib.MISSING;
1040         }
1041
1042         public void set_tracker_interval(int tracker_interval) {
1043                 if (tracker_interval != AltosLib.MISSING)
1044                         tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1045                 tracker_interval_label.setVisible(tracker_interval != AltosLib.MISSING);
1046                 tracker_interval_value.setVisible(tracker_interval != AltosLib.MISSING);
1047         }
1048
1049         public int tracker_interval() throws AltosConfigDataException {
1050                 if (tracker_interval_value.isVisible())
1051                         return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1052                 return AltosLib.MISSING;
1053         }
1054
1055         public void set_aprs_interval(int new_aprs_interval) {
1056                 if (new_aprs_interval != AltosLib.MISSING)
1057                         aprs_interval_value.setSelectedItem(Integer.toString(new_aprs_interval));
1058                 aprs_interval_value.setVisible(new_aprs_interval != AltosLib.MISSING);
1059                 aprs_interval_label.setVisible(new_aprs_interval != AltosLib.MISSING);
1060                 set_aprs_interval_tool_tip();
1061         }
1062
1063         public int aprs_interval() throws AltosConfigDataException {
1064                 if (aprs_interval_value.isVisible()) {
1065                         String  s = aprs_interval_value.getSelectedItem().toString();
1066
1067                         return parse_int("aprs interval", s, false);
1068                 }
1069                 return AltosLib.MISSING;
1070         }
1071
1072         public void set_aprs_ssid(int new_aprs_ssid) {
1073                 if (new_aprs_ssid != AltosLib.MISSING)
1074                         aprs_ssid_value.setSelectedItem(new_aprs_ssid);
1075                 aprs_ssid_value.setVisible(new_aprs_ssid != AltosLib.MISSING);
1076                 aprs_ssid_label.setVisible(new_aprs_ssid != AltosLib.MISSING);
1077                 set_aprs_ssid_tool_tip();
1078         }
1079
1080         public int aprs_ssid() throws AltosConfigDataException {
1081                 if (aprs_ssid_value.isVisible()) {
1082                         Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1083                         return i;
1084                 }
1085                 return AltosLib.MISSING;
1086         }
1087
1088         public void set_aprs_format(int new_aprs_format) {
1089                 if (new_aprs_format != AltosLib.MISSING)
1090                         aprs_format_value.setSelectedIndex(new_aprs_format);
1091                 aprs_format_value.setVisible(new_aprs_format != AltosLib.MISSING);
1092                 aprs_format_label.setVisible(new_aprs_format != AltosLib.MISSING);
1093                 set_aprs_format_tool_tip();
1094         }
1095
1096         public int aprs_format() throws AltosConfigDataException {
1097                 if (aprs_format_value.isVisible())
1098                         return aprs_format_value.getSelectedIndex();
1099                 return AltosLib.MISSING;
1100         }
1101         public void set_aprs_offset(int new_aprs_offset) {
1102                 if (new_aprs_offset != AltosLib.MISSING)
1103                         aprs_offset_value.setSelectedItem(new_aprs_offset);
1104                 aprs_offset_value.setVisible(new_aprs_offset != AltosLib.MISSING);
1105                 aprs_offset_label.setVisible(new_aprs_offset != AltosLib.MISSING);
1106                 set_aprs_offset_tool_tip();
1107         }
1108
1109         public int aprs_offset() throws AltosConfigDataException {
1110                 if (aprs_offset_value.isVisible()) {
1111                         Integer i = (Integer) aprs_offset_value.getSelectedItem();
1112                         return i;
1113                 }
1114                 return AltosLib.MISSING;
1115         }
1116 }