telegps: Was mis-configuring the 'Configure Device' dialog
[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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package org.altusmetrum.telegps;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import javax.swing.event.*;
24 import org.altusmetrum.altoslib_5.*;
25 import org.altusmetrum.altosuilib_3.*;
26
27 public class TeleGPSConfigUI
28         extends AltosUIDialog
29         implements ActionListener, ItemListener, DocumentListener, AltosConfigValues, AltosUnitsListener
30 {
31
32         Container               pane;
33         JLabel                  product_label;
34         JLabel                  version_label;
35         JLabel                  serial_label;
36         JLabel                  frequency_label;
37         JLabel                  radio_calibration_label;
38         JLabel                  radio_frequency_label;
39         JLabel                  radio_enable_label;
40         JLabel                  rate_label;
41         JLabel                  aprs_interval_label;
42         JLabel                  aprs_ssid_label;
43         JLabel                  flight_log_max_label;
44         JLabel                  callsign_label;
45         JLabel                  tracker_motion_label;
46         JLabel                  tracker_interval_label;
47
48         public boolean          dirty;
49
50         JFrame                  owner;
51         JLabel                  product_value;
52         JLabel                  version_value;
53         JLabel                  serial_value;
54         AltosUIFreqList         radio_frequency_value;
55         JTextField              radio_calibration_value;
56         JRadioButton            radio_enable_value;
57         AltosUIRateList         rate_value;
58         JComboBox<String>       aprs_interval_value;
59         JComboBox<Integer>      aprs_ssid_value;
60         JComboBox<String>       flight_log_max_value;
61         JTextField              callsign_value;
62         JComboBox<String>       tracker_motion_value;
63         JComboBox<String>       tracker_interval_value;
64
65         JButton                 save;
66         JButton                 reset;
67         JButton                 reboot;
68         JButton                 close;
69
70         ActionListener          listener;
71
72         static String[]         aprs_interval_values = {
73                 "Disabled",
74                 "2",
75                 "5",
76                 "10"
77         };
78
79         static Integer[]        aprs_ssid_values = {
80                 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
81         };
82
83         static String[]         tracker_motion_values_m = {
84                 "2",
85                 "5",
86                 "10",
87                 "25",
88         };
89
90         static String[]         tracker_motion_values_ft = {
91                 "5",
92                 "20",
93                 "50",
94                 "100"
95         };
96
97         static String[]         tracker_interval_values = {
98                 "1",
99                 "2",
100                 "5",
101                 "10"
102         };
103
104         /* A window listener to catch closing events and tell the config code */
105         class ConfigListener extends WindowAdapter {
106                 TeleGPSConfigUI ui;
107
108                 public ConfigListener(TeleGPSConfigUI this_ui) {
109                         ui = this_ui;
110                 }
111
112                 public void windowClosing(WindowEvent e) {
113                         ui.actionPerformed(new ActionEvent(e.getSource(),
114                                                            ActionEvent.ACTION_PERFORMED,
115                                                            "Close"));
116                 }
117         }
118
119         public void set_pyros(AltosPyro[] new_pyros) {
120         }
121
122         public AltosPyro[] pyros() {
123                 return null;
124         }
125
126         public void set_pyro_firing_time(double new_pyro_firing_time) {
127         }
128
129         public double pyro_firing_time() {
130                 return -1;
131         }
132
133         boolean is_telemetrum() {
134                 String  product = product_value.getText();
135                 return product != null && product.startsWith("TeleGPS");
136         }
137
138         void set_radio_calibration_tool_tip() {
139                 if (radio_calibration_value.isEnabled())
140                         radio_calibration_value.setToolTipText("Tune radio output to match desired frequency");
141                 else
142                         radio_calibration_value.setToolTipText("Cannot tune radio while connected over packet mode");
143         }
144
145         void set_radio_enable_tool_tip() {
146                 if (radio_enable_value.isEnabled())
147                         radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
148                 else
149                         radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
150         }
151
152         void set_rate_tool_tip() {
153                 if (rate_value.isEnabled())
154                         rate_value.setToolTipText("Select telemetry baud rate");
155                 else
156                         rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
157         }
158
159         void set_aprs_interval_tool_tip() {
160                 if (aprs_interval_value.isEnabled())
161                         aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
162                 else
163                         aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
164         }
165
166         void set_aprs_ssid_tool_tip() {
167                 if (aprs_ssid_value.isEnabled())
168                         aprs_interval_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
169                 else if (aprs_interval_value.isEnabled())
170                         aprs_interval_value.setToolTipText("Software version doesn't support setting the APRS SSID");
171                 else
172                         aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
173         }
174
175         void set_flight_log_max_tool_tip() {
176                 if (flight_log_max_value.isEnabled())
177                         flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
178                 else
179                         flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
180         }
181
182         /* Build the UI using a grid bag */
183         public TeleGPSConfigUI(JFrame in_owner) {
184                 super (in_owner, "Configure Device", false);
185
186                 owner = in_owner;
187                 GridBagConstraints c;
188                 int row = 0;
189
190                 Insets il = new Insets(4,4,4,4);
191                 Insets ir = new Insets(4,4,4,4);
192
193                 pane = getContentPane();
194                 pane.setLayout(new GridBagLayout());
195
196                 /* Product */
197                 c = new GridBagConstraints();
198                 c.gridx = 0; c.gridy = row;
199                 c.gridwidth = 4;
200                 c.fill = GridBagConstraints.NONE;
201                 c.anchor = GridBagConstraints.LINE_START;
202                 c.insets = il;
203                 product_label = new JLabel("Product:");
204                 pane.add(product_label, c);
205
206                 c = new GridBagConstraints();
207                 c.gridx = 4; c.gridy = row;
208                 c.gridwidth = 4;
209                 c.fill = GridBagConstraints.HORIZONTAL;
210                 c.weightx = 1;
211                 c.anchor = GridBagConstraints.LINE_START;
212                 c.insets = ir;
213                 product_value = new JLabel("");
214                 pane.add(product_value, c);
215                 row++;
216
217                 /* Version */
218                 c = new GridBagConstraints();
219                 c.gridx = 0; c.gridy = row;
220                 c.gridwidth = 4;
221                 c.fill = GridBagConstraints.NONE;
222                 c.anchor = GridBagConstraints.LINE_START;
223                 c.insets = il;
224                 c.ipady = 5;
225                 version_label = new JLabel("Software version:");
226                 pane.add(version_label, c);
227
228                 c = new GridBagConstraints();
229                 c.gridx = 4; c.gridy = row;
230                 c.gridwidth = 4;
231                 c.fill = GridBagConstraints.HORIZONTAL;
232                 c.weightx = 1;
233                 c.anchor = GridBagConstraints.LINE_START;
234                 c.insets = ir;
235                 c.ipady = 5;
236                 version_value = new JLabel("");
237                 pane.add(version_value, c);
238                 row++;
239
240                 /* Serial */
241                 c = new GridBagConstraints();
242                 c.gridx = 0; c.gridy = row;
243                 c.gridwidth = 4;
244                 c.fill = GridBagConstraints.NONE;
245                 c.anchor = GridBagConstraints.LINE_START;
246                 c.insets = il;
247                 c.ipady = 5;
248                 serial_label = new JLabel("Serial:");
249                 pane.add(serial_label, c);
250
251                 c = new GridBagConstraints();
252                 c.gridx = 4; c.gridy = row;
253                 c.gridwidth = 4;
254                 c.fill = GridBagConstraints.HORIZONTAL;
255                 c.weightx = 1;
256                 c.anchor = GridBagConstraints.LINE_START;
257                 c.insets = ir;
258                 c.ipady = 5;
259                 serial_value = new JLabel("");
260                 pane.add(serial_value, c);
261                 row++;
262
263                 /* Frequency */
264                 c = new GridBagConstraints();
265                 c.gridx = 0; c.gridy = row;
266                 c.gridwidth = 4;
267                 c.fill = GridBagConstraints.NONE;
268                 c.anchor = GridBagConstraints.LINE_START;
269                 c.insets = il;
270                 c.ipady = 5;
271                 radio_frequency_label = new JLabel("Frequency:");
272                 pane.add(radio_frequency_label, c);
273
274                 c = new GridBagConstraints();
275                 c.gridx = 4; c.gridy = row;
276                 c.gridwidth = 4;
277                 c.fill = GridBagConstraints.HORIZONTAL;
278                 c.weightx = 1;
279                 c.anchor = GridBagConstraints.LINE_START;
280                 c.insets = ir;
281                 c.ipady = 5;
282                 radio_frequency_value = new AltosUIFreqList();
283                 radio_frequency_value.addItemListener(this);
284                 pane.add(radio_frequency_value, c);
285                 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
286                 row++;
287
288                 /* Radio Calibration */
289                 c = new GridBagConstraints();
290                 c.gridx = 0; c.gridy = row;
291                 c.gridwidth = 4;
292                 c.fill = GridBagConstraints.NONE;
293                 c.anchor = GridBagConstraints.LINE_START;
294                 c.insets = il;
295                 c.ipady = 5;
296                 radio_calibration_label = new JLabel("RF Calibration:");
297                 pane.add(radio_calibration_label, c);
298
299                 c = new GridBagConstraints();
300                 c.gridx = 4; c.gridy = row;
301                 c.gridwidth = 4;
302                 c.fill = GridBagConstraints.HORIZONTAL;
303                 c.weightx = 1;
304                 c.anchor = GridBagConstraints.LINE_START;
305                 c.insets = ir;
306                 c.ipady = 5;
307                 radio_calibration_value = new JTextField(String.format("%d", 1186611));
308                 radio_calibration_value.getDocument().addDocumentListener(this);
309                 pane.add(radio_calibration_value, c);
310                 set_radio_calibration_tool_tip();
311                 row++;
312
313                 /* Radio Enable */
314                 c = new GridBagConstraints();
315                 c.gridx = 0; c.gridy = row;
316                 c.gridwidth = 4;
317                 c.fill = GridBagConstraints.NONE;
318                 c.anchor = GridBagConstraints.LINE_START;
319                 c.insets = il;
320                 c.ipady = 5;
321                 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
322                 pane.add(radio_enable_label, c);
323
324                 c = new GridBagConstraints();
325                 c.gridx = 4; c.gridy = row;
326                 c.gridwidth = 4;
327                 c.fill = GridBagConstraints.HORIZONTAL;
328                 c.weightx = 1;
329                 c.anchor = GridBagConstraints.LINE_START;
330                 c.insets = ir;
331                 c.ipady = 5;
332                 radio_enable_value = new JRadioButton("Enabled");
333                 radio_enable_value.addItemListener(this);
334                 pane.add(radio_enable_value, c);
335                 set_radio_enable_tool_tip();
336                 row++;
337
338                 /* Telemetry Rate */
339                 c = new GridBagConstraints();
340                 c.gridx = 0; c.gridy = row;
341                 c.gridwidth = 4;
342                 c.fill = GridBagConstraints.NONE;
343                 c.anchor = GridBagConstraints.LINE_START;
344                 c.insets = il;
345                 c.ipady = 5;
346                 rate_label = new JLabel("Telemetry baud rate:");
347                 pane.add(rate_label, c);
348
349                 c = new GridBagConstraints();
350                 c.gridx = 4; c.gridy = row;
351                 c.gridwidth = 4;
352                 c.fill = GridBagConstraints.HORIZONTAL;
353                 c.weightx = 1;
354                 c.anchor = GridBagConstraints.LINE_START;
355                 c.insets = ir;
356                 c.ipady = 5;
357                 rate_value = new AltosUIRateList();
358                 rate_value.addItemListener(this);
359                 pane.add(rate_value, c);
360                 set_rate_tool_tip();
361                 row++;
362
363                 /* APRS interval */
364                 c = new GridBagConstraints();
365                 c.gridx = 0; c.gridy = row;
366                 c.gridwidth = 4;
367                 c.fill = GridBagConstraints.NONE;
368                 c.anchor = GridBagConstraints.LINE_START;
369                 c.insets = il;
370                 c.ipady = 5;
371                 aprs_interval_label = new JLabel("APRS Interval(s):");
372                 pane.add(aprs_interval_label, c);
373
374                 c = new GridBagConstraints();
375                 c.gridx = 4; c.gridy = row;
376                 c.gridwidth = 4;
377                 c.fill = GridBagConstraints.HORIZONTAL;
378                 c.weightx = 1;
379                 c.anchor = GridBagConstraints.LINE_START;
380                 c.insets = ir;
381                 c.ipady = 5;
382                 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
383                 aprs_interval_value.setEditable(true);
384                 aprs_interval_value.addItemListener(this);
385                 pane.add(aprs_interval_value, c);
386                 set_aprs_interval_tool_tip();
387                 row++;
388
389                 /* APRS SSID */
390                 c = new GridBagConstraints();
391                 c.gridx = 0; c.gridy = row;
392                 c.gridwidth = 4;
393                 c.fill = GridBagConstraints.NONE;
394                 c.anchor = GridBagConstraints.LINE_START;
395                 c.insets = il;
396                 c.ipady = 5;
397                 aprs_ssid_label = new JLabel("APRS SSID:");
398                 pane.add(aprs_ssid_label, c);
399
400                 c = new GridBagConstraints();
401                 c.gridx = 4; c.gridy = row;
402                 c.gridwidth = 4;
403                 c.fill = GridBagConstraints.HORIZONTAL;
404                 c.weightx = 1;
405                 c.anchor = GridBagConstraints.LINE_START;
406                 c.insets = ir;
407                 c.ipady = 5;
408                 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
409                 aprs_ssid_value.setEditable(false);
410                 aprs_ssid_value.addItemListener(this);
411                 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
412                 pane.add(aprs_ssid_value, c);
413                 set_aprs_ssid_tool_tip();
414                 row++;
415
416                 /* Callsign */
417                 c = new GridBagConstraints();
418                 c.gridx = 0; c.gridy = row;
419                 c.gridwidth = 4;
420                 c.fill = GridBagConstraints.NONE;
421                 c.anchor = GridBagConstraints.LINE_START;
422                 c.insets = il;
423                 c.ipady = 5;
424                 callsign_label = new JLabel("Callsign:");
425                 pane.add(callsign_label, c);
426
427                 c = new GridBagConstraints();
428                 c.gridx = 4; c.gridy = row;
429                 c.gridwidth = 4;
430                 c.fill = GridBagConstraints.HORIZONTAL;
431                 c.weightx = 1;
432                 c.anchor = GridBagConstraints.LINE_START;
433                 c.insets = ir;
434                 c.ipady = 5;
435                 callsign_value = new JTextField(AltosUIPreferences.callsign());
436                 callsign_value.getDocument().addDocumentListener(this);
437                 pane.add(callsign_value, c);
438                 callsign_value.setToolTipText("Callsign reported in telemetry data");
439                 row++;
440
441                 /* Flight log max */
442                 c = new GridBagConstraints();
443                 c.gridx = 0; c.gridy = row;
444                 c.gridwidth = 4;
445                 c.fill = GridBagConstraints.NONE;
446                 c.anchor = GridBagConstraints.LINE_START;
447                 c.insets = il;
448                 c.ipady = 5;
449                 flight_log_max_label = new JLabel("Maximum Log Size (kB):");
450                 pane.add(flight_log_max_label, c);
451
452                 c = new GridBagConstraints();
453                 c.gridx = 4; c.gridy = row;
454                 c.gridwidth = 4;
455                 c.fill = GridBagConstraints.HORIZONTAL;
456                 c.weightx = 1;
457                 c.anchor = GridBagConstraints.LINE_START;
458                 c.insets = ir;
459                 c.ipady = 5;
460                 flight_log_max_value = new JComboBox<String>();
461                 flight_log_max_value.setEditable(true);
462                 flight_log_max_value.addItemListener(this);
463                 pane.add(flight_log_max_value, c);
464                 set_flight_log_max_tool_tip();
465                 row++;
466
467                 /* Tracker triger horiz distances */
468                 c = new GridBagConstraints();
469                 c.gridx = 0; c.gridy = row;
470                 c.gridwidth = 4;
471                 c.fill = GridBagConstraints.NONE;
472                 c.anchor = GridBagConstraints.LINE_START;
473                 c.insets = il;
474                 c.ipady = 5;
475                 tracker_motion_label = new JLabel(get_tracker_motion_label());
476                 pane.add(tracker_motion_label, c);
477
478                 c = new GridBagConstraints();
479                 c.gridx = 4; c.gridy = row;
480                 c.gridwidth = 4;
481                 c.fill = GridBagConstraints.HORIZONTAL;
482                 c.weightx = 1;
483                 c.anchor = GridBagConstraints.LINE_START;
484                 c.insets = ir;
485                 c.ipady = 5;
486                 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
487                 tracker_motion_value.setEditable(true);
488                 tracker_motion_value.addItemListener(this);
489                 pane.add(tracker_motion_value, c);
490                 row++;
491
492                 /* Tracker triger vert distances */
493                 c = new GridBagConstraints();
494                 c.gridx = 0; c.gridy = row;
495                 c.gridwidth = 4;
496                 c.fill = GridBagConstraints.NONE;
497                 c.anchor = GridBagConstraints.LINE_START;
498                 c.insets = il;
499                 c.ipady = 5;
500                 tracker_interval_label = new JLabel("Position Reporting Interval (s):");
501                 pane.add(tracker_interval_label, c);
502
503                 c = new GridBagConstraints();
504                 c.gridx = 4; c.gridy = row;
505                 c.gridwidth = 4;
506                 c.fill = GridBagConstraints.HORIZONTAL;
507                 c.weightx = 1;
508                 c.anchor = GridBagConstraints.LINE_START;
509                 c.insets = ir;
510                 c.ipady = 5;
511                 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
512                 tracker_interval_value.setEditable(true);
513                 tracker_interval_value.addItemListener(this);
514                 pane.add(tracker_interval_value, c);
515                 set_tracker_tool_tip();
516                 row++;
517
518                 /* Buttons */
519                 c = new GridBagConstraints();
520                 c.gridx = 0; c.gridy = row;
521                 c.gridwidth = 2;
522                 c.fill = GridBagConstraints.NONE;
523                 c.anchor = GridBagConstraints.LINE_START;
524                 c.insets = il;
525                 save = new JButton("Save");
526                 pane.add(save, c);
527                 save.addActionListener(this);
528                 save.setActionCommand("Save");
529
530                 c = new GridBagConstraints();
531                 c.gridx = 2; c.gridy = row;
532                 c.gridwidth = 2;
533                 c.fill = GridBagConstraints.NONE;
534                 c.anchor = GridBagConstraints.CENTER;
535                 c.insets = il;
536                 reset = new JButton("Reset");
537                 pane.add(reset, c);
538                 reset.addActionListener(this);
539                 reset.setActionCommand("Reset");
540
541                 c = new GridBagConstraints();
542                 c.gridx = 4; c.gridy = row;
543                 c.gridwidth = 2;
544                 c.fill = GridBagConstraints.NONE;
545                 c.anchor = GridBagConstraints.CENTER;
546                 c.insets = il;
547                 reboot = new JButton("Reboot");
548                 pane.add(reboot, c);
549                 reboot.addActionListener(this);
550                 reboot.setActionCommand("Reboot");
551
552                 c = new GridBagConstraints();
553                 c.gridx = 6; c.gridy = row;
554                 c.gridwidth = 2;
555                 c.fill = GridBagConstraints.NONE;
556                 c.anchor = GridBagConstraints.LINE_END;
557                 c.insets = il;
558                 close = new JButton("Close");
559                 pane.add(close, c);
560                 close.addActionListener(this);
561                 close.setActionCommand("Close");
562
563                 addWindowListener(new ConfigListener(this));
564                 AltosPreferences.register_units_listener(this);
565         }
566
567         /* Once the initial values are set, the config code will show the dialog */
568         public void make_visible() {
569                 pack();
570                 setLocationRelativeTo(owner);
571                 setVisible(true);
572         }
573
574         /* If any values have been changed, confirm before closing */
575         public boolean check_dirty(String operation) {
576                 if (dirty) {
577                         Object[] options = { String.format("%s anyway", operation), "Keep editing" };
578                         int i;
579                         i = JOptionPane.showOptionDialog(this,
580                                                          String.format("Configuration modified. %s anyway?", operation),
581                                                          "Configuration Modified",
582                                                          JOptionPane.DEFAULT_OPTION,
583                                                          JOptionPane.WARNING_MESSAGE,
584                                                          null, options, options[1]);
585                         if (i != 0)
586                                 return false;
587                 }
588                 return true;
589         }
590
591         void set_dirty() {
592                 dirty = true;
593                 save.setEnabled(true);
594         }
595
596         public void set_clean() {
597                 dirty = false;
598                 save.setEnabled(false);
599         }
600
601         public void dispose() {
602                 AltosPreferences.unregister_units_listener(this);
603                 super.dispose();
604         }
605
606         /* Listen for events from our buttons */
607         public void actionPerformed(ActionEvent e) {
608                 String  cmd = e.getActionCommand();
609
610                 if (cmd.equals("Close") || cmd.equals("Reboot"))
611                         if (!check_dirty(cmd))
612                                 return;
613                 listener.actionPerformed(e);
614                 if (cmd.equals("Close") || cmd.equals("Reboot")) {
615                         setVisible(false);
616                         dispose();
617                 }
618                 set_clean();
619         }
620
621         /* ItemListener interface method */
622         public void itemStateChanged(ItemEvent e) {
623                 set_dirty();
624         }
625
626         /* DocumentListener interface methods */
627         public void changedUpdate(DocumentEvent e) {
628                 set_dirty();
629         }
630
631         public void insertUpdate(DocumentEvent e) {
632                 set_dirty();
633         }
634
635         public void removeUpdate(DocumentEvent e) {
636                 set_dirty();
637         }
638
639         /* Let the config code hook on a listener */
640         public void addActionListener(ActionListener l) {
641                 listener = l;
642         }
643
644         public void units_changed(boolean imperial_units) {
645                 boolean was_dirty = dirty;
646
647                 if (tracker_motion_value.isEnabled()) {
648                         String motion = tracker_motion_value.getSelectedItem().toString();
649                         tracker_motion_label.setText(get_tracker_motion_label());
650                         set_tracker_motion_values();
651                         set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5));
652                 }
653                 if (!was_dirty)
654                         set_clean();
655         }
656
657         /* set and get all of the dialog values */
658         public void set_product(String product) {
659                 radio_frequency_value.set_product(product);
660                 product_value.setText(product);
661                 set_flight_log_max_tool_tip();
662         }
663
664         public void set_version(String version) {
665                 version_value.setText(version);
666         }
667
668         public void set_serial(int serial) {
669                 radio_frequency_value.set_serial(serial);
670                 serial_value.setText(String.format("%d", serial));
671         }
672
673         public void set_altitude_32(int altitude_32) {
674         }
675
676         public void set_main_deploy(int new_main_deploy) {
677         }
678
679         public int main_deploy() {
680                 return -1;
681         }
682
683         public void set_apogee_delay(int new_apogee_delay) { }
684
685         public int apogee_delay() {
686                 return -1;
687         }
688
689         public void set_apogee_lockout(int new_apogee_lockout) { }
690
691         public int apogee_lockout() { return -1; }
692
693         public void set_radio_frequency(double new_radio_frequency) {
694                 radio_frequency_value.set_frequency(new_radio_frequency);
695         }
696
697         public double radio_frequency() {
698                 return radio_frequency_value.frequency();
699         }
700
701         public void set_radio_calibration(int new_radio_calibration) {
702                 radio_calibration_value.setVisible(new_radio_calibration >= 0);
703                 if (new_radio_calibration < 0)
704                         radio_calibration_value.setText("Disabled");
705                 else
706                         radio_calibration_value.setText(String.format("%d", new_radio_calibration));
707         }
708
709         private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
710                 String v = s;
711                 if (split)
712                         v = s.split("\\s+")[0];
713                 try {
714                         return Integer.parseInt(v);
715                 } catch (NumberFormatException ne) {
716                         throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
717                 }
718         }
719
720         public int radio_calibration() throws AltosConfigDataException {
721                 return parse_int("radio calibration", radio_calibration_value.getText(), false);
722         }
723
724         public void set_radio_enable(int new_radio_enable) {
725                 if (new_radio_enable >= 0) {
726                         radio_enable_value.setSelected(new_radio_enable > 0);
727                         radio_enable_value.setEnabled(true);
728                 } else {
729                         radio_enable_value.setSelected(true);
730                         radio_enable_value.setVisible(radio_frequency() > 0);
731                         radio_enable_value.setEnabled(false);
732                 }
733                 set_radio_enable_tool_tip();
734         }
735
736         public int radio_enable() {
737                 if (radio_enable_value.isEnabled())
738                         return radio_enable_value.isSelected() ? 1 : 0;
739                 else
740                         return -1;
741         }
742
743         public void set_telemetry_rate(int new_rate) {
744                 rate_value.set_rate(new_rate);
745         }
746
747         public int telemetry_rate() {
748                 return rate_value.rate();
749         }
750
751         public void set_callsign(String new_callsign) {
752                 callsign_value.setVisible(new_callsign != null);
753                 callsign_value.setText(new_callsign);
754         }
755
756         public String callsign() {
757                 return callsign_value.getText();
758         }
759
760         int     flight_log_max_limit;
761         int     flight_log_max;
762
763         public String flight_log_max_label(int flight_log_max) {
764                 if (flight_log_max_limit != 0) {
765                         int     nflight = flight_log_max_limit / flight_log_max;
766                         String  plural = nflight > 1 ? "s" : "";
767
768                         return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
769                 }
770                 return String.format("%d", flight_log_max);
771         }
772
773         public void set_flight_log_max(int new_flight_log_max) {
774                 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
775                 flight_log_max = new_flight_log_max;
776                 set_flight_log_max_tool_tip();
777         }
778
779         public void set_flight_log_max_enabled(boolean enable) {
780                 flight_log_max_value.setEnabled(enable);
781                 set_flight_log_max_tool_tip();
782         }
783
784         public int flight_log_max() throws AltosConfigDataException {
785                 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
786         }
787
788         public void set_flight_log_max_limit(int new_flight_log_max_limit) {
789                 flight_log_max_limit = new_flight_log_max_limit;
790                 flight_log_max_value.removeAllItems();
791                 for (int i = 8; i >= 1; i--) {
792                         int     size = flight_log_max_limit / i;
793                         flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
794                 }
795                 if (flight_log_max != 0)
796                         set_flight_log_max(flight_log_max);
797         }
798
799         public void set_ignite_mode(int new_ignite_mode) { }
800         public int ignite_mode() { return -1; }
801
802
803         public void set_pad_orientation(int new_pad_orientation) { }
804         public int pad_orientation() { return -1; }
805
806         public void set_beep(int new_beep) { }
807
808         public int beep() { return -1; }
809
810         String[] tracker_motion_values() {
811                 if (AltosConvert.imperial_units)
812                         return tracker_motion_values_ft;
813                 else
814                         return tracker_motion_values_m;
815         }
816
817         void set_tracker_motion_values() {
818                 String[]        v = tracker_motion_values();
819                 while (tracker_motion_value.getItemCount() > 0)
820                         tracker_motion_value.removeItemAt(0);
821                 for (int i = 0; i < v.length; i++)
822                         tracker_motion_value.addItem(v[i]);
823                 tracker_motion_value.setMaximumRowCount(v.length);
824         }
825
826         String get_tracker_motion_label() {
827                 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.show_units());
828         }
829
830         void set_tracker_tool_tip() {
831                 if (tracker_motion_value.isEnabled())
832                         tracker_motion_value.setToolTipText("How far the device must move before logging");
833                 else
834                         tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
835                 if (tracker_interval_value.isEnabled())
836                         tracker_interval_value.setToolTipText("How often to report GPS position");
837                 else
838                         tracker_interval_value.setToolTipText("This device can't configure interval");
839         }
840
841         public void set_tracker_motion(int tracker_motion) {
842                 if (tracker_motion < 0) {
843                         tracker_motion_value.setEnabled(false);
844                 } else {
845                         tracker_motion_value.setEnabled(true);
846                         tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
847                 }
848         }
849
850         public int tracker_motion() throws AltosConfigDataException {
851                 return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString());
852         }
853
854         public void set_tracker_interval(int tracker_interval) {
855                 if (tracker_interval< 0) {
856                         tracker_interval_value.setEnabled(false);
857                 } else {
858                         tracker_interval_value.setEnabled(true);
859                         tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
860                 }
861         }
862
863         public int tracker_interval() throws AltosConfigDataException {
864                 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
865         }
866
867         public void set_aprs_interval(int new_aprs_interval) {
868                 String  s;
869
870                 if (new_aprs_interval <= 0)
871                         s = "Disabled";
872                 else
873                         s = Integer.toString(new_aprs_interval);
874                 aprs_interval_value.setSelectedItem(s);
875                 aprs_interval_value.setVisible(new_aprs_interval >= 0);
876                 set_aprs_interval_tool_tip();
877         }
878
879         public int aprs_interval() throws AltosConfigDataException {
880                 String  s = aprs_interval_value.getSelectedItem().toString();
881
882                 if (s.equals("Disabled"))
883                         return 0;
884                 return parse_int("aprs interval", s, false);
885         }
886
887         public void set_aprs_ssid(int new_aprs_ssid) {
888                 aprs_ssid_value.setSelectedItem(Math.max(0,new_aprs_ssid));
889                 aprs_ssid_value.setVisible(new_aprs_ssid >= 0);
890                 set_aprs_ssid_tool_tip();
891         }
892
893         public int aprs_ssid() throws AltosConfigDataException {
894                 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
895                 return i;
896         }
897 }