altosui: Add a 'Graph Flight' button to the 'landed' tab
[fw/altos] / altosui / AltosUI.java
index 73ddf979c254a8f2343c57bc8cebdf31687fc688..62e612ed07d0fc9282e00e9ab0910f7951db6a6b 100644 (file)
@@ -26,7 +26,7 @@ import java.io.*;
 import java.util.*;
 import java.text.*;
 import java.util.prefs.*;
-import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.*;
 
 import libaltosJNI.*;
 
@@ -34,7 +34,7 @@ public class AltosUI extends JFrame {
        public AltosVoice voice = new AltosVoice();
 
        public static boolean load_library(Frame frame) {
-               if (!AltosDevice.load_library()) {
+               if (!Altos.load_library()) {
                        JOptionPane.showMessageDialog(frame,
                                                      String.format("No AltOS library in \"%s\"",
                                                                    System.getProperty("java.library.path","<undefined>")),
@@ -67,6 +67,16 @@ public class AltosUI extends JFrame {
                                                      device.toShortString(),
                                                      "Unkonwn I/O error",
                                                      JOptionPane.ERROR_MESSAGE);
+               } catch (TimeoutException te) {
+                       JOptionPane.showMessageDialog(this,
+                                                     device.toShortString(),
+                                                     "Timeout error",
+                                                     JOptionPane.ERROR_MESSAGE);
+               } catch (InterruptedException ie) {
+                       JOptionPane.showMessageDialog(this,
+                                                     device.toShortString(),
+                                                     "Interrupted exception",
+                                                     JOptionPane.ERROR_MESSAGE);
                }
        }
 
@@ -99,7 +109,7 @@ public class AltosUI extends JFrame {
                if (imgURL != null)
                        setIconImage(new ImageIcon(imgURL).getImage());
 
-               AltosPreferences.init(this);
+               AltosPreferences.set_component(this);
 
                pane = getContentPane();
                gridbag = new GridBagLayout();
@@ -137,7 +147,7 @@ public class AltosUI extends JFrame {
                                                ExportData();
                                        }
                                });
-               b = addButton(0, 1, "Configure TeleMetrum");
+               b = addButton(0, 1, "Configure Altimeter");
                b.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
                                                ConfigureTeleMetrum();
@@ -172,6 +182,28 @@ public class AltosUI extends JFrame {
                                }
                        });
 
+
+               b = addButton(0, 2, "Scan Channels");
+               b.addActionListener(new ActionListener() {
+                               public void actionPerformed(ActionEvent e) {
+                                       ScanChannels();
+                               }
+                       });
+
+               b = addButton(1, 2, "Load Maps");
+               b.addActionListener(new ActionListener() {
+                               public void actionPerformed(ActionEvent e) {
+                                       LoadMaps();
+                               }
+                       });
+
+               b = addButton(2, 2, "Monitor Idle");
+               b.addActionListener(new ActionListener() {
+                               public void actionPerformed(ActionEvent e) {
+                                       IdleMonitor();
+                               }
+                       });
+
                setTitle("AltOS");
 
                pane.doLayout();
@@ -198,12 +230,8 @@ public class AltosUI extends JFrame {
        }
 
        private void ConnectToDevice() {
-               AltosBTManage   bt_manage;
-
-               bt_manage = new AltosBTManage(AltosBTDevice.bt_product_any, this);
-               bt_manage.list();
                AltosDevice     device = AltosDeviceDialog.show(AltosUI.this,
-                                                               AltosDevice.product_basestation);
+                                                               Altos.product_basestation);
 
                if (device != null)
                        telemetry_window(device);
@@ -223,13 +251,21 @@ public class AltosUI extends JFrame {
        }
 
        void FlashImage() {
-               new AltosFlashUI(AltosUI.this);
+               AltosFlashUI.show(AltosUI.this);
        }
 
        void FireIgniter() {
                new AltosIgniteUI(AltosUI.this);
        }
 
+       void ScanChannels() {
+               new AltosScanUI(AltosUI.this);
+       }
+
+       void LoadMaps() {
+               new AltosSiteMapPreload(AltosUI.this);
+       }
+
        /*
         * Replay a flight from telemetry data
         */
@@ -240,7 +276,7 @@ public class AltosUI extends JFrame {
                AltosRecordIterable iterable = chooser.runDialog();
                if (iterable != null) {
                        AltosFlightReader reader = new AltosReplayReader(iterable.iterator(),
-                                                                        chooser.filename());
+                                                                        chooser.file());
                        new AltosFlightUI(voice, reader);
                }
        }
@@ -274,13 +310,24 @@ public class AltosUI extends JFrame {
                AltosRecordIterable record_reader = chooser.runDialog();
                if (record_reader == null)
                        return;
-               new AltosGraphUI(record_reader);
+               try {
+                       new AltosGraphUI(record_reader);
+               } catch (InterruptedException ie) {
+               } catch (IOException ie) {
+               }
        }
 
        private void ConfigureAltosUI() {
                new AltosConfigureUI(AltosUI.this, voice);
        }
 
+       private void IdleMonitor() {
+               try {
+                       new AltosIdleMonitorUI(this);
+               } catch (Exception e) {
+               }
+       }
+
        static AltosRecordIterable open_logfile(String filename) {
                File file = new File (filename);
                try {
@@ -384,7 +431,7 @@ public class AltosUI extends JFrame {
                        } else {
                                recs = new AltosTelemetryIterable(in);
                        }
-                       reader = new AltosReplayReader(recs.iterator(), filename);
+                       reader = new AltosReplayReader(recs.iterator(), new File(filename));
                        AltosFlightUI flight_ui = new AltosFlightUI(new AltosVoice(), reader);
                        flight_ui.set_exit_on_close();
                        return;
@@ -401,9 +448,9 @@ public class AltosUI extends JFrame {
                        AltosUI altosui = new AltosUI();
                        altosui.setVisible(true);
 
-                       AltosDevice[] devices = AltosDevice.list(AltosDevice.product_basestation);
-                       for (int i = 0; i < devices.length; i++)
-                               altosui.telemetry_window(devices[i]);
+                       java.util.List<AltosDevice> devices = AltosUSBDevice.list(Altos.product_basestation);
+                       for (AltosDevice device : devices)
+                               altosui.telemetry_window(device);
                }
        }
 }