From d83587c3c66b730cc54ca153714eee520ee40b2c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 1 Jan 2013 15:30:11 -0800 Subject: micropeak is code complete now. Added save and download functionality. Removed 'new' from file menu. Signed-off-by: Keith Packard --- micropeak/MicroDownload.java | 139 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 micropeak/MicroDownload.java (limited to 'micropeak/MicroDownload.java') diff --git a/micropeak/MicroDownload.java b/micropeak/MicroDownload.java new file mode 100644 index 00000000..2e328b4a --- /dev/null +++ b/micropeak/MicroDownload.java @@ -0,0 +1,139 @@ +/* + * Copyright © 2012 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.micropeak; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.io.*; +import java.util.concurrent.*; +import java.util.*; +import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; + +public class MicroDownload extends AltosUIDialog implements Runnable, ActionListener { + MicroPeak owner; + Container pane; + AltosDevice device; + JButton cancel; + MicroData data; + MicroSerial serial; + + private void done_internal() { + setVisible(false); + if (data != null) { + owner = owner.SetData(data); + MicroSave save = new MicroSave(owner, data); + if (save.runDialog()) + owner.SetName(data.name); + } + dispose(); + } + + public void done() { + Runnable r = new Runnable() { + public void run() { + try { + done_internal(); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + public void run() { + try { + data = new MicroData(serial, device.toShortString()); + serial.close(); + } catch (FileNotFoundException fe) { + } catch (IOException ioe) { + } catch (InterruptedException ie) { + } + done(); + } + + Thread serial_thread; + + public void start() { + try { + serial = new MicroSerial(device); + } catch (FileNotFoundException fe) { + return; + } + serial_thread = new Thread(this); + serial_thread.start(); + } + + public void actionPerformed(ActionEvent ae) { + System.out.printf ("command %s\n", ae.getActionCommand()); + if (serial_thread != null) { + System.out.printf ("Interrupting serial_thread\n"); + serial.close(); + serial_thread.interrupt(); + } + } + + public MicroDownload(MicroPeak owner, AltosDevice device) { + super (owner, "Download MicroPeak Data", false); + + GridBagConstraints c; + Insets il = new Insets(4,4,4,4); + Insets ir = new Insets(4,4,4,4); + + this.owner = owner; + this.device = device; + + 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; + JLabel device_label = new JLabel("Device:"); + pane.add(device_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; + JLabel device_value = new JLabel(device.toString()); + pane.add(device_value, c); + + cancel = new JButton("Cancel"); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + c.gridx = 0; c.gridy = 1; + c.gridwidth = GridBagConstraints.REMAINDER; + Insets ic = new Insets(4,4,4,4); + c.insets = ic; + pane.add(cancel, c); + + cancel.addActionListener(this); + + pack(); + setLocationRelativeTo(owner); + setVisible(true); + this.start(); + } +} -- cgit v1.2.3 From 4dae5b876b089c17c87c72df2ad2fa5ec4f1657c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 1 Jan 2013 23:03:29 -0800 Subject: Build micropeak by default Signed-off-by: Keith Packard --- Makefile.am | 2 +- micropeak/MicroDownload.java | 2 -- micropeak/MicroUSB.java | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) (limited to 'micropeak/MicroDownload.java') diff --git a/Makefile.am b/Makefile.am index e8945d90..7328c04e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS=src doc altoslib libaltos altosuilib altosui ao-tools ao-utils altosdroid +SUBDIRS=src doc altoslib libaltos altosuilib altosui micropeak ao-tools ao-utils altosdroid EXTRA_DIST = ChangeLog diff --git a/micropeak/MicroDownload.java b/micropeak/MicroDownload.java index 2e328b4a..e04d6790 100644 --- a/micropeak/MicroDownload.java +++ b/micropeak/MicroDownload.java @@ -81,9 +81,7 @@ public class MicroDownload extends AltosUIDialog implements Runnable, ActionList } public void actionPerformed(ActionEvent ae) { - System.out.printf ("command %s\n", ae.getActionCommand()); if (serial_thread != null) { - System.out.printf ("Interrupting serial_thread\n"); serial.close(); serial_thread.interrupt(); } diff --git a/micropeak/MicroUSB.java b/micropeak/MicroUSB.java index 244f7bc0..908ac51b 100644 --- a/micropeak/MicroUSB.java +++ b/micropeak/MicroUSB.java @@ -98,7 +98,6 @@ public class MicroUSB extends altos_device implements AltosDevice { MicroUSB device = new MicroUSB(); if (libaltos.altos_list_next(list, device) == 0) break; - System.out.printf("Device %s\n", device.toString()); if (device.isMicro()) device_list.add(device); } -- cgit v1.2.3 From 103eaa674be7582437aa850f0fd82788e10f244b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 1 Jan 2013 23:10:04 -0800 Subject: micropeak: Check CRC on downloaded Signed-off-by: Keith Packard --- micropeak/MicroDownload.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'micropeak/MicroDownload.java') diff --git a/micropeak/MicroDownload.java b/micropeak/MicroDownload.java index e04d6790..28a7550d 100644 --- a/micropeak/MicroDownload.java +++ b/micropeak/MicroDownload.java @@ -37,10 +37,17 @@ public class MicroDownload extends AltosUIDialog implements Runnable, ActionList private void done_internal() { setVisible(false); if (data != null) { - owner = owner.SetData(data); - MicroSave save = new MicroSave(owner, data); - if (save.runDialog()) - owner.SetName(data.name); + if (data.crc_valid) { + owner = owner.SetData(data); + MicroSave save = new MicroSave(owner, data); + if (save.runDialog()) + owner.SetName(data.name); + } else { + JOptionPane.showMessageDialog(owner, + "Flight data corrupted", + "Download Failed", + JOptionPane.ERROR_MESSAGE); + } } dispose(); } -- cgit v1.2.3