From bf8e1b6eecb2bae12ffdbd730bd6ec12ccdaf23a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 25 Dec 2012 14:23:29 -0800 Subject: Start building MicroPeak GUI tool Download, save and analyze MicroPeak flight data Signed-off-by: Keith Packard --- micropeak/Makefile.am | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 micropeak/Makefile.am (limited to 'micropeak/Makefile.am') diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am new file mode 100644 index 00000000..a3ecac72 --- /dev/null +++ b/micropeak/Makefile.am @@ -0,0 +1,115 @@ +JAVAROOT=classes +AM_JAVACFLAGS=-encoding UTF-8 -Xlint:deprecation + +CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../altoslib/*:../libaltos:$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" + +bin_SCRIPTS=micropeak + +micropeakdir=$(datadir)/java + +micropeak_JAVA= \ + MicroPeak.java \ + MicroData.java \ + MicroGraph.java \ + MicroSerial.java \ + MicroUSB.java + +JFREECHART_CLASS= \ + jfreechart.jar + +JCOMMON_CLASS=\ + jcommon.jar + +JAR=micropeak.jar + +FATJAR=micropeak-fat.jar + +LIBALTOS= \ + libaltos.so \ + libaltos.dylib \ + altos.dll + +ALTOSLIB_CLASS=\ + AltosLib.jar + +all-local: micropeak-test $(JAR) + +clean-local: + -rm -rf classes $(JAR) $(FATJAR) \ + $(ALTOSLIB_CLASS) \ + $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) Manifest.txt \ + micropeak micropeak-test macosx linux windows + +micropeak: Makefile + echo "#!/bin/sh" > $@ + echo 'exec java -cp "$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" -Djava.library.path="$(altoslibdir)" -jar "$(micropeakdir)/micropeak.jar" "$$@"' >> $@ + chmod +x $@ + +micropeak-test: Makefile + echo "#!/bin/sh" > $@ + echo 'exec java -cp "./*:../libaltos/*:$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" -Djava.library.path="../libaltos/.libs" -jar micropeak.jar "$$@"' >> $@ + chmod +x $@ + +$(JAR): classmicropeak.stamp Manifest.txt $(JAVA_ICONS) $(ALTOSLIB_CLASS) + jar cfm $@ Manifest.txt \ + $(ICONJAR) \ + -C classes org \ + -C ../libaltos libaltosJNI + +$(FATJAR): classmicropeak.stamp Manifest-fat.txt $(ALTOSLIB_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(JAVA_ICONS) + jar cfm $@ Manifest-fat.txt \ + $(ICONJAR) \ + -C classes org \ + -C ../libaltos libaltosJNI + + +libaltos.so: build-libaltos + -rm -f "$@" + $(LN_S) ../libaltos/.libs/"$@" . + +libaltos.dylib: + -rm -f "$@" + $(LN_S) ../libaltos/"$@" . + +altos.dll: ../libaltos/altos.dll + -rm -f "$@" + $(LN_S) ../libaltos/"$@" . + +altos64.dll: ../libaltos/altos64.dll + -rm -f "$@" + $(LN_S) ../libaltos/"$@" . + +../libaltos/.libs/libaltos.so: build-libaltos + +../libaltos/altos.dll: build-altos-dll + +../libaltos/altos64.dll: build-altos64-dll + +build-libaltos: + +cd ../libaltos && make libaltos.la +build-altos-dll: + +cd ../libaltos && make altos.dll + +build-altos64-dll: + +cd ../libaltos && make altos64.dll + +$(ALTOSLIB_CLASS): + -rm -f "$@" + $(LN_S) ../altoslib/"$@" . + +$(JFREECHART_CLASS): + -rm -f "$@" + $(LN_S) "$(JFREECHART)"/"$@" . + +$(JCOMMON_CLASS): + -rm -f "$@" + $(LN_S) "$(JCOMMON)"/"$@" . + +Manifest.txt: Makefile + echo 'Main-Class: org.altusmetrum.micropeak.MicroPeak' > $@ + echo "Class-Path: AltosLib.jar $(JCOMMON)/jcommon.jar $(JFREECHART)/jfreechart.jar" >> $@ + +Manifest-fat.txt: + echo 'Main-Class: org.altusmetrum.micropeak.MicroPeak' > $@ + echo "Class-Path: AltosLib.jar jcommon.jar jfreechart.jar" >> $@ + -- cgit v1.2.3 From 9da9adc2718928de2af65a68cddbcc636cc3e9e8 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 25 Dec 2012 14:45:49 -0800 Subject: Add file chooser for MicroPeak Needs reasonable directory tracking Signed-off-by: Keith Packard --- micropeak/Makefile.am | 1 + micropeak/MicroFileChooser.java | 65 +++++++++++++++++++++++++++++++++++++++++ micropeak/MicroGraph.java | 19 +++++++----- micropeak/MicroPeak.java | 57 +++++++++++++++++++++--------------- 4 files changed, 111 insertions(+), 31 deletions(-) create mode 100644 micropeak/MicroFileChooser.java (limited to 'micropeak/Makefile.am') diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index a3ecac72..32be9070 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -12,6 +12,7 @@ micropeak_JAVA= \ MicroData.java \ MicroGraph.java \ MicroSerial.java \ + MicroFileChooser.java \ MicroUSB.java JFREECHART_CLASS= \ diff --git a/micropeak/MicroFileChooser.java b/micropeak/MicroFileChooser.java new file mode 100644 index 00000000..0fd63a27 --- /dev/null +++ b/micropeak/MicroFileChooser.java @@ -0,0 +1,65 @@ +/* + * 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 javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import java.io.*; +import org.altusmetrum.AltosLib.*; + +public class MicroFileChooser extends JFileChooser { + JFrame frame; + String filename; + File file; + + public String filename() { + return filename; + } + + public File file() { + return file; + } + + public InputStream runDialog() { + int ret; + + ret = showOpenDialog(frame); + if (ret == APPROVE_OPTION) { + file = getSelectedFile(); + if (file == null) + return null; + filename = file.getName(); + try { + return new FileInputStream(file); + } catch (FileNotFoundException fe) { + JOptionPane.showMessageDialog(frame, + fe.getMessage(), + "Cannot open file", + JOptionPane.ERROR_MESSAGE); + } + } + return null; + } + + public MicroFileChooser(JFrame in_frame) { + frame = in_frame; + setDialogTitle("Select MicroPeak Data File"); + setFileFilter(new FileNameExtensionFilter("MicroPeak data file", + "mpd")); + } +} diff --git a/micropeak/MicroGraph.java b/micropeak/MicroGraph.java index aac14b9a..9192cad9 100644 --- a/micropeak/MicroGraph.java +++ b/micropeak/MicroGraph.java @@ -65,6 +65,18 @@ public class MicroGraph { plot.mapDatasetToRangeAxis(index, index); } + public void setData (MicroData data) { + heightSeries.clear(); + speedSeries.clear(); + accelSeries.clear(); + for (int i = 0; i < data.pressures.length; i++) { + double x = data.time(i); + heightSeries.add(x, data.height(i)); + speedSeries.add(x, data.speed(i)); + accelSeries.add(x, data.acceleration(i)); + } + } + public MicroGraph(MicroData data) { this.data = data; @@ -73,13 +85,6 @@ public class MicroGraph { speedSeries = new XYSeries("Speed"); accelSeries = new XYSeries("Acceleration"); - for (int i = 0; i < data.pressures.length; i++) { - double x = data.time(i); - heightSeries.add(x, data.height(i)); - speedSeries.add(x, data.speed(i)); - accelSeries.add(x, data.acceleration(i)); - } - xAxis = new NumberAxis("Time (s)"); xAxis.setAutoRangeIncludesZero(true); diff --git a/micropeak/MicroPeak.java b/micropeak/MicroPeak.java index 82d926fb..cd09c475 100644 --- a/micropeak/MicroPeak.java +++ b/micropeak/MicroPeak.java @@ -32,24 +32,31 @@ public class MicroPeak extends JFrame implements ActionListener, ItemListener { MicroData data; Container pane; + private void RunFile(InputStream input) { + try { + data = new MicroData(input); + graph.setData(data); + } catch (IOException ioe) { + } + try { + input.close(); + } catch (IOException ioe) { + } + } + private void OpenFile(File filename) { try { - FileInputStream input = new FileInputStream(filename); - try { - data = new MicroData(input); - graph = new MicroGraph(data); - pane.add(graph.panel); - } catch (IOException ioe) { - } - try { - input.close(); - } catch (IOException ioe) { - } + RunFile (new FileInputStream(filename)); } catch (FileNotFoundException fne) { } } private void SelectFile() { + MicroFileChooser chooser = new MicroFileChooser(this); + InputStream input = chooser.runDialog(); + + if (input != null) + RunFile(input); } private void DownloadData() { @@ -73,17 +80,12 @@ public class MicroPeak extends JFrame implements ActionListener, ItemListener { public void itemStateChanged(ItemEvent e) { } - public MicroPeak(File filename) { + public MicroPeak() { this.filename = filename; pane = getContentPane(); -// JLabel label = new JLabel ("Hello, World"); -// pane.add(label); - - setSize(800, 500); - setTitle("MicroPeak"); JMenuBar menuBar = new JMenuBar(); @@ -116,20 +118,27 @@ public class MicroPeak extends JFrame implements ActionListener, ItemListener { } }); - if (filename != null) - this.OpenFile(filename); + graph = new MicroGraph(data); + pane.add(graph.panel); + pane.doLayout(); + pane.validate(); + doLayout(); + validate(); + Insets i = getInsets(); + Dimension ps = pane.getPreferredSize(); + ps.width += i.left + i.right; + ps.height += i.top + i.bottom; + setPreferredSize(ps); + setSize(ps); setVisible(true); } - public MicroPeak() { - this(null); - } - public static void main(final String[] args) { boolean opened = false; for (int i = 0; i < args.length; i++) { - new MicroPeak(new File(args[i])); + MicroPeak m = new MicroPeak(); + m.OpenFile(new File(args[i])); opened = true; } if (!opened) -- cgit v1.2.3 From daf8776f8646ba187f1a17f7aae797503bed3f2a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 28 Dec 2012 16:34:48 -0800 Subject: Lots more work on the MicroPeak application Signed-off-by: Keith Packard --- icon/micropeak-128.png | Bin 0 -> 4394 bytes icon/micropeak-16.png | Bin 0 -> 534 bytes icon/micropeak-256.png | Bin 0 -> 8055 bytes icon/micropeak-32.png | Bin 0 -> 1072 bytes icon/micropeak-48.png | Bin 0 -> 1662 bytes icon/micropeak-64.png | Bin 0 -> 2240 bytes micropeak/Makefile.am | 24 ++++ micropeak/MicroFontListener.java | 22 ++++ micropeak/MicroFrame.java | 74 +++++++++++ micropeak/MicroPeak.java | 2 +- micropeak/MicroPreferences.java | 221 +++++++++++++++++++++++++++++++++ micropeak/MicroPreferencesBackend.java | 101 +++++++++++++++ micropeak/MicroSerial.java | 5 +- micropeak/MicroUIListener.java | 22 ++++ 14 files changed, 469 insertions(+), 2 deletions(-) create mode 100644 icon/micropeak-128.png create mode 100644 icon/micropeak-16.png create mode 100644 icon/micropeak-256.png create mode 100644 icon/micropeak-32.png create mode 100644 icon/micropeak-48.png create mode 100644 icon/micropeak-64.png create mode 100644 micropeak/MicroFontListener.java create mode 100644 micropeak/MicroFrame.java create mode 100644 micropeak/MicroPreferences.java create mode 100644 micropeak/MicroPreferencesBackend.java create mode 100644 micropeak/MicroUIListener.java (limited to 'micropeak/Makefile.am') diff --git a/icon/micropeak-128.png b/icon/micropeak-128.png new file mode 100644 index 00000000..f045dc6a Binary files /dev/null and b/icon/micropeak-128.png differ diff --git a/icon/micropeak-16.png b/icon/micropeak-16.png new file mode 100644 index 00000000..d8140802 Binary files /dev/null and b/icon/micropeak-16.png differ diff --git a/icon/micropeak-256.png b/icon/micropeak-256.png new file mode 100644 index 00000000..b96d4706 Binary files /dev/null and b/icon/micropeak-256.png differ diff --git a/icon/micropeak-32.png b/icon/micropeak-32.png new file mode 100644 index 00000000..d34c5c12 Binary files /dev/null and b/icon/micropeak-32.png differ diff --git a/icon/micropeak-48.png b/icon/micropeak-48.png new file mode 100644 index 00000000..86dc4f7f Binary files /dev/null and b/icon/micropeak-48.png differ diff --git a/icon/micropeak-64.png b/icon/micropeak-64.png new file mode 100644 index 00000000..6ca7c2eb Binary files /dev/null and b/icon/micropeak-64.png differ diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index 32be9070..2cfd2ad3 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -10,9 +10,14 @@ micropeakdir=$(datadir)/java micropeak_JAVA= \ MicroPeak.java \ MicroData.java \ + MicroFrame.java \ MicroGraph.java \ MicroSerial.java \ MicroFileChooser.java \ + MicroPreferences.java \ + MicroPreferencesBackend.java \ + MicroFontListener.java \ + MicroUIListener.java \ MicroUSB.java JFREECHART_CLASS= \ @@ -33,6 +38,25 @@ LIBALTOS= \ ALTOSLIB_CLASS=\ AltosLib.jar +# Icons +ICONDIR=$(top_srcdir)/icon + +JAVA_ICONS=\ + $(ICONDIR)/micropeak-16.png \ + $(ICONDIR)/micropeak-32.png \ + $(ICONDIR)/micropeak-48.png \ + $(ICONDIR)/micropeak-64.png \ + $(ICONDIR)/micropeak-128.png \ + $(ICONDIR)/micropeak-256.png + +# icon base names for jar +ICONJAR= -C $(ICONDIR) micropeak-16.png \ + -C $(ICONDIR) micropeak-32.png \ + -C $(ICONDIR) micropeak-48.png \ + -C $(ICONDIR) micropeak-64.png \ + -C $(ICONDIR) micropeak-128.png \ + -C $(ICONDIR) micropeak-256.png + all-local: micropeak-test $(JAR) clean-local: diff --git a/micropeak/MicroFontListener.java b/micropeak/MicroFontListener.java new file mode 100644 index 00000000..a902584c --- /dev/null +++ b/micropeak/MicroFontListener.java @@ -0,0 +1,22 @@ +/* + * 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.micropeak; + +public interface MicroFontListener { + void font_size_changed(int font_size); +} diff --git a/micropeak/MicroFrame.java b/micropeak/MicroFrame.java new file mode 100644 index 00000000..a9b9a37a --- /dev/null +++ b/micropeak/MicroFrame.java @@ -0,0 +1,74 @@ +/* + * 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.micropeak; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.util.*; + +class MicroFrameListener extends WindowAdapter { + public void windowClosing (WindowEvent e) { + MicroPreferences.unregister_ui_listener((MicroFrame) e.getWindow()); + } +} + +public class MicroFrame extends JFrame implements MicroUIListener { + + public void ui_changed(String look_and_feel) { + SwingUtilities.updateComponentTreeUI(this); + this.pack(); + } + + static final String[] icon_names = { + "/micropeak-16.png", + "/micropeak-32.png", + "/micropeak-48.png", + "/micropeak-64.png", + "/micropeak-128.png", + "/micropeak-256.png" + }; + + public void set_icon() { + ArrayList icons = new ArrayList(); + + for (int i = 0; i < icon_names.length; i++) { + java.net.URL imgURL = MicroPeak.class.getResource(icon_names[i]); + if (imgURL != null) + icons.add(new ImageIcon(imgURL).getImage()); + } + + setIconImages(icons); + } + + public MicroFrame() { + super(); + MicroPreferences.set_component(this); + MicroPreferences.register_ui_listener(this); + addWindowListener(new MicroFrameListener()); + set_icon(); + } + + public MicroFrame(String name) { + super(name); + MicroPreferences.set_component(this); + MicroPreferences.register_ui_listener(this); + addWindowListener(new MicroFrameListener()); + set_icon(); + } +} diff --git a/micropeak/MicroPeak.java b/micropeak/MicroPeak.java index cd09c475..c9074348 100644 --- a/micropeak/MicroPeak.java +++ b/micropeak/MicroPeak.java @@ -25,7 +25,7 @@ import java.util.concurrent.*; import java.util.*; import org.altusmetrum.AltosLib.*; -public class MicroPeak extends JFrame implements ActionListener, ItemListener { +public class MicroPeak extends MicroFrame implements ActionListener, ItemListener { File filename; MicroGraph graph; diff --git a/micropeak/MicroPreferences.java b/micropeak/MicroPreferences.java new file mode 100644 index 00000000..70c2557c --- /dev/null +++ b/micropeak/MicroPreferences.java @@ -0,0 +1,221 @@ +/* + * 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.micropeak; + +import java.io.*; +import java.util.*; +import java.awt.Component; +import javax.swing.*; +import java.awt.*; +import org.altusmetrum.AltosLib.*; + +public class MicroPreferences extends AltosPreferences { + + static final int tab_elt_pad = 5; + + static Font label_font; + static Font value_font; + static Font status_font; + static Font table_label_font; + static Font table_value_font; + + final static int font_size_small = 1; + final static int font_size_medium = 2; + final static int font_size_large = 3; + + static void set_fonts(int size) { + int brief_size; + int table_size; + int status_size; + + switch (size) { + case font_size_small: + brief_size = 16; + status_size = 18; + table_size = 11; + break; + default: + case font_size_medium: + brief_size = 22; + status_size = 24; + table_size = 14; + break; + case font_size_large: + brief_size = 26; + status_size = 30; + table_size = 17; + break; + } + label_font = new Font("Dialog", Font.PLAIN, brief_size); + value_font = new Font("Monospaced", Font.PLAIN, brief_size); + status_font = new Font("SansSerif", Font.BOLD, status_size); + table_label_font = new Font("SansSerif", Font.PLAIN, table_size); + table_value_font = new Font("Monospaced", Font.PLAIN, table_size); + } + + /* font size preferences name */ + final static String fontSizePreference = "FONT-SIZE"; + + /* Look&Feel preference name */ + final static String lookAndFeelPreference = "LOOK-AND-FEEL"; + + /* UI Component to pop dialogs up */ + static Component component; + + static LinkedList font_listeners; + + static int font_size = font_size_medium; + + static LinkedList ui_listeners; + + static String look_and_feel = null; + + /* Serial debug */ + static boolean serial_debug; + + public static void init() { + AltosPreferences.init(new MicroPreferencesBackend()); + + font_listeners = new LinkedList(); + + font_size = backend.getInt(fontSizePreference, font_size_medium); + set_fonts(font_size); + look_and_feel = backend.getString(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName()); + + ui_listeners = new LinkedList(); + serial_debug = backend.getBoolean(serialDebugPreference, false); + } + + static { init(); } + + static void set_component(Component in_component) { + component = in_component; + } + + private static boolean check_dir(File dir) { + if (!dir.exists()) { + if (!dir.mkdirs()) { + JOptionPane.showMessageDialog(component, + dir.getName(), + "Cannot create directory", + JOptionPane.ERROR_MESSAGE); + return false; + } + } else if (!dir.isDirectory()) { + JOptionPane.showMessageDialog(component, + dir.getName(), + "Is not a directory", + JOptionPane.ERROR_MESSAGE); + return false; + } + return true; + } + + /* Configure the log directory. This is where all telemetry and eeprom files + * will be written to, and where replay will look for telemetry files + */ + public static void ConfigureLog() { + JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile()); + + logdir_chooser.setDialogTitle("Configure Data Logging Directory"); + logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + + if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) { + File dir = logdir_chooser.getSelectedFile(); + if (check_dir(dir)) + set_logdir(dir); + } + } + public static int font_size() { + synchronized (backend) { + return font_size; + } + } + + static void set_fonts() { + } + + public static void set_font_size(int new_font_size) { + synchronized (backend) { + font_size = new_font_size; + backend.putInt(fontSizePreference, font_size); + flush_preferences(); + set_fonts(font_size); + for (MicroFontListener l : font_listeners) + l.font_size_changed(font_size); + } + } + + public static void register_font_listener(MicroFontListener l) { + synchronized (backend) { + font_listeners.add(l); + } + } + + public static void unregister_font_listener(MicroFontListener l) { + synchronized (backend) { + font_listeners.remove(l); + } + } + + public static void set_look_and_feel(String new_look_and_feel) { + try { + UIManager.setLookAndFeel(new_look_and_feel); + } catch (Exception e) { + } + synchronized(backend) { + look_and_feel = new_look_and_feel; + backend.putString(lookAndFeelPreference, look_and_feel); + flush_preferences(); + for (MicroUIListener l : ui_listeners) + l.ui_changed(look_and_feel); + } + } + + public static String look_and_feel() { + synchronized (backend) { + return look_and_feel; + } + } + + public static void register_ui_listener(MicroUIListener l) { + synchronized(backend) { + ui_listeners.add(l); + } + } + + public static void unregister_ui_listener(MicroUIListener l) { + synchronized (backend) { + ui_listeners.remove(l); + } + } + public static void set_serial_debug(boolean new_serial_debug) { + synchronized (backend) { + serial_debug = new_serial_debug; + backend.putBoolean(serialDebugPreference, serial_debug); + flush_preferences(); + } + } + + public static boolean serial_debug() { + synchronized (backend) { + return serial_debug; + } + } + +} diff --git a/micropeak/MicroPreferencesBackend.java b/micropeak/MicroPreferencesBackend.java new file mode 100644 index 00000000..7d92f6be --- /dev/null +++ b/micropeak/MicroPreferencesBackend.java @@ -0,0 +1,101 @@ +/* + * Copyright © 2012 Mike Beattie + * + * 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.io.File; +import java.util.prefs.*; +import org.altusmetrum.AltosLib.*; +import javax.swing.filechooser.FileSystemView; + +public class MicroPreferencesBackend implements AltosPreferencesBackend { + + private Preferences _preferences = null; + + public MicroPreferencesBackend() { + _preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); + } + + public MicroPreferencesBackend(Preferences in_preferences) { + _preferences = in_preferences; + } + + public String getString(String key, String def) { + return _preferences.get(key, def); + } + public void putString(String key, String value) { + _preferences.put(key, value); + } + + public int getInt(String key, int def) { + return _preferences.getInt(key, def); + } + public void putInt(String key, int value) { + _preferences.putInt(key, value); + } + + public double getDouble(String key, double def) { + return _preferences.getDouble(key, def); + } + public void putDouble(String key, double value) { + _preferences.putDouble(key, value); + } + + public boolean getBoolean(String key, boolean def) { + return _preferences.getBoolean(key, def); + } + public void putBoolean(String key, boolean value) { + _preferences.putBoolean(key, value); + } + + public boolean nodeExists(String key) { + try { + return _preferences.nodeExists(key); + } catch (BackingStoreException be) { + return false; + } + } + + public AltosPreferencesBackend node(String key) { + return new MicroPreferencesBackend(_preferences.node(key)); + } + + public String[] keys() { + try { + return _preferences.keys(); + } catch (BackingStoreException be) { + return null; + } + } + + public void remove(String key) { + _preferences.remove(key); + } + + public void flush() { + try { + _preferences.flush(); + } catch (BackingStoreException ee) { + System.err.printf("Cannot save preferences\n"); + } + } + + public File homeDirectory() { + /* Use the file system view default directory */ + return FileSystemView.getFileSystemView().getDefaultDirectory(); + } +} diff --git a/micropeak/MicroSerial.java b/micropeak/MicroSerial.java index afe55532..8546276e 100644 --- a/micropeak/MicroSerial.java +++ b/micropeak/MicroSerial.java @@ -24,7 +24,10 @@ public class MicroSerial extends InputStream { SWIGTYPE_p_altos_file file; public int read() { - return libaltos.altos_getchar(file, 0); + int c = libaltos.altos_getchar(file, 0); + if (MicroPreferences.serial_debug) + System.out.printf("%c", c); + return c; } public void close() { diff --git a/micropeak/MicroUIListener.java b/micropeak/MicroUIListener.java new file mode 100644 index 00000000..9aed8dae --- /dev/null +++ b/micropeak/MicroUIListener.java @@ -0,0 +1,22 @@ +/* + * 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.micropeak; + +public interface MicroUIListener { + public void ui_changed(String look_and_feel); +} -- cgit v1.2.3 From 56a1210a7b04a3623d19ec282f26fecc79c126dd Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 31 Dec 2012 11:42:57 -0800 Subject: micropeak: Use altosuilib This removes a pile of code stolen from altosui Signed-off-by: Keith Packard --- micropeak/.gitignore | 6 + micropeak/Makefile.am | 22 ++-- micropeak/MicroFileChooser.java | 2 + micropeak/MicroFontListener.java | 22 ---- micropeak/MicroFrame.java | 45 +------ micropeak/MicroGraph.java | 82 +++++++++--- micropeak/MicroPeak.java | 21 +++- micropeak/MicroPreferences.java | 221 --------------------------------- micropeak/MicroPreferencesBackend.java | 101 --------------- micropeak/MicroSerial.java | 4 +- micropeak/MicroUIListener.java | 22 ---- 11 files changed, 109 insertions(+), 439 deletions(-) create mode 100644 micropeak/.gitignore delete mode 100644 micropeak/MicroFontListener.java delete mode 100644 micropeak/MicroPreferences.java delete mode 100644 micropeak/MicroPreferencesBackend.java delete mode 100644 micropeak/MicroUIListener.java (limited to 'micropeak/Makefile.am') diff --git a/micropeak/.gitignore b/micropeak/.gitignore new file mode 100644 index 00000000..fc99b31c --- /dev/null +++ b/micropeak/.gitignore @@ -0,0 +1,6 @@ +*.jar +Manifest.txt +classes +*.stamp +micropeak +micropeak-test diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index 2cfd2ad3..fde981a6 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -1,7 +1,7 @@ JAVAROOT=classes AM_JAVACFLAGS=-encoding UTF-8 -Xlint:deprecation -CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../altoslib/*:../libaltos:$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" +CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../altoslib/*:../altosuilib/*:../libaltos:$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" bin_SCRIPTS=micropeak @@ -14,10 +14,6 @@ micropeak_JAVA= \ MicroGraph.java \ MicroSerial.java \ MicroFileChooser.java \ - MicroPreferences.java \ - MicroPreferencesBackend.java \ - MicroFontListener.java \ - MicroUIListener.java \ MicroUSB.java JFREECHART_CLASS= \ @@ -38,6 +34,9 @@ LIBALTOS= \ ALTOSLIB_CLASS=\ AltosLib.jar +ALTOSUILIB_CLASS=\ + AltosUILib.jar + # Icons ICONDIR=$(top_srcdir)/icon @@ -62,6 +61,7 @@ all-local: micropeak-test $(JAR) clean-local: -rm -rf classes $(JAR) $(FATJAR) \ $(ALTOSLIB_CLASS) \ + $(ALTOSUILIB_CLASS) \ $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) Manifest.txt \ micropeak micropeak-test macosx linux windows @@ -75,13 +75,13 @@ micropeak-test: Makefile echo 'exec java -cp "./*:../libaltos/*:$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" -Djava.library.path="../libaltos/.libs" -jar micropeak.jar "$$@"' >> $@ chmod +x $@ -$(JAR): classmicropeak.stamp Manifest.txt $(JAVA_ICONS) $(ALTOSLIB_CLASS) +$(JAR): classmicropeak.stamp Manifest.txt $(JAVA_ICONS) $(ALTOSLIB_CLASS) $(ALTOSUILIB_CLASS) jar cfm $@ Manifest.txt \ $(ICONJAR) \ -C classes org \ -C ../libaltos libaltosJNI -$(FATJAR): classmicropeak.stamp Manifest-fat.txt $(ALTOSLIB_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(JAVA_ICONS) +$(FATJAR): classmicropeak.stamp Manifest-fat.txt $(ALTOSLIB_CLASS) $(ALTOSUILIB_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(JAVA_ICONS) jar cfm $@ Manifest-fat.txt \ $(ICONJAR) \ -C classes org \ @@ -122,6 +122,10 @@ $(ALTOSLIB_CLASS): -rm -f "$@" $(LN_S) ../altoslib/"$@" . +$(ALTOSUILIB_CLASS): + -rm -f "$@" + $(LN_S) ../altosuilib/"$@" . + $(JFREECHART_CLASS): -rm -f "$@" $(LN_S) "$(JFREECHART)"/"$@" . @@ -132,9 +136,9 @@ $(JCOMMON_CLASS): Manifest.txt: Makefile echo 'Main-Class: org.altusmetrum.micropeak.MicroPeak' > $@ - echo "Class-Path: AltosLib.jar $(JCOMMON)/jcommon.jar $(JFREECHART)/jfreechart.jar" >> $@ + echo "Class-Path: AltosLib.jar AltosUILib.jar $(JCOMMON)/jcommon.jar $(JFREECHART)/jfreechart.jar" >> $@ Manifest-fat.txt: echo 'Main-Class: org.altusmetrum.micropeak.MicroPeak' > $@ - echo "Class-Path: AltosLib.jar jcommon.jar jfreechart.jar" >> $@ + echo "Class-Path: AltosLib.jar AltosUILib.jar jcommon.jar jfreechart.jar" >> $@ diff --git a/micropeak/MicroFileChooser.java b/micropeak/MicroFileChooser.java index 0fd63a27..d2540987 100644 --- a/micropeak/MicroFileChooser.java +++ b/micropeak/MicroFileChooser.java @@ -21,6 +21,7 @@ import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.io.*; import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; public class MicroFileChooser extends JFileChooser { JFrame frame; @@ -61,5 +62,6 @@ public class MicroFileChooser extends JFileChooser { setDialogTitle("Select MicroPeak Data File"); setFileFilter(new FileNameExtensionFilter("MicroPeak data file", "mpd")); + setCurrentDirectory(AltosUIPreferences.logdir()); } } diff --git a/micropeak/MicroFontListener.java b/micropeak/MicroFontListener.java deleted file mode 100644 index a902584c..00000000 --- a/micropeak/MicroFontListener.java +++ /dev/null @@ -1,22 +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 org.altusmetrum.micropeak; - -public interface MicroFontListener { - void font_size_changed(int font_size); -} diff --git a/micropeak/MicroFrame.java b/micropeak/MicroFrame.java index a9b9a37a..03e3af0c 100644 --- a/micropeak/MicroFrame.java +++ b/micropeak/MicroFrame.java @@ -21,21 +21,10 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; +import org.altusmetrum.altosuilib.*; -class MicroFrameListener extends WindowAdapter { - public void windowClosing (WindowEvent e) { - MicroPreferences.unregister_ui_listener((MicroFrame) e.getWindow()); - } -} - -public class MicroFrame extends JFrame implements MicroUIListener { - - public void ui_changed(String look_and_feel) { - SwingUtilities.updateComponentTreeUI(this); - this.pack(); - } - - static final String[] icon_names = { +public class MicroFrame extends AltosUIFrame { + static String[] micro_icon_names = { "/micropeak-16.png", "/micropeak-32.png", "/micropeak-48.png", @@ -44,31 +33,5 @@ public class MicroFrame extends JFrame implements MicroUIListener { "/micropeak-256.png" }; - public void set_icon() { - ArrayList icons = new ArrayList(); - - for (int i = 0; i < icon_names.length; i++) { - java.net.URL imgURL = MicroPeak.class.getResource(icon_names[i]); - if (imgURL != null) - icons.add(new ImageIcon(imgURL).getImage()); - } - - setIconImages(icons); - } - - public MicroFrame() { - super(); - MicroPreferences.set_component(this); - MicroPreferences.register_ui_listener(this); - addWindowListener(new MicroFrameListener()); - set_icon(); - } - - public MicroFrame(String name) { - super(name); - MicroPreferences.set_component(this); - MicroPreferences.register_ui_listener(this); - addWindowListener(new MicroFrameListener()); - set_icon(); - } + static { set_icon_names(micro_icon_names); } } diff --git a/micropeak/MicroGraph.java b/micropeak/MicroGraph.java index 9192cad9..38f54fe0 100644 --- a/micropeak/MicroGraph.java +++ b/micropeak/MicroGraph.java @@ -34,15 +34,47 @@ import org.jfree.chart.labels.*; import org.jfree.data.xy.*; import org.jfree.data.*; -public class MicroGraph { +class MicroSeries extends XYSeries { + NumberAxis axis; + String label; + String units; + Color color; + + String label() { + return String.format("%s (%s)", label, units); + } + + void set_units(String units) { + this.units = units; + + axis.setLabel(label()); + } + + public MicroSeries (String label, String units, Color color) { + super(label); + this.label = label; + this.units = units; + this.color = color; + + axis = new NumberAxis(label()); + axis.setLabelPaint(color); + axis.setTickLabelPaint(color); + } +} + +public class MicroGraph implements AltosUnitsListener { XYPlot plot; JFreeChart chart; ChartPanel panel; NumberAxis xAxis; - XYSeries heightSeries; - XYSeries speedSeries; - XYSeries accelSeries; + MicroSeries heightSeries; + MicroSeries speedSeries; + MicroSeries accelSeries; + + static final private Color red = new Color(194,31,31); + static final private Color green = new Color(31,194,31); + static final private Color blue = new Color(31,31,194); MicroData data; @@ -50,40 +82,50 @@ public class MicroGraph { return panel; } - private void addSeries(XYSeries series, int index, String label, String units) { + private MicroSeries addSeries(int index, String label, String units, Color color) { + MicroSeries series = new MicroSeries(label, units, color); XYSeriesCollection dataset = new XYSeriesCollection(series); - NumberAxis axis = new NumberAxis(String.format("%s (%s)", label, units)); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); + renderer.setSeriesPaint(0, color); renderer.setPlot(plot); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})", units), new java.text.DecimalFormat("0.00"), new java.text.DecimalFormat("0.00"))); - plot.setRangeAxis(index, axis); + plot.setRangeAxis(index, series.axis); plot.setDataset(index, dataset); plot.setRenderer(index, renderer); plot.mapDatasetToRangeAxis(index, index); + return series; } - public void setData (MicroData data) { + public void resetData() { heightSeries.clear(); speedSeries.clear(); accelSeries.clear(); for (int i = 0; i < data.pressures.length; i++) { double x = data.time(i); - heightSeries.add(x, data.height(i)); - speedSeries.add(x, data.speed(i)); - accelSeries.add(x, data.acceleration(i)); + heightSeries.add(x, AltosConvert.height.value(data.height(i))); + speedSeries.add(x, AltosConvert.speed.value(data.speed(i))); + accelSeries.add(x, AltosConvert.accel.value(data.acceleration(i))); } } - public MicroGraph(MicroData data) { - + public void setData (MicroData data) { this.data = data; + resetData(); + } - heightSeries = new XYSeries("Height"); - speedSeries = new XYSeries("Speed"); - accelSeries = new XYSeries("Acceleration"); + public void units_changed(boolean imperial_units) { + if (data != null) { + heightSeries.set_units(AltosConvert.height.show_units()); + speedSeries.set_units(AltosConvert.speed.show_units()); + accelSeries.set_units(AltosConvert.accel.show_units()); + resetData(); + } + } + + public MicroGraph() { xAxis = new NumberAxis("Time (s)"); @@ -95,9 +137,9 @@ public class MicroGraph { plot.setDomainPannable(true); plot.setRangePannable(true); - addSeries(heightSeries, 0, "Height", "m"); - addSeries(speedSeries, 1, "Speed", "m/s"); - addSeries(accelSeries, 2, "Acceleration", "m/s²"); + heightSeries = addSeries(0, "Height", AltosConvert.height.show_units(), red); + speedSeries = addSeries(1, "Speed", AltosConvert.speed.show_units(), green); + accelSeries = addSeries(2, "Acceleration", AltosConvert.accel.show_units(), blue); chart = new JFreeChart("Flight", JFreeChart.DEFAULT_TITLE_FONT, plot, true); @@ -106,5 +148,7 @@ public class MicroGraph { panel = new ChartPanel(chart); panel.setMouseWheelEnabled(true); panel.setPreferredSize(new java.awt.Dimension(800, 500)); + + AltosPreferences.register_units_listener(this); } } \ No newline at end of file diff --git a/micropeak/MicroPeak.java b/micropeak/MicroPeak.java index c9074348..463238c8 100644 --- a/micropeak/MicroPeak.java +++ b/micropeak/MicroPeak.java @@ -24,6 +24,7 @@ import java.io.*; import java.util.concurrent.*; import java.util.*; import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; public class MicroPeak extends MicroFrame implements ActionListener, ItemListener { @@ -59,6 +60,10 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene RunFile(input); } + private void Preferences() { + new AltosConfigureUI(this); + } + private void DownloadData() { java.util.List devices = MicroUSB.list(); for (MicroUSB device : devices) @@ -66,7 +71,6 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene } public void actionPerformed(ActionEvent ev) { - System.out.printf("action %s %s\n", ev.getActionCommand(), ev.paramString()); if ("Exit".equals(ev.getActionCommand())) System.exit(0); else if ("Open".equals(ev.getActionCommand())) @@ -75,6 +79,8 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene new MicroPeak(); else if ("Download".equals(ev.getActionCommand())) DownloadData(); + else if ("Preferences".equals(ev.getActionCommand())) + Preferences(); } public void itemStateChanged(ItemEvent e) { @@ -82,7 +88,7 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene public MicroPeak() { - this.filename = filename; + AltosUIPreferences.set_component(this); pane = getContentPane(); @@ -106,6 +112,10 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene fileMenu.add(downloadAction); downloadAction.addActionListener(this); + JMenuItem preferencesAction = new JMenuItem("Preferences"); + fileMenu.add(preferencesAction); + preferencesAction.addActionListener(this); + JMenuItem exitAction = new JMenuItem("Exit"); fileMenu.add(exitAction); exitAction.addActionListener(this); @@ -118,7 +128,7 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene } }); - graph = new MicroGraph(data); + graph = new MicroGraph(); pane.add(graph.panel); pane.doLayout(); pane.validate(); @@ -136,6 +146,11 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene public static void main(final String[] args) { boolean opened = false; + try { + UIManager.setLookAndFeel(AltosUIPreferences.look_and_feel()); + } catch (Exception e) { + } + for (int i = 0; i < args.length; i++) { MicroPeak m = new MicroPeak(); m.OpenFile(new File(args[i])); diff --git a/micropeak/MicroPreferences.java b/micropeak/MicroPreferences.java deleted file mode 100644 index 70c2557c..00000000 --- a/micropeak/MicroPreferences.java +++ /dev/null @@ -1,221 +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 org.altusmetrum.micropeak; - -import java.io.*; -import java.util.*; -import java.awt.Component; -import javax.swing.*; -import java.awt.*; -import org.altusmetrum.AltosLib.*; - -public class MicroPreferences extends AltosPreferences { - - static final int tab_elt_pad = 5; - - static Font label_font; - static Font value_font; - static Font status_font; - static Font table_label_font; - static Font table_value_font; - - final static int font_size_small = 1; - final static int font_size_medium = 2; - final static int font_size_large = 3; - - static void set_fonts(int size) { - int brief_size; - int table_size; - int status_size; - - switch (size) { - case font_size_small: - brief_size = 16; - status_size = 18; - table_size = 11; - break; - default: - case font_size_medium: - brief_size = 22; - status_size = 24; - table_size = 14; - break; - case font_size_large: - brief_size = 26; - status_size = 30; - table_size = 17; - break; - } - label_font = new Font("Dialog", Font.PLAIN, brief_size); - value_font = new Font("Monospaced", Font.PLAIN, brief_size); - status_font = new Font("SansSerif", Font.BOLD, status_size); - table_label_font = new Font("SansSerif", Font.PLAIN, table_size); - table_value_font = new Font("Monospaced", Font.PLAIN, table_size); - } - - /* font size preferences name */ - final static String fontSizePreference = "FONT-SIZE"; - - /* Look&Feel preference name */ - final static String lookAndFeelPreference = "LOOK-AND-FEEL"; - - /* UI Component to pop dialogs up */ - static Component component; - - static LinkedList font_listeners; - - static int font_size = font_size_medium; - - static LinkedList ui_listeners; - - static String look_and_feel = null; - - /* Serial debug */ - static boolean serial_debug; - - public static void init() { - AltosPreferences.init(new MicroPreferencesBackend()); - - font_listeners = new LinkedList(); - - font_size = backend.getInt(fontSizePreference, font_size_medium); - set_fonts(font_size); - look_and_feel = backend.getString(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName()); - - ui_listeners = new LinkedList(); - serial_debug = backend.getBoolean(serialDebugPreference, false); - } - - static { init(); } - - static void set_component(Component in_component) { - component = in_component; - } - - private static boolean check_dir(File dir) { - if (!dir.exists()) { - if (!dir.mkdirs()) { - JOptionPane.showMessageDialog(component, - dir.getName(), - "Cannot create directory", - JOptionPane.ERROR_MESSAGE); - return false; - } - } else if (!dir.isDirectory()) { - JOptionPane.showMessageDialog(component, - dir.getName(), - "Is not a directory", - JOptionPane.ERROR_MESSAGE); - return false; - } - return true; - } - - /* Configure the log directory. This is where all telemetry and eeprom files - * will be written to, and where replay will look for telemetry files - */ - public static void ConfigureLog() { - JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile()); - - logdir_chooser.setDialogTitle("Configure Data Logging Directory"); - logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - - if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) { - File dir = logdir_chooser.getSelectedFile(); - if (check_dir(dir)) - set_logdir(dir); - } - } - public static int font_size() { - synchronized (backend) { - return font_size; - } - } - - static void set_fonts() { - } - - public static void set_font_size(int new_font_size) { - synchronized (backend) { - font_size = new_font_size; - backend.putInt(fontSizePreference, font_size); - flush_preferences(); - set_fonts(font_size); - for (MicroFontListener l : font_listeners) - l.font_size_changed(font_size); - } - } - - public static void register_font_listener(MicroFontListener l) { - synchronized (backend) { - font_listeners.add(l); - } - } - - public static void unregister_font_listener(MicroFontListener l) { - synchronized (backend) { - font_listeners.remove(l); - } - } - - public static void set_look_and_feel(String new_look_and_feel) { - try { - UIManager.setLookAndFeel(new_look_and_feel); - } catch (Exception e) { - } - synchronized(backend) { - look_and_feel = new_look_and_feel; - backend.putString(lookAndFeelPreference, look_and_feel); - flush_preferences(); - for (MicroUIListener l : ui_listeners) - l.ui_changed(look_and_feel); - } - } - - public static String look_and_feel() { - synchronized (backend) { - return look_and_feel; - } - } - - public static void register_ui_listener(MicroUIListener l) { - synchronized(backend) { - ui_listeners.add(l); - } - } - - public static void unregister_ui_listener(MicroUIListener l) { - synchronized (backend) { - ui_listeners.remove(l); - } - } - public static void set_serial_debug(boolean new_serial_debug) { - synchronized (backend) { - serial_debug = new_serial_debug; - backend.putBoolean(serialDebugPreference, serial_debug); - flush_preferences(); - } - } - - public static boolean serial_debug() { - synchronized (backend) { - return serial_debug; - } - } - -} diff --git a/micropeak/MicroPreferencesBackend.java b/micropeak/MicroPreferencesBackend.java deleted file mode 100644 index 7d92f6be..00000000 --- a/micropeak/MicroPreferencesBackend.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright © 2012 Mike Beattie - * - * 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.io.File; -import java.util.prefs.*; -import org.altusmetrum.AltosLib.*; -import javax.swing.filechooser.FileSystemView; - -public class MicroPreferencesBackend implements AltosPreferencesBackend { - - private Preferences _preferences = null; - - public MicroPreferencesBackend() { - _preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); - } - - public MicroPreferencesBackend(Preferences in_preferences) { - _preferences = in_preferences; - } - - public String getString(String key, String def) { - return _preferences.get(key, def); - } - public void putString(String key, String value) { - _preferences.put(key, value); - } - - public int getInt(String key, int def) { - return _preferences.getInt(key, def); - } - public void putInt(String key, int value) { - _preferences.putInt(key, value); - } - - public double getDouble(String key, double def) { - return _preferences.getDouble(key, def); - } - public void putDouble(String key, double value) { - _preferences.putDouble(key, value); - } - - public boolean getBoolean(String key, boolean def) { - return _preferences.getBoolean(key, def); - } - public void putBoolean(String key, boolean value) { - _preferences.putBoolean(key, value); - } - - public boolean nodeExists(String key) { - try { - return _preferences.nodeExists(key); - } catch (BackingStoreException be) { - return false; - } - } - - public AltosPreferencesBackend node(String key) { - return new MicroPreferencesBackend(_preferences.node(key)); - } - - public String[] keys() { - try { - return _preferences.keys(); - } catch (BackingStoreException be) { - return null; - } - } - - public void remove(String key) { - _preferences.remove(key); - } - - public void flush() { - try { - _preferences.flush(); - } catch (BackingStoreException ee) { - System.err.printf("Cannot save preferences\n"); - } - } - - public File homeDirectory() { - /* Use the file system view default directory */ - return FileSystemView.getFileSystemView().getDefaultDirectory(); - } -} diff --git a/micropeak/MicroSerial.java b/micropeak/MicroSerial.java index 8546276e..a1a77a1d 100644 --- a/micropeak/MicroSerial.java +++ b/micropeak/MicroSerial.java @@ -16,16 +16,18 @@ */ package org.altusmetrum.micropeak; + import java.util.*; import java.io.*; import libaltosJNI.*; +import org.altusmetrum.altosuilib.*; public class MicroSerial extends InputStream { SWIGTYPE_p_altos_file file; public int read() { int c = libaltos.altos_getchar(file, 0); - if (MicroPreferences.serial_debug) + if (AltosUIPreferences.serial_debug) System.out.printf("%c", c); return c; } diff --git a/micropeak/MicroUIListener.java b/micropeak/MicroUIListener.java deleted file mode 100644 index 9aed8dae..00000000 --- a/micropeak/MicroUIListener.java +++ /dev/null @@ -1,22 +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 org.altusmetrum.micropeak; - -public interface MicroUIListener { - public void ui_changed(String look_and_feel); -} -- cgit v1.2.3 From 2bd6aca54fc465995d6985c8799cd0d016c9a543 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 31 Dec 2012 14:17:26 -0800 Subject: micropeak: Add flight stats pane Shows graph or stats in alternate panes Signed-off-by: Keith Packard --- altosuilib/AltosUILib.java | 18 ++-- micropeak/Makefile.am | 2 + micropeak/MicroData.java | 100 ++++++++++++++++++++++ micropeak/MicroPeak.java | 15 +++- micropeak/MicroStats.java | 184 +++++++++++++++++++++++++++++++++++++++++ micropeak/MicroStatsTable.java | 138 +++++++++++++++++++++++++++++++ 6 files changed, 445 insertions(+), 12 deletions(-) create mode 100644 micropeak/MicroStats.java create mode 100644 micropeak/MicroStatsTable.java (limited to 'micropeak/Makefile.am') diff --git a/altosuilib/AltosUILib.java b/altosuilib/AltosUILib.java index 717678ba..5d5f9aaa 100644 --- a/altosuilib/AltosUILib.java +++ b/altosuilib/AltosUILib.java @@ -24,17 +24,17 @@ import org.altusmetrum.AltosLib.*; public class AltosUILib extends AltosLib { - static final int tab_elt_pad = 5; + public static final int tab_elt_pad = 5; - static Font label_font; - static Font value_font; - static Font status_font; - static Font table_label_font; - static Font table_value_font; + public static Font label_font; + public static Font value_font; + public static Font status_font; + public static Font table_label_font; + public static Font table_value_font; - final static int font_size_small = 1; - final static int font_size_medium = 2; - final static int font_size_large = 3; + final public static int font_size_small = 1; + final public static int font_size_medium = 2; + final public static int font_size_large = 3; static void set_fonts(int size) { int brief_size; diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index fde981a6..e0de690c 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -13,6 +13,8 @@ micropeak_JAVA= \ MicroFrame.java \ MicroGraph.java \ MicroSerial.java \ + MicroStats.java \ + MicroStatsTable.java \ MicroFileChooser.java \ MicroUSB.java diff --git a/micropeak/MicroData.java b/micropeak/MicroData.java index 783ae40f..ec9b83d8 100644 --- a/micropeak/MicroData.java +++ b/micropeak/MicroData.java @@ -22,6 +22,87 @@ import java.io.*; import java.util.*; import org.altusmetrum.AltosLib.*; +abstract class MicroIterator implements Iterator { + int i; + MicroData data; + + public boolean hasNext() { + return i < data.pressures.length; + } + + public MicroIterator (MicroData data) { + this.data = data; + i = 0; + } + + public void remove() { + } +} + +class MicroHeightIterator extends MicroIterator { + public Double next() { + return data.height(i++); + } + + public MicroHeightIterator(MicroData data) { + super(data); + } +} + +class MicroHeightIterable implements Iterable { + MicroData data; + + public Iterator iterator() { + return new MicroHeightIterator(data); + } + + public MicroHeightIterable(MicroData data) { + this.data = data; + } +} + +class MicroSpeedIterator extends MicroIterator { + public Double next() { + return data.speed(i++); + } + public MicroSpeedIterator(MicroData data) { + super(data); + } +} + +class MicroSpeedIterable implements Iterable { + MicroData data; + + public Iterator iterator() { + return new MicroSpeedIterator(data); + } + + public MicroSpeedIterable(MicroData data) { + this.data = data; + } +} + +class MicroAccelIterator extends MicroIterator { + public Double next() { + return data.acceleration(i++); + } + public MicroAccelIterator(MicroData data) { + super(data); + } +} + +class MicroAccelIterable implements Iterable { + MicroData data; + + public Iterator iterator() { + return new MicroAccelIterator(data); + } + + public MicroAccelIterable(MicroData data) { + this.data = data; + } +} + public class MicroData { public int ground_pressure; public int min_pressure; @@ -143,6 +224,18 @@ public class MicroData { return AltosConvert.pressure_to_altitude(pressures[i]); } + public Iterable heights() { + return new MicroHeightIterable(this); + } + + public Iterable speeds() { + return new MicroSpeedIterable(this); + } + + public Iterable accels() { + return new MicroAccelIterable(this); + } + int fact(int n) { if (n == 0) return 1; @@ -266,5 +359,12 @@ public class MicroData { throw new IOException(); } } + + public MicroData() { + ground_pressure = 101000; + min_pressure = 101000; + pressures = new int[1]; + pressures[0] = 101000; + } } diff --git a/micropeak/MicroPeak.java b/micropeak/MicroPeak.java index 463238c8..c69f7167 100644 --- a/micropeak/MicroPeak.java +++ b/micropeak/MicroPeak.java @@ -30,13 +30,16 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene File filename; MicroGraph graph; + MicroStatsTable stats; MicroData data; - Container pane; + Container container; + JTabbedPane pane; private void RunFile(InputStream input) { try { data = new MicroData(input); graph.setData(data); + stats.setData(data); } catch (IOException ioe) { } try { @@ -90,7 +93,8 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene AltosUIPreferences.set_component(this); - pane = getContentPane(); + container = getContentPane(); + pane = new JTabbedPane(); setTitle("MicroPeak"); @@ -129,9 +133,14 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene }); graph = new MicroGraph(); - pane.add(graph.panel); + stats = new MicroStatsTable(); + pane.add(graph.panel, "Graph"); + pane.add(stats, "Statistics"); pane.doLayout(); pane.validate(); + container.add(pane); + container.doLayout(); + container.validate(); doLayout(); validate(); Insets i = getInsets(); diff --git a/micropeak/MicroStats.java b/micropeak/MicroStats.java new file mode 100644 index 00000000..6ae8a2b2 --- /dev/null +++ b/micropeak/MicroStats.java @@ -0,0 +1,184 @@ +/* + * 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.micropeak; + +import java.io.*; +import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; + +public class MicroStats { + double coast_height; + double coast_time; + + double apogee_height; + double apogee_time; + + double landed_height; + double landed_time; + + double max_speed; + double max_accel; + + MicroData data; + + void find_landing() { + landed_height = 0; + + int t = 0; + for (double height : data.heights()) { + landed_height = height; + t++; + } + landed_time = data.time(t); + + t = 0; + boolean above = false; + for (double height : data.heights()) { + if (height > landed_height + 10) { + above = true; + } else { + if (above && height < landed_height + 2) { + above = false; + landed_time = data.time(t); + } + } + t++; + } + } + + void find_apogee() { + apogee_height = 0; + apogee_time = 0; + + int t = 0; + for (double height : data.heights()) { + if (height > apogee_height) { + apogee_height = height; + apogee_time = data.time(t); + } + t++; + } + } + + void find_coast() { + coast_height = 0; + coast_time = 0; + + int t = 0; + for (double accel : data.accels()) { + if (accel < -9.8) + break; + t++; + } + coast_time = data.time(t); + + int coast_t = t; + t = 0; + for (double height : data.heights()) { + if (t >= coast_t) { + coast_height = height; + break; + } + t++; + } + } + + void find_max_speed() { + max_speed = 0; + int t = 0; + for (double speed : data.speeds()) { + if (data.time(t) > apogee_time) + break; + if (speed > max_speed) + max_speed = speed; + t++; + } + } + + void find_max_accel() { + max_accel = 0; + + int t = 0; + for (double accel : data.accels()) { + if (data.time(t) > apogee_time) + break; + if (accel > max_accel) + max_accel = accel; + t++; + } + } + + double boost_duration() { + return coast_time; + } + + double boost_height() { + return coast_height; + } + + double boost_speed() { + return coast_height / coast_time; + } + + double boost_accel() { + return boost_speed() / boost_duration(); + } + + double coast_duration() { + return apogee_time - coast_time; + } + + double coast_height() { + return apogee_height - coast_height; + } + + double coast_speed() { + return coast_height() / coast_duration(); + } + + double coast_accel() { + return coast_speed() / coast_duration(); + } + + double descent_duration() { + return landed_time - apogee_time; + } + + double descent_height() { + return apogee_height - landed_height; + } + + double descent_speed() { + return descent_height() / descent_duration(); + } + + public MicroStats(MicroData data) { + + this.data = data; + + find_coast(); + find_apogee(); + find_landing(); + find_max_speed(); + find_max_accel(); + } + + public MicroStats() { + this(new MicroData()); + } +} diff --git a/micropeak/MicroStatsTable.java b/micropeak/MicroStatsTable.java new file mode 100644 index 00000000..f373e25d --- /dev/null +++ b/micropeak/MicroStatsTable.java @@ -0,0 +1,138 @@ +/* + * 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.micropeak; + +import java.awt.*; +import javax.swing.*; +import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; + +public class MicroStatsTable extends JComponent { + GridBagLayout layout; + + class MicroStat { + JLabel label; + JTextField[] texts; + + public void set_values(String ... values) { + for (int j = 0; j < values.length; j++) { + texts[j].setText(values[j]); + } + } + + public MicroStat(GridBagLayout layout, int y, String label_text, String ... values) { + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad); + c.weighty = 1; + + label = new JLabel(label_text); + label.setFont(AltosUILib.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 0; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + texts = new JTextField[values.length]; + for (int j = 0; j < values.length; j++) { + JTextField value = new JTextField(values[j]); + value.setFont(AltosUILib.value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + texts[j] = value; + c.gridx = j+1; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value, c); + add(value); + } + } + } + + MicroStat max_height, max_speed; + MicroStat max_accel, avg_accel; + MicroStat boost_duration; + MicroStat coast_duration; + MicroStat descent_speed; + MicroStat descent_duration; + MicroStat flight_time; + + public void setStats(MicroStats stats) { + max_height.set_values(String.format("%5.0f m", stats.apogee_height), + String.format("%5.0f ft", AltosConvert.meters_to_feet(stats.apogee_height))); + max_speed.set_values(String.format("%5.0f m/s", stats.max_speed), + String.format("%5.0f mph", AltosConvert.meters_to_mph(stats.max_speed)), + String.format("Mach %4.1f", AltosConvert.meters_to_mach(stats.max_speed))); + max_accel.set_values(String.format("%5.0f m/s²", stats.max_accel), + String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.max_accel)), + String.format("%5.0f G", AltosConvert.meters_to_g(stats.max_accel))); + avg_accel.set_values(String.format("%5.0f m/s²", stats.boost_accel(), + String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.boost_accel())), + String.format("%5.0f G", AltosConvert.meters_to_g(stats.boost_accel())))); + boost_duration.set_values(String.format("%6.1f s", stats.boost_duration())); + coast_duration.set_values(String.format("%6.1f s", stats.coast_duration())); + descent_speed.set_values(String.format("%5.0f m/s", stats.descent_speed()), + String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.descent_speed()))); + descent_duration.set_values(String.format("%6.1f s", stats.descent_duration())); + flight_time.set_values(String.format("%6.1f s", stats.landed_time)); + } + + public void setData(MicroData data) { + setStats(new MicroStats(data)); + } + + public MicroStatsTable(MicroStats stats) { + layout = new GridBagLayout(); + + setLayout(layout); + int y = 0; + max_height = new MicroStat(layout, y++, "Maximum height", + String.format("%5.0f m", stats.apogee_height), + String.format("%5.0f ft", AltosConvert.meters_to_feet(stats.apogee_height))); + max_speed = new MicroStat(layout, y++, "Maximum speed", + String.format("%5.0f m/s", stats.max_speed), + String.format("%5.0f mph", AltosConvert.meters_to_mph(stats.max_speed)), + String.format("Mach %4.1f", AltosConvert.meters_to_mach(stats.max_speed))); + max_accel = new MicroStat(layout, y++, "Maximum boost acceleration", + String.format("%5.0f m/s²", stats.max_accel), + String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.max_accel)), + String.format("%5.0f G", AltosConvert.meters_to_g(stats.max_accel))); + avg_accel = new MicroStat(layout, y++, "Average boost acceleration", + String.format("%5.0f m/s²", stats.boost_accel(), + String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.boost_accel())), + String.format("%5.0f G", AltosConvert.meters_to_g(stats.boost_accel())))); + boost_duration = new MicroStat(layout, y++, "Boost duration", + String.format("%6.0f s", stats.boost_duration())); + coast_duration = new MicroStat(layout, y++, "Coast duration", + String.format("%6.1f s", stats.coast_duration())); + descent_speed = new MicroStat(layout, y++, "Descent rate", + String.format("%5.0f m/s", stats.descent_speed()), + String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.descent_speed()))); + descent_duration = new MicroStat(layout, y++, "Descent duration", + String.format("%6.1f s", stats.descent_duration())); + flight_time = new MicroStat(layout, y++, "Flight Time", + String.format("%6.0f s", stats.landed_time)); + } + + public MicroStatsTable() { + this(new MicroStats()); + } + +} \ No newline at end of file -- cgit v1.2.3 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 --- altoslib/AltosLib.java | 1 + altosuilib/AltosDevice.java | 30 +++++++ altosuilib/AltosDeviceDialog.java | 163 ++++++++++++++++++++++++++++++++++++++ altosuilib/AltosUSBDevice.java | 112 ++++++++++++++++++++++++++ altosuilib/Makefile.am | 3 + libaltos/libaltos.c | 4 + micropeak/Makefile.am | 3 + micropeak/MicroData.java | 15 +++- micropeak/MicroDeviceDialog.java | 50 ++++++++++++ micropeak/MicroDownload.java | 139 ++++++++++++++++++++++++++++++++ micropeak/MicroGraph.java | 5 ++ micropeak/MicroPeak.java | 81 +++++++++++++++---- micropeak/MicroSave.java | 102 ++++++++++++++++++++++++ micropeak/MicroSerial.java | 12 ++- micropeak/MicroUSB.java | 19 +++-- 15 files changed, 708 insertions(+), 31 deletions(-) create mode 100644 altosuilib/AltosDevice.java create mode 100644 altosuilib/AltosDeviceDialog.java create mode 100644 altosuilib/AltosUSBDevice.java create mode 100644 micropeak/MicroDeviceDialog.java create mode 100644 micropeak/MicroDownload.java create mode 100644 micropeak/MicroSave.java (limited to 'micropeak/Makefile.am') diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index 07516aeb..67138450 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -97,6 +97,7 @@ public class AltosLib { public final static int product_any = 0x10000; public final static int product_basestation = 0x10000 + 1; public final static int product_altimeter = 0x10000 + 2; + public final static int product_micropeak_serial = 0x10000 + 3; /* Bluetooth "identifier" (bluetooth sucks) */ public final static String bt_product_telebt = "TeleBT"; diff --git a/altosuilib/AltosDevice.java b/altosuilib/AltosDevice.java new file mode 100644 index 00000000..69b025ba --- /dev/null +++ b/altosuilib/AltosDevice.java @@ -0,0 +1,30 @@ +/* + * 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; + +import libaltosJNI.*; + +public interface AltosDevice { + public abstract String toString(); + public abstract String toShortString(); + public abstract int getSerial(); + public abstract String getPath(); + public abstract boolean matchProduct(int product); + public abstract String getErrorString(); + public SWIGTYPE_p_altos_file open(); +} diff --git a/altosuilib/AltosDeviceDialog.java b/altosuilib/AltosDeviceDialog.java new file mode 100644 index 00000000..82620b8b --- /dev/null +++ b/altosuilib/AltosDeviceDialog.java @@ -0,0 +1,163 @@ +/* + * 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; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public abstract class AltosDeviceDialog extends AltosUIDialog implements ActionListener { + + private AltosDevice value; + private JList list; + private JButton cancel_button; + private JButton select_button; + private JButton manage_bluetooth_button; + private Frame frame; + private int product; + + public AltosDevice getValue() { + return value; + } + + public abstract AltosDevice[] devices(); + + private void update_devices() { + AltosDevice[] devices = devices(); + list.setListData(devices); + select_button.setEnabled(devices.length > 0); + } + + public AltosDeviceDialog (Frame in_frame, Component location, int in_product) { + super(in_frame, "Device Selection", true); + + product = in_product; + frame = in_frame; + value = null; + + AltosDevice[] devices = devices(); + + cancel_button = new JButton("Cancel"); + cancel_button.setActionCommand("cancel"); + cancel_button.addActionListener(this); + +// manage_bluetooth_button = new JButton("Manage Bluetooth"); +// manage_bluetooth_button.setActionCommand("manage"); +// manage_bluetooth_button.addActionListener(this); + + select_button = new JButton("Select"); + select_button.setActionCommand("select"); + select_button.addActionListener(this); + if (devices.length == 0) + select_button.setEnabled(false); + getRootPane().setDefaultButton(select_button); + + list = new JList(devices) { + //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); + } + }; + + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + list.setLayoutOrientation(JList.HORIZONTAL_WRAP); + list.setVisibleRowCount(-1); + list.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + select_button.doClick(); //emulate button click + } + } + }); + JScrollPane listScroller = new JScrollPane(list); + listScroller.setPreferredSize(new Dimension(400, 80)); + listScroller.setAlignmentX(LEFT_ALIGNMENT); + + //Create a container so that we can add a title around + //the scroll pane. Can't add a title directly to the + //scroll pane because its background would be white. + //Lay out the label and scroll pane from top to bottom. + JPanel listPane = new JPanel(); + listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); + + JLabel label = new JLabel("Select Device"); + label.setLabelFor(list); + listPane.add(label); + listPane.add(Box.createRigidArea(new Dimension(0,5))); + listPane.add(listScroller); + listPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); + + //Lay out the buttons from left to right. + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); + buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); + buttonPane.add(Box.createHorizontalGlue()); + buttonPane.add(cancel_button); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); +// buttonPane.add(manage_bluetooth_button); +// buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + buttonPane.add(select_button); + + //Put everything together, using the content pane's BorderLayout. + Container contentPane = getContentPane(); + contentPane.add(listPane, BorderLayout.CENTER); + contentPane.add(buttonPane, BorderLayout.PAGE_END); + + //Initialize values. + if (devices != null && devices.length != 0) + list.setSelectedValue(devices[0], true); + pack(); + setLocationRelativeTo(location); + } + + //Handle clicks on the Set and Cancel buttons. + public void actionPerformed(ActionEvent e) { + if ("select".equals(e.getActionCommand())) + value = (AltosDevice)(list.getSelectedValue()); +// if ("manage".equals(e.getActionCommand())) { +// AltosBTManage.show(frame, AltosBTKnown.bt_known()); +// update_devices(); +// return; +// } + setVisible(false); + } + +} diff --git a/altosuilib/AltosUSBDevice.java b/altosuilib/AltosUSBDevice.java new file mode 100644 index 00000000..2f4e0dc6 --- /dev/null +++ b/altosuilib/AltosUSBDevice.java @@ -0,0 +1,112 @@ +/* + * 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; + +import java.util.*; +import libaltosJNI.*; + +public class AltosUSBDevice extends altos_device implements AltosDevice { + + public String toString() { + String name = getName(); + if (name == null) + name = "Altus Metrum"; + return String.format("%-20.20s %4d %s", + name, getSerial(), getPath()); + } + + public String toShortString() { + String name = getName(); + if (name == null) + name = "Altus Metrum"; + return String.format("%s %d %s", + name, getSerial(), getPath()); + + } + + 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 SWIGTYPE_p_altos_file open() { + return libaltos.altos_open(this); + } + + private boolean isAltusMetrum() { + if (getVendor() != AltosUILib.vendor_altusmetrum) + return false; + if (getProduct() < AltosUILib.product_altusmetrum_min) + return false; + if (getProduct() > AltosUILib.product_altusmetrum_max) + return false; + return true; + } + + public boolean matchProduct(int want_product) { + + if (!isAltusMetrum()) + return false; + + if (want_product == AltosUILib.product_any) + return true; + + if (want_product == AltosUILib.product_basestation) + return matchProduct(AltosUILib.product_teledongle) || + matchProduct(AltosUILib.product_teleterra) || + matchProduct(AltosUILib.product_telebt) || + matchProduct(AltosUILib.product_megadongle); + + if (want_product == AltosUILib.product_altimeter) + return matchProduct(AltosUILib.product_telemetrum) || + matchProduct(AltosUILib.product_megametrum); + + int have_product = getProduct(); + + if (have_product == AltosUILib.product_altusmetrum) /* old devices match any request */ + return true; + + if (want_product == have_product) + return true; + + return false; + } + + static java.util.List list(int product) { + if (!AltosUILib.load_library()) + return null; + + SWIGTYPE_p_altos_list list = libaltos.altos_list_start(); + + ArrayList device_list = new ArrayList(); + if (list != null) { + for (;;) { + AltosUSBDevice device = new AltosUSBDevice(); + if (libaltos.altos_list_next(list, device) == 0) + break; + if (device.matchProduct(product)) + device_list.add(device); + } + libaltos.altos_list_finish(list); + } + + return device_list; + } +} \ No newline at end of file diff --git a/altosuilib/Makefile.am b/altosuilib/Makefile.am index 26aee7c4..e2ff8cb5 100644 --- a/altosuilib/Makefile.am +++ b/altosuilib/Makefile.am @@ -11,6 +11,9 @@ AltosUILibdir = $(datadir)/java AltosUILib_JAVA = \ AltosConfigureUI.java \ + AltosDevice.java \ + AltosDeviceDialog.java \ + AltosUSBDevice.java \ AltosFontListener.java \ AltosUIDialog.java \ AltosUIFrame.java \ diff --git a/libaltos/libaltos.c b/libaltos/libaltos.c index d7b266cf..6e884c80 100644 --- a/libaltos/libaltos.c +++ b/libaltos/libaltos.c @@ -116,6 +116,7 @@ altos_open(struct altos_device *device) return NULL; } + printf ("open\n"); // altos_set_last_error(12, "yeah yeah, failed again"); // free(file); // return NULL; @@ -148,6 +149,8 @@ altos_open(struct altos_device *device) return NULL; } cfmakeraw(&term); + cfsetospeed(&term, B9600); + cfsetispeed(&term, B9600); #ifdef USE_POLL term.c_cc[VMIN] = 1; term.c_cc[VTIME] = 0; @@ -609,6 +612,7 @@ altos_list_next(struct altos_list *list, struct altos_device *device) { struct altos_usbdev *dev; if (list->current >= list->ndev) { + printf ("end\n"); return 0; } dev = list->dev[list->current]; diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index e0de690c..a54b78a5 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -10,12 +10,15 @@ micropeakdir=$(datadir)/java micropeak_JAVA= \ MicroPeak.java \ MicroData.java \ + MicroDownload.java \ MicroFrame.java \ MicroGraph.java \ + MicroSave.java \ MicroSerial.java \ MicroStats.java \ MicroStatsTable.java \ MicroFileChooser.java \ + MicroDeviceDialog.java \ MicroUSB.java JFREECHART_CLASS= \ diff --git a/micropeak/MicroData.java b/micropeak/MicroData.java index ec9b83d8..8ccd5fd8 100644 --- a/micropeak/MicroData.java +++ b/micropeak/MicroData.java @@ -110,6 +110,7 @@ public class MicroData { private double time_step; private double ground_altitude; private ArrayList bytes; + String name; class FileEndedException extends Exception { @@ -310,12 +311,18 @@ public class MicroData { public void save (OutputStream f) throws IOException { for (int c : bytes) f.write(c); + f.write('\n'); } - public MicroData (InputStream f) throws IOException { + public void set_name(String name) { + this.name = name; + } + + public MicroData (InputStream f, String name) throws IOException, InterruptedException { + this.name = name; bytes = new ArrayList(); if (!find_header(f)) - throw new IOException(); + throw new IOException("No MicroPeak data header found"); try { file_crc = 0xffff; ground_pressure = get_32(f); @@ -354,9 +361,9 @@ public class MicroData { time_step = 0.192; } catch (FileEndedException fe) { - throw new IOException(); + throw new IOException("File Ended Unexpectedly"); } catch (NonHexcharException ne) { - throw new IOException(); + throw new IOException("Non hexadecimal character found"); } } diff --git a/micropeak/MicroDeviceDialog.java b/micropeak/MicroDeviceDialog.java new file mode 100644 index 00000000..7b8a630c --- /dev/null +++ b/micropeak/MicroDeviceDialog.java @@ -0,0 +1,50 @@ +/* + * 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 javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import org.altusmetrum.altosuilib.*; + +public class MicroDeviceDialog extends AltosDeviceDialog { + + public AltosDevice[] devices() { + java.util.List list = MicroUSB.list(); + int num_devices = list.size(); + AltosDevice[] devices = new AltosDevice[num_devices]; + + for (int i = 0; i < num_devices; i++) + devices[i] = list.get(i); + return devices; + } + + public MicroDeviceDialog (Frame in_frame, Component location) { + super(in_frame, location, 0); + } + + public static AltosDevice show (Component frameComp) { + Frame frame = JOptionPane.getFrameForComponent(frameComp); + MicroDeviceDialog dialog; + + dialog = new MicroDeviceDialog (frame, frameComp); + dialog.setVisible(true); + return dialog.getValue(); + } +} 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(); + } +} diff --git a/micropeak/MicroGraph.java b/micropeak/MicroGraph.java index 38f54fe0..b9b084f8 100644 --- a/micropeak/MicroGraph.java +++ b/micropeak/MicroGraph.java @@ -111,8 +111,13 @@ public class MicroGraph implements AltosUnitsListener { } } + public void setName (String name) { + chart.setTitle(name); + } + public void setData (MicroData data) { this.data = data; + chart.setTitle(data.name); resetData(); } diff --git a/micropeak/MicroPeak.java b/micropeak/MicroPeak.java index c69f7167..5e375057 100644 --- a/micropeak/MicroPeak.java +++ b/micropeak/MicroPeak.java @@ -34,13 +34,36 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene MicroData data; Container container; JTabbedPane pane; + static int number_of_windows; - private void RunFile(InputStream input) { + MicroPeak SetData(MicroData data) { + MicroPeak mp = this; + if (this.data != null) { + mp = new MicroPeak(); + return mp.SetData(data); + } + this.data = data; + graph.setData(data); + stats.setData(data); + setTitle(data.name); + return this; + } + + void SetName(String name) { + graph.setName(name); + setTitle(name); + } + + private void RunFile(InputStream input, String name) { try { - data = new MicroData(input); - graph.setData(data); - stats.setData(data); + MicroData data = new MicroData(input, name); + SetData(data); } catch (IOException ioe) { + JOptionPane.showMessageDialog(this, + ioe.getMessage(), + "File Read Error", + JOptionPane.ERROR_MESSAGE); + } catch (InterruptedException ie) { } try { input.close(); @@ -50,8 +73,12 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene private void OpenFile(File filename) { try { - RunFile (new FileInputStream(filename)); + RunFile (new FileInputStream(filename), filename.getName()); } catch (FileNotFoundException fne) { + JOptionPane.showMessageDialog(this, + fne.getMessage(), + "Cannot open file", + JOptionPane.ERROR_MESSAGE); } } @@ -60,30 +87,44 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene InputStream input = chooser.runDialog(); if (input != null) - RunFile(input); + RunFile(input, chooser.filename); } private void Preferences() { new AltosConfigureUI(this); } - + private void DownloadData() { - java.util.List devices = MicroUSB.list(); - for (MicroUSB device : devices) - System.out.printf("device %s\n", device.toString()); + AltosDevice device = MicroDeviceDialog.show(this); + + if (device != null) + new MicroDownload(this, device); } + private void Save() { + if (data == null) { + JOptionPane.showMessageDialog(this, + "No data available", + "No data", + JOptionPane.INFORMATION_MESSAGE); + return; + } + MicroSave save = new MicroSave (this, data); + if (save.runDialog()) + SetName(data.name); + } + public void actionPerformed(ActionEvent ev) { if ("Exit".equals(ev.getActionCommand())) System.exit(0); else if ("Open".equals(ev.getActionCommand())) SelectFile(); - else if ("New".equals(ev.getActionCommand())) - new MicroPeak(); else if ("Download".equals(ev.getActionCommand())) DownloadData(); else if ("Preferences".equals(ev.getActionCommand())) Preferences(); + else if ("Save a Copy".equals(ev.getActionCommand())) + Save(); } public void itemStateChanged(ItemEvent e) { @@ -91,6 +132,8 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene public MicroPeak() { + ++number_of_windows; + AltosUIPreferences.set_component(this); container = getContentPane(); @@ -104,10 +147,6 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); - JMenuItem newAction = new JMenuItem("New"); - fileMenu.add(newAction); - newAction.addActionListener(this); - JMenuItem openAction = new JMenuItem("Open"); fileMenu.add(openAction); openAction.addActionListener(this); @@ -116,6 +155,10 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene fileMenu.add(downloadAction); downloadAction.addActionListener(this); + JMenuItem saveAction = new JMenuItem("Save a Copy"); + fileMenu.add(saveAction); + saveAction.addActionListener(this); + JMenuItem preferencesAction = new JMenuItem("Preferences"); fileMenu.add(preferencesAction); preferencesAction.addActionListener(this); @@ -128,7 +171,11 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { - System.exit(0); + setVisible(false); + dispose(); + --number_of_windows; + if (number_of_windows == 0) + System.exit(0); } }); diff --git a/micropeak/MicroSave.java b/micropeak/MicroSave.java new file mode 100644 index 00000000..cb4b4221 --- /dev/null +++ b/micropeak/MicroSave.java @@ -0,0 +1,102 @@ +/* + * 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 javax.swing.filechooser.FileNameExtensionFilter; +import java.io.*; +import java.util.concurrent.*; +import java.util.*; +import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; + +public class MicroSave extends JFileChooser { + + JFrame frame; + MicroData data; + + public boolean runDialog() { + int ret; + + for (;;) { + ret = showSaveDialog(frame); + if (ret != APPROVE_OPTION) + return false; + File file; + String filename; + file = getSelectedFile(); + if (file == null) + continue; + if (!file.getName().contains(".")) { + String fullname = file.getPath(); + file = new File(fullname.concat(".mpd")); + } + filename = file.getName(); + if (file.exists()) { + if (file.isDirectory()) { + JOptionPane.showMessageDialog(frame, + String.format("\"%s\" is a directory", + filename), + "Directory", + JOptionPane.ERROR_MESSAGE); + continue; + } + int r = JOptionPane.showConfirmDialog(frame, + String.format("\"%s\" already exists. Overwrite?", + filename), + "Overwrite file?", + JOptionPane.YES_NO_OPTION); + if (r != JOptionPane.YES_OPTION) + continue; + + if (!file.canWrite()) { + JOptionPane.showMessageDialog(frame, + String.format("\"%s\" is not writable", + filename), + "File not writable", + JOptionPane.ERROR_MESSAGE); + continue; + } + } + try { + FileOutputStream fos = new FileOutputStream(file); + data.save(fos); + fos.close(); + data.set_name(filename); + return true; + } catch (FileNotFoundException fe) { + JOptionPane.showMessageDialog(frame, + fe.getMessage(), + "Cannot create file", + JOptionPane.ERROR_MESSAGE); + } catch (IOException ioe) { + } + } + } + + public MicroSave(JFrame frame, MicroData data) { + this.frame = frame; + this.data = data; + setDialogTitle("Save MicroPeak Data File"); + setFileFilter(new FileNameExtensionFilter("MicroPeak data file", + "mpd")); + setCurrentDirectory(AltosUIPreferences.logdir()); + } +} diff --git a/micropeak/MicroSerial.java b/micropeak/MicroSerial.java index a1a77a1d..15ef8582 100644 --- a/micropeak/MicroSerial.java +++ b/micropeak/MicroSerial.java @@ -27,6 +27,10 @@ public class MicroSerial extends InputStream { public int read() { int c = libaltos.altos_getchar(file, 0); + if (Thread.interrupted()) + return -1; + if (c == -1) + return -1; if (AltosUIPreferences.serial_debug) System.out.printf("%c", c); return c; @@ -39,12 +43,12 @@ public class MicroSerial extends InputStream { } } - public MicroSerial(MicroUSB usb) throws FileNotFoundException { - file = usb.open(); + public MicroSerial(AltosDevice device) throws FileNotFoundException { + file = device.open(); if (file == null) { - final String message = usb.getErrorString(); + final String message = device.getErrorString(); throw new FileNotFoundException(String.format("%s (%s)", - usb.toShortString(), + device.toShortString(), message)); } } diff --git a/micropeak/MicroUSB.java b/micropeak/MicroUSB.java index d48610fe..244f7bc0 100644 --- a/micropeak/MicroUSB.java +++ b/micropeak/MicroUSB.java @@ -16,10 +16,12 @@ */ package org.altusmetrum.micropeak; + import java.util.*; import libaltosJNI.*; +import org.altusmetrum.altosuilib.*; -public class MicroUSB extends altos_device { +public class MicroUSB extends altos_device implements AltosDevice { static boolean initialized = false; static boolean loaded_library = false; @@ -48,16 +50,16 @@ public class MicroUSB extends altos_device { String name = getName(); if (name == null) name = "Altus Metrum"; - return String.format("%-20.20s %4d %s", - name, getSerial(), getPath()); + return String.format("%-20.20s %s", + name, getPath()); } public String toShortString() { String name = getName(); if (name == null) name = "Altus Metrum"; - return String.format("%s %d %s", - name, getSerial(), getPath()); + return String.format("%s %s", + name, getPath()); } @@ -75,11 +77,15 @@ public class MicroUSB extends altos_device { private boolean isMicro() { if (getVendor() != 0x0403) return false; - if (getProduct() != 0x6001) + if (getProduct() != 0x6015) return false; return true; } + public boolean matchProduct(int product) { + return isMicro(); + } + static java.util.List list() { if (!load_library()) return null; @@ -92,6 +98,7 @@ public class MicroUSB extends altos_device { 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 3ac109132d1878abbd277ae21215716326404781 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 1 Jan 2013 18:20:23 -0800 Subject: Build installable versions of MicroPeak GUI Makes windows/mac/linux versions. Windows version appears to work on Wine at least. Signed-off-by: Keith Packard --- configure.ac | 1 + icon/altus-metrum.ico | Bin 15086 -> 285478 bytes icon/micro-peak.ico | Bin 0 -> 285478 bytes micropeak/Info.plist.in | 45 ++++++++ micropeak/Makefile.am | 79 ++++++++++++- .../Contents/MacOS/JavaApplicationStub | Bin 0 -> 61296 bytes micropeak/MicroPeak.app/Contents/PkgInfo | 1 + .../Contents/Resources/AltosUIIcon.icns | Bin 0 -> 129010 bytes micropeak/micropeak-fat | 4 + micropeak/micropeak-windows.nsi | 123 +++++++++++++++++++++ 10 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 icon/micro-peak.ico create mode 100644 micropeak/Info.plist.in create mode 100755 micropeak/MicroPeak.app/Contents/MacOS/JavaApplicationStub create mode 100644 micropeak/MicroPeak.app/Contents/PkgInfo create mode 100644 micropeak/MicroPeak.app/Contents/Resources/AltosUIIcon.icns create mode 100755 micropeak/micropeak-fat create mode 100644 micropeak/micropeak-windows.nsi (limited to 'micropeak/Makefile.am') diff --git a/configure.ac b/configure.ac index 6ad2591c..312f9678 100644 --- a/configure.ac +++ b/configure.ac @@ -153,6 +153,7 @@ altosui/AltosVersion.java altosui/Info.plist libaltos/Makefile micropeak/Makefile +micropeak/Info.plist altosdroid/Makefile altosdroid/local.properties ao-tools/Makefile diff --git a/icon/altus-metrum.ico b/icon/altus-metrum.ico index e32b4f1e..bedf04ef 100644 Binary files a/icon/altus-metrum.ico and b/icon/altus-metrum.ico differ diff --git a/icon/micro-peak.ico b/icon/micro-peak.ico new file mode 100644 index 00000000..b672aa04 Binary files /dev/null and b/icon/micro-peak.ico differ diff --git a/micropeak/Info.plist.in b/micropeak/Info.plist.in new file mode 100644 index 00000000..d3c17a49 --- /dev/null +++ b/micropeak/Info.plist.in @@ -0,0 +1,45 @@ + + + + + CFBundleName + MicroPeak + CFBundleVersion + @VERSION@ + CFBundleAllowMixedLocalizations + true + CFBundleExecutable + JavaApplicationStub + CFBundleDevelopmentRegion + English + CFBundlePackageType + APPL + CFBundleIdentifier + org.altusmetrum.altosui + CFBundleSignature + Altu + CFBundleGetInfoString + MicroPeak UI version @VERSION@ + CFBundleInfoDictionaryVersion + 6.0 + CFBundleIconFile + MicroPeak.icns + Java + + MainClass + org.altusmetrum.micropeak.MicroPeak + JVMVersion + 1.5+ + ClassPath + + $JAVAROOT/micropeak.jar + + VMOptions + + -Xms512M + -Xmx512M + -Dosgi.clean=true + + + + diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index a54b78a5..2dd9c69c 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -34,6 +34,7 @@ FATJAR=micropeak-fat.jar LIBALTOS= \ libaltos.so \ libaltos.dylib \ + altos64.dll \ altos.dll ALTOSLIB_CLASS=\ @@ -61,15 +62,58 @@ ICONJAR= -C $(ICONDIR) micropeak-16.png \ -C $(ICONDIR) micropeak-128.png \ -C $(ICONDIR) micropeak-256.png +WINDOWS_ICON=$(ICONDIR)/micro-peak.ico + all-local: micropeak-test $(JAR) clean-local: -rm -rf classes $(JAR) $(FATJAR) \ + $(LINUX_DIST) $(MACOSX_DIST) windows $(WINDOWS_DIST) \ $(ALTOSLIB_CLASS) \ $(ALTOSUILIB_CLASS) \ $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) Manifest.txt \ micropeak micropeak-test macosx linux windows +LINUX_DIST=MicroPeak-Linux-$(VERSION).tar.bz2 +MACOSX_DIST=MicroPeak-Mac-$(VERSION).zip +WINDOWS_DIST=MicroPeak-Windows-$(VERSION_DASH).exe + +FAT_FILES=$(FATJAR) $(ALTOSLIB_CLASS) $(ALTOSUILIB_CLASS) $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) + +LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) $(DOC) +LINUX_EXTRA=micropeak-fat + +MACOSX_INFO_PLIST=Info.plist +MACOSX_FILES=$(FAT_FILES) libaltos.dylib $(MACOSX_INFO_PLIST) + +WINDOWS_FILES=$(FAT_FILES) altos.dll altos64.dll $(top_srcdir)/telemetrum.inf $(WINDOWS_ICON) + +if FATINSTALL + +FATTARGET=$(FATDIR)/$(VERSION) + +LINUX_DIST_TARGET=$(FATTARGET)/$(LINUX_DIST) +MACOSX_DIST_TARGET=$(FATTARGET)/$(MACOSX_DIST) +WINDOWS_DIST_TARGET=$(FATTARGET)/$(WINDOWS_DIST) + +fat: $(LINUX_DIST_TARGET) $(MACOSX_DIST_TARGET) $(WINDOWS_DIST_TARGET) + +$(LINUX_DIST_TARGET): $(LINUX_DIST) + mkdir -p $(FATTARGET) + cp -p $< $@ + +$(MACOSX_DIST_TARGET): $(MACOSX_DIST) + mkdir -p $(FATTARGET) + cp -p $< $@ + +$(WINDOWS_DIST_TARGET): $(WINDOWS_DIST) + mkdir -p $(FATTARGET) + cp -p $< $@ + +else +fat: $(LINUX_DIST) $(MACOSX_DIST) $(WINDOWS_DIST) +endif + micropeak: Makefile echo "#!/bin/sh" > $@ echo 'exec java -cp "$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" -Djava.library.path="$(altoslibdir)" -jar "$(micropeakdir)/micropeak.jar" "$$@"' >> $@ @@ -80,6 +124,12 @@ micropeak-test: Makefile echo 'exec java -cp "./*:../libaltos/*:$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" -Djava.library.path="../libaltos/.libs" -jar micropeak.jar "$$@"' >> $@ chmod +x $@ +install-micropeakJAVA: micropeak.jar + @$(NORMAL_INSTALL) + test -z "$(micropeakdir)" || $(MKDIR_P) "$(DESTDIR)$(micropeakdir)" + echo " $(INSTALL_DATA)" "$<" "'$(DESTDIR)$(micropeakdir)/micropeak.jar'"; \ + $(INSTALL_DATA) "$<" "$(DESTDIR)$(micropeakdir)" + $(JAR): classmicropeak.stamp Manifest.txt $(JAVA_ICONS) $(ALTOSLIB_CLASS) $(ALTOSUILIB_CLASS) jar cfm $@ Manifest.txt \ $(ICONJAR) \ @@ -92,7 +142,6 @@ $(FATJAR): classmicropeak.stamp Manifest-fat.txt $(ALTOSLIB_CLASS) $(ALTOSUILIB_ -C classes org \ -C ../libaltos libaltosJNI - libaltos.so: build-libaltos -rm -f "$@" $(LN_S) ../libaltos/.libs/"$@" . @@ -139,6 +188,34 @@ $(JCOMMON_CLASS): -rm -f "$@" $(LN_S) "$(JCOMMON)"/"$@" . +$(LINUX_DIST): $(LINUX_FILES) $(LINUX_EXTRA) + -rm -f $@ + -rm -rf linux + mkdir -p linux/MicroPeak + cp -p $(LINUX_FILES) linux/MicroPeak + cp -p micropeak-fat linux/MicroPeak/micropeak + chmod +x linux/MicroPeak/micropeak + tar cjf $@ -C linux MicroPeak + +$(MACOSX_DIST): $(MACOSX_FILES) + -rm -f $@ + -rm -rf macosx + mkdir macosx + cp -a MicroPeak.app macosx/ + cp -p Info.plist macosx/MicroPeak.app/Contents + mkdir -p macosx/MicroPeak macosx/MicroPeak.app/Contents/Resources/Java + cp -p $(FATJAR) macosx/MicroPeak.app/Contents/Resources/Java/micropeak.jar + cp -p libaltos.dylib macosx/MicroPeak.app/Contents/Resources/Java + cp -p $(ALTOSLIB_CLASS) macosx/MicroPeak.app/Contents/Resources/Java + cp -p $(ALTOSUILIB_CLASS) macosx/MicroPeak.app/Contents/Resources/Java + cp -p $(JFREECHART_CLASS) macosx/MicroPeak.app/Contents/Resources/Java + cp -p $(JCOMMON_CLASS) macosx/MicroPeak.app/Contents/Resources/Java + cd macosx && zip -r ../$@ MicroPeak.app MicroPeak + +$(WINDOWS_DIST): $(WINDOWS_FILES) micropeak-windows.nsi + -rm -f $@ + makensis -Omicropeak-windows.log "-XOutFile $@" "-DVERSION=$(VERSION)" micropeak-windows.nsi + Manifest.txt: Makefile echo 'Main-Class: org.altusmetrum.micropeak.MicroPeak' > $@ echo "Class-Path: AltosLib.jar AltosUILib.jar $(JCOMMON)/jcommon.jar $(JFREECHART)/jfreechart.jar" >> $@ diff --git a/micropeak/MicroPeak.app/Contents/MacOS/JavaApplicationStub b/micropeak/MicroPeak.app/Contents/MacOS/JavaApplicationStub new file mode 100755 index 00000000..c661d3e1 Binary files /dev/null and b/micropeak/MicroPeak.app/Contents/MacOS/JavaApplicationStub differ diff --git a/micropeak/MicroPeak.app/Contents/PkgInfo b/micropeak/MicroPeak.app/Contents/PkgInfo new file mode 100644 index 00000000..8a43480f --- /dev/null +++ b/micropeak/MicroPeak.app/Contents/PkgInfo @@ -0,0 +1 @@ +APPLAM.O diff --git a/micropeak/MicroPeak.app/Contents/Resources/AltosUIIcon.icns b/micropeak/MicroPeak.app/Contents/Resources/AltosUIIcon.icns new file mode 100644 index 00000000..fe49f362 Binary files /dev/null and b/micropeak/MicroPeak.app/Contents/Resources/AltosUIIcon.icns differ diff --git a/micropeak/micropeak-fat b/micropeak/micropeak-fat new file mode 100755 index 00000000..ace7548d --- /dev/null +++ b/micropeak/micropeak-fat @@ -0,0 +1,4 @@ +#!/bin/sh +me=`which "$0"` +dir=`dirname "$me"` +exec java -cp "$dir/*" -Djava.library.path="$dir" -jar "$dir"/micropeak-fat.jar "$@" diff --git a/micropeak/micropeak-windows.nsi b/micropeak/micropeak-windows.nsi new file mode 100644 index 00000000..425048bd --- /dev/null +++ b/micropeak/micropeak-windows.nsi @@ -0,0 +1,123 @@ +!addplugindir Instdrv/NSIS/Plugins +; Definitions for Java 1.6 Detection +!define JRE_VERSION "1.6" +!define JRE_ALTERNATE "1.7" +!define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=52247&/jre-6u27-windows-i586-p.exe" +!define PRODUCT_NAME "Altus Metrum Windows Software" + +Name "Altus Metrum MicroPeak Installer" + +; Default install directory +InstallDir "$PROGRAMFILES\AltusMetrum" + +; Tell the installer where to re-install a new version +InstallDirRegKey HKLM "Software\AltusMetrum" "Install_Dir" + +LicenseText "GNU General Public License Version 2" +LicenseData "../COPYING" + +; Need admin privs for Vista or Win7 +RequestExecutionLevel admin + +ShowInstDetails Show + +ComponentText "Altus Metrum MicroPeak Software Installer" + +Function GetJRE + MessageBox MB_OK "${PRODUCT_NAME} uses Java ${JRE_VERSION} 32-bit, it will now \ + be downloaded and installed" + + StrCpy $2 "$TEMP\Java Runtime Environment.exe" + nsisdl::download /TIMEOUT=30000 ${JRE_URL} $2 + Pop $R0 ;Get the return value + StrCmp $R0 "success" +3 + MessageBox MB_OK "Download failed: $R0" + Quit + ExecWait $2 + Delete $2 +FunctionEnd + + +Function DetectJRE + ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" \ + "CurrentVersion" + StrCmp $2 ${JRE_VERSION} done + + StrCmp $2 ${JRE_ALTERNATE} done + + Call GetJRE + + done: +FunctionEnd + +; Pages to present + +Page license +Page components +Page directory +Page instfiles + +UninstPage uninstConfirm +UninstPage instfiles + +; And the stuff to install + +Section "MicroPeak Application" + Call DetectJRE + + SetOutPath $INSTDIR + + File "micropeak-fat.jar" + File "AltosLib.jar" + File "AltosUILib.jar" + File "jfreechart.jar" + File "jcommon.jar" + + File "*.dll" + + File "../icon/*.ico" + + CreateShortCut "$SMPROGRAMS\MicroPeak.lnk" "$SYSDIR\javaw.exe" "-jar micropeak-fat.jar" "$INSTDIR\micro-peak.ico" +SectionEnd + +Section "MicroPeak Desktop Shortcut" + CreateShortCut "$DESKTOP\MicroPeak.lnk" "$INSTDIR\micropeak-fat.jar" "" "$INSTDIR\micro-peak.ico" +SectionEnd + +Section "Documentation" + + SetOutPath $INSTDIR + + File "../doc/micropeak.pdf" +SectionEnd + +Section "Uninstaller" + + ; Deal with the uninstaller + + SetOutPath $INSTDIR + + ; Write the install path to the registry + WriteRegStr HKLM SOFTWARE\AltusMetrum "Install_Dir" "$INSTDIR" + + ; Write the uninstall keys for windows + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "DisplayName" "Altus Metrum" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "UninstallString" '"$INSTDIR\uninstall.exe"' + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoModify" "1" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoRepair" "1" + + WriteUninstaller "uninstall.exe" +SectionEnd + +Section "Uninstall" + DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" + DeleteRegKey HKLM "Software\AltusMetrum" + + Delete "$INSTDIR\*.*" + RMDir "$INSTDIR" + + ; Remove shortcuts, if any + Delete "$SMPROGRAMS\MicroPeak.lnk" + Delete "$DESKTOP\MicroPeak.lnk" + +SectionEnd -- cgit v1.2.3 From 93d640de65a1ecedfef89c96521c21632f96f372 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 2 Jan 2013 11:22:11 -0800 Subject: micropoint: Add MicroDataPoint This holds height/speed/accel data all in one place Signed-off-by: Keith Packard --- micropeak/Makefile.am | 1 + micropeak/MicroData.java | 77 +++++++------------------------------------ micropeak/MicroDataPoint.java | 39 ++++++++++++++++++++++ micropeak/MicroGraph.java | 9 +++-- micropeak/MicroStats.java | 68 +++++++++++++------------------------- 5 files changed, 78 insertions(+), 116 deletions(-) create mode 100644 micropeak/MicroDataPoint.java (limited to 'micropeak/Makefile.am') diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index 2dd9c69c..26431bd5 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -10,6 +10,7 @@ micropeakdir=$(datadir)/java micropeak_JAVA= \ MicroPeak.java \ MicroData.java \ + MicroDataPoint.java \ MicroDownload.java \ MicroFrame.java \ MicroGraph.java \ diff --git a/micropeak/MicroData.java b/micropeak/MicroData.java index 8ccd5fd8..2afd3cd7 100644 --- a/micropeak/MicroData.java +++ b/micropeak/MicroData.java @@ -22,7 +22,7 @@ import java.io.*; import java.util.*; import org.altusmetrum.AltosLib.*; -abstract class MicroIterator implements Iterator { +class MicroIterator implements Iterator { int i; MicroData data; @@ -30,6 +30,10 @@ abstract class MicroIterator implements Iterator { return i < data.pressures.length; } + public MicroDataPoint next() { + return new MicroDataPoint(data, i++); + } + public MicroIterator (MicroData data) { this.data = data; i = 0; @@ -39,66 +43,15 @@ abstract class MicroIterator implements Iterator { } } -class MicroHeightIterator extends MicroIterator { - public Double next() { - return data.height(i++); - } - - public MicroHeightIterator(MicroData data) { - super(data); - } -} - -class MicroHeightIterable implements Iterable { - MicroData data; - - public Iterator iterator() { - return new MicroHeightIterator(data); - } - - public MicroHeightIterable(MicroData data) { - this.data = data; - } -} - -class MicroSpeedIterator extends MicroIterator { - public Double next() { - return data.speed(i++); - } - public MicroSpeedIterator(MicroData data) { - super(data); - } -} - -class MicroSpeedIterable implements Iterable { - MicroData data; - - public Iterator iterator() { - return new MicroSpeedIterator(data); - } - - public MicroSpeedIterable(MicroData data) { - this.data = data; - } -} +class MicroIterable implements Iterable { -class MicroAccelIterator extends MicroIterator { - public Double next() { - return data.acceleration(i++); - } - public MicroAccelIterator(MicroData data) { - super(data); - } -} - -class MicroAccelIterable implements Iterable { MicroData data; - public Iterator iterator() { - return new MicroAccelIterator(data); + public Iterator iterator() { + return new MicroIterator(data); } - public MicroAccelIterable(MicroData data) { + public MicroIterable(MicroData data) { this.data = data; } } @@ -225,16 +178,8 @@ public class MicroData { return AltosConvert.pressure_to_altitude(pressures[i]); } - public Iterable heights() { - return new MicroHeightIterable(this); - } - - public Iterable speeds() { - return new MicroSpeedIterable(this); - } - - public Iterable accels() { - return new MicroAccelIterable(this); + public Iterable points() { + return new MicroIterable(this); } int fact(int n) { diff --git a/micropeak/MicroDataPoint.java b/micropeak/MicroDataPoint.java new file mode 100644 index 00000000..3fd1e641 --- /dev/null +++ b/micropeak/MicroDataPoint.java @@ -0,0 +1,39 @@ +/* + * 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; + +public class MicroDataPoint { + public double time; + public double height; + public double speed; + public double accel; + + public MicroDataPoint (double height, double speed, double accel, double time) { + this.height = height; + this.speed = speed; + this.accel = accel; + this.time = time; + } + + public MicroDataPoint(MicroData data, int i) { + this(data.height(i), + data.speed(i), + data.acceleration(i), + data.time(i)); + } +} \ No newline at end of file diff --git a/micropeak/MicroGraph.java b/micropeak/MicroGraph.java index c5580634..8330a67b 100644 --- a/micropeak/MicroGraph.java +++ b/micropeak/MicroGraph.java @@ -106,11 +106,10 @@ public class MicroGraph implements AltosUnitsListener { heightSeries.clear(); speedSeries.clear(); accelSeries.clear(); - for (int i = 0; i < data.pressures.length; i++) { - double x = data.time(i); - heightSeries.add(x, AltosConvert.height.value(data.height(i))); - speedSeries.add(x, AltosConvert.speed.value(data.speed(i))); - accelSeries.add(x, AltosConvert.accel.value(data.acceleration(i))); + for (MicroDataPoint point : data.points()) { + heightSeries.add(point.time, AltosConvert.height.value(point.height)); + speedSeries.add(point.time, AltosConvert.speed.value(point.speed)); + accelSeries.add(point.time, AltosConvert.accel.value(point.accel)); } } diff --git a/micropeak/MicroStats.java b/micropeak/MicroStats.java index 6ae8a2b2..056fac7d 100644 --- a/micropeak/MicroStats.java +++ b/micropeak/MicroStats.java @@ -39,25 +39,21 @@ public class MicroStats { void find_landing() { landed_height = 0; - int t = 0; - for (double height : data.heights()) { - landed_height = height; - t++; + for (MicroDataPoint point : data.points()) { + landed_height = point.height; + landed_time = point.time; } - landed_time = data.time(t); - t = 0; boolean above = false; - for (double height : data.heights()) { - if (height > landed_height + 10) { + for (MicroDataPoint point : data.points()) { + if (point.height > landed_height + 10) { above = true; } else { - if (above && height < landed_height + 2) { + if (above && point.height < landed_height + 2) { above = false; - landed_time = data.time(t); + landed_time = point.time; } } - t++; } } @@ -65,13 +61,11 @@ public class MicroStats { apogee_height = 0; apogee_time = 0; - int t = 0; - for (double height : data.heights()) { - if (height > apogee_height) { - apogee_height = height; - apogee_time = data.time(t); + for (MicroDataPoint point : data.points()) { + if (point.height > apogee_height) { + apogee_height = point.height; + apogee_time = point.time; } - t++; } } @@ -79,47 +73,31 @@ public class MicroStats { coast_height = 0; coast_time = 0; - int t = 0; - for (double accel : data.accels()) { - if (accel < -9.8) + for (MicroDataPoint point : data.points()) { + if (point.accel < -9.8) break; - t++; - } - coast_time = data.time(t); - - int coast_t = t; - t = 0; - for (double height : data.heights()) { - if (t >= coast_t) { - coast_height = height; - break; - } - t++; + coast_time = point.time; + coast_height = point.height; } } void find_max_speed() { max_speed = 0; - int t = 0; - for (double speed : data.speeds()) { - if (data.time(t) > apogee_time) + for (MicroDataPoint point : data.points()) { + if (point.time > apogee_time) break; - if (speed > max_speed) - max_speed = speed; - t++; + if (point.speed > max_speed) + max_speed = point.speed; } } void find_max_accel() { max_accel = 0; - - int t = 0; - for (double accel : data.accels()) { - if (data.time(t) > apogee_time) + for (MicroDataPoint point : data.points()) { + if (point.time > apogee_time) break; - if (accel > max_accel) - max_accel = accel; - t++; + if (point.accel > max_accel) + max_accel = point.accel; } } -- cgit v1.2.3 From 2c423d9287c6b9ea7233f5e3430682cb1c865da1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 2 Jan 2013 11:44:32 -0800 Subject: micropeak: Add CSV export Signed-off-by: Keith Packard --- micropeak/Makefile.am | 1 + micropeak/MicroData.java | 4 ++ micropeak/MicroDataPoint.java | 7 ++- micropeak/MicroExport.java | 106 ++++++++++++++++++++++++++++++++++++++++++ micropeak/MicroPeak.java | 22 ++++++++- 5 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 micropeak/MicroExport.java (limited to 'micropeak/Makefile.am') diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index 26431bd5..f5f8ccd9 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -12,6 +12,7 @@ micropeak_JAVA= \ MicroData.java \ MicroDataPoint.java \ MicroDownload.java \ + MicroExport.java \ MicroFrame.java \ MicroGraph.java \ MicroSave.java \ diff --git a/micropeak/MicroData.java b/micropeak/MicroData.java index 2afd3cd7..836d3c35 100644 --- a/micropeak/MicroData.java +++ b/micropeak/MicroData.java @@ -221,6 +221,10 @@ public class MicroData { return alt; } + public double pressure(int i) { + return pressures[i]; + } + public double height(int i) { return altitude(i) - ground_altitude; } diff --git a/micropeak/MicroDataPoint.java b/micropeak/MicroDataPoint.java index 3fd1e641..c58708e6 100644 --- a/micropeak/MicroDataPoint.java +++ b/micropeak/MicroDataPoint.java @@ -19,11 +19,13 @@ package org.altusmetrum.micropeak; public class MicroDataPoint { public double time; + public double pressure; public double height; public double speed; public double accel; - public MicroDataPoint (double height, double speed, double accel, double time) { + public MicroDataPoint (double pressure, double height, double speed, double accel, double time) { + this.pressure = pressure; this.height = height; this.speed = speed; this.accel = accel; @@ -31,7 +33,8 @@ public class MicroDataPoint { } public MicroDataPoint(MicroData data, int i) { - this(data.height(i), + this(data.pressure(i), + data.height(i), data.speed(i), data.acceleration(i), data.time(i)); diff --git a/micropeak/MicroExport.java b/micropeak/MicroExport.java new file mode 100644 index 00000000..06a03469 --- /dev/null +++ b/micropeak/MicroExport.java @@ -0,0 +1,106 @@ +/* + * 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.io.*; +import java.util.ArrayList; + +import java.awt.*; +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; + +public class MicroExport extends JFileChooser { + + JFrame frame; + MicroData data; + + public boolean runDialog() { + int ret; + + setSelectedFile(new File(AltosLib.replace_extension(data.name, ".csv"))); + for (;;) { + ret = showSaveDialog(frame); + if (ret != APPROVE_OPTION) + return false; + File file; + String filename; + file = getSelectedFile(); + if (file == null) + continue; + if (!file.getName().contains(".")) { + String fullname = file.getPath(); + file = new File(fullname.concat(".csv")); + } + filename = file.getName(); + if (file.exists()) { + if (file.isDirectory()) { + JOptionPane.showMessageDialog(frame, + String.format("\"%s\" is a directory", + filename), + "Directory", + JOptionPane.ERROR_MESSAGE); + continue; + } + int r = JOptionPane.showConfirmDialog(frame, + String.format("\"%s\" already exists. Overwrite?", + filename), + "Overwrite file?", + JOptionPane.YES_NO_OPTION); + if (r != JOptionPane.YES_OPTION) + continue; + + if (!file.canWrite()) { + JOptionPane.showMessageDialog(frame, + String.format("\"%s\" is not writable", + filename), + "File not writable", + JOptionPane.ERROR_MESSAGE); + continue; + } + } + try { + FileWriter fw = new FileWriter(file); + PrintWriter pw = new PrintWriter(fw); + pw.printf(" Time, Press, Height, Speed, Accel\n"); + for (MicroDataPoint point : data.points()) { + pw.printf("%5.2f,%6.0f,%7.1f,%7.2f,%7.2f\n", + point.time, point.pressure, point.height, point.speed, point.accel); + } + fw.close(); + return true; + } catch (FileNotFoundException fe) { + JOptionPane.showMessageDialog(frame, + fe.getMessage(), + "Cannot create file", + JOptionPane.ERROR_MESSAGE); + } catch (IOException ioe) { + } + } + } + + public MicroExport(JFrame frame, MicroData data) { + this.frame = frame; + this.data = data; + setDialogTitle("Export MicroPeak Data File"); + setFileFilter(new FileNameExtensionFilter("MicroPeak CSV file", + "csv")); + setCurrentDirectory(AltosUIPreferences.logdir()); + } +} diff --git a/micropeak/MicroPeak.java b/micropeak/MicroPeak.java index 544f3ae0..f2f09a10 100644 --- a/micropeak/MicroPeak.java +++ b/micropeak/MicroPeak.java @@ -101,12 +101,15 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene new MicroDownload(this, device); } - private void Save() { - if (data == null) { + private void no_data() { JOptionPane.showMessageDialog(this, "No data available", "No data", JOptionPane.INFORMATION_MESSAGE); + } + private void Save() { + if (data == null) { + no_data(); return; } MicroSave save = new MicroSave (this, data); @@ -114,6 +117,15 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene SetName(data.name); } + private void Export() { + if (data == null) { + no_data(); + return; + } + MicroExport export = new MicroExport (this, data); + export.runDialog(); + } + private void Close() { setVisible(false); dispose(); @@ -131,6 +143,8 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene SelectFile(); else if ("Download".equals(ev.getActionCommand())) DownloadData(); + else if ("Export".equals(ev.getActionCommand())) + Export(); else if ("Preferences".equals(ev.getActionCommand())) Preferences(); else if ("Save a Copy".equals(ev.getActionCommand())) @@ -169,6 +183,10 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene fileMenu.add(saveAction); saveAction.addActionListener(this); + JMenuItem exportAction = new JMenuItem("Export"); + fileMenu.add(exportAction); + exportAction.addActionListener(this); + JMenuItem preferencesAction = new JMenuItem("Preferences"); fileMenu.add(preferencesAction); preferencesAction.addActionListener(this); -- cgit v1.2.3 From 31fa139578a86821844e3e2efb1a84bdea4f1370 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 2 Jan 2013 12:24:44 -0800 Subject: micropeak: Add view of raw data in GUI Looks just like the export file Signed-off-by: Keith Packard --- micropeak/Makefile.am | 1 + micropeak/MicroExport.java | 4 ++-- micropeak/MicroPeak.java | 4 ++++ micropeak/MicroRaw.java | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 micropeak/MicroRaw.java (limited to 'micropeak/Makefile.am') diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index f5f8ccd9..89ff2fb3 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -15,6 +15,7 @@ micropeak_JAVA= \ MicroExport.java \ MicroFrame.java \ MicroGraph.java \ + MicroRaw.java \ MicroSave.java \ MicroSerial.java \ MicroStats.java \ diff --git a/micropeak/MicroExport.java b/micropeak/MicroExport.java index 06a03469..219184da 100644 --- a/micropeak/MicroExport.java +++ b/micropeak/MicroExport.java @@ -78,9 +78,9 @@ public class MicroExport extends JFileChooser { try { FileWriter fw = new FileWriter(file); PrintWriter pw = new PrintWriter(fw); - pw.printf(" Time, Press, Height, Speed, Accel\n"); + pw.printf(" Time, Press, Height, Speed, Accel\n"); for (MicroDataPoint point : data.points()) { - pw.printf("%5.2f,%6.0f,%7.1f,%7.2f,%7.2f\n", + pw.printf("%6.3f,%6.0f,%7.1f,%7.2f,%7.2f\n", point.time, point.pressure, point.height, point.speed, point.accel); } fw.close(); diff --git a/micropeak/MicroPeak.java b/micropeak/MicroPeak.java index f2f09a10..290511e7 100644 --- a/micropeak/MicroPeak.java +++ b/micropeak/MicroPeak.java @@ -31,6 +31,7 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene File filename; MicroGraph graph; MicroStatsTable stats; + MicroRaw raw; MicroData data; Container container; JTabbedPane pane; @@ -45,6 +46,7 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene this.data = data; graph.setData(data); stats.setData(data); + raw.setData(data); setTitle(data.name); return this; } @@ -209,8 +211,10 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene graph = new MicroGraph(); stats = new MicroStatsTable(); + raw = new MicroRaw(); pane.add(graph.panel, "Graph"); pane.add(stats, "Statistics"); + pane.add(raw, "Raw Data"); pane.doLayout(); pane.validate(); container.add(pane); diff --git a/micropeak/MicroRaw.java b/micropeak/MicroRaw.java new file mode 100644 index 00000000..6b006f32 --- /dev/null +++ b/micropeak/MicroRaw.java @@ -0,0 +1,41 @@ +/* + * Copyright © 2013 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 javax.swing.*; +import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; + +public class MicroRaw extends TextArea { + + public void setData(MicroData data) { + setRows(data.pressures.length); + setText(" Time, Press, Height, Speed, Accel\n"); + for (MicroDataPoint point : data.points()) { + append(String.format( + "%6.3f,%6.0f,%7.1f,%7.2f,%7.2f\n", + point.time, point.pressure, point.height, point.speed, point.accel)); + } + } + + public MicroRaw() { + super(1, 30); + setFont(AltosUILib.table_value_font); + } +} -- cgit v1.2.3 From 1979063928f1cdfc75c01ec098164c2822a5138d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 2 Jan 2013 16:07:49 -0800 Subject: altosuilib: Fix install issues on Linux altosuilib.jar wasn't getting installed micropeak was using the wrong name Signed-off-by: Keith Packard --- altosuilib/Makefile.am | 6 +++--- micropeak/Makefile.am | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'micropeak/Makefile.am') diff --git a/altosuilib/Makefile.am b/altosuilib/Makefile.am index d4aa0116..da5fb848 100644 --- a/altosuilib/Makefile.am +++ b/altosuilib/Makefile.am @@ -30,11 +30,11 @@ all-local: $(JAR) clean-local: -rm -rf $(JAVAROOT) $(JAR) -install-altosuilibjava: $(JAR) +install-altosuilibJAVA: $(JAR) @$(NORMAL_INSTALL) test -z "$(altosuilibdir)" || $(MKDIR_P) "$(DESTDIR)$(altosuilibdir)" - echo " $(INSTALL_DATA)" "$<" "'$(DESTDIR)$(altosuilibdir)/$(JAR)"; \ - $(INSTALL_DATA) "$<" "$(DESTDIR)$(altosuilibdir)" + echo " $(INSTALL_DATA)" "$(JAR)" "'$(DESTDIR)$(altosuilibdir)/$(JAR)"; \ + $(INSTALL_DATA) "$(JAR)" "$(DESTDIR)$(altosuilibdir)" $(JAVAROOT): mkdir -p $(JAVAROOT) diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index 89ff2fb3..c452db97 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -44,7 +44,7 @@ ALTOSLIB_CLASS=\ AltosLib.jar ALTOSUILIB_CLASS=\ - AltosUILib.jar + altosuilib.jar # Icons ICONDIR=$(top_srcdir)/icon @@ -221,9 +221,9 @@ $(WINDOWS_DIST): $(WINDOWS_FILES) micropeak-windows.nsi Manifest.txt: Makefile echo 'Main-Class: org.altusmetrum.micropeak.MicroPeak' > $@ - echo "Class-Path: AltosLib.jar AltosUILib.jar $(JCOMMON)/jcommon.jar $(JFREECHART)/jfreechart.jar" >> $@ + echo "Class-Path: $(ALTOSLIB_CLASS) $(ALTOSUILIB_CLASS) $(JCOMMON)/jcommon.jar $(JFREECHART)/jfreechart.jar" >> $@ Manifest-fat.txt: echo 'Main-Class: org.altusmetrum.micropeak.MicroPeak' > $@ - echo "Class-Path: AltosLib.jar AltosUILib.jar jcommon.jar jfreechart.jar" >> $@ + echo "Class-Path: $(ALTOSLIB_CLASS) $(ALTOSUILIB_CLASS) jcommon.jar jfreechart.jar" >> $@ -- cgit v1.2.3 From 0c9eecfae02e8499e7c3d53a4386f026c54b04cd Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 5 Jan 2013 10:38:20 -0800 Subject: micropeak: Create .dmg file for apple. Create micropeak-jdb script Signed-off-by: Keith Packard --- micropeak/Makefile.am | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'micropeak/Makefile.am') diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index c452db97..ea7385a7 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -67,7 +67,7 @@ ICONJAR= -C $(ICONDIR) micropeak-16.png \ WINDOWS_ICON=$(ICONDIR)/micro-peak.ico -all-local: micropeak-test $(JAR) +all-local: micropeak-test micropeak-jdb $(JAR) clean-local: -rm -rf classes $(JAR) $(FATJAR) \ @@ -78,7 +78,7 @@ clean-local: micropeak micropeak-test macosx linux windows LINUX_DIST=MicroPeak-Linux-$(VERSION).tar.bz2 -MACOSX_DIST=MicroPeak-Mac-$(VERSION).zip +MACOSX_DIST=MicroPeak-Mac-$(VERSION).dmg WINDOWS_DIST=MicroPeak-Windows-$(VERSION_DASH).exe FAT_FILES=$(FATJAR) $(ALTOSLIB_CLASS) $(ALTOSUILIB_CLASS) $(FREETTS_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) @@ -122,6 +122,11 @@ micropeak: Makefile echo 'exec java -cp "$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" -Djava.library.path="$(altoslibdir)" -jar "$(micropeakdir)/micropeak.jar" "$$@"' >> $@ chmod +x $@ +micropeak-jdb: Makefile + echo "#!/bin/sh" > $@ + echo 'exec jdb -classpath "classes:./*:../libaltos:$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" -Djava.library.path="../libaltos/.libs" org.altusmetrum.micropeak.MicroPeak "$$@"' >> $@ + chmod +x $@ + micropeak-test: Makefile echo "#!/bin/sh" > $@ echo 'exec java -cp "./*:../libaltos/*:$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" -Djava.library.path="../libaltos/.libs" -jar micropeak.jar "$$@"' >> $@ @@ -206,14 +211,14 @@ $(MACOSX_DIST): $(MACOSX_FILES) mkdir macosx cp -a MicroPeak.app macosx/ cp -p Info.plist macosx/MicroPeak.app/Contents - mkdir -p macosx/MicroPeak macosx/MicroPeak.app/Contents/Resources/Java + mkdir -p macosx/MicroPeak.app/Contents/Resources/Java cp -p $(FATJAR) macosx/MicroPeak.app/Contents/Resources/Java/micropeak.jar cp -p libaltos.dylib macosx/MicroPeak.app/Contents/Resources/Java cp -p $(ALTOSLIB_CLASS) macosx/MicroPeak.app/Contents/Resources/Java cp -p $(ALTOSUILIB_CLASS) macosx/MicroPeak.app/Contents/Resources/Java cp -p $(JFREECHART_CLASS) macosx/MicroPeak.app/Contents/Resources/Java cp -p $(JCOMMON_CLASS) macosx/MicroPeak.app/Contents/Resources/Java - cd macosx && zip -r ../$@ MicroPeak.app MicroPeak + genisoimage -D -V MicroPeak-$(VERSION) -no-pad -r -apple -o $@ macosx $(WINDOWS_DIST): $(WINDOWS_FILES) micropeak-windows.nsi -rm -f $@ -- cgit v1.2.3 From d663da13db60e1200535282ee1a0ea6305cad98c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 5 Jan 2013 10:59:26 -0800 Subject: micropeak: Suggest filenames for saving data Uses the format '---flight-.mpd' Signed-off-by: Keith Packard --- micropeak/Makefile.am | 1 + micropeak/MicroFile.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ micropeak/MicroSave.java | 1 + 3 files changed, 47 insertions(+) create mode 100644 micropeak/MicroFile.java (limited to 'micropeak/Makefile.am') diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index ea7385a7..19b23a0f 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -13,6 +13,7 @@ micropeak_JAVA= \ MicroDataPoint.java \ MicroDownload.java \ MicroExport.java \ + MicroFile.java \ MicroFrame.java \ MicroGraph.java \ MicroRaw.java \ diff --git a/micropeak/MicroFile.java b/micropeak/MicroFile.java new file mode 100644 index 00000000..13d48380 --- /dev/null +++ b/micropeak/MicroFile.java @@ -0,0 +1,45 @@ +/* + * Copyright © 2013 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.io.*; +import java.util.*; +import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; + +public class MicroFile { + + public static File make(File directory, int year, int month, int day) { + for (int sequence = 1;; sequence++) { + String s = String.format("%04d-%02d-%02d-flight-%03d.mpd", + year, month, day, sequence); + File file = new File(directory, s); + if (!file.exists()) + return file; + } + } + + public static File make(File directory) { + Calendar cal = Calendar.getInstance(); + return make(directory, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH)); + } + + public static File make() { + return make(AltosUIPreferences.logdir()); + } +} \ No newline at end of file diff --git a/micropeak/MicroSave.java b/micropeak/MicroSave.java index 2664f170..7879ff90 100644 --- a/micropeak/MicroSave.java +++ b/micropeak/MicroSave.java @@ -102,5 +102,6 @@ public class MicroSave extends JFileChooser { setFileFilter(new FileNameExtensionFilter("MicroPeak data file", "mpd")); setCurrentDirectory(AltosUIPreferences.logdir()); + setSelectedFile(MicroFile.make()); } } -- cgit v1.2.3 From 0f05b1996122b6c6bce81ca33e85c2a65c3ded18 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 6 Jan 2013 12:52:25 -0800 Subject: micropeak: Create Mac OS X package Includes the FTDI driver and the MicroPeak app Signed-off-by: Keith Packard --- libaltos/Makefile-standalone | 15 ++++++- libaltos/libaltos.dylib | Bin 41648 -> 41596 bytes micropeak/FTDI.tar.gz | Bin 0 -> 251029 bytes micropeak/Info.plist | 45 --------------------- micropeak/Info.plist.in | 7 +++- micropeak/Makefile.am | 4 +- .../Contents/Resources/AltosUIIcon.icns | Bin 129010 -> 0 bytes .../Contents/Resources/MicroPeak.icns | Bin 0 -> 133711 bytes 8 files changed, 22 insertions(+), 49 deletions(-) create mode 100644 micropeak/FTDI.tar.gz delete mode 100644 micropeak/Info.plist delete mode 100644 micropeak/MicroPeak.app/Contents/Resources/AltosUIIcon.icns create mode 100644 micropeak/MicroPeak.app/Contents/Resources/MicroPeak.icns (limited to 'micropeak/Makefile.am') diff --git a/libaltos/Makefile-standalone b/libaltos/Makefile-standalone index 4e438050..a1f9f5bc 100644 --- a/libaltos/Makefile-standalone +++ b/libaltos/Makefile-standalone @@ -22,9 +22,20 @@ endif # ifeq ($(OS),Darwin) +#OS_LIB_CFLAGS=\ +# -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 \ +# --sysroot=/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 \ +# -iwithsysroot /System/Library/Frameworks/JavaVM.framework/Headers \ +# -iwithsysroot /System/Library/Frameworks/IOKit.framework/Headers \ +# -iwithsysroot /System/Library/Frameworks/CoreFoundation.framework/Headers + +XCODE=/Applications/Xcode.app +SDK=$(XCODE)/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk +MINVERSION=10.5 + OS_LIB_CFLAGS=\ - -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 \ - --sysroot=/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 \ + -DDARWIN -DPOSIX_TTY -arch i386 -arch x86_64 -isysroot $(SDK) \ + -mmacosx-version-min=10.5 \ -iwithsysroot /System/Library/Frameworks/JavaVM.framework/Headers \ -iwithsysroot /System/Library/Frameworks/IOKit.framework/Headers \ -iwithsysroot /System/Library/Frameworks/CoreFoundation.framework/Headers diff --git a/libaltos/libaltos.dylib b/libaltos/libaltos.dylib index 1038817d..cfbd3f54 100755 Binary files a/libaltos/libaltos.dylib and b/libaltos/libaltos.dylib differ diff --git a/micropeak/FTDI.tar.gz b/micropeak/FTDI.tar.gz new file mode 100644 index 00000000..cd08ecf2 Binary files /dev/null and b/micropeak/FTDI.tar.gz differ diff --git a/micropeak/Info.plist b/micropeak/Info.plist deleted file mode 100644 index 5705cc1a..00000000 --- a/micropeak/Info.plist +++ /dev/null @@ -1,45 +0,0 @@ - - - - - CFBundleName - MicroPeak - CFBundleVersion - 1.1.9.2 - CFBundleAllowMixedLocalizations - true - CFBundleExecutable - JavaApplicationStub - CFBundleDevelopmentRegion - English - CFBundlePackageType - APPL - CFBundleIdentifier - org.altusmetrum.altosui - CFBundleSignature - Altu - CFBundleGetInfoString - MicroPeak UI version 1.1.9.2 - CFBundleInfoDictionaryVersion - 6.0 - CFBundleIconFile - MicroPeak.icns - Java - - MainClass - org.altusmetrum.micropeak.MicroPeak - JVMVersion - 1.5+ - ClassPath - - $JAVAROOT/micropeak.jar - - VMOptions - - -Xms512M - -Xmx512M - -Dosgi.clean=true - - - - diff --git a/micropeak/Info.plist.in b/micropeak/Info.plist.in index d3c17a49..40984c5a 100644 --- a/micropeak/Info.plist.in +++ b/micropeak/Info.plist.in @@ -15,7 +15,7 @@ CFBundlePackageType APPL CFBundleIdentifier - org.altusmetrum.altosui + org.altusmetrum.micropeak CFBundleSignature Altu CFBundleGetInfoString @@ -34,6 +34,11 @@ $JAVAROOT/micropeak.jar + Properties + + apple.laf.useScreenMenuBar + true + VMOptions -Xms512M diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index 19b23a0f..38945e82 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -88,7 +88,8 @@ LINUX_FILES=$(FAT_FILES) libaltos.so $(FIRMWARE) $(DOC) LINUX_EXTRA=micropeak-fat MACOSX_INFO_PLIST=Info.plist -MACOSX_FILES=$(FAT_FILES) libaltos.dylib $(MACOSX_INFO_PLIST) +MACOSX_DRIVER=FTDI.tar.gz +MACOSX_FILES=$(FAT_FILES) libaltos.dylib $(MACOSX_INFO_PLIST) $(MACOSX_DRIVER) WINDOWS_FILES=$(FAT_FILES) altos.dll altos64.dll $(top_srcdir)/telemetrum.inf $(WINDOWS_ICON) @@ -212,6 +213,7 @@ $(MACOSX_DIST): $(MACOSX_FILES) mkdir macosx cp -a MicroPeak.app macosx/ cp -p Info.plist macosx/MicroPeak.app/Contents + tar xzf $(MACOSX_DRIVER) -C macosx mkdir -p macosx/MicroPeak.app/Contents/Resources/Java cp -p $(FATJAR) macosx/MicroPeak.app/Contents/Resources/Java/micropeak.jar cp -p libaltos.dylib macosx/MicroPeak.app/Contents/Resources/Java diff --git a/micropeak/MicroPeak.app/Contents/Resources/AltosUIIcon.icns b/micropeak/MicroPeak.app/Contents/Resources/AltosUIIcon.icns deleted file mode 100644 index fe49f362..00000000 Binary files a/micropeak/MicroPeak.app/Contents/Resources/AltosUIIcon.icns and /dev/null differ diff --git a/micropeak/MicroPeak.app/Contents/Resources/MicroPeak.icns b/micropeak/MicroPeak.app/Contents/Resources/MicroPeak.icns new file mode 100644 index 00000000..9ba83bf5 Binary files /dev/null and b/micropeak/MicroPeak.app/Contents/Resources/MicroPeak.icns differ -- cgit v1.2.3 From 2582e9b45bb81ff70fbd5c8581370c8c1b5bd5e5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 6 Jan 2013 13:00:00 -0800 Subject: micropeak: Add ReadMe.rtf to Mac distribution There are *two* steps to installing MicroPeak on Mac OSX. Best help out the poor user by explaining that. Signed-off-by: Keith Packard --- micropeak/Makefile.am | 4 +++- micropeak/ReadMe-Mac.rtf | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 micropeak/ReadMe-Mac.rtf (limited to 'micropeak/Makefile.am') diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index 38945e82..b80cabf2 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -89,7 +89,8 @@ LINUX_EXTRA=micropeak-fat MACOSX_INFO_PLIST=Info.plist MACOSX_DRIVER=FTDI.tar.gz -MACOSX_FILES=$(FAT_FILES) libaltos.dylib $(MACOSX_INFO_PLIST) $(MACOSX_DRIVER) +MACOSX_README=ReadMe-Mac.rtf +MACOSX_FILES=$(FAT_FILES) libaltos.dylib $(MACOSX_INFO_PLIST) $(MACOSX_DRIVER) $(MACOSX_README) WINDOWS_FILES=$(FAT_FILES) altos.dll altos64.dll $(top_srcdir)/telemetrum.inf $(WINDOWS_ICON) @@ -212,6 +213,7 @@ $(MACOSX_DIST): $(MACOSX_FILES) -rm -rf macosx mkdir macosx cp -a MicroPeak.app macosx/ + cp -a $(MACOSX_README) macosx/ReadMe.rtf cp -p Info.plist macosx/MicroPeak.app/Contents tar xzf $(MACOSX_DRIVER) -C macosx mkdir -p macosx/MicroPeak.app/Contents/Resources/Java diff --git a/micropeak/ReadMe-Mac.rtf b/micropeak/ReadMe-Mac.rtf new file mode 100644 index 00000000..64bbdeb6 --- /dev/null +++ b/micropeak/ReadMe-Mac.rtf @@ -0,0 +1,19 @@ +{\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf510 +{\fonttbl\f0\fswiss\fcharset0 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\margl1440\margr1440\vieww10800\viewh8400\viewkind0 +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural + +\f0\fs24 \cf0 Installing MicroPeak software for Mac OS X computers\ +\ +There are two files included in the Mac OS X distribution:\ +\ + 1) The MicroPeak application\ +\ + 2) The FTDI device drivers\ +\ +As with most Mac OS X applications, install MicroPeak by dragging it from the distribution disk image to a suitable place on your computer.\ +\ +To communicate with the MicroPeak serial adapter, you need to installed the FTDI device drivers, which is done by double-clicking on the FTDIUSBSerialDriver package file. That will guide you through the installation process.\ +\ +Thanks for choosing AltusMetrum products!} \ No newline at end of file -- cgit v1.2.3 From c3e807ffcd34d514f36bc11adbae9337991a1743 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 10 Jan 2013 21:41:35 -0800 Subject: micropeak: Create 'micropeak' script correctly Add altoslibdir, remove -cp argument Signed-off-by: Keith Packard --- micropeak/Makefile.am | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'micropeak/Makefile.am') diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index b80cabf2..95c95f40 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -1,6 +1,8 @@ JAVAROOT=classes AM_JAVACFLAGS=-encoding UTF-8 -Xlint:deprecation +altoslibdir=$(libdir)/altos + CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../altoslib/*:../altosuilib/*:../libaltos:$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" bin_SCRIPTS=micropeak @@ -122,7 +124,7 @@ endif micropeak: Makefile echo "#!/bin/sh" > $@ - echo 'exec java -cp "$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" -Djava.library.path="$(altoslibdir)" -jar "$(micropeakdir)/micropeak.jar" "$$@"' >> $@ + echo 'exec java -Djava.library.path="$(altoslibdir)" -jar "$(micropeakdir)/micropeak.jar" "$$@"' >> $@ chmod +x $@ micropeak-jdb: Makefile -- cgit v1.2.3 From 962e3bd0461f187cd599ba54e7129c84f97d4c4d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 10 Jan 2013 22:11:36 -0800 Subject: altosui,micropeak: Link altoslib.jar and altosuilib.jar before compiling The symlinks for the libraries have to be present before compiling stuff. Signed-off-by: Keith Packard --- micropeak/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) (limited to 'micropeak/Makefile.am') diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index 95c95f40..4a7aaaa1 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -155,6 +155,8 @@ $(FATJAR): classmicropeak.stamp Manifest-fat.txt $(ALTOSLIB_CLASS) $(ALTOSUILIB_ -C classes org \ -C ../libaltos libaltosJNI +classaltosui.stamp: $(ALTOSLIB_CLASS) $(ALTOSUILIB_CLASS) + libaltos.so: build-libaltos -rm -f "$@" $(LN_S) ../libaltos/.libs/"$@" . -- cgit v1.2.3