From 233ab58df8ac8e1fdeab8d4c2f6c8c9d3f6e7be1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 22 Jul 2012 11:53:44 -0700 Subject: [PATCH] altosui: Move AltosIgnite.java to altoslib To be shared with altosdroid eventually Signed-off-by: Keith Packard --- {altosui => altoslib}/AltosIgnite.java | 91 +++++++++++--------------- altoslib/Makefile.am | 1 + altosui/AltosIgniteUI.java | 7 +- altosui/Makefile.am | 1 - 4 files changed, 44 insertions(+), 56 deletions(-) rename {altosui => altoslib}/AltosIgnite.java (67%) diff --git a/altosui/AltosIgnite.java b/altoslib/AltosIgnite.java similarity index 67% rename from altosui/AltosIgnite.java rename to 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 \ -- 2.30.2