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