telegps: Add info table
[fw/altos] / telegps / TeleGPS.java
index 45482decbca20aa16a5dff413048e234d0e6a848..d30d8dc53e632b6e98d4a75ec295275501fab4e3 100644 (file)
@@ -50,15 +50,25 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
        AltosFlightReader       reader;
        AltosDisplayThread      thread;
 
-       JTabbedPane     pane;
+       JMenuBar                menu_bar;
 
-       AltosSiteMap    sitemap;
-       boolean         has_map;
+       JMenu                   file_menu;
+       JMenu                   monitor_menu;
+       JMenu                   device_menu;
+       AltosFreqList           frequencies;
+
+       Container               bag;
+
+       TeleGPSStatus           telegps_status;
+       TeleGPSStatusUpdate     status_update;
+
+       JTabbedPane             pane;
+
+       AltosSiteMap            sitemap;
+       TeleGPSInfo             gps_info;
+       AltosInfoTable          info_table;
 
-       JMenuBar        menu_bar;
-       JMenu           file_menu;
-       JMenu           monitor_menu;
-       JMenu           device_menu;
+       LinkedList<AltosFlightDisplay>  displays;
 
        /* File menu */
        final static String     new_command = "new";
@@ -88,21 +98,19 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
 
        /* Device menu */
        final static String     download_command = "download";
-       final static String     configure_command = "configure";
        final static String     export_command = "export";
        final static String     graph_command = "graph";
+       final static String     configure_command = "configure";
+       final static String     flash_command = "flash";
 
        static final String[][] device_menu_entries = new String[][] {
                { "Download Data",      download_command },
                { "Configure Device",   configure_command },
                { "Export Data",        export_command },
                { "Graph Data",         graph_command },
+               { "Flash Device",       flash_command },
        };
 
-//     private AltosInfoTable flightInfo;
-
-       boolean exit_on_close = false;
-
        void stop_display() {
                if (thread != null && thread.isAlive()) {
                        thread.interrupt();
@@ -114,54 +122,57 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
        }
 
        public void reset() {
-               sitemap.reset();
+               for (AltosFlightDisplay display : displays)
+                       display.reset();
        }
 
        public void set_font() {
-               sitemap.set_font();
+               for (AltosFlightDisplay display : displays)
+                       display.set_font();
        }
 
        public void font_size_changed(int font_size) {
                set_font();
        }
 
-
-//     AltosFlightStatusUpdate status_update;
-
        public void show(AltosState state, AltosListenerState listener_state) {
-//             status_update.saved_state = state;
+               try {
+                       status_update.saved_state = state;
 
-               if (state == null)
-                       state = new AltosState();
+                       if (state == null)
+                               state = new AltosState();
 
-               sitemap.show(state, listener_state);
-               telegps_status.show(state, listener_state);
+                       int i = 0;
+                       for (AltosFlightDisplay display : displays) {
+                               display.show(state, listener_state);
+                               i++;
+                       }
+               } catch (Exception ex) {
+                       System.out.printf("Exception %s\n", ex.toString());
+                       for (StackTraceElement e : ex.getStackTrace())
+                               System.out.printf("%s\n", e.toString());
+               }
        }
 
-       Container               bag;
-       AltosFreqList           frequencies;
-       JLabel                  telemetry;
-       TeleGPSStatus           telegps_status;
-       TeleGPSStatusUpdate     status_update;
-
-       ActionListener          show_timer;
-
        void new_window() {
                new TeleGPS();
        }
 
        void preferences() {
+               new TeleGPSPreferences(this, voice());
        }
 
        void load_maps() {
                new AltosSiteMapPreload(this);
        }
 
-       void monitor() {
-               AltosDevice     device = AltosDeviceUIDialog.show(this,
-                                                                 AltosLib.product_basestation);
-               if (device == null)
-                       return;
+       void disconnect() {
+               setTitle("TeleGPS");
+               stop_display();
+               remove_frequency_menu();
+       }
+
+       void connect(AltosDevice device) {
                if (reader != null)
                        disconnect();
                try {
@@ -197,27 +208,46 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
                }
        }
 
-       void disconnect() {
-               setTitle("TeleGPS");
-               stop_display();
-               remove_frequency_menu();
+       void monitor() {
+               AltosDevice     device = AltosDeviceUIDialog.show(this,
+                                                                 AltosLib.product_basestation);
+               if (device == null)
+                       return;
+               connect(device);
+       }
+
+       public void scan_device_selected(AltosDevice device) {
+               connect(device);
        }
 
        void scan() {
+               new AltosScanUI(this, false);
        }
 
        void download(){
+               new AltosEepromManage(this, AltosLib.product_telegps);
        }
 
        void configure() {
+               new TeleGPSConfig(this);
        }
 
        void export() {
+               AltosDataChooser chooser;
+               chooser = new AltosDataChooser(this);
+               AltosStateIterable states = chooser.runDialog();
+               if (states == null)
+                       return;
+               new AltosCSVUI(this, states, chooser.file());
        }
 
        void graph() {
        }
 
+       void flash() {
+               AltosFlashUI.show(this);
+       }
+
        public void actionPerformed(ActionEvent ev) {
 
                /* File menu */
@@ -271,6 +301,10 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
                        graph();
                        return;
                }
+               if (flash_command.equals(ev.getActionCommand())) {
+                       flash();
+                       return;
+               }
        }
 
        void add_frequency_menu(int serial, final AltosFlightReader reader) {
@@ -351,6 +385,7 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
                file_menu = make_menu("File", file_menu_entries);
                monitor_menu = make_menu("Monitor", monitor_menu_entries);
                device_menu = make_menu("Device", device_menu_entries);
+               displays = new LinkedList<AltosFlightDisplay>();
 
                int serial = -1;
 
@@ -363,6 +398,7 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
                c.gridwidth = 2;
                bag.add(telegps_status, c);
                c.gridwidth = 1;
+               displays.add(telegps_status);
 
 
                /* The rest of the window uses a tabbed pane to
@@ -381,6 +417,15 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
 
                sitemap = new AltosSiteMap();
                pane.add("Site Map", sitemap);
+               displays.add(sitemap);
+
+               gps_info = new TeleGPSInfo();
+               pane.add("Info", gps_info);
+               displays.add(gps_info);
+
+               info_table = new AltosInfoTable();
+               pane.add("Table", info_table);
+               displays.add(info_table);
 
                setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
 
@@ -408,6 +453,11 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
                set_reader(reader);
        }
 
+       public TeleGPS(AltosDevice device) {
+               this();
+               connect(device);
+       }
+
        static AltosStateIterable record_iterable(File file) {
                FileInputStream in;
                try {
@@ -537,7 +587,15 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
                }
                if (errors != 0)
                        System.exit(errors);
-               if (!any_created)
-                       new TeleGPS();
+               if (!any_created) {
+                       java.util.List<AltosDevice> devices = AltosUSBDevice.list(AltosLib.product_basestation);
+                       if (devices != null)
+                               for (AltosDevice device : devices) {
+                                       new TeleGPS(device);
+                                       any_created = true;
+                               }
+                       if (!any_created)
+                               new TeleGPS();
+               }
        }
 }