2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 import java.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.*;
33 public class AltosEepromManage implements ActionListener {
38 AltosSerial serial_line;
39 AltosEepromList flights;
40 AltosEepromDownload download;
41 AltosEepromDelete delete;
45 public void finish() {
46 if (serial_line != null) {
47 serial_line.flush_output();
53 public void actionPerformed(ActionEvent e) {
54 String cmd = e.getActionCommand();
55 boolean success = e.getID() != 0;
57 System.out.printf("Eeprom manager action %s %d\n", cmd, e.getID());
58 if (cmd.equals("download")) {
60 System.out.printf("Download succeeded\n");
66 } else if (cmd.equals("delete")) {
68 System.out.printf("Delete succeeded\n");
73 public AltosEepromManage(JFrame given_frame) {
76 device = AltosDeviceDialog.show(frame, AltosDevice.product_any);
84 serial_line = new AltosSerial(device);
85 if (!device.matchProduct(AltosDevice.product_telemetrum))
88 flights = new AltosEepromList(serial_line, remote);
90 if (flights.size() == 0) {
92 AltosEepromSelect select = new AltosEepromSelect(frame, flights);
95 for (AltosEepromLog flight : flights) {
96 any_download = any_download || flight.download;
97 any_delete = any_delete || flight.delete;
100 download = new AltosEepromDownload(frame,
104 download.addActionListener(this);
108 delete = new AltosEepromDelete(frame,
112 delete.addActionListener(this);
116 * Start flight log download
127 } catch (FileNotFoundException ee) {
128 JOptionPane.showMessageDialog(frame,
129 String.format("Cannot open device \"%s\"",
130 device.toShortString()),
131 "Cannot open target device",
132 JOptionPane.ERROR_MESSAGE);
133 } catch (AltosSerialInUseException si) {
134 JOptionPane.showMessageDialog(frame,
135 String.format("Device \"%s\" already in use",
136 device.toShortString()),
138 JOptionPane.ERROR_MESSAGE);
139 } catch (IOException ee) {
140 JOptionPane.showMessageDialog(frame,
141 device.toShortString(),
142 ee.getLocalizedMessage(),
143 JOptionPane.ERROR_MESSAGE);
145 } catch (TimeoutException te) {
146 JOptionPane.showMessageDialog(frame,
147 String.format("Communications failed with \"%s\"",
148 device.toShortString()),
149 "Cannot open target device",
150 JOptionPane.ERROR_MESSAGE);
152 } catch (InterruptedException ie) {