public void finish() {
if (serial_line != null) {
- serial_line.flush_output();
+ serial_line.flush_input();
serial_line.close();
serial_line = null;
}
}
+ private String showDeletedFlights() {
+ String result = "";
+
+ for (AltosEepromLog flight : flights) {
+ if (flight.delete) {
+ if (result.equals(""))
+ result = String.format("%d", flight.flight);
+ else
+ result = String.format("%s, %d", result, flight.flight);
+ }
+ }
+ return result;
+ }
+
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
boolean success = e.getID() != 0;
+ boolean running = false;
- System.out.printf("Eeprom manager action %s %d\n", cmd, e.getID());
if (cmd.equals("download")) {
if (success) {
- System.out.printf("Download succeeded\n");
- if (any_delete)
+ if (any_delete) {
delete.start();
- else
- finish();
+ running = true;
+ }
}
} else if (cmd.equals("delete")) {
- if (success)
- System.out.printf("Delete succeeded\n");
- finish();
+ if (success) {
+ JOptionPane.showMessageDialog(frame,
+ String.format("Flights erased: %s",
+ showDeletedFlights()),
+ serial_line.device.toShortString(),
+ JOptionPane.INFORMATION_MESSAGE);
+ }
}
+ if (!running)
+ finish();
}
public AltosEepromManage(JFrame given_frame) {
+ boolean running = false;
+
frame = given_frame;
device = AltosDeviceDialog.show(frame, AltosDevice.product_any);
flights = new AltosEepromList(serial_line, remote);
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);
* Start flight log download
*/
- if (any_download)
+ if (any_download) {
download.start();
- else if (any_delete)
+ running = true;
+ }
+ else if (any_delete) {
delete.start();
- else
- finish();
+ running = true;
+ }
}
}
} catch (FileNotFoundException ee) {
device.toShortString(),
ee.getLocalizedMessage(),
JOptionPane.ERROR_MESSAGE);
- finish();
} catch (TimeoutException te) {
JOptionPane.showMessageDialog(frame,
String.format("Communications failed with \"%s\"",
device.toShortString()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
- finish();
} catch (InterruptedException ie) {
- finish();
}
+ if (!running)
+ finish();
}
}
}