telegps: Add flash device functionality
[fw/altos] / telegps / TeleGPS.java
index 1bb505e03c068e102e1a1551bce205c3750d0681..7f34c763428b1cc750de4303620773e1a1398af7 100644 (file)
@@ -89,21 +89,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();
@@ -240,6 +238,10 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
        void graph() {
        }
 
+       void flash() {
+               AltosFlashUI.show(this);
+       }
+
        public void actionPerformed(ActionEvent ev) {
 
                /* File menu */
@@ -293,6 +295,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) {
@@ -433,6 +439,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 {
@@ -562,7 +573,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();
+               }
        }
 }