diff options
author | Bdale Garbee <bdale@gag.com> | 2013-12-19 01:38:40 -0700 |
---|---|---|
committer | Bdale Garbee <bdale@gag.com> | 2013-12-19 01:38:40 -0700 |
commit | 575bbaf976c5840fd0e308549c45a466fdec1352 (patch) | |
tree | 11bfb498348bf7687bffc24699c4b1a998988ee4 /altoslib/AltosIMU.java | |
parent | b825116df173b77e2cab217a7b76112c742f9279 (diff) | |
parent | bc3610d8cecbfed40c62d4dcb93fc9a4d2a7c9e3 (diff) |
Merge branch 'branch-1.3' into debian
Conflicts:
ChangeLog
altoslib/AltosRecordMM.java
altosui/Makefile.am
altosui/altos-windows.nsi.in
configure.ac
debian/changelog
debian/control
doc/Makefile
doc/altusmetrum.xsl
doc/release-notes-1.2.1.xsl
doc/release-notes-1.2.xsl
Diffstat (limited to 'altoslib/AltosIMU.java')
-rw-r--r-- | altoslib/AltosIMU.java | 70 |
1 files changed, 67 insertions, 3 deletions
diff --git a/altoslib/AltosIMU.java b/altoslib/AltosIMU.java index 8f6731fa..6d88ccae 100644 --- a/altoslib/AltosIMU.java +++ b/altoslib/AltosIMU.java @@ -15,9 +15,11 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; -public class AltosIMU { +import java.util.concurrent.*; + +public class AltosIMU implements Cloneable { public int accel_x; public int accel_y; public int accel_z; @@ -25,5 +27,67 @@ public class AltosIMU { public int gyro_x; public int gyro_y; public int gyro_z; + + public boolean parse_string(String line) { + if (!line.startsWith("Accel:")) + return false; + + String[] items = line.split("\\s+"); + + if (items.length >= 8) { + accel_x = Integer.parseInt(items[1]); + accel_y = Integer.parseInt(items[2]); + accel_z = Integer.parseInt(items[3]); + gyro_x = Integer.parseInt(items[5]); + gyro_y = Integer.parseInt(items[6]); + gyro_z = Integer.parseInt(items[7]); + } + return true; + } + + public AltosIMU clone() { + AltosIMU n = new AltosIMU(); + + n.accel_x = accel_x; + n.accel_y = accel_y; + n.accel_z = accel_z; + + n.gyro_x = gyro_x; + n.gyro_y = gyro_y; + n.gyro_z = gyro_z; + return n; + } + + static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException { + try { + AltosIMU imu = new AltosIMU(link); + + if (imu != null) + state.set_imu(imu); + } catch (TimeoutException te) { + } + } + + public AltosIMU() { + accel_x = AltosLib.MISSING; + accel_y = AltosLib.MISSING; + accel_z = AltosLib.MISSING; + + gyro_x = AltosLib.MISSING; + gyro_y = AltosLib.MISSING; + gyro_z = AltosLib.MISSING; + } + + public AltosIMU(AltosLink link) throws InterruptedException, TimeoutException { + this(); + link.printf("I\n"); + for (;;) { + String line = link.get_reply_no_dialog(5000); + if (line == null) { + throw new TimeoutException(); + } + if (parse_string(line)) + break; + } + } } -
\ No newline at end of file |