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