summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2012-07-22 11:53:44 -0700
committerKeith Packard <keithp@keithp.com>2012-07-22 11:54:17 -0700
commit233ab58df8ac8e1fdeab8d4c2f6c8c9d3f6e7be1 (patch)
tree97077b121ed77cb576424f7c0cf4b6936a735e64
parent38f66a31174dd367e39d717c527f555add60a9d4 (diff)
altosui: Move AltosIgnite.java to altoslib
To be shared with altosdroid eventually Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--altoslib/AltosIgnite.java (renamed from altosui/AltosIgnite.java)91
-rw-r--r--altoslib/Makefile.am1
-rw-r--r--altosui/AltosIgniteUI.java7
-rw-r--r--altosui/Makefile.am1
4 files changed, 44 insertions, 56 deletions
diff --git a/altosui/AltosIgnite.java b/altoslib/AltosIgnite.java
index f84db0b9..cc814337 100644
--- a/altosui/AltosIgnite.java
+++ b/altoslib/AltosIgnite.java
@@ -15,46 +15,39 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-package altosui;
+package org.altusmetrum.AltosLib;
import java.io.*;
import java.util.concurrent.*;
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-import javax.swing.filechooser.FileNameExtensionFilter;
-import javax.swing.table.*;
-import javax.swing.event.*;
-import org.altusmetrum.AltosLib.*;
public class AltosIgnite {
- AltosDevice device;
- AltosSerial serial;
+ AltosLink link;
boolean remote;
- boolean serial_started;
- final static int None = 0;
- final static int Apogee = 1;
- final static int Main = 2;
-
- final static int Unknown = 0;
- final static int Ready = 1;
- final static int Active = 2;
- final static int Open = 3;
-
- private void start_serial() throws InterruptedException, TimeoutException {
- serial_started = true;
+ boolean link_started;
+
+ public final static int None = 0;
+ public final static int Apogee = 1;
+ public final static int Main = 2;
+
+ public final static int Unknown = 0;
+ public final static int Ready = 1;
+ public final static int Active = 2;
+ public final static int Open = 3;
+
+ private void start_link() throws InterruptedException, TimeoutException {
+ link_started = true;
if (remote)
- serial.start_remote();
+ link.start_remote();
}
- private void stop_serial() throws InterruptedException {
- if (!serial_started)
+ private void stop_link() throws InterruptedException {
+ if (!link_started)
return;
- serial_started = false;
- if (serial == null)
+ link_started = false;
+ if (link == null)
return;
if (remote)
- serial.stop_remote();
+ link.stop_remote();
}
class string_ref {
@@ -100,14 +93,14 @@ public class AltosIgnite {
public int status(int igniter) throws InterruptedException, TimeoutException {
int status = Unknown;
- if (serial == null)
+ if (link == null)
return status;
string_ref status_name = new string_ref();
try {
- start_serial();
- serial.printf("t\n");
+ start_link();
+ link.printf("t\n");
for (;;) {
- String line = serial.get_reply(5000);
+ String line = link.get_reply(5000);
if (line == null)
throw new TimeoutException();
String[] items = line.split("\\s+");
@@ -131,7 +124,7 @@ public class AltosIgnite {
}
}
} finally {
- stop_serial();
+ stop_link();
}
return status;
}
@@ -147,23 +140,23 @@ public class AltosIgnite {
}
public void fire(int igniter) {
- if (serial == null)
+ if (link == null)
return;
try {
- start_serial();
+ start_link();
switch (igniter) {
case Main:
- serial.printf("i DoIt main\n");
+ link.printf("i DoIt main\n");
break;
case Apogee:
- serial.printf("i DoIt drogue\n");
+ link.printf("i DoIt drogue\n");
break;
}
} catch (InterruptedException ie) {
} catch (TimeoutException te) {
} finally {
try {
- stop_serial();
+ stop_link();
} catch (InterruptedException ie) {
}
}
@@ -171,25 +164,17 @@ public class AltosIgnite {
public void close() {
try {
- stop_serial();
+ stop_link();
} catch (InterruptedException ie) {
}
- serial.close();
- serial = null;
+ link.close();
+ link = null;
}
- public void set_frame(Frame frame) {
- serial.set_frame(frame);
- }
-
- public AltosIgnite(AltosDevice in_device)
- throws FileNotFoundException, AltosSerialInUseException, TimeoutException, InterruptedException {
-
- device = in_device;
- serial = new AltosSerial(device);
- remote = false;
+ public AltosIgnite(AltosLink in_link, boolean in_remote)
+ throws FileNotFoundException, TimeoutException, InterruptedException {
- if (!device.matchProduct(Altos.product_altimeter))
- remote = true;
+ link = in_link;
+ remote = in_remote;
}
} \ No newline at end of file
diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am
index a39623ee..1f42140b 100644
--- a/altoslib/Makefile.am
+++ b/altoslib/Makefile.am
@@ -29,6 +29,7 @@ AltosLib_JAVA = \
$(SRC)/AltosGreatCircle.java \
$(SRC)/AltosIdleMonitor.java \
$(SRC)/AltosIdleMonitorListener.java \
+ $(SRC)/AltosIgnite.java \
$(SRC)/AltosLine.java \
$(SRC)/AltosLink.java \
$(SRC)/AltosLog.java \
diff --git a/altosui/AltosIgniteUI.java b/altosui/AltosIgniteUI.java
index 076d99b2..78eba8e6 100644
--- a/altosui/AltosIgniteUI.java
+++ b/altosui/AltosIgniteUI.java
@@ -72,12 +72,15 @@ public class AltosIgniteUI
public void run () {
try {
- ignite = new AltosIgnite(device);
+ AltosSerial serial = new AltosSerial(device);
+ serial.set_frame(owner);
+ ignite = new AltosIgnite(serial,
+ !device.matchProduct(Altos.product_altimeter));
+
} catch (Exception e) {
send_exception(e);
return;
}
- ignite.set_frame(owner);
for (;;) {
Runnable r;
diff --git a/altosui/Makefile.am b/altosui/Makefile.am
index 1c8ea491..19db6698 100644
--- a/altosui/Makefile.am
+++ b/altosui/Makefile.am
@@ -55,7 +55,6 @@ altosui_JAVA = \
AltosHexfile.java \
Altos.java \
AltosIdleMonitorUI.java \
- AltosIgnite.java \
AltosIgniteUI.java \
AltosLaunch.java \
AltosLaunchUI.java \