altoslib: Remove ascending/descending from pyro config
[fw/altos] / altosui / AltosIgniteUI.java
index 944c659bfd06bf5707fb323ec31eede94c19dbfa..debbf763481136e781ff274d165da27c2d0abb54 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
@@ -24,8 +25,8 @@ import java.io.*;
 import java.text.*;
 import java.util.*;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_6.*;
-import org.altusmetrum.altosuilib_6.*;
+import org.altusmetrum.altoslib_12.*;
+import org.altusmetrum.altosuilib_12.*;
 
 public class AltosIgniteUI
        extends AltosUIDialog
@@ -48,9 +49,9 @@ public class AltosIgniteUI
        int             time_remaining;
        boolean         timer_running;
 
-       LinkedBlockingQueue<String>     command_queue;
+       int             poll_remaining;
 
-       LinkedBlockingQueue<String>     reply_queue;
+       LinkedBlockingQueue<String>     command_queue;
 
        class Igniter {
                JRadioButton    button;
@@ -150,8 +151,7 @@ public class AltosIgniteUI
                                                }
                                                reply = "status";
                                        } else if (command.equals("get_npyro")) {
-                                               put_reply(String.format("%d", ignite.npyro()));
-                                               continue;
+                                               reply = String.format("npyro %d", ignite.npyro());
                                        } else if (command.equals("quit")) {
                                                ignite.close();
                                                break;
@@ -211,6 +211,11 @@ public class AltosIgniteUI
                        set_ignite_status();
                } else if (reply.equals("fired")) {
                        fired();
+               } else if (reply.startsWith("npyro")) {
+                       npyro = Integer.parseInt(reply.substring(6));
+                       if (npyro == AltosLib.MISSING)
+                               npyro = 0;
+                       make_ui();
                }
        }
 
@@ -250,49 +255,26 @@ public class AltosIgniteUI
                }
        }
 
-       void put_reply(String reply) {
-               try {
-                       reply_queue.put(reply);
-               } catch (Exception ex) {
-                       ignite_exception(ex);
-               }
-       }
-
-       String get_reply() {
-               String reply = "";
-               try {
-                       reply = reply_queue.take();
-               } catch (Exception ex) {
-                       ignite_exception(ex);
-               }
-               return reply;
-       }
-
        boolean getting_status = false;
 
-       boolean visible = false;
-
        void set_ignite_status() {
                getting_status = false;
-               if (!visible) {
-                       visible = true;
+               poll_remaining = 2;
+               if (!isVisible())
                        setVisible(true);
-               }
        }
 
        void poll_ignite_status() {
+               if (poll_remaining > 0) {
+                       --poll_remaining;
+                       return;
+               }
                if (!getting_status) {
                        getting_status = true;
                        send_command("get_status");
                }
        }
 
-       int get_npyro() {
-               send_command("get_npyro");
-               String reply = get_reply();
-               return Integer.parseInt(reply);
-       }
-
        boolean firing = false;
 
        void start_fire(String which) {
@@ -310,8 +292,9 @@ public class AltosIgniteUI
        void close() {
                if (opened) {
                        send_command("quit");
-                       timer.stop();
                }
+               if (timer != null)
+                       timer.stop();
                setVisible(false);
                dispose();
        }
@@ -383,7 +366,6 @@ public class AltosIgniteUI
 
        private boolean open() {
                command_queue = new LinkedBlockingQueue<String>();
-               reply_queue = new LinkedBlockingQueue<String>();
 
                opened = false;
                device = AltosDeviceUIDialog.show(owner, Altos.product_any);
@@ -403,13 +385,7 @@ public class AltosIgniteUI
                return false;
        }
 
-       public AltosIgniteUI(JFrame in_owner) {
-
-               owner = in_owner;
-
-               if (!open())
-                       return;
-
+       private void make_ui() {
                group = new ButtonGroup();
 
                Container               pane = getContentPane();
@@ -422,8 +398,6 @@ public class AltosIgniteUI
                timer_running = false;
                timer.restart();
 
-               owner = in_owner;
-
                pane.setLayout(new GridBagLayout());
 
                c.fill = GridBagConstraints.NONE;
@@ -443,8 +417,6 @@ public class AltosIgniteUI
 
                y++;
 
-               int npyro = get_npyro();
-
                igniters = new Igniter[2 + npyro];
 
                igniters[0] = new Igniter(this, "Apogee", AltosIgnite.Apogee, y++);
@@ -492,4 +464,14 @@ public class AltosIgniteUI
 
                addWindowListener(new ConfigListener(this));
        }
-}
\ No newline at end of file
+
+       public AltosIgniteUI(JFrame in_owner) {
+
+               owner = in_owner;
+
+               if (!open())
+                       return;
+
+               send_command("get_npyro");
+       }
+}