From a7fd31842a602a8ac803d0e09efb4ffabf7a289b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 May 2014 20:19:44 -0700 Subject: telegps: Add device configuration dialogs Signed-off-by: Keith Packard --- telegps/TeleGPSConfigUI.java | 648 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 648 insertions(+) create mode 100644 telegps/TeleGPSConfigUI.java (limited to 'telegps/TeleGPSConfigUI.java') diff --git a/telegps/TeleGPSConfigUI.java b/telegps/TeleGPSConfigUI.java new file mode 100644 index 00000000..d1f66eef --- /dev/null +++ b/telegps/TeleGPSConfigUI.java @@ -0,0 +1,648 @@ +/* + * Copyright © 2010 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.telegps; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import org.altusmetrum.altoslib_4.*; +import org.altusmetrum.altosuilib_2.*; + +public class TeleGPSConfigUI + extends AltosUIDialog + implements ActionListener, ItemListener, DocumentListener, AltosConfigValues +{ + + Container pane; + JLabel product_label; + JLabel version_label; + JLabel serial_label; + JLabel frequency_label; + JLabel radio_calibration_label; + JLabel radio_frequency_label; + JLabel radio_enable_label; + JLabel aprs_interval_label; + JLabel flight_log_max_label; + JLabel callsign_label; + + public boolean dirty; + + JFrame owner; + JLabel product_value; + JLabel version_value; + JLabel serial_value; + AltosFreqList radio_frequency_value; + JTextField radio_calibration_value; + JRadioButton radio_enable_value; + JComboBox aprs_interval_value; + JComboBox flight_log_max_value; + JTextField callsign_value; + + JButton save; + JButton reset; + JButton reboot; + JButton close; + + ActionListener listener; + + static String[] flight_log_max_values = { + "64", "128", "192", "256", "320", + "384", "448", "512", "576", "640", + "704", "768", "832", "896", "960", + }; + + static String[] aprs_interval_values = { + "Disabled", + "2", + "5", + "10" + }; + + /* A window listener to catch closing events and tell the config code */ + class ConfigListener extends WindowAdapter { + TeleGPSConfigUI ui; + + public ConfigListener(TeleGPSConfigUI this_ui) { + ui = this_ui; + } + + public void windowClosing(WindowEvent e) { + ui.actionPerformed(new ActionEvent(e.getSource(), + ActionEvent.ACTION_PERFORMED, + "Close")); + } + } + + public void set_pyros(AltosPyro[] new_pyros) { + } + + public AltosPyro[] pyros() { + return null; + } + + boolean is_telemetrum() { + String product = product_value.getText(); + return product != null && product.startsWith("TeleGPS"); + } + + void set_radio_calibration_tool_tip() { + if (radio_calibration_value.isEnabled()) + radio_calibration_value.setToolTipText("Tune radio output to match desired frequency"); + else + radio_calibration_value.setToolTipText("Cannot tune radio while connected over packet mode"); + } + + void set_radio_enable_tool_tip() { + if (radio_enable_value.isEnabled()) + radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions"); + else + radio_enable_value.setToolTipText("Firmware version does not support disabling radio"); + } + + void set_aprs_interval_tool_tip() { + if (aprs_interval_value.isEnabled()) + aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports"); + else + aprs_interval_value.setToolTipText("Hardware doesn't support APRS"); + } + + void set_flight_log_max_tool_tip() { + if (flight_log_max_value.isEnabled()) + flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)"); + else + flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory"); + } + + /* Build the UI using a grid bag */ + public TeleGPSConfigUI(JFrame in_owner) { + super (in_owner, "Configure Flight Computer", false); + + owner = in_owner; + GridBagConstraints c; + int row = 0; + + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); + + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + /* Product */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + product_label = new JLabel("Product:"); + pane.add(product_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + product_value = new JLabel(""); + pane.add(product_value, c); + row++; + + /* Version */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + version_label = new JLabel("Software version:"); + pane.add(version_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + version_value = new JLabel(""); + pane.add(version_value, c); + row++; + + /* Serial */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + serial_label = new JLabel("Serial:"); + pane.add(serial_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + serial_value = new JLabel(""); + pane.add(serial_value, c); + row++; + + /* Frequency */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + radio_frequency_label = new JLabel("Frequency:"); + pane.add(radio_frequency_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + radio_frequency_value = new AltosFreqList(); + radio_frequency_value.addItemListener(this); + pane.add(radio_frequency_value, c); + radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency"); + row++; + + /* Radio Calibration */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + radio_calibration_label = new JLabel("RF Calibration:"); + pane.add(radio_calibration_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + radio_calibration_value = new JTextField(String.format("%d", 1186611)); + radio_calibration_value.getDocument().addDocumentListener(this); + pane.add(radio_calibration_value, c); + set_radio_calibration_tool_tip(); + row++; + + /* Radio Enable */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:"); + pane.add(radio_enable_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + radio_enable_value = new JRadioButton("Enabled"); + radio_enable_value.addItemListener(this); + pane.add(radio_enable_value, c); + set_radio_enable_tool_tip(); + row++; + + /* APRS interval */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + aprs_interval_label = new JLabel("APRS Interval(s):"); + pane.add(aprs_interval_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + aprs_interval_value = new JComboBox(aprs_interval_values); + aprs_interval_value.setEditable(true); + aprs_interval_value.addItemListener(this); + pane.add(aprs_interval_value, c); + set_aprs_interval_tool_tip(); + row++; + + /* Callsign */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + callsign_label = new JLabel("Callsign:"); + pane.add(callsign_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + callsign_value = new JTextField(AltosUIPreferences.callsign()); + callsign_value.getDocument().addDocumentListener(this); + pane.add(callsign_value, c); + callsign_value.setToolTipText("Callsign reported in telemetry data"); + row++; + + /* Flight log max */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + flight_log_max_label = new JLabel("Maximum Flight Log Size:"); + pane.add(flight_log_max_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + flight_log_max_value = new JComboBox(flight_log_max_values); + flight_log_max_value.setEditable(true); + flight_log_max_value.addItemListener(this); + pane.add(flight_log_max_value, c); + set_flight_log_max_tool_tip(); + row++; + + /* Buttons */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + save = new JButton("Save"); + pane.add(save, c); + save.addActionListener(this); + save.setActionCommand("Save"); + + c = new GridBagConstraints(); + c.gridx = 2; c.gridy = row; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = il; + reset = new JButton("Reset"); + pane.add(reset, c); + reset.addActionListener(this); + reset.setActionCommand("Reset"); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.insets = il; + reboot = new JButton("Reboot"); + pane.add(reboot, c); + reboot.addActionListener(this); + reboot.setActionCommand("Reboot"); + + c = new GridBagConstraints(); + c.gridx = 6; c.gridy = row; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_END; + c.insets = il; + close = new JButton("Close"); + pane.add(close, c); + close.addActionListener(this); + close.setActionCommand("Close"); + + addWindowListener(new ConfigListener(this)); + } + + /* Once the initial values are set, the config code will show the dialog */ + public void make_visible() { + pack(); + setLocationRelativeTo(owner); + setVisible(true); + } + + /* If any values have been changed, confirm before closing */ + public boolean check_dirty(String operation) { + if (dirty) { + Object[] options = { String.format("%s anyway", operation), "Keep editing" }; + int i; + i = JOptionPane.showOptionDialog(this, + String.format("Configuration modified. %s anyway?", operation), + "Configuration Modified", + JOptionPane.DEFAULT_OPTION, + JOptionPane.WARNING_MESSAGE, + null, options, options[1]); + if (i != 0) + return false; + } + return true; + } + + void set_dirty() { + dirty = true; + save.setEnabled(true); + } + + public void set_clean() { + dirty = false; + save.setEnabled(false); + } + + public void dispose() { + super.dispose(); + } + + /* Listen for events from our buttons */ + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + + if (cmd.equals("Close") || cmd.equals("Reboot")) + if (!check_dirty(cmd)) + return; + listener.actionPerformed(e); + if (cmd.equals("Close") || cmd.equals("Reboot")) { + setVisible(false); + dispose(); + } + set_clean(); + } + + /* ItemListener interface method */ + public void itemStateChanged(ItemEvent e) { + set_dirty(); + } + + /* DocumentListener interface methods */ + public void changedUpdate(DocumentEvent e) { + set_dirty(); + } + + public void insertUpdate(DocumentEvent e) { + set_dirty(); + } + + public void removeUpdate(DocumentEvent e) { + set_dirty(); + } + + /* Let the config code hook on a listener */ + public void addActionListener(ActionListener l) { + listener = l; + } + + /* set and get all of the dialog values */ + public void set_product(String product) { + radio_frequency_value.set_product(product); + product_value.setText(product); + set_flight_log_max_tool_tip(); + } + + public void set_version(String version) { + version_value.setText(version); + } + + public void set_serial(int serial) { + radio_frequency_value.set_serial(serial); + serial_value.setText(String.format("%d", serial)); + } + + public void set_main_deploy(int new_main_deploy) { + } + + public int main_deploy() { + return -1; + } + +/* + String get_main_deploy_label() { + return String.format("Main Deploy Altitude(%s):", AltosConvert.height.show_units()); + } + + String[] main_deploy_values() { + if (AltosConvert.imperial_units) + return main_deploy_values_ft; + else + return main_deploy_values_m; + } + + void set_main_deploy_values() { + String[] v = main_deploy_values(); + while (main_deploy_value.getItemCount() > 0) + main_deploy_value.removeItemAt(0); + for (int i = 0; i < v.length; i++) + main_deploy_value.addItem(v[i]); + main_deploy_value.setMaximumRowCount(v.length); + } +*/ + + public void set_apogee_delay(int new_apogee_delay) { } + + public int apogee_delay() { + return -1; + } + + public void set_apogee_lockout(int new_apogee_lockout) { } + + public int apogee_lockout() { return -1; } + + public void set_radio_frequency(double new_radio_frequency) { + radio_frequency_value.set_frequency(new_radio_frequency); + } + + public double radio_frequency() { + return radio_frequency_value.frequency(); + } + + public void set_radio_calibration(int new_radio_calibration) { + radio_calibration_value.setVisible(new_radio_calibration >= 0); + if (new_radio_calibration < 0) + radio_calibration_value.setText("Disabled"); + else + radio_calibration_value.setText(String.format("%d", new_radio_calibration)); + } + + public int radio_calibration() { + return Integer.parseInt(radio_calibration_value.getText()); + } + + public void set_radio_enable(int new_radio_enable) { + if (new_radio_enable >= 0) { + radio_enable_value.setSelected(new_radio_enable > 0); + radio_enable_value.setEnabled(true); + } else { + radio_enable_value.setSelected(true); + radio_enable_value.setVisible(radio_frequency() > 0); + radio_enable_value.setEnabled(false); + } + set_radio_enable_tool_tip(); + } + + public int radio_enable() { + if (radio_enable_value.isEnabled()) + return radio_enable_value.isSelected() ? 1 : 0; + else + return -1; + } + + public void set_callsign(String new_callsign) { + callsign_value.setVisible(new_callsign != null); + callsign_value.setText(new_callsign); + } + + public String callsign() { + return callsign_value.getText(); + } + + public void set_flight_log_max(int new_flight_log_max) { + flight_log_max_value.setSelectedItem(Integer.toString(new_flight_log_max)); + set_flight_log_max_tool_tip(); + } + + public void set_flight_log_max_enabled(boolean enable) { + flight_log_max_value.setEnabled(enable); + set_flight_log_max_tool_tip(); + } + + public int flight_log_max() { + return Integer.parseInt(flight_log_max_value.getSelectedItem().toString()); + } + + public void set_flight_log_max_limit(int flight_log_max_limit) { + //boolean any_added = false; + flight_log_max_value.removeAllItems(); + for (int i = 0; i < flight_log_max_values.length; i++) { + if (Integer.parseInt(flight_log_max_values[i]) < flight_log_max_limit){ + flight_log_max_value.addItem(flight_log_max_values[i]); + //any_added = true; + } + } + flight_log_max_value.addItem(String.format("%d", flight_log_max_limit)); + } + + public void set_ignite_mode(int new_ignite_mode) { } + public int ignite_mode() { return -1; } + + + public void set_pad_orientation(int new_pad_orientation) { } + public int pad_orientation() { return -1; } + + public void set_beep(int new_beep) { } + + public int beep() { return -1; } + + public void set_aprs_interval(int new_aprs_interval) { + String s; + + if (new_aprs_interval <= 0) + s = "Disabled"; + else + s = Integer.toString(new_aprs_interval); + aprs_interval_value.setSelectedItem(s); + aprs_interval_value.setVisible(new_aprs_interval >= 0); + set_aprs_interval_tool_tip(); + } + + public int aprs_interval() { + String s = aprs_interval_value.getSelectedItem().toString(); + + if (s.equals("Disabled")) + return 0; + return Integer.parseInt(s); + } +} -- cgit v1.2.3 From 2d9842ee011139f5783a102ceb2b7f4c88b1a10f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 30 May 2014 17:17:42 -0700 Subject: telegps: Add config for tracker starting distances Signed-off-by: Keith Packard --- altoslib/AltosConfigData.java | 30 ++++++ altoslib/AltosConfigValues.java | 4 + altosui/AltosConfigUI.java | 171 ++++++++++++++++++++++++++++++++++ telegps/TeleGPSConfigUI.java | 199 +++++++++++++++++++++++++++++++++++----- 4 files changed, 381 insertions(+), 23 deletions(-) (limited to 'telegps/TeleGPSConfigUI.java') diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index e5c546ff..83c184cd 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -80,6 +80,9 @@ public class AltosConfigData implements Iterable { /* Log listing replies */ public int stored_flight; + /* HAS_TRACKER */ + public int[] tracker_distances; + public static String get_string(String line, String label) throws ParseException { if (line.startsWith(label)) { String quoted = line.substring(label.length()).trim(); @@ -103,6 +106,20 @@ public class AltosConfigData implements Iterable { throw new ParseException("mismatch", 0); } + public static int[] get_distances(String line, String label) throws NumberFormatException, ParseException { + if (line.startsWith(label)) { + String tail = line.substring(label.length()).trim(); + String[] tokens = tail.split("\\s+"); + if (tokens.length > 1) { + int[] distances = new int[2]; + distances[0] = Integer.parseInt(tokens[0]); + distances[1] = Integer.parseInt(tokens[1]); + return distances; + } + } + throw new ParseException("mismatch", 0); + } + public Iterator iterator() { return lines.iterator(); } @@ -215,6 +232,8 @@ public class AltosConfigData implements Iterable { beep = -1; + tracker_distances = null; + storage_size = -1; storage_erase_unit = -1; stored_flight = 0; @@ -294,6 +313,9 @@ public class AltosConfigData implements Iterable { /* HAS_BEEP */ try { beep = get_int(line, "Beeper setting:"); } catch (Exception e) {} + /* HAS_TRACKER */ + try { tracker_distances = get_distances(line, "Tracker setting:"); } catch (Exception e) {} + /* Storage info replies */ try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {} try { storage_erase_unit = get_int(line, "Storage erase unit:"); } catch (Exception e) {} @@ -424,6 +446,9 @@ public class AltosConfigData implements Iterable { /* HAS_BEEP */ if (beep >= 0) beep = source.beep(); + /* HAS_TRACKER */ + if (tracker_distances != null) + tracker_distances = source.tracker_distances(); } public void set_values(AltosConfigValues dest) { @@ -463,6 +488,7 @@ public class AltosConfigData implements Iterable { dest.set_pyros(null); dest.set_aprs_interval(aprs_interval); dest.set_beep(beep); + dest.set_tracker_distances(tracker_distances); } public void save(AltosLink link, boolean remote) throws InterruptedException, TimeoutException { @@ -533,6 +559,10 @@ public class AltosConfigData implements Iterable { if (beep >= 0) link.printf("c b %d\n", beep); + /* HAS_TRACKER */ + if (tracker_distances != null) + link.printf("c t %d %d\n", tracker_distances[0], tracker_distances[1]); + link.printf("c w\n"); link.flush_output(); } diff --git a/altoslib/AltosConfigValues.java b/altoslib/AltosConfigValues.java index b7c0c6ed..37af2ed5 100644 --- a/altoslib/AltosConfigValues.java +++ b/altoslib/AltosConfigValues.java @@ -80,4 +80,8 @@ public interface AltosConfigValues { public abstract int beep(); public abstract void set_beep(int new_beep); + + public abstract int[] tracker_distances(); + + public abstract void set_tracker_distances(int[] tracker_distances); } diff --git a/altosui/AltosConfigUI.java b/altosui/AltosConfigUI.java index 3ec3cdb0..2a9d727d 100644 --- a/altosui/AltosConfigUI.java +++ b/altosui/AltosConfigUI.java @@ -46,6 +46,8 @@ public class AltosConfigUI JLabel pad_orientation_label; JLabel callsign_label; JLabel beep_label; + JLabel tracker_horiz_label; + JLabel tracker_vert_label; public boolean dirty; @@ -65,6 +67,8 @@ public class AltosConfigUI JComboBox pad_orientation_value; JTextField callsign_value; JComboBox beep_value; + JComboBox tracker_horiz_value; + JComboBox tracker_vert_value; JButton pyro; @@ -125,6 +129,34 @@ public class AltosConfigUI "Antenna Down", }; + static String[] tracker_horiz_values_m = { + "250", + "500", + "1000", + "2000" + }; + + static String[] tracker_horiz_values_ft = { + "500", + "1000", + "2500", + "5000" + }; + + static String[] tracker_vert_values_m = { + "25", + "50", + "100", + "200" + }; + + static String[] tracker_vert_values_ft = { + "50", + "100", + "250", + "500" + }; + /* A window listener to catch closing events and tell the config code */ class ConfigListener extends WindowAdapter { AltosConfigUI ui; @@ -610,6 +642,57 @@ public class AltosConfigUI set_beep_tool_tip(); row++; + /* Tracker triger horiz distances */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + tracker_horiz_label = new JLabel(get_tracker_horiz_label()); + pane.add(tracker_horiz_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + tracker_horiz_value = new JComboBox(tracker_horiz_values()); + tracker_horiz_value.setEditable(true); + tracker_horiz_value.addItemListener(this); + pane.add(tracker_horiz_value, c); + row++; + + /* Tracker triger vert distances */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + tracker_vert_label = new JLabel(get_tracker_vert_label()); + pane.add(tracker_vert_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + tracker_vert_value = new JComboBox(tracker_vert_values()); + tracker_vert_value.setEditable(true); + tracker_vert_value.addItemListener(this); + pane.add(tracker_vert_value, c); + set_tracker_tool_tip(); + row++; + /* Pyro channels */ c = new GridBagConstraints(); c.gridx = 4; c.gridy = row; @@ -814,6 +897,20 @@ public class AltosConfigUI set_main_deploy_values(); int m = (int) (AltosConvert.height.parse(v, !imperial_units) + 0.5); set_main_deploy(m); + + if (tracker_horiz_value.isEnabled() && tracker_vert_value.isEnabled()) { + String th = tracker_horiz_value.getSelectedItem().toString(); + String tv = tracker_vert_value.getSelectedItem().toString(); + tracker_horiz_label.setText(get_tracker_horiz_label()); + tracker_vert_label.setText(get_tracker_vert_label()); + set_tracker_horiz_values(); + set_tracker_vert_values(); + int[] t = { + (int) (AltosConvert.height.parse(th, !imperial_units) + 0.5), + (int) (AltosConvert.height.parse(tv, !imperial_units) + 0.5) + }; + set_tracker_distances(t); + } } public void set_apogee_delay(int new_apogee_delay) { @@ -969,6 +1066,80 @@ public class AltosConfigUI return -1; } + String[] tracker_horiz_values() { + if (AltosConvert.imperial_units) + return tracker_horiz_values_ft; + else + return tracker_horiz_values_m; + } + + void set_tracker_horiz_values() { + String[] v = tracker_horiz_values(); + while (tracker_horiz_value.getItemCount() > 0) + tracker_horiz_value.removeItemAt(0); + for (int i = 0; i < v.length; i++) + tracker_horiz_value.addItem(v[i]); + tracker_horiz_value.setMaximumRowCount(v.length); + } + + String get_tracker_horiz_label() { + return String.format("Logging Trigger Horizontal (%s):", AltosConvert.height.show_units()); + } + + String[] tracker_vert_values() { + if (AltosConvert.imperial_units) + return tracker_vert_values_ft; + else + return tracker_vert_values_m; + } + + void set_tracker_vert_values() { + String[] v = tracker_vert_values(); + while (tracker_vert_value.getItemCount() > 0) + tracker_vert_value.removeItemAt(0); + for (int i = 0; i < v.length; i++) + tracker_vert_value.addItem(v[i]); + tracker_vert_value.setMaximumRowCount(v.length); + } + + void set_tracker_tool_tip() { + if (tracker_horiz_value.isEnabled()) + tracker_horiz_value.setToolTipText("How far the device must move before logging is enabled"); + else + tracker_horiz_value.setToolTipText("This device doesn't disable logging before motion"); + if (tracker_vert_value.isEnabled()) + tracker_vert_value.setToolTipText("How far the device must move before logging is enabled"); + else + tracker_vert_value.setToolTipText("This device doesn't disable logging before motion"); + } + + String get_tracker_vert_label() { + return String.format("Logging Trigger Vertical (%s):", AltosConvert.height.show_units()); + } + + public void set_tracker_distances(int[] tracker_distances) { + if (tracker_distances != null) { + tracker_horiz_value.setSelectedItem(AltosConvert.height.say(tracker_distances[0])); + tracker_vert_value.setSelectedItem(AltosConvert.height.say(tracker_distances[1])); + tracker_horiz_value.setEnabled(true); + tracker_vert_value.setEnabled(true); + } else { + tracker_horiz_value.setEnabled(false); + tracker_vert_value.setEnabled(false); + } + } + + public int[] tracker_distances() { + if (tracker_horiz_value.isEnabled() && tracker_vert_value.isEnabled()) { + int[] t = { + (int) (AltosConvert.height.parse(tracker_horiz_value.getSelectedItem().toString()) + 0.5), + (int) (AltosConvert.height.parse(tracker_vert_value.getSelectedItem().toString()) + 0.5), + }; + return t; + } + return null; + } + public void set_pyros(AltosPyro[] new_pyros) { pyros = new_pyros; pyro.setVisible(pyros != null); diff --git a/telegps/TeleGPSConfigUI.java b/telegps/TeleGPSConfigUI.java index d1f66eef..863d61bb 100644 --- a/telegps/TeleGPSConfigUI.java +++ b/telegps/TeleGPSConfigUI.java @@ -26,7 +26,7 @@ import org.altusmetrum.altosuilib_2.*; public class TeleGPSConfigUI extends AltosUIDialog - implements ActionListener, ItemListener, DocumentListener, AltosConfigValues + implements ActionListener, ItemListener, DocumentListener, AltosConfigValues, AltosUnitsListener { Container pane; @@ -40,6 +40,8 @@ public class TeleGPSConfigUI JLabel aprs_interval_label; JLabel flight_log_max_label; JLabel callsign_label; + JLabel tracker_horiz_label; + JLabel tracker_vert_label; public boolean dirty; @@ -53,6 +55,8 @@ public class TeleGPSConfigUI JComboBox aprs_interval_value; JComboBox flight_log_max_value; JTextField callsign_value; + JComboBox tracker_horiz_value; + JComboBox tracker_vert_value; JButton save; JButton reset; @@ -74,6 +78,34 @@ public class TeleGPSConfigUI "10" }; + static String[] tracker_horiz_values_m = { + "250", + "500", + "1000", + "2000" + }; + + static String[] tracker_horiz_values_ft = { + "500", + "1000", + "2500", + "5000" + }; + + static String[] tracker_vert_values_m = { + "25", + "50", + "100", + "200" + }; + + static String[] tracker_vert_values_ft = { + "50", + "100", + "250", + "500" + }; + /* A window listener to catch closing events and tell the config code */ class ConfigListener extends WindowAdapter { TeleGPSConfigUI ui; @@ -362,6 +394,57 @@ public class TeleGPSConfigUI set_flight_log_max_tool_tip(); row++; + /* Tracker triger horiz distances */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + tracker_horiz_label = new JLabel(get_tracker_horiz_label()); + pane.add(tracker_horiz_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + tracker_horiz_value = new JComboBox(tracker_horiz_values()); + tracker_horiz_value.setEditable(true); + tracker_horiz_value.addItemListener(this); + pane.add(tracker_horiz_value, c); + row++; + + /* Tracker triger vert distances */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + tracker_vert_label = new JLabel(get_tracker_vert_label()); + pane.add(tracker_vert_label, c); + + c = new GridBagConstraints(); + c.gridx = 4; c.gridy = row; + c.gridwidth = 4; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + tracker_vert_value = new JComboBox(tracker_vert_values()); + tracker_vert_value.setEditable(true); + tracker_vert_value.addItemListener(this); + pane.add(tracker_vert_value, c); + set_tracker_tool_tip(); + row++; + /* Buttons */ c = new GridBagConstraints(); c.gridx = 0; c.gridy = row; @@ -408,6 +491,7 @@ public class TeleGPSConfigUI close.setActionCommand("Close"); addWindowListener(new ConfigListener(this)); + AltosPreferences.register_units_listener(this); } /* Once the initial values are set, the config code will show the dialog */ @@ -445,6 +529,7 @@ public class TeleGPSConfigUI } public void dispose() { + AltosPreferences.unregister_units_listener(this); super.dispose(); } @@ -486,6 +571,22 @@ public class TeleGPSConfigUI listener = l; } + public void units_changed(boolean imperial_units) { + if (tracker_horiz_value.isEnabled() && tracker_vert_value.isEnabled()) { + String th = tracker_horiz_value.getSelectedItem().toString(); + String tv = tracker_vert_value.getSelectedItem().toString(); + tracker_horiz_label.setText(get_tracker_horiz_label()); + tracker_vert_label.setText(get_tracker_vert_label()); + set_tracker_horiz_values(); + set_tracker_vert_values(); + int[] t = { + (int) (AltosConvert.height.parse(th, !imperial_units) + 0.5), + (int) (AltosConvert.height.parse(tv, !imperial_units) + 0.5) + }; + set_tracker_distances(t); + } + } + /* set and get all of the dialog values */ public void set_product(String product) { radio_frequency_value.set_product(product); @@ -509,28 +610,6 @@ public class TeleGPSConfigUI return -1; } -/* - String get_main_deploy_label() { - return String.format("Main Deploy Altitude(%s):", AltosConvert.height.show_units()); - } - - String[] main_deploy_values() { - if (AltosConvert.imperial_units) - return main_deploy_values_ft; - else - return main_deploy_values_m; - } - - void set_main_deploy_values() { - String[] v = main_deploy_values(); - while (main_deploy_value.getItemCount() > 0) - main_deploy_value.removeItemAt(0); - for (int i = 0; i < v.length; i++) - main_deploy_value.addItem(v[i]); - main_deploy_value.setMaximumRowCount(v.length); - } -*/ - public void set_apogee_delay(int new_apogee_delay) { } public int apogee_delay() { @@ -626,6 +705,80 @@ public class TeleGPSConfigUI public int beep() { return -1; } + String[] tracker_horiz_values() { + if (AltosConvert.imperial_units) + return tracker_horiz_values_ft; + else + return tracker_horiz_values_m; + } + + void set_tracker_horiz_values() { + String[] v = tracker_horiz_values(); + while (tracker_horiz_value.getItemCount() > 0) + tracker_horiz_value.removeItemAt(0); + for (int i = 0; i < v.length; i++) + tracker_horiz_value.addItem(v[i]); + tracker_horiz_value.setMaximumRowCount(v.length); + } + + String get_tracker_horiz_label() { + return String.format("Logging Trigger Horizontal (%s):", AltosConvert.height.show_units()); + } + + String[] tracker_vert_values() { + if (AltosConvert.imperial_units) + return tracker_vert_values_ft; + else + return tracker_vert_values_m; + } + + void set_tracker_vert_values() { + String[] v = tracker_vert_values(); + while (tracker_vert_value.getItemCount() > 0) + tracker_vert_value.removeItemAt(0); + for (int i = 0; i < v.length; i++) + tracker_vert_value.addItem(v[i]); + tracker_vert_value.setMaximumRowCount(v.length); + } + + void set_tracker_tool_tip() { + if (tracker_horiz_value.isEnabled()) + tracker_horiz_value.setToolTipText("How far the device must move before logging is enabled"); + else + tracker_horiz_value.setToolTipText("This device doesn't disable logging before motion"); + if (tracker_vert_value.isEnabled()) + tracker_vert_value.setToolTipText("How far the device must move before logging is enabled"); + else + tracker_vert_value.setToolTipText("This device doesn't disable logging before motion"); + } + + String get_tracker_vert_label() { + return String.format("Logging Trigger Vertical (%s):", AltosConvert.height.show_units()); + } + + public void set_tracker_distances(int[] tracker_distances) { + if (tracker_distances != null) { + tracker_horiz_value.setSelectedItem(AltosConvert.height.say(tracker_distances[0])); + tracker_vert_value.setSelectedItem(AltosConvert.height.say(tracker_distances[1])); + tracker_horiz_value.setEnabled(true); + tracker_vert_value.setEnabled(true); + } else { + tracker_horiz_value.setEnabled(false); + tracker_vert_value.setEnabled(false); + } + } + + public int[] tracker_distances() { + if (tracker_horiz_value.isEnabled() && tracker_vert_value.isEnabled()) { + int[] t = { + (int) (AltosConvert.height.parse(tracker_horiz_value.getSelectedItem().toString()) + 0.5), + (int) (AltosConvert.height.parse(tracker_vert_value.getSelectedItem().toString()) + 0.5), + }; + return t; + } + return null; + } + public void set_aprs_interval(int new_aprs_interval) { String s; -- cgit v1.2.3 From ae1174317fc476e39077f7dc257ec08709c6b301 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 10 Jun 2014 10:11:03 -0700 Subject: altoslib/altosui/telegps: Change log size configuration * Use new log-space value provided by firmware when available. * Divide that up into 1-8 flights and offer those sizes as options to the user instead of a fixed set of sizes. * Show how many flights each selection will store * This also checks values provided by the user Signed-off-by: Keith Packard --- altoslib/AltosConfigData.java | 38 ++++--- altosui/AltosConfig.java | 24 ++--- altosui/AltosConfigUI.java | 72 ++++++++----- telegps/Makefile.am | 3 +- telegps/TeleGPS.java | 4 +- telegps/TeleGPSConfig.java | 24 ++--- telegps/TeleGPSConfigUI.java | 64 +++++++----- telegps/TeleGPSDisplayThread.java | 209 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 345 insertions(+), 93 deletions(-) create mode 100644 telegps/TeleGPSDisplayThread.java (limited to 'telegps/TeleGPSConfigUI.java') diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index 9292a5a2..9462ae6f 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -29,6 +29,7 @@ public class AltosConfigData implements Iterable { public int serial; public int flight; public int log_format; + public int log_space; public String version; /* Strings returned */ @@ -124,6 +125,22 @@ public class AltosConfigData implements Iterable { return lines.iterator(); } + public int log_space() { + if (log_space > 0) + return log_space; + + if (storage_size > 0) { + int space = storage_size; + + if (storage_erase_unit > 0 && use_flash_for_config()) + space -= storage_erase_unit; + + if (space > 0) + return space; + } + return 0; + } + public int log_available() { switch (log_format) { case AltosLib.AO_LOG_FORMAT_TINY: @@ -137,7 +154,7 @@ public class AltosConfigData implements Iterable { if (flight_log_max <= 0) return 1; int log_max = flight_log_max * 1024; - int log_space = storage_size - storage_erase_unit; + int log_space = log_space(); int log_used; if (stored_flight <= 0) @@ -202,6 +219,7 @@ public class AltosConfigData implements Iterable { serial = 0; flight = 0; log_format = AltosLib.AO_LOG_FORMAT_UNKNOWN; + log_space = -1; version = "unknown"; main_deploy = -1; @@ -247,6 +265,7 @@ public class AltosConfigData implements Iterable { try { serial = get_int(line, "serial-number"); } catch (Exception e) {} try { flight = get_int(line, "current-flight"); } catch (Exception e) {} try { log_format = get_int(line, "log-format"); } catch (Exception e) {} + try { log_space = get_int(line, "log-space"); } catch (Exception e) {} try { version = get_string(line, "software-version"); } catch (Exception e) {} /* Version also contains MS5607 info, which we ignore here */ @@ -390,19 +409,6 @@ public class AltosConfigData implements Iterable { } - public int log_limit() { - if (storage_size > 0) { - int log_limit = storage_size; - - if (storage_erase_unit > 0 && use_flash_for_config()) - log_limit -= storage_erase_unit; - - if (log_limit > 0) - return log_limit / 1024; - } - return 1024; - } - public void get_values(AltosConfigValues source) throws AltosConfigDataException { /* HAS_FLIGHT */ @@ -462,7 +468,7 @@ public class AltosConfigData implements Iterable { dest.set_radio_frequency(frequency()); boolean max_enabled = true; - if (log_limit() == 0) + if (log_space() == 0) max_enabled = false; switch (log_format) { @@ -477,7 +483,7 @@ public class AltosConfigData implements Iterable { dest.set_flight_log_max_enabled(max_enabled); dest.set_radio_enable(radio_enable); - dest.set_flight_log_max_limit(log_limit()); + dest.set_flight_log_max_limit(log_space() / 1024); dest.set_flight_log_max(flight_log_max); dest.set_ignite_mode(ignite_mode); dest.set_pad_orientation(pad_orientation); diff --git a/altosui/AltosConfig.java b/altosui/AltosConfig.java index 2cf69525..6eb7d40c 100644 --- a/altosui/AltosConfig.java +++ b/altosui/AltosConfig.java @@ -229,20 +229,20 @@ public class AltosConfig implements ActionListener { void save_data() { - /* bounds check stuff */ - if (config_ui.flight_log_max() > data.log_limit()) { - JOptionPane.showMessageDialog(owner, - String.format("Requested flight log, %dk, is larger than the available space, %dk.\n", - config_ui.flight_log_max(), - data.log_limit()), - "Maximum Flight Log Too Large", - JOptionPane.ERROR_MESSAGE); - return; - } + try { + /* bounds check stuff */ + if (config_ui.flight_log_max() > data.log_space() / 1024) { + JOptionPane.showMessageDialog(owner, + String.format("Requested flight log, %dk, is larger than the available space, %dk.\n", + config_ui.flight_log_max(), + data.log_space() / 1024), + "Maximum Flight Log Too Large", + JOptionPane.ERROR_MESSAGE); + return; + } - /* Pull data out of the UI and stuff back into our local data record */ + /* Pull data out of the UI and stuff back into our local data record */ - try { data.get_values(config_ui); run_serial_thread(serial_mode_save); } catch (AltosConfigDataException ae) { diff --git a/altosui/AltosConfigUI.java b/altosui/AltosConfigUI.java index bcb3e12c..f936d92c 100644 --- a/altosui/AltosConfigUI.java +++ b/altosui/AltosConfigUI.java @@ -99,12 +99,6 @@ public class AltosConfigUI "0", "5", "10", "15", "20" }; - static String[] flight_log_max_values = { - "64", "128", "192", "256", "320", - "384", "448", "512", "576", "640", - "704", "768", "832", "896", "960", - }; - static String[] ignite_mode_values = { "Dual Deploy", "Redundant Apogee", @@ -546,7 +540,7 @@ public class AltosConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = il; c.ipady = 5; - flight_log_max_label = new JLabel("Maximum Flight Log Size:"); + flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):"); pane.add(flight_log_max_label, c); c = new GridBagConstraints(); @@ -557,7 +551,7 @@ public class AltosConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = ir; c.ipady = 5; - flight_log_max_value = new JComboBox(flight_log_max_values); + flight_log_max_value = new JComboBox(); flight_log_max_value.setEditable(true); flight_log_max_value.addItemListener(this); pane.add(flight_log_max_value, c); @@ -918,8 +912,19 @@ public class AltosConfigUI apogee_delay_value.setEnabled(new_apogee_delay >= 0); } - public int apogee_delay() { - return Integer.parseInt(apogee_delay_value.getSelectedItem().toString()); + private int parse_int(String name, String s, boolean split) throws AltosConfigDataException { + String v = s; + if (split) + v = s.split("\\s+")[0]; + try { + return Integer.parseInt(v); + } catch (NumberFormatException ne) { + throw new AltosConfigDataException("Invalid %s \"%s\"", name, s); + } + } + + public int apogee_delay() throws AltosConfigDataException { + return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false); } public void set_apogee_lockout(int new_apogee_lockout) { @@ -927,8 +932,8 @@ public class AltosConfigUI apogee_lockout_value.setEnabled(new_apogee_lockout >= 0); } - public int apogee_lockout() { - return Integer.parseInt(apogee_lockout_value.getSelectedItem().toString()); + public int apogee_lockout() throws AltosConfigDataException { + return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false); } public void set_radio_frequency(double new_radio_frequency) { @@ -947,8 +952,8 @@ public class AltosConfigUI radio_calibration_value.setText(String.format("%d", new_radio_calibration)); } - public int radio_calibration() { - return Integer.parseInt(radio_calibration_value.getText()); + public int radio_calibration() throws AltosConfigDataException { + return parse_int("radio calibration", radio_calibration_value.getText(), false); } public void set_radio_enable(int new_radio_enable) { @@ -979,8 +984,22 @@ public class AltosConfigUI return callsign_value.getText(); } + int flight_log_max_limit; + int flight_log_max; + + public String flight_log_max_label(int flight_log_max) { + if (flight_log_max_limit != 0) { + int nflight = flight_log_max_limit / flight_log_max; + String plural = nflight > 1 ? "s" : ""; + + return String.format("%d (%d flight%s)", flight_log_max, nflight, plural); + } + return String.format("%d", flight_log_max); + } + public void set_flight_log_max(int new_flight_log_max) { - flight_log_max_value.setSelectedItem(Integer.toString(new_flight_log_max)); + flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max)); + flight_log_max = new_flight_log_max; set_flight_log_max_tool_tip(); } @@ -989,20 +1008,19 @@ public class AltosConfigUI set_flight_log_max_tool_tip(); } - public int flight_log_max() { - return Integer.parseInt(flight_log_max_value.getSelectedItem().toString()); + public int flight_log_max() throws AltosConfigDataException { + return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true); } - public void set_flight_log_max_limit(int flight_log_max_limit) { - //boolean any_added = false; + public void set_flight_log_max_limit(int new_flight_log_max_limit) { + flight_log_max_limit = new_flight_log_max_limit; flight_log_max_value.removeAllItems(); - for (int i = 0; i < flight_log_max_values.length; i++) { - if (Integer.parseInt(flight_log_max_values[i]) < flight_log_max_limit){ - flight_log_max_value.addItem(flight_log_max_values[i]); - //any_added = true; - } + for (int i = 8; i >= 1; i--) { + int size = flight_log_max_limit / i; + flight_log_max_value.addItem(String.format("%d (%d flights)", size, i)); } - flight_log_max_value.addItem(String.format("%d", flight_log_max_limit)); + if (flight_log_max != 0) + set_flight_log_max(flight_log_max); } public void set_ignite_mode(int new_ignite_mode) { @@ -1165,11 +1183,11 @@ public class AltosConfigUI set_aprs_interval_tool_tip(); } - public int aprs_interval() { + public int aprs_interval() throws AltosConfigDataException { String s = aprs_interval_value.getSelectedItem().toString(); if (s.equals("Disabled")) return 0; - return Integer.parseInt(s); + return parse_int("aprs interval", s, false); } } diff --git a/telegps/Makefile.am b/telegps/Makefile.am index 7e17b331..e0d596e7 100644 --- a/telegps/Makefile.am +++ b/telegps/Makefile.am @@ -19,7 +19,8 @@ telegps_JAVA= \ TeleGPSConfig.java \ TeleGPSConfigUI.java \ TeleGPSPreferences.java \ - TeleGPSGraphUI.java + TeleGPSGraphUI.java \ + TeleGPSDisplayThread.java JFREECHART_CLASS= \ jfreechart.jar diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java index 71174436..c61b245e 100644 --- a/telegps/TeleGPS.java +++ b/telegps/TeleGPS.java @@ -51,7 +51,7 @@ public class TeleGPS } AltosFlightReader reader; - AltosDisplayThread thread; + TeleGPSDisplayThread thread; JMenuBar menu_bar; @@ -349,7 +349,7 @@ public class TeleGPS public void set_reader(AltosFlightReader reader) { setTitle(String.format("TeleGPS %s", reader.name)); - thread = new AltosDisplayThread(this, voice(), this, reader); + thread = new TeleGPSDisplayThread(this, voice(), this, reader); thread.start(); } diff --git a/telegps/TeleGPSConfig.java b/telegps/TeleGPSConfig.java index 22e6a3ac..3505b0bb 100644 --- a/telegps/TeleGPSConfig.java +++ b/telegps/TeleGPSConfig.java @@ -221,20 +221,20 @@ public class TeleGPSConfig implements ActionListener { void save_data() { - /* bounds check stuff */ - if (config_ui.flight_log_max() > data.log_limit()) { - JOptionPane.showMessageDialog(owner, - String.format("Requested flight log, %dk, is larger than the available space, %dk.\n", - config_ui.flight_log_max(), - data.log_limit()), - "Maximum Flight Log Too Large", - JOptionPane.ERROR_MESSAGE); - return; - } + try { + /* bounds check stuff */ + if (config_ui.flight_log_max() > data.log_space()/1024) { + JOptionPane.showMessageDialog(owner, + String.format("Requested flight log, %dk, is larger than the available space, %dk.\n", + config_ui.flight_log_max(), + data.log_space()/1024), + "Maximum Flight Log Too Large", + JOptionPane.ERROR_MESSAGE); + return; + } - /* Pull data out of the UI and stuff back into our local data record */ + /* Pull data out of the UI and stuff back into our local data record */ - try { data.get_values(config_ui); run_serial_thread(serial_mode_save); } catch (AltosConfigDataException ae) { diff --git a/telegps/TeleGPSConfigUI.java b/telegps/TeleGPSConfigUI.java index 863d61bb..03666036 100644 --- a/telegps/TeleGPSConfigUI.java +++ b/telegps/TeleGPSConfigUI.java @@ -65,12 +65,6 @@ public class TeleGPSConfigUI ActionListener listener; - static String[] flight_log_max_values = { - "64", "128", "192", "256", "320", - "384", "448", "512", "576", "640", - "704", "768", "832", "896", "960", - }; - static String[] aprs_interval_values = { "Disabled", "2", @@ -376,7 +370,7 @@ public class TeleGPSConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = il; c.ipady = 5; - flight_log_max_label = new JLabel("Maximum Flight Log Size:"); + flight_log_max_label = new JLabel("Maximum Log Size (kB):"); pane.add(flight_log_max_label, c); c = new GridBagConstraints(); @@ -387,7 +381,7 @@ public class TeleGPSConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = ir; c.ipady = 5; - flight_log_max_value = new JComboBox(flight_log_max_values); + flight_log_max_value = new JComboBox(); flight_log_max_value.setEditable(true); flight_log_max_value.addItemListener(this); pane.add(flight_log_max_value, c); @@ -636,8 +630,19 @@ public class TeleGPSConfigUI radio_calibration_value.setText(String.format("%d", new_radio_calibration)); } - public int radio_calibration() { - return Integer.parseInt(radio_calibration_value.getText()); + private int parse_int(String name, String s, boolean split) throws AltosConfigDataException { + String v = s; + if (split) + v = s.split("\\s+")[0]; + try { + return Integer.parseInt(v); + } catch (NumberFormatException ne) { + throw new AltosConfigDataException("Invalid %s \"%s\"", name, s); + } + } + + public int radio_calibration() throws AltosConfigDataException { + return parse_int("radio calibration", radio_calibration_value.getText(), false); } public void set_radio_enable(int new_radio_enable) { @@ -668,8 +673,22 @@ public class TeleGPSConfigUI return callsign_value.getText(); } + int flight_log_max_limit; + int flight_log_max; + + public String flight_log_max_label(int flight_log_max) { + if (flight_log_max_limit != 0) { + int nflight = flight_log_max_limit / flight_log_max; + String plural = nflight > 1 ? "s" : ""; + + return String.format("%d (%d flight%s)", flight_log_max, nflight, plural); + } + return String.format("%d", flight_log_max); + } + public void set_flight_log_max(int new_flight_log_max) { - flight_log_max_value.setSelectedItem(Integer.toString(new_flight_log_max)); + flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max)); + flight_log_max = new_flight_log_max; set_flight_log_max_tool_tip(); } @@ -678,20 +697,19 @@ public class TeleGPSConfigUI set_flight_log_max_tool_tip(); } - public int flight_log_max() { - return Integer.parseInt(flight_log_max_value.getSelectedItem().toString()); + public int flight_log_max() throws AltosConfigDataException { + return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true); } - public void set_flight_log_max_limit(int flight_log_max_limit) { - //boolean any_added = false; + public void set_flight_log_max_limit(int new_flight_log_max_limit) { + flight_log_max_limit = new_flight_log_max_limit; flight_log_max_value.removeAllItems(); - for (int i = 0; i < flight_log_max_values.length; i++) { - if (Integer.parseInt(flight_log_max_values[i]) < flight_log_max_limit){ - flight_log_max_value.addItem(flight_log_max_values[i]); - //any_added = true; - } + for (int i = 8; i >= 1; i--) { + int size = flight_log_max_limit / i; + flight_log_max_value.addItem(String.format("%d (%d flights)", size, i)); } - flight_log_max_value.addItem(String.format("%d", flight_log_max_limit)); + if (flight_log_max != 0) + set_flight_log_max(flight_log_max); } public void set_ignite_mode(int new_ignite_mode) { } @@ -791,11 +809,11 @@ public class TeleGPSConfigUI set_aprs_interval_tool_tip(); } - public int aprs_interval() { + public int aprs_interval() throws AltosConfigDataException { String s = aprs_interval_value.getSelectedItem().toString(); if (s.equals("Disabled")) return 0; - return Integer.parseInt(s); + return parse_int("aprs interval", s, false); } } diff --git a/telegps/TeleGPSDisplayThread.java b/telegps/TeleGPSDisplayThread.java new file mode 100644 index 00000000..9de33098 --- /dev/null +++ b/telegps/TeleGPSDisplayThread.java @@ -0,0 +1,209 @@ +/* + * Copyright © 2010 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.telegps; + +import java.awt.*; +import javax.swing.*; +import java.io.*; +import java.text.*; +import org.altusmetrum.altoslib_4.*; +import org.altusmetrum.altosuilib_2.*; + +public class TeleGPSDisplayThread extends Thread { + + Frame parent; + IdleThread idle_thread; + AltosVoice voice; + AltosFlightReader reader; + AltosState old_state, state; + AltosListenerState listener_state; + AltosFlightDisplay display; + + synchronized void show_safely() { + final AltosState my_state = state; + final AltosListenerState my_listener_state = listener_state; + Runnable r = new Runnable() { + public void run() { + try { + display.show(my_state, my_listener_state); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + void reading_error_internal() { + JOptionPane.showMessageDialog(parent, + String.format("Error reading from \"%s\"", reader.name), + "Telemetry Read Error", + JOptionPane.ERROR_MESSAGE); + } + + void reading_error_safely() { + Runnable r = new Runnable() { + public void run() { + try { + reading_error_internal(); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + class IdleThread extends Thread { + + boolean started; + int report_interval; + long report_time; + + public synchronized void report(boolean last) { + if (state == null) + return; + + if (state.height() != AltosLib.MISSING) { + if (state.from_pad != null) { + voice.speak("Height %s, bearing %s %d, elevation %d, range %s, .\n", + AltosConvert.height.say(state.gps_height()), + state.from_pad.bearing_words( + AltosGreatCircle.BEARING_VOICE), + (int) (state.from_pad.bearing + 0.5), + (int) (state.elevation + 0.5), + AltosConvert.distance.say(state.range)); + } else { + voice.speak("Height %s.\n", + AltosConvert.height.say(state.height())); + } + } else { + voice.speak("Height is unknown.\n"); + } + } + + long now () { + return System.currentTimeMillis(); + } + + void set_report_time() { + report_time = now() + report_interval; + } + + public void run () { + try { + for (;;) { + if (reader.has_monitor_battery()) { + listener_state.battery = reader.monitor_battery(); + show_safely(); + } + set_report_time(); + for (;;) { + voice.drain(); + synchronized (this) { + long sleep_time = report_time - now(); + if (sleep_time <= 0) + break; + wait(sleep_time); + } + } + + report(false); + } + } catch (InterruptedException ie) { + try { + voice.drain(); + } catch (InterruptedException iie) { } + } + } + + public synchronized void notice(boolean spoken) { + if (old_state != null && old_state.state != state.state) { + report_time = now(); + this.notify(); + } else if (spoken) + set_report_time(); + } + + public IdleThread() { + report_interval = 10000; + } + } + + synchronized boolean tell() { + boolean ret = false; + if (old_state == null || old_state.gps_ready != state.gps_ready) { + if (state.gps_ready) { + voice.speak("GPS ready"); + ret = true; + } + else if (old_state != null) { + voice.speak("GPS lost"); + ret = true; + } + } + old_state = state; + return ret; + } + + public void run() { + boolean interrupted = false; + boolean told; + + idle_thread = new IdleThread(); + idle_thread.start(); + + try { + for (;;) { + try { + state = reader.read(); + if (state == null) + break; + reader.update(state); + show_safely(); + told = tell(); + idle_thread.notice(told); + } catch (ParseException pp) { + System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage()); + } catch (AltosCRCException ce) { + ++listener_state.crc_errors; + show_safely(); + } + } + } catch (InterruptedException ee) { + interrupted = true; + } catch (IOException ie) { + reading_error_safely(); + } finally { + if (!interrupted) + idle_thread.report(true); + reader.close(interrupted); + idle_thread.interrupt(); + try { + idle_thread.join(); + } catch (InterruptedException ie) {} + } + } + + public TeleGPSDisplayThread(Frame in_parent, AltosVoice in_voice, AltosFlightDisplay in_display, AltosFlightReader in_reader) { + listener_state = new AltosListenerState(); + parent = in_parent; + voice = in_voice; + display = in_display; + reader = in_reader; + display.reset(); + } +} -- cgit v1.2.3 From 5f2029bd4e31289fb03e6af39abdbc16f8b8fa78 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 10 Jun 2014 10:14:07 -0700 Subject: altoslib/altosui/telegps: Switch TeleGPS config to motion/interval TeleGPS had configurable boost-detect values; those have been replaced with a configurable stop-tracking motion limit and logging/telemetry interval value. Signed-off-by: Keith Packard --- altoslib/AltosConfigData.java | 35 +++++---- altoslib/AltosConfigValues.java | 24 +++--- altosui/AltosConfigUI.java | 165 +++++++++++++++------------------------- telegps/TeleGPSConfigUI.java | 165 +++++++++++++++------------------------- 4 files changed, 160 insertions(+), 229 deletions(-) (limited to 'telegps/TeleGPSConfigUI.java') diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index 9462ae6f..563bef4b 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -82,7 +82,8 @@ public class AltosConfigData implements Iterable { public int stored_flight; /* HAS_TRACKER */ - public int[] tracker_distances; + public int tracker_motion; + public int tracker_interval; public static String get_string(String line, String label) throws ParseException { if (line.startsWith(label)) { @@ -107,15 +108,15 @@ public class AltosConfigData implements Iterable { throw new ParseException("mismatch", 0); } - public static int[] get_distances(String line, String label) throws NumberFormatException, ParseException { + public static int[] get_values(String line, String label) throws NumberFormatException, ParseException { if (line.startsWith(label)) { String tail = line.substring(label.length()).trim(); String[] tokens = tail.split("\\s+"); if (tokens.length > 1) { - int[] distances = new int[2]; - distances[0] = Integer.parseInt(tokens[0]); - distances[1] = Integer.parseInt(tokens[1]); - return distances; + int[] values = new int[2]; + values[0] = Integer.parseInt(tokens[0]); + values[1] = Integer.parseInt(tokens[1]); + return values; } } throw new ParseException("mismatch", 0); @@ -250,7 +251,8 @@ public class AltosConfigData implements Iterable { beep = -1; - tracker_distances = null; + tracker_motion = -1; + tracker_interval = -1; storage_size = -1; storage_erase_unit = -1; @@ -333,7 +335,11 @@ public class AltosConfigData implements Iterable { try { beep = get_int(line, "Beeper setting:"); } catch (Exception e) {} /* HAS_TRACKER */ - try { tracker_distances = get_distances(line, "Tracker setting:"); } catch (Exception e) {} + try { + int[] values = get_values(line, "Tracker setting:"); + tracker_motion = values[0]; + tracker_interval = values[1]; + } catch (Exception e) {} /* Storage info replies */ try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {} @@ -453,8 +459,10 @@ public class AltosConfigData implements Iterable { if (beep >= 0) beep = source.beep(); /* HAS_TRACKER */ - if (tracker_distances != null) - tracker_distances = source.tracker_distances(); + if (tracker_motion >= 0) + tracker_motion = source.tracker_motion(); + if (tracker_interval >= 0) + tracker_interval = source.tracker_interval(); } public void set_values(AltosConfigValues dest) { @@ -494,7 +502,8 @@ public class AltosConfigData implements Iterable { dest.set_pyros(null); dest.set_aprs_interval(aprs_interval); dest.set_beep(beep); - dest.set_tracker_distances(tracker_distances); + dest.set_tracker_motion(tracker_motion); + dest.set_tracker_interval(tracker_interval); } public void save(AltosLink link, boolean remote) throws InterruptedException, TimeoutException { @@ -566,8 +575,8 @@ public class AltosConfigData implements Iterable { link.printf("c b %d\n", beep); /* HAS_TRACKER */ - if (tracker_distances != null) - link.printf("c t %d %d\n", tracker_distances[0], tracker_distances[1]); + if (tracker_motion >= 0 && tracker_interval >= 0) + link.printf("c t %d %d\n", tracker_motion, tracker_interval); link.printf("c w\n"); link.flush_output(); diff --git a/altoslib/AltosConfigValues.java b/altoslib/AltosConfigValues.java index 6ca1f5c6..778f1222 100644 --- a/altoslib/AltosConfigValues.java +++ b/altoslib/AltosConfigValues.java @@ -27,23 +27,23 @@ public interface AltosConfigValues { public abstract void set_main_deploy(int new_main_deploy); - public abstract int main_deploy(); + public abstract int main_deploy() throws AltosConfigDataException; public abstract void set_apogee_delay(int new_apogee_delay); - public abstract int apogee_delay(); + public abstract int apogee_delay() throws AltosConfigDataException; public abstract void set_apogee_lockout(int new_apogee_lockout); - public abstract int apogee_lockout(); + public abstract int apogee_lockout() throws AltosConfigDataException; public abstract void set_radio_frequency(double new_radio_frequency); - public abstract double radio_frequency(); + public abstract double radio_frequency() throws AltosConfigDataException; public abstract void set_radio_calibration(int new_radio_calibration); - public abstract int radio_calibration(); + public abstract int radio_calibration() throws AltosConfigDataException; public abstract void set_radio_enable(int new_radio_enable); @@ -57,7 +57,7 @@ public interface AltosConfigValues { public abstract void set_flight_log_max_enabled(boolean enable); - public abstract int flight_log_max(); + public abstract int flight_log_max() throws AltosConfigDataException; public abstract void set_flight_log_max_limit(int flight_log_max_limit); @@ -73,15 +73,19 @@ public interface AltosConfigValues { public abstract AltosPyro[] pyros() throws AltosConfigDataException; - public abstract int aprs_interval(); + public abstract int aprs_interval() throws AltosConfigDataException; public abstract void set_aprs_interval(int new_aprs_interval); - public abstract int beep(); + public abstract int beep() throws AltosConfigDataException; public abstract void set_beep(int new_beep); - public abstract int[] tracker_distances(); + public abstract int tracker_motion() throws AltosConfigDataException; - public abstract void set_tracker_distances(int[] tracker_distances); + public abstract void set_tracker_motion(int tracker_motion); + + public abstract int tracker_interval() throws AltosConfigDataException; + + public abstract void set_tracker_interval(int tracker_motion); } diff --git a/altosui/AltosConfigUI.java b/altosui/AltosConfigUI.java index f936d92c..ee54e31e 100644 --- a/altosui/AltosConfigUI.java +++ b/altosui/AltosConfigUI.java @@ -46,8 +46,8 @@ public class AltosConfigUI JLabel pad_orientation_label; JLabel callsign_label; JLabel beep_label; - JLabel tracker_horiz_label; - JLabel tracker_vert_label; + JLabel tracker_motion_label; + JLabel tracker_interval_label; public boolean dirty; @@ -67,8 +67,8 @@ public class AltosConfigUI JComboBox pad_orientation_value; JTextField callsign_value; JComboBox beep_value; - JComboBox tracker_horiz_value; - JComboBox tracker_vert_value; + JComboBox tracker_motion_value; + JComboBox tracker_interval_value; JButton pyro; @@ -123,32 +123,25 @@ public class AltosConfigUI "Antenna Down", }; - static String[] tracker_horiz_values_m = { - "250", - "500", - "1000", - "2000" - }; - - static String[] tracker_horiz_values_ft = { - "500", - "1000", - "2500", - "5000" + static String[] tracker_motion_values_m = { + "2", + "5", + "10", + "25", }; - static String[] tracker_vert_values_m = { - "25", + static String[] tracker_motion_values_ft = { + "5", + "20", "50", - "100", - "200" + "100" }; - static String[] tracker_vert_values_ft = { - "50", - "100", - "250", - "500" + static String[] tracker_interval_values = { + "1", + "2", + "5", + "10" }; /* A window listener to catch closing events and tell the config code */ @@ -644,8 +637,8 @@ public class AltosConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = il; c.ipady = 5; - tracker_horiz_label = new JLabel(get_tracker_horiz_label()); - pane.add(tracker_horiz_label, c); + tracker_motion_label = new JLabel(get_tracker_motion_label()); + pane.add(tracker_motion_label, c); c = new GridBagConstraints(); c.gridx = 4; c.gridy = row; @@ -655,10 +648,10 @@ public class AltosConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = ir; c.ipady = 5; - tracker_horiz_value = new JComboBox(tracker_horiz_values()); - tracker_horiz_value.setEditable(true); - tracker_horiz_value.addItemListener(this); - pane.add(tracker_horiz_value, c); + tracker_motion_value = new JComboBox(tracker_motion_values()); + tracker_motion_value.setEditable(true); + tracker_motion_value.addItemListener(this); + pane.add(tracker_motion_value, c); row++; /* Tracker triger vert distances */ @@ -669,8 +662,8 @@ public class AltosConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = il; c.ipady = 5; - tracker_vert_label = new JLabel(get_tracker_vert_label()); - pane.add(tracker_vert_label, c); + tracker_interval_label = new JLabel("Position Reporting Interval(s):"); + pane.add(tracker_interval_label, c); c = new GridBagConstraints(); c.gridx = 4; c.gridy = row; @@ -680,10 +673,10 @@ public class AltosConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = ir; c.ipady = 5; - tracker_vert_value = new JComboBox(tracker_vert_values()); - tracker_vert_value.setEditable(true); - tracker_vert_value.addItemListener(this); - pane.add(tracker_vert_value, c); + tracker_interval_value = new JComboBox(tracker_interval_values); + tracker_interval_value.setEditable(true); + tracker_interval_value.addItemListener(this); + pane.add(tracker_interval_value, c); set_tracker_tool_tip(); row++; @@ -892,18 +885,11 @@ public class AltosConfigUI int m = (int) (AltosConvert.height.parse(v, !imperial_units) + 0.5); set_main_deploy(m); - if (tracker_horiz_value.isEnabled() && tracker_vert_value.isEnabled()) { - String th = tracker_horiz_value.getSelectedItem().toString(); - String tv = tracker_vert_value.getSelectedItem().toString(); - tracker_horiz_label.setText(get_tracker_horiz_label()); - tracker_vert_label.setText(get_tracker_vert_label()); - set_tracker_horiz_values(); - set_tracker_vert_values(); - int[] t = { - (int) (AltosConvert.height.parse(th, !imperial_units) + 0.5), - (int) (AltosConvert.height.parse(tv, !imperial_units) + 0.5) - }; - set_tracker_distances(t); + if (tracker_motion_value.isEnabled()) { + String motion = tracker_motion_value.getSelectedItem().toString(); + tracker_motion_label.setText(get_tracker_motion_label()); + set_tracker_motion_values(); + set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5)); } } @@ -1084,78 +1070,51 @@ public class AltosConfigUI return -1; } - String[] tracker_horiz_values() { + String[] tracker_motion_values() { if (AltosConvert.imperial_units) - return tracker_horiz_values_ft; + return tracker_motion_values_ft; else - return tracker_horiz_values_m; + return tracker_motion_values_m; } - void set_tracker_horiz_values() { - String[] v = tracker_horiz_values(); - while (tracker_horiz_value.getItemCount() > 0) - tracker_horiz_value.removeItemAt(0); + void set_tracker_motion_values() { + String[] v = tracker_motion_values(); + while (tracker_motion_value.getItemCount() > 0) + tracker_motion_value.removeItemAt(0); for (int i = 0; i < v.length; i++) - tracker_horiz_value.addItem(v[i]); - tracker_horiz_value.setMaximumRowCount(v.length); + tracker_motion_value.addItem(v[i]); + tracker_motion_value.setMaximumRowCount(v.length); } - String get_tracker_horiz_label() { - return String.format("Logging Trigger Horizontal (%s):", AltosConvert.height.show_units()); - } - - String[] tracker_vert_values() { - if (AltosConvert.imperial_units) - return tracker_vert_values_ft; - else - return tracker_vert_values_m; - } - - void set_tracker_vert_values() { - String[] v = tracker_vert_values(); - while (tracker_vert_value.getItemCount() > 0) - tracker_vert_value.removeItemAt(0); - for (int i = 0; i < v.length; i++) - tracker_vert_value.addItem(v[i]); - tracker_vert_value.setMaximumRowCount(v.length); + String get_tracker_motion_label() { + return String.format("Logging Trigger Motion (%s):", AltosConvert.height.show_units()); } void set_tracker_tool_tip() { - if (tracker_horiz_value.isEnabled()) - tracker_horiz_value.setToolTipText("How far the device must move before logging is enabled"); + if (tracker_motion_value.isEnabled()) + tracker_motion_value.setToolTipText("How far the device must move before logging"); else - tracker_horiz_value.setToolTipText("This device doesn't disable logging before motion"); - if (tracker_vert_value.isEnabled()) - tracker_vert_value.setToolTipText("How far the device must move before logging is enabled"); + tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary"); + if (tracker_interval_value.isEnabled()) + tracker_interval_value.setToolTipText("How often to report GPS position"); else - tracker_vert_value.setToolTipText("This device doesn't disable logging before motion"); + tracker_interval_value.setToolTipText("This device can't configure interval"); } - String get_tracker_vert_label() { - return String.format("Logging Trigger Vertical (%s):", AltosConvert.height.show_units()); + public void set_tracker_motion(int tracker_motion) { + tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion)); } - public void set_tracker_distances(int[] tracker_distances) { - if (tracker_distances != null) { - tracker_horiz_value.setSelectedItem(AltosConvert.height.say(tracker_distances[0])); - tracker_vert_value.setSelectedItem(AltosConvert.height.say(tracker_distances[1])); - tracker_horiz_value.setEnabled(true); - tracker_vert_value.setEnabled(true); - } else { - tracker_horiz_value.setEnabled(false); - tracker_vert_value.setEnabled(false); - } + public int tracker_motion() throws AltosConfigDataException { + return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString()); } - public int[] tracker_distances() { - if (tracker_horiz_value.isEnabled() && tracker_vert_value.isEnabled()) { - int[] t = { - (int) (AltosConvert.height.parse(tracker_horiz_value.getSelectedItem().toString()) + 0.5), - (int) (AltosConvert.height.parse(tracker_vert_value.getSelectedItem().toString()) + 0.5), - }; - return t; - } - return null; + public void set_tracker_interval(int tracker_interval) { + tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval)); + } + + public int tracker_interval() throws AltosConfigDataException { + return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false); } public void set_pyros(AltosPyro[] new_pyros) { diff --git a/telegps/TeleGPSConfigUI.java b/telegps/TeleGPSConfigUI.java index 03666036..325ca7b9 100644 --- a/telegps/TeleGPSConfigUI.java +++ b/telegps/TeleGPSConfigUI.java @@ -40,8 +40,8 @@ public class TeleGPSConfigUI JLabel aprs_interval_label; JLabel flight_log_max_label; JLabel callsign_label; - JLabel tracker_horiz_label; - JLabel tracker_vert_label; + JLabel tracker_motion_label; + JLabel tracker_interval_label; public boolean dirty; @@ -55,8 +55,8 @@ public class TeleGPSConfigUI JComboBox aprs_interval_value; JComboBox flight_log_max_value; JTextField callsign_value; - JComboBox tracker_horiz_value; - JComboBox tracker_vert_value; + JComboBox tracker_motion_value; + JComboBox tracker_interval_value; JButton save; JButton reset; @@ -72,32 +72,25 @@ public class TeleGPSConfigUI "10" }; - static String[] tracker_horiz_values_m = { - "250", - "500", - "1000", - "2000" - }; - - static String[] tracker_horiz_values_ft = { - "500", - "1000", - "2500", - "5000" + static String[] tracker_motion_values_m = { + "2", + "5", + "10", + "25", }; - static String[] tracker_vert_values_m = { - "25", + static String[] tracker_motion_values_ft = { + "5", + "20", "50", - "100", - "200" + "100" }; - static String[] tracker_vert_values_ft = { - "50", - "100", - "250", - "500" + static String[] tracker_interval_values = { + "1", + "2", + "5", + "10" }; /* A window listener to catch closing events and tell the config code */ @@ -396,8 +389,8 @@ public class TeleGPSConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = il; c.ipady = 5; - tracker_horiz_label = new JLabel(get_tracker_horiz_label()); - pane.add(tracker_horiz_label, c); + tracker_motion_label = new JLabel(get_tracker_motion_label()); + pane.add(tracker_motion_label, c); c = new GridBagConstraints(); c.gridx = 4; c.gridy = row; @@ -407,10 +400,10 @@ public class TeleGPSConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = ir; c.ipady = 5; - tracker_horiz_value = new JComboBox(tracker_horiz_values()); - tracker_horiz_value.setEditable(true); - tracker_horiz_value.addItemListener(this); - pane.add(tracker_horiz_value, c); + tracker_motion_value = new JComboBox(tracker_motion_values()); + tracker_motion_value.setEditable(true); + tracker_motion_value.addItemListener(this); + pane.add(tracker_motion_value, c); row++; /* Tracker triger vert distances */ @@ -421,8 +414,8 @@ public class TeleGPSConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = il; c.ipady = 5; - tracker_vert_label = new JLabel(get_tracker_vert_label()); - pane.add(tracker_vert_label, c); + tracker_interval_label = new JLabel("Position Reporting Interval (s):"); + pane.add(tracker_interval_label, c); c = new GridBagConstraints(); c.gridx = 4; c.gridy = row; @@ -432,10 +425,10 @@ public class TeleGPSConfigUI c.anchor = GridBagConstraints.LINE_START; c.insets = ir; c.ipady = 5; - tracker_vert_value = new JComboBox(tracker_vert_values()); - tracker_vert_value.setEditable(true); - tracker_vert_value.addItemListener(this); - pane.add(tracker_vert_value, c); + tracker_interval_value = new JComboBox(tracker_interval_values); + tracker_interval_value.setEditable(true); + tracker_interval_value.addItemListener(this); + pane.add(tracker_interval_value, c); set_tracker_tool_tip(); row++; @@ -566,18 +559,11 @@ public class TeleGPSConfigUI } public void units_changed(boolean imperial_units) { - if (tracker_horiz_value.isEnabled() && tracker_vert_value.isEnabled()) { - String th = tracker_horiz_value.getSelectedItem().toString(); - String tv = tracker_vert_value.getSelectedItem().toString(); - tracker_horiz_label.setText(get_tracker_horiz_label()); - tracker_vert_label.setText(get_tracker_vert_label()); - set_tracker_horiz_values(); - set_tracker_vert_values(); - int[] t = { - (int) (AltosConvert.height.parse(th, !imperial_units) + 0.5), - (int) (AltosConvert.height.parse(tv, !imperial_units) + 0.5) - }; - set_tracker_distances(t); + if (tracker_motion_value.isEnabled()) { + String motion = tracker_motion_value.getSelectedItem().toString(); + tracker_motion_label.setText(get_tracker_motion_label()); + set_tracker_motion_values(); + set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5)); } } @@ -723,78 +709,51 @@ public class TeleGPSConfigUI public int beep() { return -1; } - String[] tracker_horiz_values() { + String[] tracker_motion_values() { if (AltosConvert.imperial_units) - return tracker_horiz_values_ft; + return tracker_motion_values_ft; else - return tracker_horiz_values_m; + return tracker_motion_values_m; } - void set_tracker_horiz_values() { - String[] v = tracker_horiz_values(); - while (tracker_horiz_value.getItemCount() > 0) - tracker_horiz_value.removeItemAt(0); + void set_tracker_motion_values() { + String[] v = tracker_motion_values(); + while (tracker_motion_value.getItemCount() > 0) + tracker_motion_value.removeItemAt(0); for (int i = 0; i < v.length; i++) - tracker_horiz_value.addItem(v[i]); - tracker_horiz_value.setMaximumRowCount(v.length); - } - - String get_tracker_horiz_label() { - return String.format("Logging Trigger Horizontal (%s):", AltosConvert.height.show_units()); - } - - String[] tracker_vert_values() { - if (AltosConvert.imperial_units) - return tracker_vert_values_ft; - else - return tracker_vert_values_m; + tracker_motion_value.addItem(v[i]); + tracker_motion_value.setMaximumRowCount(v.length); } - void set_tracker_vert_values() { - String[] v = tracker_vert_values(); - while (tracker_vert_value.getItemCount() > 0) - tracker_vert_value.removeItemAt(0); - for (int i = 0; i < v.length; i++) - tracker_vert_value.addItem(v[i]); - tracker_vert_value.setMaximumRowCount(v.length); + String get_tracker_motion_label() { + return String.format("Logging Trigger Motion (%s):", AltosConvert.height.show_units()); } void set_tracker_tool_tip() { - if (tracker_horiz_value.isEnabled()) - tracker_horiz_value.setToolTipText("How far the device must move before logging is enabled"); + if (tracker_motion_value.isEnabled()) + tracker_motion_value.setToolTipText("How far the device must move before logging"); else - tracker_horiz_value.setToolTipText("This device doesn't disable logging before motion"); - if (tracker_vert_value.isEnabled()) - tracker_vert_value.setToolTipText("How far the device must move before logging is enabled"); + tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary"); + if (tracker_interval_value.isEnabled()) + tracker_interval_value.setToolTipText("How often to report GPS position"); else - tracker_vert_value.setToolTipText("This device doesn't disable logging before motion"); + tracker_interval_value.setToolTipText("This device can't configure interval"); } - String get_tracker_vert_label() { - return String.format("Logging Trigger Vertical (%s):", AltosConvert.height.show_units()); + public void set_tracker_motion(int tracker_motion) { + tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion)); } - public void set_tracker_distances(int[] tracker_distances) { - if (tracker_distances != null) { - tracker_horiz_value.setSelectedItem(AltosConvert.height.say(tracker_distances[0])); - tracker_vert_value.setSelectedItem(AltosConvert.height.say(tracker_distances[1])); - tracker_horiz_value.setEnabled(true); - tracker_vert_value.setEnabled(true); - } else { - tracker_horiz_value.setEnabled(false); - tracker_vert_value.setEnabled(false); - } + public int tracker_motion() throws AltosConfigDataException { + return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString()); } - public int[] tracker_distances() { - if (tracker_horiz_value.isEnabled() && tracker_vert_value.isEnabled()) { - int[] t = { - (int) (AltosConvert.height.parse(tracker_horiz_value.getSelectedItem().toString()) + 0.5), - (int) (AltosConvert.height.parse(tracker_vert_value.getSelectedItem().toString()) + 0.5), - }; - return t; - } - return null; + public void set_tracker_interval(int tracker_interval) { + tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval)); + } + + public int tracker_interval() throws AltosConfigDataException { + return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false); } public void set_aprs_interval(int new_aprs_interval) { -- cgit v1.2.3 From d744e588b7504f314e39b1407152d11c031673c9 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 11 Jun 2014 19:51:37 -0700 Subject: altosui: Add pyro firing time configuration Signed-off-by: Keith Packard --- altoslib/AltosConfigData.java | 8 +++++++ altoslib/AltosConfigValues.java | 4 ++++ altosui/AltosConfigPyroUI.java | 50 ++++++++++++++++++++++++++++++++++++++++- altosui/AltosConfigUI.java | 16 ++++++++++++- telegps/TeleGPSConfigUI.java | 7 ++++++ 5 files changed, 83 insertions(+), 2 deletions(-) (limited to 'telegps/TeleGPSConfigUI.java') diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index 563bef4b..e1043958 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -67,6 +67,7 @@ public class AltosConfigData implements Iterable { public AltosPyro[] pyros; public int npyro; public int pyro; + public double pyro_firing_time; /* HAS_APRS */ public int aprs_interval; @@ -246,6 +247,7 @@ public class AltosConfigData implements Iterable { pyro = 0; npyro = 0; pyros = null; + pyro_firing_time = -1; aprs_interval = -1; @@ -327,6 +329,7 @@ public class AltosConfigData implements Iterable { pyros[pyro++] = p; } catch (Exception e) {} } + try { pyro_firing_time = get_int(line, "Pyro time:") / 100.0; } catch (Exception e) {} /* HAS_APRS */ try { aprs_interval = get_int(line, "APRS interval:"); } catch (Exception e) {} @@ -450,6 +453,8 @@ public class AltosConfigData implements Iterable { /* AO_PYRO_NUM */ if (npyro > 0) pyros = source.pyros(); + if (pyro_firing_time >= 0) + pyro_firing_time = source.pyro_firing_time(); /* HAS_APRS */ if (aprs_interval >= 0) @@ -500,6 +505,7 @@ public class AltosConfigData implements Iterable { dest.set_pyros(pyros); else dest.set_pyros(null); + dest.set_pyro_firing_time(pyro_firing_time); dest.set_aprs_interval(aprs_interval); dest.set_beep(beep); dest.set_tracker_motion(tracker_motion); @@ -565,6 +571,8 @@ public class AltosConfigData implements Iterable { pyros[p].toString()); } } + if (pyro_firing_time >= 0) + link.printf("c I %d\n", (int) (pyro_firing_time * 100.0 + 0.5)); /* HAS_APRS */ if (aprs_interval >= 0) diff --git a/altoslib/AltosConfigValues.java b/altoslib/AltosConfigValues.java index 778f1222..724ba7dc 100644 --- a/altoslib/AltosConfigValues.java +++ b/altoslib/AltosConfigValues.java @@ -73,6 +73,10 @@ public interface AltosConfigValues { public abstract AltosPyro[] pyros() throws AltosConfigDataException; + public abstract void set_pyro_firing_time(double new_pyro_firing_time); + + public abstract double pyro_firing_time() throws AltosConfigDataException; + public abstract int aprs_interval() throws AltosConfigDataException; public abstract void set_aprs_interval(int new_aprs_interval); diff --git a/altosui/AltosConfigPyroUI.java b/altosui/AltosConfigPyroUI.java index 7a298a3c..f0b4f0f9 100644 --- a/altosui/AltosConfigPyroUI.java +++ b/altosui/AltosConfigPyroUI.java @@ -278,6 +278,28 @@ public class AltosConfigPyroUI return pyros; } + JLabel pyro_firing_time_label; + JComboBox pyro_firing_time_value; + + static String[] pyro_firing_time_values = { + "0.050", "0.100", "0.250", "0.500", "1.0", "2.0" + }; + + public void set_pyro_firing_time(double new_pyro_firing_time) { + pyro_firing_time_value.setSelectedItem(Double.toString(new_pyro_firing_time)); + pyro_firing_time_value.setEnabled(new_pyro_firing_time >= 0); + } + + public double get_pyro_firing_time() throws AltosConfigDataException { + String v = pyro_firing_time_value.getSelectedItem().toString(); + + try { + return Double.parseDouble(v); + } catch (NumberFormatException e) { + throw new AltosConfigDataException("Invalid pyro firing time \"%s\"", v); + } + } + public void set_dirty() { owner.set_dirty(); } @@ -334,7 +356,7 @@ public class AltosConfigPyroUI setVisible(false); } - public AltosConfigPyroUI(AltosConfigUI in_owner, AltosPyro[] pyros) { + public AltosConfigPyroUI(AltosConfigUI in_owner, AltosPyro[] pyros, double pyro_firing_time) { super(in_owner, "Configure Pyro Channels", false); @@ -379,6 +401,32 @@ public class AltosConfigPyroUI columns[i].set(pyros[i]); } + /* Pyro firing time */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = row; + c.gridwidth = 2; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + c.ipady = 5; + pyro_firing_time_label = new JLabel("Pyro Firing Time(s):"); + pane.add(pyro_firing_time_label, c); + + c = new GridBagConstraints(); + c.gridx = 2; c.gridy = row; + c.gridwidth = 7; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + c.ipady = 5; + pyro_firing_time_value = new JComboBox(pyro_firing_time_values); + pyro_firing_time_value.setEditable(true); + pyro_firing_time_value.addItemListener(this); + set_pyro_firing_time(pyro_firing_time); + pane.add(pyro_firing_time_value, c); + pyro_firing_time_value.setToolTipText("Length of extra pyro channel firing pulse"); + c = new GridBagConstraints(); c.gridx = pyros.length*2-1; c.fill = GridBagConstraints.HORIZONTAL; diff --git a/altosui/AltosConfigUI.java b/altosui/AltosConfigUI.java index ee54e31e..56d0d2a7 100644 --- a/altosui/AltosConfigUI.java +++ b/altosui/AltosConfigUI.java @@ -78,6 +78,7 @@ public class AltosConfigUI JButton close; AltosPyro[] pyros; + double pyro_firing_time; ActionListener listener; @@ -792,7 +793,7 @@ public class AltosConfigUI if (cmd.equals("Pyro")) { if (pyro_ui == null && pyros != null) - pyro_ui = new AltosConfigPyroUI(this, pyros); + pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time); if (pyro_ui != null) pyro_ui.make_visible(); return; @@ -1130,6 +1131,19 @@ public class AltosConfigUI return pyros; } + public void set_pyro_firing_time(double new_pyro_firing_time) { + pyro_firing_time = new_pyro_firing_time; + pyro.setVisible(pyro_firing_time >= 0); + if (pyro_firing_time >= 0 && pyro_ui != null) + pyro_ui.set_pyro_firing_time(pyro_firing_time); + } + + public double pyro_firing_time() throws AltosConfigDataException { + if (pyro_ui != null) + pyro_firing_time = pyro_ui.get_pyro_firing_time(); + return pyro_firing_time; + } + public void set_aprs_interval(int new_aprs_interval) { String s; diff --git a/telegps/TeleGPSConfigUI.java b/telegps/TeleGPSConfigUI.java index 325ca7b9..f6c69040 100644 --- a/telegps/TeleGPSConfigUI.java +++ b/telegps/TeleGPSConfigUI.java @@ -115,6 +115,13 @@ public class TeleGPSConfigUI return null; } + public void set_pyro_firing_time(double new_pyro_firing_time) { + } + + public double pyro_firing_time() { + return -1; + } + boolean is_telemetrum() { String product = product_value.getText(); return product != null && product.startsWith("TeleGPS"); -- cgit v1.2.3 From 1ed591c7bdf19fe54bbde1827d0717f0ae51e003 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 11 Jun 2014 23:27:16 -0700 Subject: telegps: Remove 'Flight' from titles Signed-off-by: Keith Packard --- telegps/TeleGPSConfigUI.java | 2 +- telegps/TeleGPSGraphUI.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'telegps/TeleGPSConfigUI.java') diff --git a/telegps/TeleGPSConfigUI.java b/telegps/TeleGPSConfigUI.java index f6c69040..5f269fd3 100644 --- a/telegps/TeleGPSConfigUI.java +++ b/telegps/TeleGPSConfigUI.java @@ -157,7 +157,7 @@ public class TeleGPSConfigUI /* Build the UI using a grid bag */ public TeleGPSConfigUI(JFrame in_owner) { - super (in_owner, "Configure Flight Computer", false); + super (in_owner, "Configure Device", false); owner = in_owner; GridBagConstraints c; diff --git a/telegps/TeleGPSGraphUI.java b/telegps/TeleGPSGraphUI.java index fbc9657e..244eb7b9 100644 --- a/telegps/TeleGPSGraphUI.java +++ b/telegps/TeleGPSGraphUI.java @@ -71,7 +71,7 @@ public class TeleGPSGraphUI extends AltosUIFrame map = new AltosUIMap(); - pane.add("Flight Graph", graph.panel); + pane.add("Graph", graph.panel); pane.add("Configure Graph", enable); pane.add("Statistics", statsTable); fill_map(states); -- cgit v1.2.3