altos: Remove unused ao_adc_get from ao_adc_stm.c
[fw/altos] / micropeak / MicroPeak.java
index 27a8db02a262845ba2fb2feb5c0f3f763a62ccb3..eee5bc07a04b0bd4c6711fa0efd4f386c993a01b 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -23,18 +24,17 @@ import javax.swing.*;
 import java.io.*;
 import java.util.concurrent.*;
 import java.util.*;
-import org.altusmetrum.altoslib_2.*;
-import org.altusmetrum.altosuilib_1.*;
+import org.altusmetrum.altoslib_13.*;
+import org.altusmetrum.altosuilib_13.*;
 
-public class MicroPeak extends MicroFrame implements ActionListener, ItemListener {
+public class MicroPeak extends MicroFrame implements ActionListener, ItemListener, AltosFilterListener {
 
        File            filename;
-       MicroGraph      graph;
+       AltosGraph      graph;
        AltosUIEnable   enable;
-       MicroStatsTable statsTable;
+       AltosFlightStatsTable   statsTable;
        MicroRaw        raw;
        MicroData       data;
-       MicroStats      stats;
        Container       container;
        JTabbedPane     pane;
        static int      number_of_windows;
@@ -46,9 +46,12 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
                        return mp.SetData(data);
                }
                this.data = data;
-               stats = new MicroStats(data);
-               graph.setDataSet(data);
-               statsTable.setStats(stats);
+               if (data.flight_series == null)
+                       System.out.printf("no data in flight\n");
+               if (data.flight_stats == null)
+                       System.out.printf("no stats in flight\n");
+               graph.set_data(data.flight_stats, data.flight_series);
+               statsTable.set_stats(data.flight_stats);
                raw.setData(data);
                setTitle(data.name);
                return this;
@@ -65,6 +68,10 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
                try {
                        data = new MicroData((InputStream) fis, filename.getName());
                        AltosUIPreferences.set_last_logdir(filename);
+               } catch (MicroData.NonHexcharException nhe) {
+                       data = null;
+               } catch (MicroData.FileEndedException nhe) {
+                       data = null;
                } catch (InterruptedException ie) {
                        data = null;
                } finally {
@@ -103,7 +110,7 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
 
        private void DownloadData() {
                AltosDevice     device = MicroDeviceDialog.show(this);
-               
+
                if (device != null)
                        new MicroDownload(this, device);
        }
@@ -124,7 +131,7 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
                if (save.runDialog())
                        SetName(data.name);
        }
-       
+
        private void Export() {
                if (data == null) {
                        no_data();
@@ -186,10 +193,44 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
        public void itemStateChanged(ItemEvent e) {
        }
 
+       /* OSXAdapter interfaces */
+       public void macosx_file_handler(String path) {
+               CommandGraph(new File(path));
+       }
+
+       public void macosx_quit_handler() {
+               System.exit(0);
+       }
+
+       public void macosx_preferences_handler() {
+               Preferences();
+       }
+
+       public void filter_changed(double speed_filter, double accel_filter) {
+               data.flight_series.set_filter(speed_filter, accel_filter);
+               graph.filter_changed();
+               data.flight_stats = new AltosFlightStats(data.flight_series);
+               statsTable.filter_changed(data.flight_stats);
+       }
+
+       public double speed_filter() {
+               if (data != null && data.flight_series != null)
+                       return data.flight_series.speed_filter_width;
+               return 4.0;
+       }
+
+       public double accel_filter() {
+               if (data != null && data.flight_series != null)
+                       return data.flight_series.accel_filter_width;
+               return 1.0;
+       }
+
        public MicroPeak() {
 
                ++number_of_windows;
 
+               register_for_macosx_events();
+
                AltosUIPreferences.set_component(this);
 
                container = getContentPane();
@@ -240,13 +281,15 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
                        @Override
                        public void windowClosing(WindowEvent e) {
                                statsTable.tell_closing();
+                               raw.tell_closing();
                                Close();
                        }
                });
 
-               enable = new AltosUIEnable();
-               graph = new MicroGraph(enable);
-               statsTable = new MicroStatsTable();
+               enable = new AltosUIEnable(this);
+
+               graph = new AltosGraph(enable);
+               statsTable = new AltosFlightStatsTable();
                raw = new MicroRaw();
                pane.add(graph.panel, "Graph");
                pane.add(enable, "Configure Graph");
@@ -304,8 +347,9 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
                                                CommandExport(file);
                                        opened = true;
                                } catch (Exception e) {
-                                       System.err.printf("Error processing \"%s\": %s\n",
-                                                         file.getName(), e.getMessage());
+                                       System.err.printf("Error processing \"%s\": %s %s\n",
+                                                         file.getName(), e.toString(), e.getMessage());
+                                       e.printStackTrace();
                                }
                        }
                }