From f0216d721ed13f4d3dc608bb6ad8f83732b27c0a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 25 May 2014 21:01:38 -0700 Subject: altoslib/altosuilib: Change versions to altoslib:4, altosuilib:2 API has changed for these libraries, time to bump the file versions Signed-off-by: Keith Packard --- altosui/AltosEepromDelete.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'altosui/AltosEepromDelete.java') diff --git a/altosui/AltosEepromDelete.java b/altosui/AltosEepromDelete.java index b2d2e291..b6ac7edb 100644 --- a/altosui/AltosEepromDelete.java +++ b/altosui/AltosEepromDelete.java @@ -21,7 +21,7 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_3.*; +import org.altusmetrum.altoslib_4.*; public class AltosEepromDelete implements Runnable { AltosEepromList flights; -- cgit v1.2.3 From 9b3516419981967a1c6ab956269139977ac368ca Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 May 2014 16:06:14 -0700 Subject: altosui/altosuilib: Shuffle lots more code from altosui into altosuilib All of the bluetooth management stuff, and AltosSerial. Signed-off-by: Keith Packard --- altosui/AltosBTDevice.java | 124 ----------- altosui/AltosBTDeviceIterator.java | 62 ------ altosui/AltosBTKnown.java | 101 --------- altosui/AltosBTManage.java | 353 ------------------------------ altosui/AltosDeviceUIDialog.java | 70 ------ altosui/AltosEepromDelete.java | 3 +- altosui/AltosSerial.java | 210 ------------------ altosui/AltosSerialInUseException.java | 27 --- altosui/Makefile.am | 12 +- altosuilib/AltosBTDevice.java | 125 +++++++++++ altosuilib/AltosBTDeviceIterator.java | 64 ++++++ altosuilib/AltosBTKnown.java | 101 +++++++++ altosuilib/AltosBTManage.java | 353 ++++++++++++++++++++++++++++++ altosuilib/AltosDeviceUIDialog.java | 69 ++++++ altosuilib/AltosSerial.java | 208 ++++++++++++++++++ altosuilib/AltosSerialInUseException.java | 26 +++ altosuilib/Makefile.am | 10 +- 17 files changed, 958 insertions(+), 960 deletions(-) delete mode 100644 altosui/AltosBTDevice.java delete mode 100644 altosui/AltosBTDeviceIterator.java delete mode 100644 altosui/AltosBTKnown.java delete mode 100644 altosui/AltosBTManage.java delete mode 100644 altosui/AltosDeviceUIDialog.java delete mode 100644 altosui/AltosSerial.java delete mode 100644 altosui/AltosSerialInUseException.java create mode 100644 altosuilib/AltosBTDevice.java create mode 100644 altosuilib/AltosBTDeviceIterator.java create mode 100644 altosuilib/AltosBTKnown.java create mode 100644 altosuilib/AltosBTManage.java create mode 100644 altosuilib/AltosDeviceUIDialog.java create mode 100644 altosuilib/AltosSerial.java create mode 100644 altosuilib/AltosSerialInUseException.java (limited to 'altosui/AltosEepromDelete.java') diff --git a/altosui/AltosBTDevice.java b/altosui/AltosBTDevice.java deleted file mode 100644 index e920803a..00000000 --- a/altosui/AltosBTDevice.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright © 2011 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 altosui; -import libaltosJNI.*; -import org.altusmetrum.altosuilib_2.*; - -public class AltosBTDevice extends altos_bt_device implements AltosDevice { - - public String getProductName() { - String name = getName(); - if (name == null) - return "Altus Metrum"; - int dash = name.lastIndexOf("-"); - if (dash < 0) - return name; - return name.substring(0,dash); - } - - public int getProduct() { - if (Altos.bt_product_telebt.equals(getProductName())) - return Altos.product_telebt; - return 0; - } - - public String getPath() { - return getAddr(); - } - - public String getErrorString() { - altos_error error = new altos_error(); - - libaltos.altos_get_last_error(error); - return String.format("%s (%d)", error.getString(), error.getCode()); - } - - public int getSerial() { - String name = getName(); - if (name == null) - return 0; - int dash = name.lastIndexOf("-"); - if (dash < 0 || dash >= name.length()) - return 0; - String sn = name.substring(dash + 1, name.length()); - try { - return Integer.parseInt(sn); - } catch (NumberFormatException ne) { - return 0; - } - } - - public String toString() { - return String.format("%-20.20s %4d %s", - getProductName(), getSerial(), getAddr()); - } - - public String toShortString() { - return String.format("%s %d %s", - getProductName(), getSerial(), getAddr()); - - } - - public SWIGTYPE_p_altos_file open() { - return libaltos.altos_bt_open(this); - } - - /* - private boolean isAltusMetrum() { - if (getName().startsWith(Altos.bt_product_telebt)) - return true; - return false; - } - */ - - public boolean matchProduct(int want_product) { - -// if (!isAltusMetrum()) -// return false; - - if (want_product == Altos.product_any) - return true; - - if (want_product == Altos.product_basestation) - return matchProduct(Altos.product_telebt); - - if (want_product == getProduct()) - return true; - - return false; - } - - public boolean equals(Object o) { - if (!(o instanceof AltosBTDevice)) - return false; - AltosBTDevice other = (AltosBTDevice) o; - return getName().equals(other.getName()) && getAddr().equals(other.getAddr()); - } - - public int hashCode() { - return getName().hashCode() ^ getAddr().hashCode(); - } - - public AltosBTDevice(String name, String addr) { - Altos.load_library(); - libaltos.altos_bt_fill_in(name, addr,this); - } - - public AltosBTDevice() { - } -} \ No newline at end of file diff --git a/altosui/AltosBTDeviceIterator.java b/altosui/AltosBTDeviceIterator.java deleted file mode 100644 index 4be5edf5..00000000 --- a/altosui/AltosBTDeviceIterator.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright © 2011 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 altosui; -import java.util.*; -import libaltosJNI.*; - -public class AltosBTDeviceIterator implements Iterator { - AltosBTDevice current; - boolean done; - SWIGTYPE_p_altos_bt_list list; - - public boolean hasNext() { - if (list == null) - return false; - if (current != null) - return true; - if (done) - return false; - current = new AltosBTDevice(); - while (libaltos.altos_bt_list_next(list, current) != 0) { -// if (current.matchProduct(product)) - return true; - } - current = null; - done = true; - return false; - } - - public AltosBTDevice next() { - if (hasNext()) { - AltosBTDevice next = current; - current = null; - return next; - } - return null; - } - - public void remove() { - throw new UnsupportedOperationException(); - } - - public AltosBTDeviceIterator(int inquiry_time) { - done = false; - current = null; - list = libaltos.altos_bt_list_start(inquiry_time); - } -} diff --git a/altosui/AltosBTKnown.java b/altosui/AltosBTKnown.java deleted file mode 100644 index 3abbbe08..00000000 --- a/altosui/AltosBTKnown.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright © 2011 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 altosui; -import java.util.*; -import org.altusmetrum.altoslib_4.*; -import org.altusmetrum.altosuilib_2.*; - -public class AltosBTKnown implements Iterable { - LinkedList devices = new LinkedList(); - AltosPreferencesBackend bt_pref = AltosUIPreferences.bt_devices(); - - private String get_address(String name) { - return bt_pref.getString(name, ""); - } - - private void set_address(String name, String addr) { - bt_pref.putString(name, addr); - } - - private void remove(String name) { - bt_pref.remove(name); - } - - private void load() { - try { - String[] names = bt_pref.keys(); - for (int i = 0; i < names.length; i++) { - String name = names[i]; - String addr = get_address(name); - devices.add(new AltosBTDevice(name, addr)); - } - } catch (IllegalStateException ie) { - } - } - - public Iterator iterator() { - return devices.iterator(); - } - - private void flush() { - AltosUIPreferences.flush_preferences(); - } - - public void set(Iterable new_devices) { - for (AltosBTDevice old : devices) { - boolean found = false; - for (AltosBTDevice new_device : new_devices) { - if (new_device.equals(old)) { - found = true; - break; - } - } - if (!found) - remove(old.getName()); - } - devices = new LinkedList(); - for (AltosBTDevice new_device : new_devices) { - devices.add(new_device); - set_address(new_device.getName(), new_device.getAddr()); - } - flush(); - } - - public List list(int product) { - LinkedList list = new LinkedList(); - for (AltosBTDevice device : devices) { - if (device.matchProduct(product)) - list.add(device); - } - return list; - } - - public AltosBTKnown() { - devices = new LinkedList(); - bt_pref = AltosUIPreferences.bt_devices(); - load(); - } - - static AltosBTKnown known; - - static public AltosBTKnown bt_known() { - if (known == null) - known = new AltosBTKnown(); - return known; - } -} diff --git a/altosui/AltosBTManage.java b/altosui/AltosBTManage.java deleted file mode 100644 index e6e7efd4..00000000 --- a/altosui/AltosBTManage.java +++ /dev/null @@ -1,353 +0,0 @@ -/* - * Copyright © 2011 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 altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.plaf.basic.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altosuilib_2.*; - -public class AltosBTManage extends AltosUIDialog implements ActionListener, Iterable { - LinkedBlockingQueue found_devices; - Frame frame; - LinkedList listeners; - AltosBTKnown bt_known; - - class DeviceList extends JList implements Iterable { - LinkedList devices; - DefaultListModel list_model; - - public void add (AltosBTDevice device) { - if (!devices.contains(device)) { - devices.add(device); - list_model.addElement(device); - } - } - - public void remove (AltosBTDevice device) { - if (devices.contains(device)) { - devices.remove(device); - list_model.removeElement(device); - } - } - - public boolean contains(AltosBTDevice device) { - return devices.contains(device); - } - - //Subclass JList to workaround bug 4832765, which can cause the - //scroll pane to not let the user easily scroll up to the beginning - //of the list. An alternative would be to set the unitIncrement - //of the JScrollBar to a fixed value. You wouldn't get the nice - //aligned scrolling, but it should work. - public int getScrollableUnitIncrement(Rectangle visibleRect, - int orientation, - int direction) { - int row; - if (orientation == SwingConstants.VERTICAL && - direction < 0 && (row = getFirstVisibleIndex()) != -1) { - Rectangle r = getCellBounds(row, row); - if ((r.y == visibleRect.y) && (row != 0)) { - Point loc = r.getLocation(); - loc.y--; - int prevIndex = locationToIndex(loc); - Rectangle prevR = getCellBounds(prevIndex, prevIndex); - - if (prevR == null || prevR.y >= r.y) { - return 0; - } - return prevR.height; - } - } - return super.getScrollableUnitIncrement( - visibleRect, orientation, direction); - } - - public Iterator iterator() { - return devices.iterator(); - } - - public java.util.List selected_list() throws InterruptedException { - return getSelectedValuesList(); - } - - public DeviceList() { - devices = new LinkedList(); - list_model = new DefaultListModel(); - setModel(list_model); - setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - setLayoutOrientation(JList.HORIZONTAL_WRAP); - setVisibleRowCount(-1); - } - } - - DeviceList visible_devices; - - DeviceList known_devices; - Thread bt_thread; - - public Iterator iterator() { - return known_devices.iterator(); - } - - public void commit() { - bt_known.set(this); - } - - public void add_known() { - try { - for (AltosBTDevice device : visible_devices.selected_list()) { - known_devices.add(device); - visible_devices.remove(device); - } - } catch (InterruptedException ie) { - } - } - - public void remove_known() { - try { - for (AltosBTDevice device : known_devices.selected_list()) { - known_devices.remove(device); - visible_devices.add(device); - } - } catch (InterruptedException ie) { - } - } - - public void addActionListener(ActionListener l) { - listeners.add(l); - } - - private void forwardAction(ActionEvent e) { - for (ActionListener l : listeners) - l.actionPerformed(e); - } - - public void actionPerformed(ActionEvent e) { - String command = e.getActionCommand(); - if ("ok".equals(command)) { - bt_thread.interrupt(); - commit(); - setVisible(false); - forwardAction(e); - } else if ("cancel".equals(command)) { - bt_thread.interrupt(); - setVisible(false); - forwardAction(e); - } else if ("select".equals(command)) { - add_known(); - } else if ("deselect".equals(command)) { - remove_known(); - } - } - - public void got_visible_device() { - while (!found_devices.isEmpty()) { - AltosBTDevice device = found_devices.remove(); - if (!known_devices.contains(device)) - visible_devices.add(device); - } - } - - class BTGetVisibleDevices implements Runnable { - public void run () { - for (;;) - for (int time = 1; time <= 8; time <<= 1) { - AltosBTDeviceIterator i = new AltosBTDeviceIterator(time); - AltosBTDevice device; - - if (Thread.interrupted()) - return; - try { - while ((device = i.next()) != null) { - Runnable r; - - if (Thread.interrupted()) - return; - found_devices.add(device); - r = new Runnable() { - public void run() { - got_visible_device(); - } - }; - SwingUtilities.invokeLater(r); - } - } catch (Exception e) { - System.out.printf("uh-oh, exception %s\n", e.toString()); - } - } - } - } - - public static void show(Component frameComp, AltosBTKnown known) { - Frame frame = JOptionPane.getFrameForComponent(frameComp); - AltosBTManage dialog; - - dialog = new AltosBTManage(frame, known); - dialog.setVisible(true); - } - - public AltosBTManage(Frame in_frame, AltosBTKnown in_known) { - super(in_frame, "Manage Bluetooth Devices", true); - - frame = in_frame; - bt_known = in_known; - BTGetVisibleDevices get_visible_devices = new BTGetVisibleDevices(); - bt_thread = new Thread(get_visible_devices); - bt_thread.start(); - - listeners = new LinkedList(); - - found_devices = new LinkedBlockingQueue(); - - Container pane = getContentPane(); - pane.setLayout(new GridBagLayout()); - - GridBagConstraints c = new GridBagConstraints(); - c.insets = new Insets(4,4,4,4); - - /* - * Known devices label and list - */ - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.WEST; - c.gridx = 0; - c.gridy = 0; - c.gridwidth = 1; - c.gridheight = 1; - c.weightx = 0; - c.weighty = 0; - pane.add(new JLabel("Known Devices"), c); - - known_devices = new DeviceList(); - for (AltosBTDevice device : bt_known) - known_devices.add(device); - - JScrollPane known_list_scroller = new JScrollPane(known_devices); - known_list_scroller.setPreferredSize(new Dimension(400, 80)); - known_list_scroller.setAlignmentX(LEFT_ALIGNMENT); - c.fill = GridBagConstraints.BOTH; - c.anchor = GridBagConstraints.WEST; - c.gridx = 0; - c.gridy = 1; - c.gridwidth = 1; - c.gridheight = 2; - c.weightx = 1; - c.weighty = 1; - pane.add(known_list_scroller, c); - - /* - * Visible devices label and list - */ - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.WEST; - c.gridx = 2; - c.gridy = 0; - c.gridwidth = 1; - c.gridheight = 1; - c.weightx = 0; - c.weighty = 0; - - pane.add(new JLabel("Visible Devices"), c); - - visible_devices = new DeviceList(); - JScrollPane visible_list_scroller = new JScrollPane(visible_devices); - visible_list_scroller.setPreferredSize(new Dimension(400, 80)); - visible_list_scroller.setAlignmentX(LEFT_ALIGNMENT); - c.fill = GridBagConstraints.BOTH; - c.anchor = GridBagConstraints.WEST; - c.gridx = 2; - c.gridy = 1; - c.gridheight = 2; - c.gridwidth = 1; - c.weightx = 1; - c.weighty = 1; - pane.add(visible_list_scroller, c); - - /* - * Arrows between the two lists - */ - BasicArrowButton select_arrow = new BasicArrowButton(SwingConstants.WEST); - select_arrow.setActionCommand("select"); - select_arrow.addActionListener(this); - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.SOUTH; - c.gridx = 1; - c.gridy = 1; - c.gridheight = 1; - c.gridwidth = 1; - c.weightx = 0; - c.weighty = 0; - pane.add(select_arrow, c); - - BasicArrowButton deselect_arrow = new BasicArrowButton(SwingConstants.EAST); - deselect_arrow.setActionCommand("deselect"); - deselect_arrow.addActionListener(this); - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.NORTH; - c.gridx = 1; - c.gridy = 2; - c.gridheight = 1; - c.gridwidth = 1; - c.weightx = 0; - c.weighty = 0; - pane.add(deselect_arrow, c); - - JButton cancel_button = new JButton("Cancel"); - cancel_button.setActionCommand("cancel"); - cancel_button.addActionListener(this); - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.gridx = 0; - c.gridy = 3; - c.gridheight = 1; - c.gridwidth = 1; - c.weightx = 0; - c.weighty = 0; - pane.add(cancel_button, c); - - JButton ok_button = new JButton("OK"); - ok_button.setActionCommand("ok"); - ok_button.addActionListener(this); - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.gridx = 2; - c.gridy = 3; - c.gridheight = 1; - c.gridwidth = 1; - c.weightx = 0; - c.weighty = 0; - pane.add(ok_button, c); - - getRootPane().setDefaultButton(ok_button); - - pack(); - setLocationRelativeTo(frame); - setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - bt_thread.interrupt(); - setVisible(false); - } - }); - } -} diff --git a/altosui/AltosDeviceUIDialog.java b/altosui/AltosDeviceUIDialog.java deleted file mode 100644 index 307c77f8..00000000 --- a/altosui/AltosDeviceUIDialog.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 altosui; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; -import org.altusmetrum.altosuilib_2.*; - -public class AltosDeviceUIDialog extends AltosDeviceDialog { - - public AltosDevice[] devices() { - java.util.List usb_devices = AltosUSBDevice.list(product); - int num_devices = usb_devices.size(); - java.util.List bt_devices = AltosBTKnown.bt_known().list(product); - num_devices += bt_devices.size(); - AltosDevice[] devices = new AltosDevice[num_devices]; - - for (int i = 0; i < usb_devices.size(); i++) - devices[i] = usb_devices.get(i); - int off = usb_devices.size(); - for (int j = 0; j < bt_devices.size(); j++) - devices[off + j] = bt_devices.get(j); - return devices; - } - - public void add_bluetooth() { - JButton manage_bluetooth_button = new JButton("Manage Bluetooth"); - manage_bluetooth_button.setActionCommand("manage"); - manage_bluetooth_button.addActionListener(this); - buttonPane.add(manage_bluetooth_button); - buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); - } - - public void actionPerformed(ActionEvent e) { - super.actionPerformed(e); - if ("manage".equals(e.getActionCommand())) { - AltosBTManage.show(frame, AltosBTKnown.bt_known()); - update_devices(); - } - } - - public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product) { - super(in_frame, location, in_product); - } - - public static AltosDevice show (Component frameComp, int product) { - Frame frame = JOptionPane.getFrameForComponent(frameComp); - AltosDeviceUIDialog dialog; - - dialog = new AltosDeviceUIDialog(frame, frameComp, product); - dialog.setVisible(true); - return dialog.getValue(); - } -} diff --git a/altosui/AltosEepromDelete.java b/altosui/AltosEepromDelete.java index b6ac7edb..df2ade78 100644 --- a/altosui/AltosEepromDelete.java +++ b/altosui/AltosEepromDelete.java @@ -21,6 +21,7 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; +import org.altusmetrum.altosuilib_2.*; import org.altusmetrum.altoslib_4.*; public class AltosEepromDelete implements Runnable { @@ -140,4 +141,4 @@ public class AltosEepromDelete implements Runnable { flights = given_flights; success = false; } -} \ No newline at end of file +} diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java deleted file mode 100644 index 9b2180ba..00000000 --- a/altosui/AltosSerial.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * 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. - */ - -/* - * Deal with TeleDongle on a serial port - */ - -package altosui; - -import java.io.*; -import java.util.*; -import java.awt.*; -import javax.swing.*; -import org.altusmetrum.altoslib_4.*; -import org.altusmetrum.altosuilib_2.*; - -import libaltosJNI.*; - -/* - * This class reads from the serial port and places each received - * line in a queue. Dealing with that queue is left up to other - * threads. - */ - -public class AltosSerial extends AltosLink { - - static java.util.List devices_opened = Collections.synchronizedList(new LinkedList()); - - AltosDevice device; - SWIGTYPE_p_altos_file altos; - Thread input_thread; - String line; - byte[] line_bytes; - int line_count; - Frame frame; - - public int getchar() { - if (altos == null) - return ERROR; - return libaltos.altos_getchar(altos, 0); - } - - public void flush_output() { - super.flush_output(); - if (altos != null) { - if (libaltos.altos_flush(altos) != 0) - close_serial(); - } - } - - JDialog timeout_dialog; - - private void start_timeout_dialog_internal() { - - Object[] options = { "Cancel" }; - - JOptionPane pane = new JOptionPane(); - pane.setMessage(String.format("Connecting to %s, %7.3f MHz as %s", device.toShortString(), frequency, callsign)); - pane.setOptions(options); - pane.setInitialValue(null); - - timeout_dialog = pane.createDialog(frame, "Connecting..."); - - timeout_dialog.setVisible(true); - - Object o = pane.getValue(); - if (o == null) - return; - if (options[0].equals(o)) - reply_abort = true; - timeout_dialog.dispose(); - timeout_dialog = null; - } - - /* - * These are required by the AltosLink implementation - */ - - public boolean can_cancel_reply() { - /* - * Can cancel any replies not called from the dispatch thread - */ - return !SwingUtilities.isEventDispatchThread(); - } - - public boolean show_reply_timeout() { - if (!SwingUtilities.isEventDispatchThread() && frame != null) { - Runnable r = new Runnable() { - public void run() { - start_timeout_dialog_internal(); - } - }; - SwingUtilities.invokeLater(r); - return true; - } - return false; - } - - public void hide_reply_timeout() { - Runnable r = new Runnable() { - public void run() { - timeout_dialog.setVisible(false); - } - }; - SwingUtilities.invokeLater(r); - } - - private void close_serial() { - synchronized (devices_opened) { - devices_opened.remove(device.getPath()); - } - if (altos != null) { - libaltos.altos_free(altos); - altos = null; - } - abort_reply(); - } - - public void close() { - if (remote) { - try { - stop_remote(); - } catch (InterruptedException ie) { - } - } - if (in_reply != 0) - System.out.printf("Uh-oh. Closing active serial device\n"); - - close_serial(); - - if (input_thread != null) { - try { - input_thread.interrupt(); - input_thread.join(); - } catch (InterruptedException ie) { - } - input_thread = null; - } - if (debug) - System.out.printf("Closing %s\n", device.getPath()); - } - - private void putc(char c) { - if (altos != null) - if (libaltos.altos_putchar(altos, c) != 0) - close_serial(); - } - - public void putchar(byte c) { - if (altos != null) { - if (debug) - System.out.printf(" %02x", (int) c & 0xff); - if (libaltos.altos_putchar(altos, (char) c) != 0) - close_serial(); - } - } - - public void print(String data) { - for (int i = 0; i < data.length(); i++) - putc(data.charAt(i)); - } - - private void open() throws FileNotFoundException, AltosSerialInUseException { - synchronized (devices_opened) { - if (devices_opened.contains(device.getPath())) - throw new AltosSerialInUseException(device); - devices_opened.add(device.getPath()); - } - altos = device.open(); - if (altos == null) { - final String message = device.getErrorString(); - close(); - throw new FileNotFoundException(String.format("%s (%s)", - device.toShortString(), message)); - } - if (debug) - System.out.printf("Open %s\n", device.getPath()); - input_thread = new Thread(this); - input_thread.start(); - print("~\nE 0\n"); - set_monitor(false); - flush_output(); - } - - public void set_frame(Frame in_frame) { - frame = in_frame; - } - - public AltosSerial(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { - device = in_device; - frame = null; - serial = device.getSerial(); - name = device.toShortString(); - open(); - } -} diff --git a/altosui/AltosSerialInUseException.java b/altosui/AltosSerialInUseException.java deleted file mode 100644 index 318155c8..00000000 --- a/altosui/AltosSerialInUseException.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 altosui; -import org.altusmetrum.altosuilib_2.*; - -public class AltosSerialInUseException extends Exception { - public AltosDevice device; - - public AltosSerialInUseException (AltosDevice in_device) { - device = in_device; - } -} diff --git a/altosui/Makefile.am b/altosui/Makefile.am index df9fe5d1..6f491d7d 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -10,12 +10,6 @@ CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH="$(JAVAROOT):../altoslib/*:../alto bin_SCRIPTS=altosui -altosui_BT = \ - AltosBTDevice.java \ - AltosBTDeviceIterator.java \ - AltosBTManage.java \ - AltosBTKnown.java - altosui_JAVA = \ AltosAscent.java \ AltosChannelMenu.java \ @@ -29,7 +23,6 @@ altosui_JAVA = \ AltosConfigTDUI.java \ AltosCSVUI.java \ AltosDescent.java \ - AltosDeviceUIDialog.java \ AltosEepromDelete.java \ AltosEepromManage.java \ AltosEepromMonitorUI.java \ @@ -54,15 +47,12 @@ altosui_JAVA = \ AltosUIPreferencesBackend.java \ AltosRomconfigUI.java \ AltosScanUI.java \ - AltosSerial.java \ - AltosSerialInUseException.java \ AltosUI.java \ AltosGraph.java \ AltosGraphDataPoint.java \ AltosGraphDataSet.java \ AltosGraphUI.java \ - AltosDataChooser.java \ - $(altosui_BT) + AltosDataChooser.java JFREECHART_CLASS= \ jfreechart.jar diff --git a/altosuilib/AltosBTDevice.java b/altosuilib/AltosBTDevice.java new file mode 100644 index 00000000..beefa532 --- /dev/null +++ b/altosuilib/AltosBTDevice.java @@ -0,0 +1,125 @@ +/* + * Copyright © 2011 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.altosuilib_2; + +import libaltosJNI.*; +import org.altusmetrum.altoslib_4.*; + +public class AltosBTDevice extends altos_bt_device implements AltosDevice { + + public String getProductName() { + String name = getName(); + if (name == null) + return "Altus Metrum"; + int dash = name.lastIndexOf("-"); + if (dash < 0) + return name; + return name.substring(0,dash); + } + + public int getProduct() { + if (AltosLib.bt_product_telebt.equals(getProductName())) + return AltosLib.product_telebt; + return 0; + } + + public String getPath() { + return getAddr(); + } + + public String getErrorString() { + altos_error error = new altos_error(); + + libaltos.altos_get_last_error(error); + return String.format("%s (%d)", error.getString(), error.getCode()); + } + + public int getSerial() { + String name = getName(); + if (name == null) + return 0; + int dash = name.lastIndexOf("-"); + if (dash < 0 || dash >= name.length()) + return 0; + String sn = name.substring(dash + 1, name.length()); + try { + return Integer.parseInt(sn); + } catch (NumberFormatException ne) { + return 0; + } + } + + public String toString() { + return String.format("%-20.20s %4d %s", + getProductName(), getSerial(), getAddr()); + } + + public String toShortString() { + return String.format("%s %d %s", + getProductName(), getSerial(), getAddr()); + + } + + public SWIGTYPE_p_altos_file open() { + return libaltos.altos_bt_open(this); + } + + /* + private boolean isAltusMetrum() { + if (getName().startsWith(Altos.bt_product_telebt)) + return true; + return false; + } + */ + + public boolean matchProduct(int want_product) { + +// if (!isAltusMetrum()) +// return false; + + if (want_product == AltosLib.product_any) + return true; + + if (want_product == AltosLib.product_basestation) + return matchProduct(AltosLib.product_telebt); + + if (want_product == getProduct()) + return true; + + return false; + } + + public boolean equals(Object o) { + if (!(o instanceof AltosBTDevice)) + return false; + AltosBTDevice other = (AltosBTDevice) o; + return getName().equals(other.getName()) && getAddr().equals(other.getAddr()); + } + + public int hashCode() { + return getName().hashCode() ^ getAddr().hashCode(); + } + + public AltosBTDevice(String name, String addr) { + AltosUILib.load_library(); + libaltos.altos_bt_fill_in(name, addr,this); + } + + public AltosBTDevice() { + } +} diff --git a/altosuilib/AltosBTDeviceIterator.java b/altosuilib/AltosBTDeviceIterator.java new file mode 100644 index 00000000..cad60ffb --- /dev/null +++ b/altosuilib/AltosBTDeviceIterator.java @@ -0,0 +1,64 @@ +/* + * Copyright © 2011 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.altosuilib_2; + +import java.util.*; +import libaltosJNI.*; +import org.altusmetrum.altoslib_4.*; + +public class AltosBTDeviceIterator implements Iterator { + AltosBTDevice current; + boolean done; + SWIGTYPE_p_altos_bt_list list; + + public boolean hasNext() { + if (list == null) + return false; + if (current != null) + return true; + if (done) + return false; + current = new AltosBTDevice(); + while (libaltos.altos_bt_list_next(list, current) != 0) { +// if (current.matchProduct(product)) + return true; + } + current = null; + done = true; + return false; + } + + public AltosBTDevice next() { + if (hasNext()) { + AltosBTDevice next = current; + current = null; + return next; + } + return null; + } + + public void remove() { + throw new UnsupportedOperationException(); + } + + public AltosBTDeviceIterator(int inquiry_time) { + done = false; + current = null; + list = libaltos.altos_bt_list_start(inquiry_time); + } +} diff --git a/altosuilib/AltosBTKnown.java b/altosuilib/AltosBTKnown.java new file mode 100644 index 00000000..02883c75 --- /dev/null +++ b/altosuilib/AltosBTKnown.java @@ -0,0 +1,101 @@ +/* + * Copyright © 2011 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.altosuilib_2; + +import java.util.*; +import org.altusmetrum.altoslib_4.*; + +public class AltosBTKnown implements Iterable { + LinkedList devices = new LinkedList(); + AltosPreferencesBackend bt_pref = AltosUIPreferences.bt_devices(); + + private String get_address(String name) { + return bt_pref.getString(name, ""); + } + + private void set_address(String name, String addr) { + bt_pref.putString(name, addr); + } + + private void remove(String name) { + bt_pref.remove(name); + } + + private void load() { + try { + String[] names = bt_pref.keys(); + for (int i = 0; i < names.length; i++) { + String name = names[i]; + String addr = get_address(name); + devices.add(new AltosBTDevice(name, addr)); + } + } catch (IllegalStateException ie) { + } + } + + public Iterator iterator() { + return devices.iterator(); + } + + private void flush() { + AltosUIPreferences.flush_preferences(); + } + + public void set(Iterable new_devices) { + for (AltosBTDevice old : devices) { + boolean found = false; + for (AltosBTDevice new_device : new_devices) { + if (new_device.equals(old)) { + found = true; + break; + } + } + if (!found) + remove(old.getName()); + } + devices = new LinkedList(); + for (AltosBTDevice new_device : new_devices) { + devices.add(new_device); + set_address(new_device.getName(), new_device.getAddr()); + } + flush(); + } + + public List list(int product) { + LinkedList list = new LinkedList(); + for (AltosBTDevice device : devices) { + if (device.matchProduct(product)) + list.add(device); + } + return list; + } + + public AltosBTKnown() { + devices = new LinkedList(); + bt_pref = AltosUIPreferences.bt_devices(); + load(); + } + + static AltosBTKnown known; + + static public AltosBTKnown bt_known() { + if (known == null) + known = new AltosBTKnown(); + return known; + } +} diff --git a/altosuilib/AltosBTManage.java b/altosuilib/AltosBTManage.java new file mode 100644 index 00000000..6da0a3eb --- /dev/null +++ b/altosuilib/AltosBTManage.java @@ -0,0 +1,353 @@ +/* + * Copyright © 2011 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.altosuilib_2; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.plaf.basic.*; +import java.util.*; +import java.util.concurrent.*; +import org.altusmetrum.altoslib_4.*; + +public class AltosBTManage extends AltosUIDialog implements ActionListener, Iterable { + LinkedBlockingQueue found_devices; + Frame frame; + LinkedList listeners; + AltosBTKnown bt_known; + + class DeviceList extends JList implements Iterable { + LinkedList devices; + DefaultListModel list_model; + + public void add (AltosBTDevice device) { + if (!devices.contains(device)) { + devices.add(device); + list_model.addElement(device); + } + } + + public void remove (AltosBTDevice device) { + if (devices.contains(device)) { + devices.remove(device); + list_model.removeElement(device); + } + } + + public boolean contains(AltosBTDevice device) { + return devices.contains(device); + } + + //Subclass JList to workaround bug 4832765, which can cause the + //scroll pane to not let the user easily scroll up to the beginning + //of the list. An alternative would be to set the unitIncrement + //of the JScrollBar to a fixed value. You wouldn't get the nice + //aligned scrolling, but it should work. + public int getScrollableUnitIncrement(Rectangle visibleRect, + int orientation, + int direction) { + int row; + if (orientation == SwingConstants.VERTICAL && + direction < 0 && (row = getFirstVisibleIndex()) != -1) { + Rectangle r = getCellBounds(row, row); + if ((r.y == visibleRect.y) && (row != 0)) { + Point loc = r.getLocation(); + loc.y--; + int prevIndex = locationToIndex(loc); + Rectangle prevR = getCellBounds(prevIndex, prevIndex); + + if (prevR == null || prevR.y >= r.y) { + return 0; + } + return prevR.height; + } + } + return super.getScrollableUnitIncrement( + visibleRect, orientation, direction); + } + + public Iterator iterator() { + return devices.iterator(); + } + + public java.util.List selected_list() throws InterruptedException { + return getSelectedValuesList(); + } + + public DeviceList() { + devices = new LinkedList(); + list_model = new DefaultListModel(); + setModel(list_model); + setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + setLayoutOrientation(JList.HORIZONTAL_WRAP); + setVisibleRowCount(-1); + } + } + + DeviceList visible_devices; + + DeviceList known_devices; + Thread bt_thread; + + public Iterator iterator() { + return known_devices.iterator(); + } + + public void commit() { + bt_known.set(this); + } + + public void add_known() { + try { + for (AltosBTDevice device : visible_devices.selected_list()) { + known_devices.add(device); + visible_devices.remove(device); + } + } catch (InterruptedException ie) { + } + } + + public void remove_known() { + try { + for (AltosBTDevice device : known_devices.selected_list()) { + known_devices.remove(device); + visible_devices.add(device); + } + } catch (InterruptedException ie) { + } + } + + public void addActionListener(ActionListener l) { + listeners.add(l); + } + + private void forwardAction(ActionEvent e) { + for (ActionListener l : listeners) + l.actionPerformed(e); + } + + public void actionPerformed(ActionEvent e) { + String command = e.getActionCommand(); + if ("ok".equals(command)) { + bt_thread.interrupt(); + commit(); + setVisible(false); + forwardAction(e); + } else if ("cancel".equals(command)) { + bt_thread.interrupt(); + setVisible(false); + forwardAction(e); + } else if ("select".equals(command)) { + add_known(); + } else if ("deselect".equals(command)) { + remove_known(); + } + } + + public void got_visible_device() { + while (!found_devices.isEmpty()) { + AltosBTDevice device = found_devices.remove(); + if (!known_devices.contains(device)) + visible_devices.add(device); + } + } + + class BTGetVisibleDevices implements Runnable { + public void run () { + for (;;) + for (int time = 1; time <= 8; time <<= 1) { + AltosBTDeviceIterator i = new AltosBTDeviceIterator(time); + AltosBTDevice device; + + if (Thread.interrupted()) + return; + try { + while ((device = i.next()) != null) { + Runnable r; + + if (Thread.interrupted()) + return; + found_devices.add(device); + r = new Runnable() { + public void run() { + got_visible_device(); + } + }; + SwingUtilities.invokeLater(r); + } + } catch (Exception e) { + System.out.printf("uh-oh, exception %s\n", e.toString()); + } + } + } + } + + public static void show(Component frameComp, AltosBTKnown known) { + Frame frame = JOptionPane.getFrameForComponent(frameComp); + AltosBTManage dialog; + + dialog = new AltosBTManage(frame, known); + dialog.setVisible(true); + } + + public AltosBTManage(Frame in_frame, AltosBTKnown in_known) { + super(in_frame, "Manage Bluetooth Devices", true); + + frame = in_frame; + bt_known = in_known; + BTGetVisibleDevices get_visible_devices = new BTGetVisibleDevices(); + bt_thread = new Thread(get_visible_devices); + bt_thread.start(); + + listeners = new LinkedList(); + + found_devices = new LinkedBlockingQueue(); + + Container pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(4,4,4,4); + + /* + * Known devices label and list + */ + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + c.gridx = 0; + c.gridy = 0; + c.gridwidth = 1; + c.gridheight = 1; + c.weightx = 0; + c.weighty = 0; + pane.add(new JLabel("Known Devices"), c); + + known_devices = new DeviceList(); + for (AltosBTDevice device : bt_known) + known_devices.add(device); + + JScrollPane known_list_scroller = new JScrollPane(known_devices); + known_list_scroller.setPreferredSize(new Dimension(400, 80)); + known_list_scroller.setAlignmentX(LEFT_ALIGNMENT); + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.WEST; + c.gridx = 0; + c.gridy = 1; + c.gridwidth = 1; + c.gridheight = 2; + c.weightx = 1; + c.weighty = 1; + pane.add(known_list_scroller, c); + + /* + * Visible devices label and list + */ + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + c.gridx = 2; + c.gridy = 0; + c.gridwidth = 1; + c.gridheight = 1; + c.weightx = 0; + c.weighty = 0; + + pane.add(new JLabel("Visible Devices"), c); + + visible_devices = new DeviceList(); + JScrollPane visible_list_scroller = new JScrollPane(visible_devices); + visible_list_scroller.setPreferredSize(new Dimension(400, 80)); + visible_list_scroller.setAlignmentX(LEFT_ALIGNMENT); + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.WEST; + c.gridx = 2; + c.gridy = 1; + c.gridheight = 2; + c.gridwidth = 1; + c.weightx = 1; + c.weighty = 1; + pane.add(visible_list_scroller, c); + + /* + * Arrows between the two lists + */ + BasicArrowButton select_arrow = new BasicArrowButton(SwingConstants.WEST); + select_arrow.setActionCommand("select"); + select_arrow.addActionListener(this); + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.SOUTH; + c.gridx = 1; + c.gridy = 1; + c.gridheight = 1; + c.gridwidth = 1; + c.weightx = 0; + c.weighty = 0; + pane.add(select_arrow, c); + + BasicArrowButton deselect_arrow = new BasicArrowButton(SwingConstants.EAST); + deselect_arrow.setActionCommand("deselect"); + deselect_arrow.addActionListener(this); + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.NORTH; + c.gridx = 1; + c.gridy = 2; + c.gridheight = 1; + c.gridwidth = 1; + c.weightx = 0; + c.weighty = 0; + pane.add(deselect_arrow, c); + + JButton cancel_button = new JButton("Cancel"); + cancel_button.setActionCommand("cancel"); + cancel_button.addActionListener(this); + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; + c.gridy = 3; + c.gridheight = 1; + c.gridwidth = 1; + c.weightx = 0; + c.weighty = 0; + pane.add(cancel_button, c); + + JButton ok_button = new JButton("OK"); + ok_button.setActionCommand("ok"); + ok_button.addActionListener(this); + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 2; + c.gridy = 3; + c.gridheight = 1; + c.gridwidth = 1; + c.weightx = 0; + c.weighty = 0; + pane.add(ok_button, c); + + getRootPane().setDefaultButton(ok_button); + + pack(); + setLocationRelativeTo(frame); + setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + bt_thread.interrupt(); + setVisible(false); + } + }); + } +} diff --git a/altosuilib/AltosDeviceUIDialog.java b/altosuilib/AltosDeviceUIDialog.java new file mode 100644 index 00000000..3013612a --- /dev/null +++ b/altosuilib/AltosDeviceUIDialog.java @@ -0,0 +1,69 @@ +/* + * 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.altosuilib_2; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class AltosDeviceUIDialog extends AltosDeviceDialog { + + public AltosDevice[] devices() { + java.util.List usb_devices = AltosUSBDevice.list(product); + int num_devices = usb_devices.size(); + java.util.List bt_devices = AltosBTKnown.bt_known().list(product); + num_devices += bt_devices.size(); + AltosDevice[] devices = new AltosDevice[num_devices]; + + for (int i = 0; i < usb_devices.size(); i++) + devices[i] = usb_devices.get(i); + int off = usb_devices.size(); + for (int j = 0; j < bt_devices.size(); j++) + devices[off + j] = bt_devices.get(j); + return devices; + } + + public void add_bluetooth() { + JButton manage_bluetooth_button = new JButton("Manage Bluetooth"); + manage_bluetooth_button.setActionCommand("manage"); + manage_bluetooth_button.addActionListener(this); + buttonPane.add(manage_bluetooth_button); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + } + + public void actionPerformed(ActionEvent e) { + super.actionPerformed(e); + if ("manage".equals(e.getActionCommand())) { + AltosBTManage.show(frame, AltosBTKnown.bt_known()); + update_devices(); + } + } + + public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product) { + super(in_frame, location, in_product); + } + + public static AltosDevice show (Component frameComp, int product) { + Frame frame = JOptionPane.getFrameForComponent(frameComp); + AltosDeviceUIDialog dialog; + + dialog = new AltosDeviceUIDialog(frame, frameComp, product); + dialog.setVisible(true); + return dialog.getValue(); + } +} diff --git a/altosuilib/AltosSerial.java b/altosuilib/AltosSerial.java new file mode 100644 index 00000000..0632ca70 --- /dev/null +++ b/altosuilib/AltosSerial.java @@ -0,0 +1,208 @@ +/* + * 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. + */ + +/* + * Deal with TeleDongle on a serial port + */ + +package org.altusmetrum.altosuilib_2; + +import java.io.*; +import java.util.*; +import java.awt.*; +import javax.swing.*; +import org.altusmetrum.altoslib_4.*; +import libaltosJNI.*; + +/* + * This class reads from the serial port and places each received + * line in a queue. Dealing with that queue is left up to other + * threads. + */ + +public class AltosSerial extends AltosLink { + + static java.util.List devices_opened = Collections.synchronizedList(new LinkedList()); + + public AltosDevice device; + SWIGTYPE_p_altos_file altos; + Thread input_thread; + String line; + byte[] line_bytes; + int line_count; + Frame frame; + + public int getchar() { + if (altos == null) + return ERROR; + return libaltos.altos_getchar(altos, 0); + } + + public void flush_output() { + super.flush_output(); + if (altos != null) { + if (libaltos.altos_flush(altos) != 0) + close_serial(); + } + } + + JDialog timeout_dialog; + + private void start_timeout_dialog_internal() { + + Object[] options = { "Cancel" }; + + JOptionPane pane = new JOptionPane(); + pane.setMessage(String.format("Connecting to %s, %7.3f MHz as %s", device.toShortString(), frequency, callsign)); + pane.setOptions(options); + pane.setInitialValue(null); + + timeout_dialog = pane.createDialog(frame, "Connecting..."); + + timeout_dialog.setVisible(true); + + Object o = pane.getValue(); + if (o == null) + return; + if (options[0].equals(o)) + reply_abort = true; + timeout_dialog.dispose(); + timeout_dialog = null; + } + + /* + * These are required by the AltosLink implementation + */ + + public boolean can_cancel_reply() { + /* + * Can cancel any replies not called from the dispatch thread + */ + return !SwingUtilities.isEventDispatchThread(); + } + + public boolean show_reply_timeout() { + if (!SwingUtilities.isEventDispatchThread() && frame != null) { + Runnable r = new Runnable() { + public void run() { + start_timeout_dialog_internal(); + } + }; + SwingUtilities.invokeLater(r); + return true; + } + return false; + } + + public void hide_reply_timeout() { + Runnable r = new Runnable() { + public void run() { + timeout_dialog.setVisible(false); + } + }; + SwingUtilities.invokeLater(r); + } + + private void close_serial() { + synchronized (devices_opened) { + devices_opened.remove(device.getPath()); + } + if (altos != null) { + libaltos.altos_free(altos); + altos = null; + } + abort_reply(); + } + + public void close() { + if (remote) { + try { + stop_remote(); + } catch (InterruptedException ie) { + } + } + if (in_reply != 0) + System.out.printf("Uh-oh. Closing active serial device\n"); + + close_serial(); + + if (input_thread != null) { + try { + input_thread.interrupt(); + input_thread.join(); + } catch (InterruptedException ie) { + } + input_thread = null; + } + if (debug) + System.out.printf("Closing %s\n", device.getPath()); + } + + private void putc(char c) { + if (altos != null) + if (libaltos.altos_putchar(altos, c) != 0) + close_serial(); + } + + public void putchar(byte c) { + if (altos != null) { + if (debug) + System.out.printf(" %02x", (int) c & 0xff); + if (libaltos.altos_putchar(altos, (char) c) != 0) + close_serial(); + } + } + + public void print(String data) { + for (int i = 0; i < data.length(); i++) + putc(data.charAt(i)); + } + + private void open() throws FileNotFoundException, AltosSerialInUseException { + synchronized (devices_opened) { + if (devices_opened.contains(device.getPath())) + throw new AltosSerialInUseException(device); + devices_opened.add(device.getPath()); + } + altos = device.open(); + if (altos == null) { + final String message = device.getErrorString(); + close(); + throw new FileNotFoundException(String.format("%s (%s)", + device.toShortString(), message)); + } + if (debug) + System.out.printf("Open %s\n", device.getPath()); + input_thread = new Thread(this); + input_thread.start(); + print("~\nE 0\n"); + set_monitor(false); + flush_output(); + } + + public void set_frame(Frame in_frame) { + frame = in_frame; + } + + public AltosSerial(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException { + device = in_device; + frame = null; + serial = device.getSerial(); + name = device.toShortString(); + open(); + } +} diff --git a/altosuilib/AltosSerialInUseException.java b/altosuilib/AltosSerialInUseException.java new file mode 100644 index 00000000..1e8207d1 --- /dev/null +++ b/altosuilib/AltosSerialInUseException.java @@ -0,0 +1,26 @@ +/* + * 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.altosuilib_2; + +public class AltosSerialInUseException extends Exception { + public AltosDevice device; + + public AltosSerialInUseException (AltosDevice in_device) { + device = in_device; + } +} diff --git a/altosuilib/Makefile.am b/altosuilib/Makefile.am index 10b756b8..fe0c3ec7 100644 --- a/altosuilib/Makefile.am +++ b/altosuilib/Makefile.am @@ -40,7 +40,15 @@ altosuilib_JAVA = \ AltosSiteMapImage.java \ AltosVoice.java \ AltosDisplayThread.java \ - AltosFreqList.java + AltosDeviceUIDialog.java \ + AltosFreqList.java \ + AltosSerial.java \ + AltosSerialInUseException.java \ + AltosBTDevice.java \ + AltosBTDeviceIterator.java \ + AltosBTManage.java \ + AltosBTKnown.java + JAR=altosuilib_$(ALTOSUILIB_VERSION).jar -- cgit v1.2.3 From 4cec35564324f909dcddeb7c0d83a2daa8223042 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 May 2014 20:58:01 -0700 Subject: telegps: Hook up data download dialog Signed-off-by: Keith Packard --- altosui/AltosEepromDelete.java | 144 ---------------- altosui/AltosEepromManage.java | 242 --------------------------- altosui/AltosEepromMonitor.java | 252 ---------------------------- altosui/AltosEepromMonitorUI.java | 311 ----------------------------------- altosui/AltosEepromSelect.java | 184 --------------------- altosui/AltosUI.java | 2 +- altosui/Makefile.am | 4 - altosuilib/AltosEepromDelete.java | 143 ++++++++++++++++ altosuilib/AltosEepromManage.java | 241 +++++++++++++++++++++++++++ altosuilib/AltosEepromMonitor.java | 251 ++++++++++++++++++++++++++++ altosuilib/AltosEepromMonitorUI.java | 310 ++++++++++++++++++++++++++++++++++ altosuilib/AltosEepromSelect.java | 183 +++++++++++++++++++++ altosuilib/Makefile.am | 4 + telegps/TeleGPS.java | 1 + 14 files changed, 1134 insertions(+), 1138 deletions(-) delete mode 100644 altosui/AltosEepromDelete.java delete mode 100644 altosui/AltosEepromManage.java delete mode 100644 altosui/AltosEepromMonitor.java delete mode 100644 altosui/AltosEepromMonitorUI.java delete mode 100644 altosui/AltosEepromSelect.java create mode 100644 altosuilib/AltosEepromDelete.java create mode 100644 altosuilib/AltosEepromManage.java create mode 100644 altosuilib/AltosEepromMonitor.java create mode 100644 altosuilib/AltosEepromMonitorUI.java create mode 100644 altosuilib/AltosEepromSelect.java (limited to 'altosui/AltosEepromDelete.java') diff --git a/altosui/AltosEepromDelete.java b/altosui/AltosEepromDelete.java deleted file mode 100644 index df2ade78..00000000 --- a/altosui/AltosEepromDelete.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright © 2011 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 altosui; - -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.util.concurrent.*; -import org.altusmetrum.altosuilib_2.*; -import org.altusmetrum.altoslib_4.*; - -public class AltosEepromDelete implements Runnable { - AltosEepromList flights; - Thread eeprom_thread; - AltosSerial serial_line; - boolean remote; - JFrame frame; - ActionListener listener; - boolean success; - - private void DeleteLog (AltosEepromLog log) - throws IOException, InterruptedException, TimeoutException { - - if (flights.config_data.flight_log_max != 0 || flights.config_data.log_format != 0) { - - /* Devices with newer firmware can erase the - * flash blocks containing each flight - */ - serial_line.flush_input(); - serial_line.printf("d %d\n", log.flight); - for (;;) { - /* It can take a while to erase the flash... */ - String line = serial_line.get_reply(20000); - if (line == null) - throw new TimeoutException(); - if (line.equals("Erased")) - break; - if (line.startsWith("No such")) - throw new IOException(line); - } - } - } - - private void show_error_internal(String message, String title) { - JOptionPane.showMessageDialog(frame, - message, - title, - JOptionPane.ERROR_MESSAGE); - } - - private void show_error(String in_message, String in_title) { - final String message = in_message; - final String title = in_title; - Runnable r = new Runnable() { - public void run() { - try { - show_error_internal(message, title); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } - - public void run () { - success = false; - try { - if (remote) - serial_line.start_remote(); - - for (AltosEepromLog log : flights) { - if (log.selected) { - DeleteLog(log); - } - } - success = true; - } catch (IOException ee) { - show_error (ee.getLocalizedMessage(), - serial_line.device.toShortString()); - } catch (InterruptedException ie) { - } catch (TimeoutException te) { - show_error (String.format("Connection to \"%s\" failed", - serial_line.device.toShortString()), - "Connection Failed"); - } finally { - try { - if (remote) - serial_line.stop_remote(); - } catch (InterruptedException ie) { - } finally { - serial_line.flush_output(); - serial_line.close(); - } - } - if (listener != null) { - Runnable r = new Runnable() { - public void run() { - try { - listener.actionPerformed(new ActionEvent(this, - success ? 1 : 0, - "delete")); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } - } - - public void start() { - eeprom_thread = new Thread(this); - eeprom_thread.start(); - } - - public void addActionListener(ActionListener l) { - listener = l; - } - - public AltosEepromDelete(JFrame given_frame, - AltosSerial given_serial_line, - boolean given_remote, - AltosEepromList given_flights) { - frame = given_frame; - serial_line = given_serial_line; - remote = given_remote; - flights = given_flights; - success = false; - } -} diff --git a/altosui/AltosEepromManage.java b/altosui/AltosEepromManage.java deleted file mode 100644 index aa43ab9e..00000000 --- a/altosui/AltosEepromManage.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright © 2011 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 altosui; - -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_4.*; -import org.altusmetrum.altosuilib_2.*; - -public class AltosEepromManage implements ActionListener { - - JFrame frame; - boolean remote; - AltosDevice device; - AltosSerial serial_line; - AltosEepromList flights; - AltosEepromDownload download; - AltosEepromDelete delete; - - public void finish() { - if (serial_line != null) { - try { - serial_line.flush_input(); - } catch (InterruptedException ie) { - } - serial_line.close(); - serial_line = null; - } - } - - private int countDeletedFlights() { - int count = 0; - for (AltosEepromLog flight : flights) { - if (flight.selected) - count++; - } - return count; - } - - private String showDeletedFlights() { - String result = ""; - - for (AltosEepromLog flight : flights) { - if (flight.selected) { - if (result.equals("")) - result = String.format("%d", flight.flight); - else - result = String.format("%s, %d", result, flight.flight); - } - } - return result; - } - - public boolean download_done() { - AltosEepromSelect select = new AltosEepromSelect(frame, flights, "Delete"); - - if (select.run()) { - boolean any_selected = false; - for (AltosEepromLog flight : flights) - any_selected = any_selected || flight.selected; - if (any_selected) { - delete = new AltosEepromDelete(frame, - serial_line, - remote, - flights); - delete.addActionListener(this); - /* - * Start flight log delete - */ - - delete.start(); - return true; - } - } - return false; - } - - public void actionPerformed(ActionEvent e) { - String cmd = e.getActionCommand(); - boolean success = e.getID() != 0; - boolean running = false; - - if (cmd.equals("download")) { - if (success) - running = download_done(); - } else if (cmd.equals("delete")) { - if (success) { - JOptionPane.showMessageDialog(frame, - String.format("%d flights erased: %s", - countDeletedFlights(), - showDeletedFlights()), - serial_line.device.toShortString(), - JOptionPane.INFORMATION_MESSAGE); - } - } - if (!running) - finish(); - } - - public void got_flights(AltosEepromList in_flights) { - boolean running = false;; - - flights = in_flights; - try { - if (flights.size() == 0) { - JOptionPane.showMessageDialog(frame, - String.format("No flights available on %d", - device.getSerial()), - serial_line.device.toShortString(), - JOptionPane.INFORMATION_MESSAGE); - } else { - AltosEepromSelect select = new AltosEepromSelect(frame, flights, "Download"); - - if (select.run()) { - boolean any_selected = false; - for (AltosEepromLog flight : flights) - any_selected = any_selected || flight.selected; - if (any_selected) { - AltosEepromMonitorUI monitor = new AltosEepromMonitorUI(frame); - monitor.addActionListener(this); - serial_line.set_frame(frame); - download = new AltosEepromDownload(monitor, - serial_line, - remote, - flights); - /* - * Start flight log download - */ - - download.start(); - running = true; - } else { - running = download_done(); - } - } - } - if (!running) - finish(); - } catch (Exception e) { - got_exception(e); - } - } - - public void got_exception(Exception e) { - if (e instanceof IOException) { - IOException ee = (IOException) e; - JOptionPane.showMessageDialog(frame, - device.toShortString(), - ee.getLocalizedMessage(), - JOptionPane.ERROR_MESSAGE); - } else if (e instanceof TimeoutException) { - //TimeoutException te = (TimeoutException) e; - JOptionPane.showMessageDialog(frame, - String.format("Communications failed with \"%s\"", - device.toShortString()), - "Cannot open target device", - JOptionPane.ERROR_MESSAGE); - } - finish(); - } - - class EepromGetList implements Runnable { - - AltosEepromManage manage; - - public void run () { - Runnable r; - try { - flights = new AltosEepromList(serial_line, remote); - r = new Runnable() { - public void run() { - got_flights(flights); - } - }; - } catch (Exception e) { - final Exception f_e = e; - r = new Runnable() { - public void run() { - got_exception(f_e); - } - }; - } - SwingUtilities.invokeLater(r); - } - - public EepromGetList(AltosEepromManage in_manage) { - manage = in_manage; - } - } - - public AltosEepromManage(JFrame given_frame) { - - //boolean running = false; - - frame = given_frame; - device = AltosDeviceUIDialog.show(frame, Altos.product_any); - - remote = false; - - if (device != null) { - try { - serial_line = new AltosSerial(device); - if (device.matchProduct(Altos.product_basestation)) - remote = true; - - serial_line.set_frame(frame); - - EepromGetList get_list = new EepromGetList(this); - Thread t = new Thread(get_list); - t.start(); - } catch (FileNotFoundException ee) { - JOptionPane.showMessageDialog(frame, - ee.getMessage(), - "Cannot open target device", - JOptionPane.ERROR_MESSAGE); - } catch (AltosSerialInUseException si) { - JOptionPane.showMessageDialog(frame, - String.format("Device \"%s\" already in use", - device.toShortString()), - "Device in use", - JOptionPane.ERROR_MESSAGE); - } - } - } -} diff --git a/altosui/AltosEepromMonitor.java b/altosui/AltosEepromMonitor.java deleted file mode 100644 index ce1c1625..00000000 --- a/altosui/AltosEepromMonitor.java +++ /dev/null @@ -1,252 +0,0 @@ -/* - * 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 altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import org.altusmetrum.altosuilib_2.*; - -public class AltosEepromMonitor extends AltosUIDialog { - - Container pane; - Box box; - JLabel serial_label; - JLabel flight_label; - JLabel file_label; - JLabel serial_value; - JLabel flight_value; - JLabel file_value; - JButton cancel; - JProgressBar pbar; - int min_state, max_state; - - public AltosEepromMonitor(JFrame owner, int in_min_state, int in_max_state) { - super (owner, "Download Flight Data", false); - - GridBagConstraints c; - Insets il = new Insets(4,4,4,4); - Insets ir = new Insets(4,4,4,4); - - pane = getContentPane(); - pane.setLayout(new GridBagLayout()); - - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 0; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - serial_label = new JLabel("Serial:"); - pane.add(serial_label, c); - - c = new GridBagConstraints(); - c.gridx = 1; c.gridy = 0; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - serial_value = new JLabel(""); - pane.add(serial_value, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.NONE; - c.gridx = 0; c.gridy = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - flight_label = new JLabel("Flight:"); - pane.add(flight_label, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.gridx = 1; c.gridy = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - flight_value = new JLabel(""); - pane.add(flight_value, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.NONE; - c.gridx = 0; c.gridy = 2; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - file_label = new JLabel("File:"); - pane.add(file_label, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.gridx = 1; c.gridy = 2; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - file_value = new JLabel(""); - pane.add(file_value, c); - - min_state = in_min_state; - max_state = in_max_state; - pbar = new JProgressBar(); - pbar.setMinimum(0); - pbar.setMaximum(1000); - pbar.setValue(0); - pbar.setString("startup"); - pbar.setStringPainted(true); - pbar.setPreferredSize(new Dimension(600, 20)); - c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.anchor = GridBagConstraints.CENTER; - c.gridx = 0; c.gridy = 3; - c.gridwidth = GridBagConstraints.REMAINDER; - Insets ib = new Insets(4,4,4,4); - c.insets = ib; - pane.add(pbar, c); - - - cancel = new JButton("Cancel"); - c = new GridBagConstraints(); - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.gridx = 0; c.gridy = 4; - c.gridwidth = GridBagConstraints.REMAINDER; - Insets ic = new Insets(4,4,4,4); - c.insets = ic; - pane.add(cancel, c); - - pack(); - setLocationRelativeTo(owner); - setVisible(true); - } - - public void addActionListener (ActionListener l) { - cancel.addActionListener(l); - } - - private void set_value_internal(String state_name, int state, int state_block, int block) { - if (state_block > 100) - state_block = 100; - if (state < min_state) state = min_state; - if (state >= max_state) state = max_state - 1; - state -= min_state; - - int pos = state * 100 + state_block; - - pbar.setString(String.format("block %d state %s", block, state_name)); - pbar.setValue(pos); - } - - public void set_value(String in_state_name, int in_state, int in_state_block, int in_block) { - final String state_name = in_state_name; - final int state = in_state; - final int state_block = in_state_block; - final int block = in_block; - Runnable r = new Runnable() { - public void run() { - try { - set_value_internal(state_name, state, state_block, block); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } - - private void set_serial_internal(int serial) { - serial_value.setText(String.format("%d", serial)); - } - - public void set_serial(int in_serial) { - final int serial = in_serial; - Runnable r = new Runnable() { - public void run() { - try { - set_serial_internal(serial); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } - - private void set_flight_internal(int flight) { - flight_value.setText(String.format("%d", flight)); - } - - public void set_flight(int in_flight) { - final int flight = in_flight; - Runnable r = new Runnable() { - public void run() { - try { - set_flight_internal(flight); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } - - private void set_file_internal(String file) { - file_value.setText(String.format("%s", file)); - } - - public void set_file(String in_file) { - final String file = in_file; - Runnable r = new Runnable() { - public void run() { - try { - set_file_internal(file); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } - - private void done_internal() { - setVisible(false); - dispose(); - } - - public void done() { - Runnable r = new Runnable() { - public void run() { - try { - done_internal(); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } - - private void reset_internal() { - set_value_internal("startup",min_state,0, 0); - set_flight_internal(0); - set_file_internal(""); - } - - public void reset() { - Runnable r = new Runnable() { - public void run() { - try { - reset_internal(); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } -} diff --git a/altosui/AltosEepromMonitorUI.java b/altosui/AltosEepromMonitorUI.java deleted file mode 100644 index c1c1eb25..00000000 --- a/altosui/AltosEepromMonitorUI.java +++ /dev/null @@ -1,311 +0,0 @@ -/* - * 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 altosui; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import org.altusmetrum.altosuilib_2.*; -import org.altusmetrum.altoslib_4.*; - -public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMonitor { - JFrame owner; - Container pane; - Box box; - JLabel serial_label; - JLabel flight_label; - JLabel file_label; - JLabel serial_value; - JLabel flight_value; - JLabel file_value; - JButton cancel; - JProgressBar pbar; - int min_state, max_state; - ActionListener listener; - - public AltosEepromMonitorUI(JFrame owner) { - super (owner, "Download Flight Data", false); - - this.owner = owner; - - GridBagConstraints c; - Insets il = new Insets(4,4,4,4); - Insets ir = new Insets(4,4,4,4); - - pane = getContentPane(); - pane.setLayout(new GridBagLayout()); - - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 0; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - serial_label = new JLabel("Serial:"); - pane.add(serial_label, c); - - c = new GridBagConstraints(); - c.gridx = 1; c.gridy = 0; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - serial_value = new JLabel(""); - pane.add(serial_value, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.NONE; - c.gridx = 0; c.gridy = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - flight_label = new JLabel("Flight:"); - pane.add(flight_label, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.gridx = 1; c.gridy = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - flight_value = new JLabel(""); - pane.add(flight_value, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.NONE; - c.gridx = 0; c.gridy = 2; - c.anchor = GridBagConstraints.LINE_START; - c.insets = il; - file_label = new JLabel("File:"); - pane.add(file_label, c); - - c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.gridx = 1; c.gridy = 2; - c.anchor = GridBagConstraints.LINE_START; - c.insets = ir; - file_value = new JLabel(""); - pane.add(file_value, c); - - pbar = new JProgressBar(); - pbar.setMinimum(0); - pbar.setMaximum(1000); - pbar.setValue(0); - pbar.setString("startup"); - pbar.setStringPainted(true); - pbar.setPreferredSize(new Dimension(600, 20)); - c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.anchor = GridBagConstraints.CENTER; - c.gridx = 0; c.gridy = 3; - c.gridwidth = GridBagConstraints.REMAINDER; - Insets ib = new Insets(4,4,4,4); - c.insets = ib; - pane.add(pbar, c); - - - cancel = new JButton("Cancel"); - c = new GridBagConstraints(); - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.gridx = 0; c.gridy = 4; - c.gridwidth = GridBagConstraints.REMAINDER; - Insets ic = new Insets(4,4,4,4); - c.insets = ic; - pane.add(cancel, c); - - pack(); - setLocationRelativeTo(owner); - } - - public void addActionListener(ActionListener l) { - listener = l; - } - - public void set_states(int min_state, int max_state) { - this.min_state = min_state; - this.max_state = max_state; - } - - public void set_thread(Thread in_eeprom_thread) { - final Thread eeprom_thread = in_eeprom_thread; - cancel.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - if (eeprom_thread != null) - eeprom_thread.interrupt(); - } - }); - } - - public void start() { - setVisible(true); - } - - private void set_value_internal(String state_name, int state, int state_block, int block) { - if (state_block > 100) - state_block = 100; - if (state < min_state) state = min_state; - if (state >= max_state) state = max_state - 1; - state -= min_state; - - int pos = state * 100 + state_block; - - pbar.setString(String.format("block %d state %s", block, state_name)); - pbar.setValue(pos); - } - - public void set_value(String in_state_name, int in_state, int in_state_block, int in_block) { - final String state_name = in_state_name; - final int state = in_state; - final int state_block = in_state_block; - final int block = in_block; - Runnable r = new Runnable() { - public void run() { - try { - set_value_internal(state_name, state, state_block, block); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } - - private void set_serial_internal(int serial) { - serial_value.setText(String.format("%d", serial)); - } - - public void set_serial(int in_serial) { - final int serial = in_serial; - Runnable r = new Runnable() { - public void run() { - try { - set_serial_internal(serial); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } - - private void set_flight_internal(int flight) { - flight_value.setText(String.format("%d", flight)); - } - - public void set_flight(int in_flight) { - final int flight = in_flight; - Runnable r = new Runnable() { - public void run() { - try { - set_flight_internal(flight); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } - - private void set_filename_internal(String filename) { - file_value.setText(String.format("%s", filename)); - } - - public void set_filename(String in_filename) { - final String filename = in_filename; - Runnable r = new Runnable() { - public void run() { - try { - set_filename_internal(filename); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } - - private void done_internal(boolean success) { - listener.actionPerformed(new ActionEvent(this, - success ? 1 : 0, - "download")); - setVisible(false); - dispose(); - } - - public void done(boolean in_success) { - final boolean success = in_success; - Runnable r = new Runnable() { - public void run() { - try { - done_internal(success); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } - - private void reset_internal() { - set_value_internal("startup",min_state,0, 0); - set_flight_internal(0); - set_filename_internal(""); - } - - public void reset() { - Runnable r = new Runnable() { - public void run() { - try { - reset_internal(); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } - - private void show_message_internal(String message, String title, int message_type) { - int joption_message_type = JOptionPane.ERROR_MESSAGE; - - switch (message_type) { - case INFO_MESSAGE: - joption_message_type = JOptionPane.INFORMATION_MESSAGE; - break; - case WARNING_MESSAGE: - joption_message_type = JOptionPane.WARNING_MESSAGE; - break; - case ERROR_MESSAGE: - joption_message_type = JOptionPane.ERROR_MESSAGE; - break; - } - JOptionPane.showMessageDialog(owner, - message, - title, - joption_message_type); - } - - public void show_message(String in_message, String in_title, int in_message_type) { - final String message = in_message; - final String title = in_title; - final int message_type = in_message_type; - Runnable r = new Runnable() { - public void run() { - try { - show_message_internal(message, title, message_type); - } catch (Exception ex) { - } - } - }; - SwingUtilities.invokeLater(r); - } -} diff --git a/altosui/AltosEepromSelect.java b/altosui/AltosEepromSelect.java deleted file mode 100644 index 66a197c9..00000000 --- a/altosui/AltosEepromSelect.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright © 2011 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 altosui; - -import javax.swing.*; -import javax.swing.border.*; -import java.awt.*; -import java.awt.event.*; -import org.altusmetrum.altoslib_4.*; -import org.altusmetrum.altosuilib_2.*; - -class AltosEepromItem implements ActionListener { - AltosEepromLog log; - JLabel label; - JCheckBox action; - JCheckBox delete; - - public void actionPerformed(ActionEvent e) { - log.selected = action.isSelected(); - } - - public AltosEepromItem(AltosEepromLog in_log) { - log = in_log; - - String text; - if (log.year != 0) - text = String.format("Flight #%02d - %04d-%02d-%02d", - log.flight, log.year, log.month, log.day); - else - text = String.format("Flight #%02d", log.flight); - - label = new JLabel(text); - - action = new JCheckBox("", log.selected); - action.addActionListener(this); - } -} - -public class AltosEepromSelect extends AltosUIDialog implements ActionListener { - //private JList list; - private JFrame frame; - JButton ok; - JButton cancel; - boolean success; - - /* Listen for events from our buttons */ - public void actionPerformed(ActionEvent e) { - String cmd = e.getActionCommand(); - - if (cmd.equals("ok")) - success = true; - setVisible(false); - } - - public boolean run() { - success = false; - setLocationRelativeTo(frame); - setVisible(true); - return success; - } - - public AltosEepromSelect (JFrame in_frame, - AltosEepromList flights, - String action) { - - super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true); - frame = in_frame; - - /* Create the container for the dialog */ - Container contentPane = getContentPane(); - - /* First, we create a pane containing the dialog's header/title */ - JLabel selectLabel = new JLabel(String.format ("Select flights to %s", action), SwingConstants.CENTER); - - JPanel labelPane = new JPanel(); - labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS)); - labelPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); - labelPane.add(Box.createHorizontalGlue()); - labelPane.add(selectLabel); - labelPane.add(Box.createHorizontalGlue()); - - /* Add the header to the container. */ - contentPane.add(labelPane, BorderLayout.PAGE_START); - - - /* Now we create the evilness that is a GridBag for the flight details */ - GridBagConstraints c; - Insets i = new Insets(4,4,4,4); - JPanel flightPane = new JPanel(); - flightPane.setLayout(new GridBagLayout()); - flightPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); - - /* Flight Header */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 0; - c.fill = GridBagConstraints.NONE; - c.weightx = 0.5; - c.anchor = GridBagConstraints.CENTER; - c.insets = i; - JLabel flightHeaderLabel = new JLabel("Flight"); - flightPane.add(flightHeaderLabel, c); - - /* Download Header */ - c = new GridBagConstraints(); - c.gridx = 1; c.gridy = 0; - c.fill = GridBagConstraints.NONE; - c.weightx = 0.5; - c.anchor = GridBagConstraints.CENTER; - c.insets = i; - JLabel downloadHeaderLabel = new JLabel(action); - flightPane.add(downloadHeaderLabel, c); - - /* Add the flights to the GridBag */ - AltosEepromItem item; - int itemNumber = 1; - for (AltosEepromLog flight : flights) { - /* Create a flight object with handlers and - * appropriate UI items - */ - item = new AltosEepromItem(flight); - - /* Add a decriptive label for the flight */ - c = new GridBagConstraints(); - c.gridx = 0; c.gridy = itemNumber; - c.fill = GridBagConstraints.NONE; - c.weightx = 0.5; - c.anchor = GridBagConstraints.CENTER; - c.insets = i; - flightPane.add(item.label, c); - - /* Add action checkbox for the flight */ - c = new GridBagConstraints(); - c.gridx = 1; c.gridy = itemNumber; - c.fill = GridBagConstraints.NONE; - c.weightx = 0.5; - c.anchor = GridBagConstraints.CENTER; - c.insets = i; - flightPane.add(item.action, c); - - itemNumber++; - } - - /* Add the GridBag to the container */ - contentPane.add(flightPane, BorderLayout.CENTER); - - /* Create the dialog buttons */ - ok = new JButton("OK"); - ok.addActionListener(this); - ok.setActionCommand("ok"); - - cancel = new JButton("Cancel"); - cancel.addActionListener(this); - cancel.setActionCommand("cancel"); - - JPanel buttonPane = new JPanel(); - buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); - buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - buttonPane.add(Box.createHorizontalGlue()); - buttonPane.add(cancel); - buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); - buttonPane.add(ok); - - /* Add the buttons to the container */ - contentPane.add(buttonPane, BorderLayout.PAGE_END); - - /* Pack the window! */ - pack(); - } -} diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java index ad7964e9..302f623f 100644 --- a/altosui/AltosUI.java +++ b/altosui/AltosUI.java @@ -306,7 +306,7 @@ public class AltosUI extends AltosUIFrame { * a TeleDongle over the packet link */ private void SaveFlightData() { - new AltosEepromManage(AltosUI.this); + new AltosEepromManage(AltosUI.this, AltosLib.product_any); } /* Load a flight log file and write out a CSV file containing diff --git a/altosui/Makefile.am b/altosui/Makefile.am index cd6af84b..c834646d 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -22,10 +22,6 @@ altosui_JAVA = \ AltosConfigTDUI.java \ AltosCSVUI.java \ AltosDescent.java \ - AltosEepromDelete.java \ - AltosEepromManage.java \ - AltosEepromMonitorUI.java \ - AltosEepromSelect.java \ AltosFlashUI.java \ AltosFlightInfoTableModel.java \ AltosFlightStatsTable.java \ diff --git a/altosuilib/AltosEepromDelete.java b/altosuilib/AltosEepromDelete.java new file mode 100644 index 00000000..981daddf --- /dev/null +++ b/altosuilib/AltosEepromDelete.java @@ -0,0 +1,143 @@ +/* + * Copyright © 2011 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.altosuilib_2; + +import java.awt.event.*; +import javax.swing.*; +import java.io.*; +import java.util.concurrent.*; +import org.altusmetrum.altoslib_4.*; + +public class AltosEepromDelete implements Runnable { + AltosEepromList flights; + Thread eeprom_thread; + AltosSerial serial_line; + boolean remote; + JFrame frame; + ActionListener listener; + boolean success; + + private void DeleteLog (AltosEepromLog log) + throws IOException, InterruptedException, TimeoutException { + + if (flights.config_data.flight_log_max != 0 || flights.config_data.log_format != 0) { + + /* Devices with newer firmware can erase the + * flash blocks containing each flight + */ + serial_line.flush_input(); + serial_line.printf("d %d\n", log.flight); + for (;;) { + /* It can take a while to erase the flash... */ + String line = serial_line.get_reply(20000); + if (line == null) + throw new TimeoutException(); + if (line.equals("Erased")) + break; + if (line.startsWith("No such")) + throw new IOException(line); + } + } + } + + private void show_error_internal(String message, String title) { + JOptionPane.showMessageDialog(frame, + message, + title, + JOptionPane.ERROR_MESSAGE); + } + + private void show_error(String in_message, String in_title) { + final String message = in_message; + final String title = in_title; + Runnable r = new Runnable() { + public void run() { + try { + show_error_internal(message, title); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + public void run () { + success = false; + try { + if (remote) + serial_line.start_remote(); + + for (AltosEepromLog log : flights) { + if (log.selected) { + DeleteLog(log); + } + } + success = true; + } catch (IOException ee) { + show_error (ee.getLocalizedMessage(), + serial_line.device.toShortString()); + } catch (InterruptedException ie) { + } catch (TimeoutException te) { + show_error (String.format("Connection to \"%s\" failed", + serial_line.device.toShortString()), + "Connection Failed"); + } finally { + try { + if (remote) + serial_line.stop_remote(); + } catch (InterruptedException ie) { + } finally { + serial_line.flush_output(); + serial_line.close(); + } + } + if (listener != null) { + Runnable r = new Runnable() { + public void run() { + try { + listener.actionPerformed(new ActionEvent(this, + success ? 1 : 0, + "delete")); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + } + + public void start() { + eeprom_thread = new Thread(this); + eeprom_thread.start(); + } + + public void addActionListener(ActionListener l) { + listener = l; + } + + public AltosEepromDelete(JFrame given_frame, + AltosSerial given_serial_line, + boolean given_remote, + AltosEepromList given_flights) { + frame = given_frame; + serial_line = given_serial_line; + remote = given_remote; + flights = given_flights; + success = false; + } +} diff --git a/altosuilib/AltosEepromManage.java b/altosuilib/AltosEepromManage.java new file mode 100644 index 00000000..2b967339 --- /dev/null +++ b/altosuilib/AltosEepromManage.java @@ -0,0 +1,241 @@ +/* + * Copyright © 2011 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.altosuilib_2; + +import java.awt.event.*; +import javax.swing.*; +import java.io.*; +import java.util.concurrent.*; +import org.altusmetrum.altoslib_4.*; + +public class AltosEepromManage implements ActionListener { + + JFrame frame; + boolean remote; + AltosDevice device; + AltosSerial serial_line; + AltosEepromList flights; + AltosEepromDownload download; + AltosEepromDelete delete; + + public void finish() { + if (serial_line != null) { + try { + serial_line.flush_input(); + } catch (InterruptedException ie) { + } + serial_line.close(); + serial_line = null; + } + } + + private int countDeletedFlights() { + int count = 0; + for (AltosEepromLog flight : flights) { + if (flight.selected) + count++; + } + return count; + } + + private String showDeletedFlights() { + String result = ""; + + for (AltosEepromLog flight : flights) { + if (flight.selected) { + if (result.equals("")) + result = String.format("%d", flight.flight); + else + result = String.format("%s, %d", result, flight.flight); + } + } + return result; + } + + public boolean download_done() { + AltosEepromSelect select = new AltosEepromSelect(frame, flights, "Delete"); + + if (select.run()) { + boolean any_selected = false; + for (AltosEepromLog flight : flights) + any_selected = any_selected || flight.selected; + if (any_selected) { + delete = new AltosEepromDelete(frame, + serial_line, + remote, + flights); + delete.addActionListener(this); + /* + * Start flight log delete + */ + + delete.start(); + return true; + } + } + return false; + } + + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + boolean success = e.getID() != 0; + boolean running = false; + + if (cmd.equals("download")) { + if (success) + running = download_done(); + } else if (cmd.equals("delete")) { + if (success) { + JOptionPane.showMessageDialog(frame, + String.format("%d flights erased: %s", + countDeletedFlights(), + showDeletedFlights()), + serial_line.device.toShortString(), + JOptionPane.INFORMATION_MESSAGE); + } + } + if (!running) + finish(); + } + + public void got_flights(AltosEepromList in_flights) { + boolean running = false;; + + flights = in_flights; + try { + if (flights.size() == 0) { + JOptionPane.showMessageDialog(frame, + String.format("No flights available on %d", + device.getSerial()), + serial_line.device.toShortString(), + JOptionPane.INFORMATION_MESSAGE); + } else { + AltosEepromSelect select = new AltosEepromSelect(frame, flights, "Download"); + + if (select.run()) { + boolean any_selected = false; + for (AltosEepromLog flight : flights) + any_selected = any_selected || flight.selected; + if (any_selected) { + AltosEepromMonitorUI monitor = new AltosEepromMonitorUI(frame); + monitor.addActionListener(this); + serial_line.set_frame(frame); + download = new AltosEepromDownload(monitor, + serial_line, + remote, + flights); + /* + * Start flight log download + */ + + download.start(); + running = true; + } else { + running = download_done(); + } + } + } + if (!running) + finish(); + } catch (Exception e) { + got_exception(e); + } + } + + public void got_exception(Exception e) { + if (e instanceof IOException) { + IOException ee = (IOException) e; + JOptionPane.showMessageDialog(frame, + device.toShortString(), + ee.getLocalizedMessage(), + JOptionPane.ERROR_MESSAGE); + } else if (e instanceof TimeoutException) { + //TimeoutException te = (TimeoutException) e; + JOptionPane.showMessageDialog(frame, + String.format("Communications failed with \"%s\"", + device.toShortString()), + "Cannot open target device", + JOptionPane.ERROR_MESSAGE); + } + finish(); + } + + class EepromGetList implements Runnable { + + AltosEepromManage manage; + + public void run () { + Runnable r; + try { + flights = new AltosEepromList(serial_line, remote); + r = new Runnable() { + public void run() { + got_flights(flights); + } + }; + } catch (Exception e) { + final Exception f_e = e; + r = new Runnable() { + public void run() { + got_exception(f_e); + } + }; + } + SwingUtilities.invokeLater(r); + } + + public EepromGetList(AltosEepromManage in_manage) { + manage = in_manage; + } + } + + public AltosEepromManage(JFrame given_frame, int product) { + + //boolean running = false; + + frame = given_frame; + device = AltosDeviceUIDialog.show(frame, product); + + remote = false; + + if (device != null) { + try { + serial_line = new AltosSerial(device); + if (device.matchProduct(AltosLib.product_basestation)) + remote = true; + + serial_line.set_frame(frame); + + EepromGetList get_list = new EepromGetList(this); + Thread t = new Thread(get_list); + t.start(); + } catch (FileNotFoundException ee) { + JOptionPane.showMessageDialog(frame, + ee.getMessage(), + "Cannot open target device", + JOptionPane.ERROR_MESSAGE); + } catch (AltosSerialInUseException si) { + JOptionPane.showMessageDialog(frame, + String.format("Device \"%s\" already in use", + device.toShortString()), + "Device in use", + JOptionPane.ERROR_MESSAGE); + } + } + } +} diff --git a/altosuilib/AltosEepromMonitor.java b/altosuilib/AltosEepromMonitor.java new file mode 100644 index 00000000..b1e85622 --- /dev/null +++ b/altosuilib/AltosEepromMonitor.java @@ -0,0 +1,251 @@ +/* + * 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.altosuilib_2; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +public class AltosEepromMonitor extends AltosUIDialog { + + Container pane; + Box box; + JLabel serial_label; + JLabel flight_label; + JLabel file_label; + JLabel serial_value; + JLabel flight_value; + JLabel file_value; + JButton cancel; + JProgressBar pbar; + int min_state, max_state; + + public AltosEepromMonitor(JFrame owner, int in_min_state, int in_max_state) { + super (owner, "Download Flight Data", false); + + GridBagConstraints c; + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); + + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + serial_label = new JLabel("Serial:"); + pane.add(serial_label, c); + + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = 0; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + serial_value = new JLabel(""); + pane.add(serial_value, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + flight_label = new JLabel("Flight:"); + pane.add(flight_label, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.gridx = 1; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + flight_value = new JLabel(""); + pane.add(flight_value, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; c.gridy = 2; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + file_label = new JLabel("File:"); + pane.add(file_label, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.gridx = 1; c.gridy = 2; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + file_value = new JLabel(""); + pane.add(file_value, c); + + min_state = in_min_state; + max_state = in_max_state; + pbar = new JProgressBar(); + pbar.setMinimum(0); + pbar.setMaximum(1000); + pbar.setValue(0); + pbar.setString("startup"); + pbar.setStringPainted(true); + pbar.setPreferredSize(new Dimension(600, 20)); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 3; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ib = new Insets(4,4,4,4); + c.insets = ib; + pane.add(pbar, c); + + + cancel = new JButton("Cancel"); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 4; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ic = new Insets(4,4,4,4); + c.insets = ic; + pane.add(cancel, c); + + pack(); + setLocationRelativeTo(owner); + setVisible(true); + } + + public void addActionListener (ActionListener l) { + cancel.addActionListener(l); + } + + private void set_value_internal(String state_name, int state, int state_block, int block) { + if (state_block > 100) + state_block = 100; + if (state < min_state) state = min_state; + if (state >= max_state) state = max_state - 1; + state -= min_state; + + int pos = state * 100 + state_block; + + pbar.setString(String.format("block %d state %s", block, state_name)); + pbar.setValue(pos); + } + + public void set_value(String in_state_name, int in_state, int in_state_block, int in_block) { + final String state_name = in_state_name; + final int state = in_state; + final int state_block = in_state_block; + final int block = in_block; + Runnable r = new Runnable() { + public void run() { + try { + set_value_internal(state_name, state, state_block, block); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + private void set_serial_internal(int serial) { + serial_value.setText(String.format("%d", serial)); + } + + public void set_serial(int in_serial) { + final int serial = in_serial; + Runnable r = new Runnable() { + public void run() { + try { + set_serial_internal(serial); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + private void set_flight_internal(int flight) { + flight_value.setText(String.format("%d", flight)); + } + + public void set_flight(int in_flight) { + final int flight = in_flight; + Runnable r = new Runnable() { + public void run() { + try { + set_flight_internal(flight); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + private void set_file_internal(String file) { + file_value.setText(String.format("%s", file)); + } + + public void set_file(String in_file) { + final String file = in_file; + Runnable r = new Runnable() { + public void run() { + try { + set_file_internal(file); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + private void done_internal() { + setVisible(false); + dispose(); + } + + public void done() { + Runnable r = new Runnable() { + public void run() { + try { + done_internal(); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + private void reset_internal() { + set_value_internal("startup",min_state,0, 0); + set_flight_internal(0); + set_file_internal(""); + } + + public void reset() { + Runnable r = new Runnable() { + public void run() { + try { + reset_internal(); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } +} diff --git a/altosuilib/AltosEepromMonitorUI.java b/altosuilib/AltosEepromMonitorUI.java new file mode 100644 index 00000000..02c71cd9 --- /dev/null +++ b/altosuilib/AltosEepromMonitorUI.java @@ -0,0 +1,310 @@ +/* + * 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.altosuilib_2; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import org.altusmetrum.altoslib_4.*; + +public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMonitor { + JFrame owner; + Container pane; + Box box; + JLabel serial_label; + JLabel flight_label; + JLabel file_label; + JLabel serial_value; + JLabel flight_value; + JLabel file_value; + JButton cancel; + JProgressBar pbar; + int min_state, max_state; + ActionListener listener; + + public AltosEepromMonitorUI(JFrame owner) { + super (owner, "Download Flight Data", false); + + this.owner = owner; + + GridBagConstraints c; + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); + + pane = getContentPane(); + pane.setLayout(new GridBagLayout()); + + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + serial_label = new JLabel("Serial:"); + pane.add(serial_label, c); + + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = 0; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + serial_value = new JLabel(""); + pane.add(serial_value, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + flight_label = new JLabel("Flight:"); + pane.add(flight_label, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.gridx = 1; c.gridy = 1; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + flight_value = new JLabel(""); + pane.add(flight_value, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.gridx = 0; c.gridy = 2; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + file_label = new JLabel("File:"); + pane.add(file_label, c); + + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1; + c.gridx = 1; c.gridy = 2; + c.anchor = GridBagConstraints.LINE_START; + c.insets = ir; + file_value = new JLabel(""); + pane.add(file_value, c); + + pbar = new JProgressBar(); + pbar.setMinimum(0); + pbar.setMaximum(1000); + pbar.setValue(0); + pbar.setString("startup"); + pbar.setStringPainted(true); + pbar.setPreferredSize(new Dimension(600, 20)); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 3; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ib = new Insets(4,4,4,4); + c.insets = ib; + pane.add(pbar, c); + + + cancel = new JButton("Cancel"); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 4; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ic = new Insets(4,4,4,4); + c.insets = ic; + pane.add(cancel, c); + + pack(); + setLocationRelativeTo(owner); + } + + public void addActionListener(ActionListener l) { + listener = l; + } + + public void set_states(int min_state, int max_state) { + this.min_state = min_state; + this.max_state = max_state; + } + + public void set_thread(Thread in_eeprom_thread) { + final Thread eeprom_thread = in_eeprom_thread; + cancel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (eeprom_thread != null) + eeprom_thread.interrupt(); + } + }); + } + + public void start() { + setVisible(true); + } + + private void set_value_internal(String state_name, int state, int state_block, int block) { + if (state_block > 100) + state_block = 100; + if (state < min_state) state = min_state; + if (state >= max_state) state = max_state - 1; + state -= min_state; + + int pos = state * 100 + state_block; + + pbar.setString(String.format("block %d state %s", block, state_name)); + pbar.setValue(pos); + } + + public void set_value(String in_state_name, int in_state, int in_state_block, int in_block) { + final String state_name = in_state_name; + final int state = in_state; + final int state_block = in_state_block; + final int block = in_block; + Runnable r = new Runnable() { + public void run() { + try { + set_value_internal(state_name, state, state_block, block); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + private void set_serial_internal(int serial) { + serial_value.setText(String.format("%d", serial)); + } + + public void set_serial(int in_serial) { + final int serial = in_serial; + Runnable r = new Runnable() { + public void run() { + try { + set_serial_internal(serial); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + private void set_flight_internal(int flight) { + flight_value.setText(String.format("%d", flight)); + } + + public void set_flight(int in_flight) { + final int flight = in_flight; + Runnable r = new Runnable() { + public void run() { + try { + set_flight_internal(flight); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + private void set_filename_internal(String filename) { + file_value.setText(String.format("%s", filename)); + } + + public void set_filename(String in_filename) { + final String filename = in_filename; + Runnable r = new Runnable() { + public void run() { + try { + set_filename_internal(filename); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + private void done_internal(boolean success) { + listener.actionPerformed(new ActionEvent(this, + success ? 1 : 0, + "download")); + setVisible(false); + dispose(); + } + + public void done(boolean in_success) { + final boolean success = in_success; + Runnable r = new Runnable() { + public void run() { + try { + done_internal(success); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + private void reset_internal() { + set_value_internal("startup",min_state,0, 0); + set_flight_internal(0); + set_filename_internal(""); + } + + public void reset() { + Runnable r = new Runnable() { + public void run() { + try { + reset_internal(); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + private void show_message_internal(String message, String title, int message_type) { + int joption_message_type = JOptionPane.ERROR_MESSAGE; + + switch (message_type) { + case INFO_MESSAGE: + joption_message_type = JOptionPane.INFORMATION_MESSAGE; + break; + case WARNING_MESSAGE: + joption_message_type = JOptionPane.WARNING_MESSAGE; + break; + case ERROR_MESSAGE: + joption_message_type = JOptionPane.ERROR_MESSAGE; + break; + } + JOptionPane.showMessageDialog(owner, + message, + title, + joption_message_type); + } + + public void show_message(String in_message, String in_title, int in_message_type) { + final String message = in_message; + final String title = in_title; + final int message_type = in_message_type; + Runnable r = new Runnable() { + public void run() { + try { + show_message_internal(message, title, message_type); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } +} diff --git a/altosuilib/AltosEepromSelect.java b/altosuilib/AltosEepromSelect.java new file mode 100644 index 00000000..293d3045 --- /dev/null +++ b/altosuilib/AltosEepromSelect.java @@ -0,0 +1,183 @@ +/* + * Copyright © 2011 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.altosuilib_2; + +import javax.swing.*; +import javax.swing.border.*; +import java.awt.*; +import java.awt.event.*; +import org.altusmetrum.altoslib_4.*; + +class AltosEepromItem implements ActionListener { + AltosEepromLog log; + JLabel label; + JCheckBox action; + JCheckBox delete; + + public void actionPerformed(ActionEvent e) { + log.selected = action.isSelected(); + } + + public AltosEepromItem(AltosEepromLog in_log) { + log = in_log; + + String text; + if (log.year != 0) + text = String.format("Flight #%02d - %04d-%02d-%02d", + log.flight, log.year, log.month, log.day); + else + text = String.format("Flight #%02d", log.flight); + + label = new JLabel(text); + + action = new JCheckBox("", log.selected); + action.addActionListener(this); + } +} + +public class AltosEepromSelect extends AltosUIDialog implements ActionListener { + //private JList list; + private JFrame frame; + JButton ok; + JButton cancel; + boolean success; + + /* Listen for events from our buttons */ + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + + if (cmd.equals("ok")) + success = true; + setVisible(false); + } + + public boolean run() { + success = false; + setLocationRelativeTo(frame); + setVisible(true); + return success; + } + + public AltosEepromSelect (JFrame in_frame, + AltosEepromList flights, + String action) { + + super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true); + frame = in_frame; + + /* Create the container for the dialog */ + Container contentPane = getContentPane(); + + /* First, we create a pane containing the dialog's header/title */ + JLabel selectLabel = new JLabel(String.format ("Select flights to %s", action), SwingConstants.CENTER); + + JPanel labelPane = new JPanel(); + labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS)); + labelPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); + labelPane.add(Box.createHorizontalGlue()); + labelPane.add(selectLabel); + labelPane.add(Box.createHorizontalGlue()); + + /* Add the header to the container. */ + contentPane.add(labelPane, BorderLayout.PAGE_START); + + + /* Now we create the evilness that is a GridBag for the flight details */ + GridBagConstraints c; + Insets i = new Insets(4,4,4,4); + JPanel flightPane = new JPanel(); + flightPane.setLayout(new GridBagLayout()); + flightPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); + + /* Flight Header */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.fill = GridBagConstraints.NONE; + c.weightx = 0.5; + c.anchor = GridBagConstraints.CENTER; + c.insets = i; + JLabel flightHeaderLabel = new JLabel("Flight"); + flightPane.add(flightHeaderLabel, c); + + /* Download Header */ + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = 0; + c.fill = GridBagConstraints.NONE; + c.weightx = 0.5; + c.anchor = GridBagConstraints.CENTER; + c.insets = i; + JLabel downloadHeaderLabel = new JLabel(action); + flightPane.add(downloadHeaderLabel, c); + + /* Add the flights to the GridBag */ + AltosEepromItem item; + int itemNumber = 1; + for (AltosEepromLog flight : flights) { + /* Create a flight object with handlers and + * appropriate UI items + */ + item = new AltosEepromItem(flight); + + /* Add a decriptive label for the flight */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = itemNumber; + c.fill = GridBagConstraints.NONE; + c.weightx = 0.5; + c.anchor = GridBagConstraints.CENTER; + c.insets = i; + flightPane.add(item.label, c); + + /* Add action checkbox for the flight */ + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = itemNumber; + c.fill = GridBagConstraints.NONE; + c.weightx = 0.5; + c.anchor = GridBagConstraints.CENTER; + c.insets = i; + flightPane.add(item.action, c); + + itemNumber++; + } + + /* Add the GridBag to the container */ + contentPane.add(flightPane, BorderLayout.CENTER); + + /* Create the dialog buttons */ + ok = new JButton("OK"); + ok.addActionListener(this); + ok.setActionCommand("ok"); + + cancel = new JButton("Cancel"); + cancel.addActionListener(this); + cancel.setActionCommand("cancel"); + + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); + buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + buttonPane.add(Box.createHorizontalGlue()); + buttonPane.add(cancel); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + buttonPane.add(ok); + + /* Add the buttons to the container */ + contentPane.add(buttonPane, BorderLayout.PAGE_END); + + /* Pack the window! */ + pack(); + } +} diff --git a/altosuilib/Makefile.am b/altosuilib/Makefile.am index b4c4f79f..4dc4c47f 100644 --- a/altosuilib/Makefile.am +++ b/altosuilib/Makefile.am @@ -46,6 +46,10 @@ altosuilib_JAVA = \ AltosSerialInUseException.java \ AltosConfigFreqUI.java \ AltosScanUI.java \ + AltosEepromDelete.java \ + AltosEepromManage.java \ + AltosEepromMonitorUI.java \ + AltosEepromSelect.java \ AltosBTDevice.java \ AltosBTDeviceIterator.java \ AltosBTManage.java \ diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java index 34509e4e..ad46fbdd 100644 --- a/telegps/TeleGPS.java +++ b/telegps/TeleGPS.java @@ -217,6 +217,7 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo } void download(){ + new AltosEepromManage(this, AltosLib.product_telegps); } void configure() { -- cgit v1.2.3