--- /dev/null
+*.jar
+Manifest.txt
+classes
+*.stamp
+micropeak
+micropeak-test
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
MicroGraph.java \
MicroSerial.java \
MicroFileChooser.java \
- MicroPreferences.java \
- MicroPreferencesBackend.java \
- MicroFontListener.java \
- MicroUIListener.java \
MicroUSB.java
JFREECHART_CLASS= \
ALTOSLIB_CLASS=\
AltosLib.jar
+ALTOSUILIB_CLASS=\
+ AltosUILib.jar
+
# Icons
ICONDIR=$(top_srcdir)/icon
clean-local:
-rm -rf classes $(JAR) $(FATJAR) \
$(ALTOSLIB_CLASS) \
+ $(ALTOSUILIB_CLASS) \
$(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) Manifest.txt \
micropeak micropeak-test macosx linux windows
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 \
-rm -f "$@"
$(LN_S) ../altoslib/"$@" .
+$(ALTOSUILIB_CLASS):
+ -rm -f "$@"
+ $(LN_S) ../altosuilib/"$@" .
+
$(JFREECHART_CLASS):
-rm -f "$@"
$(LN_S) "$(JFREECHART)"/"$@" .
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" >> $@
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.*;
import org.altusmetrum.AltosLib.*;
+import org.altusmetrum.altosuilib.*;
public class MicroFileChooser extends JFileChooser {
JFrame frame;
setDialogTitle("Select MicroPeak Data File");
setFileFilter(new FileNameExtensionFilter("MicroPeak data file",
"mpd"));
+ setCurrentDirectory(AltosUIPreferences.logdir());
}
}
+++ /dev/null
-/*
- * Copyright © 2011 Keith Packard <keithp@keithp.com>
- *
- * 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);
-}
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",
"/micropeak-256.png"
};
- public void set_icon() {
- ArrayList<Image> icons = new ArrayList<Image>();
-
- 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); }
}
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;
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)");
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);
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
import java.util.concurrent.*;
import java.util.*;
import org.altusmetrum.AltosLib.*;
+import org.altusmetrum.altosuilib.*;
public class MicroPeak extends MicroFrame implements ActionListener, ItemListener {
RunFile(input);
}
+ private void Preferences() {
+ new AltosConfigureUI(this);
+ }
+
private void DownloadData() {
java.util.List<MicroUSB> devices = MicroUSB.list();
for (MicroUSB device : devices)
}
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()))
new MicroPeak();
else if ("Download".equals(ev.getActionCommand()))
DownloadData();
+ else if ("Preferences".equals(ev.getActionCommand()))
+ Preferences();
}
public void itemStateChanged(ItemEvent e) {
public MicroPeak() {
- this.filename = filename;
+ AltosUIPreferences.set_component(this);
pane = getContentPane();
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);
}
});
- graph = new MicroGraph(data);
+ graph = new MicroGraph();
pane.add(graph.panel);
pane.doLayout();
pane.validate();
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]));
+++ /dev/null
-/*
- * Copyright © 2011 Keith Packard <keithp@keithp.com>
- *
- * 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<MicroFontListener> font_listeners;
-
- static int font_size = font_size_medium;
-
- static LinkedList<MicroUIListener> 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<MicroFontListener>();
-
- font_size = backend.getInt(fontSizePreference, font_size_medium);
- set_fonts(font_size);
- look_and_feel = backend.getString(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName());
-
- ui_listeners = new LinkedList<MicroUIListener>();
- 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;
- }
- }
-
-}
+++ /dev/null
-/*
- * Copyright © 2012 Mike Beattie <mike@ethernal.org>
- *
- * 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();
- }
-}
*/
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;
}
+++ /dev/null
-/*
- * Copyright © 2011 Keith Packard <keithp@keithp.com>
- *
- * 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);
-}