import java.text.*;
import java.util.*;
import java.util.concurrent.*;
-import org.altusmetrum.altoslib_3.*;
-import org.altusmetrum.altosuilib_1.*;
+import org.altusmetrum.altoslib_9.*;
+import org.altusmetrum.altosuilib_9.*;
public class AltosIgniteUI
extends AltosUIDialog
javax.swing.Timer timer;
JButton close;
ButtonGroup group;
+ Boolean opened;
int npyro;
LinkedBlockingQueue<String> command_queue;
- LinkedBlockingQueue<String> reply_queue;
-
class Igniter {
JRadioButton button;
JLabel status_label;
class IgniteHandler implements Runnable {
AltosIgnite ignite;
JFrame owner;
+ AltosLink link;
void send_exception(Exception e) {
final Exception f_e = e;
public void run () {
try {
- AltosSerial serial = new AltosSerial(device);
- serial.set_frame(owner);
- ignite = new AltosIgnite(serial,
+ ignite = new AltosIgnite(link,
!device.matchProduct(Altos.product_altimeter));
} catch (Exception e) {
}
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;
}
}
- public IgniteHandler(JFrame in_owner) {
+ public IgniteHandler(JFrame in_owner, AltosLink in_link) {
owner = in_owner;
+ link = in_link;
}
}
set_ignite_status();
} else if (reply.equals("fired")) {
fired();
+ } else if (reply.startsWith("npyro")) {
+ npyro = Integer.parseInt(reply.substring(6));
+ make_ui();
}
}
}
}
- 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;
}
}
- int get_npyro() {
- send_command("get_npyro");
- String reply = get_reply();
- return Integer.parseInt(reply);
- }
-
boolean firing = false;
void start_fire(String which) {
}
void close() {
- send_command("quit");
- timer.stop();
+ if (opened) {
+ send_command("quit");
+ }
+ if (timer != null)
+ timer.stop();
setVisible(false);
dispose();
}
private boolean open() {
command_queue = new LinkedBlockingQueue<String>();
- reply_queue = new LinkedBlockingQueue<String>();
+ opened = false;
device = AltosDeviceUIDialog.show(owner, Altos.product_any);
if (device != null) {
- IgniteHandler handler = new IgniteHandler(owner);
+ try {
+ AltosSerial serial = new AltosSerial(device);
+ serial.set_frame(owner);
+ IgniteHandler handler = new IgniteHandler(owner, serial);
Thread t = new Thread(handler);
t.start();
+ opened = true;
return true;
+ } catch (Exception ex) {
+ ignite_exception(ex);
+ }
}
return false;
}
- public AltosIgniteUI(JFrame in_owner) {
-
- owner = in_owner;
-
- if (!open())
- return;
-
+ private void make_ui() {
group = new ButtonGroup();
Container pane = getContentPane();
timer_running = false;
timer.restart();
- owner = in_owner;
-
pane.setLayout(new GridBagLayout());
c.fill = GridBagConstraints.NONE;
y++;
- int npyro = get_npyro();
-
igniters = new Igniter[2 + npyro];
igniters[0] = new Igniter(this, "Apogee", AltosIgnite.Apogee, y++);
pane.add(close, c);
close.addActionListener(this);
close.setActionCommand("close");
-
+
pack();
setLocationRelativeTo(owner);
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");
+ }
+}