X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=micropeak%2FMicroDownload.java;h=33c5587b9c2217c45657fae4bc924efaaab93159;hp=a03d7b3ac4a9d98b494e91a149681e4dbae538fd;hb=HEAD;hpb=4231d68bae69d9a7d1f52205002db452cd5f986d diff --git a/micropeak/MicroDownload.java b/micropeak/MicroDownload.java index a03d7b3a..4dcb7a36 100644 --- a/micropeak/MicroDownload.java +++ b/micropeak/MicroDownload.java @@ -3,7 +3,8 @@ * * 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. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -23,8 +24,8 @@ import javax.swing.*; import java.io.*; import java.util.concurrent.*; import java.util.*; -import org.altusmetrum.altoslib_6.*; -import org.altusmetrum.altosuilib_6.*; +import org.altusmetrum.altoslib_14.*; +import org.altusmetrum.altosuilib_14.*; public class MicroDownload extends AltosUIDialog implements Runnable, ActionListener, MicroSerialLog, WindowListener { MicroPeak owner; @@ -63,21 +64,27 @@ public class MicroDownload extends AltosUIDialog implements Runnable, ActionList } private void done_internal() { - setVisible(false); - dispose(); - if (data != null && data.crc_valid) { - status_value.setText("Received MicroPeak Data"); - owner = owner.SetData(data); - MicroSave save = new MicroSave(owner, data); - if (save.runDialog()) - owner.SetName(data.name); + if (data.nsamples == 0) { + JOptionPane.showMessageDialog(owner, + "No Flight Data Present", + "Empty Log", + JOptionPane.WARNING_MESSAGE); + } else { + status_value.setText("Received MicroPeak Data"); + owner = owner.SetData(data); + MicroSave save = new MicroSave(owner, data); + if (save.runDialog()) + owner.SetName(data.name); + } } else { JOptionPane.showMessageDialog(owner, "Download Failed", "Flight data corrupted", JOptionPane.ERROR_MESSAGE); } + setVisible(false); + dispose(); } public void drain_queue() { @@ -151,6 +158,7 @@ public class MicroDownload extends AltosUIDialog implements Runnable, ActionList } catch (MicroData.NonHexcharException nhe) { } } + write_thread.join(); } catch (FileNotFoundException fe) { } catch (IOException ioe) { } catch (InterruptedException ie) { @@ -161,16 +169,34 @@ public class MicroDownload extends AltosUIDialog implements Runnable, ActionList } Thread serial_thread; + Thread write_thread; + + public class SerialWriter implements Runnable { + MicroSerial serial; + + public void run () { + try { + Thread.sleep(100); + serial.write('l'); + serial.write('\n'); + serial.flush(); + } catch (InterruptedException ie) { + } + } - public void start() { - try { - serial = new MicroSerial(device); - serial.set_log(this); - } catch (FileNotFoundException fe) { - return; + public SerialWriter(MicroSerial serial) { + this.serial = serial; } + } + + public void start() { + serial.set_log(this); serial_thread = new Thread(this); serial_thread.start(); + + SerialWriter writer = new SerialWriter(serial); + write_thread = new Thread(writer); + write_thread.start(); } public void actionPerformed(ActionEvent ae) { @@ -181,7 +207,7 @@ public class MicroDownload extends AltosUIDialog implements Runnable, ActionList setVisible(false); } - public MicroDownload(MicroPeak owner, AltosDevice device) { + public MicroDownload(MicroPeak owner, AltosDevice device, MicroSerial serial) { super (owner, "Download MicroPeak Data", false); int y = 0; @@ -192,8 +218,9 @@ public class MicroDownload extends AltosUIDialog implements Runnable, ActionList this.owner = owner; this.device = device; + this.serial = serial; - pane = getContentPane(); + pane = getScrollablePane(); pane.setLayout(new GridBagLayout()); c = new GridBagConstraints();