aboutsummaryrefslogtreecommitdiffstats
path: root/Bindings/Java/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'Bindings/Java/src/test')
-rw-r--r--Bindings/Java/src/test/java/com/oculusvr/rift/RiftTest.java81
-rw-r--r--Bindings/Java/src/test/java/log4j.properties6
2 files changed, 87 insertions, 0 deletions
diff --git a/Bindings/Java/src/test/java/com/oculusvr/rift/RiftTest.java b/Bindings/Java/src/test/java/com/oculusvr/rift/RiftTest.java
new file mode 100644
index 0000000..6dd671f
--- /dev/null
+++ b/Bindings/Java/src/test/java/com/oculusvr/rift/RiftTest.java
@@ -0,0 +1,81 @@
+package com.oculusvr.rift;
+
+import java.io.IOException;
+
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.ObjectWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.codeminders.hidapi.HIDDevice;
+import com.google.common.base.Predicate;
+import com.oculusvr.rift.RiftTracker;
+import com.oculusvr.rift.hid.DisplayInfo;
+import com.oculusvr.rift.hid.SensorConfig;
+import com.oculusvr.rift.hid.SensorRange;
+import com.oculusvr.rift.tracker.TrackerMessage;
+
+public class RiftTest {
+ private static final Logger LOG = LoggerFactory.getLogger(RiftTest.class);
+
+ public static void main(String... args) throws IOException, InterruptedException {
+ final ObjectMapper mapper = new ObjectMapper();
+ final ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
+ RiftTracker tracker = RiftTracker.getInstance();
+ DisplayInfo di = tracker.getDisplayInfo();
+ LOG.info(writer.writeValueAsString(di));
+ SensorConfig sc = tracker.getSensorConfig();
+ LOG.info(writer.writeValueAsString(sc));
+ SensorRange sr = tracker.getSensorRange();
+ LOG.info(writer.writeValueAsString(sr));
+ RiftTracker.startListening(new Predicate<TrackerMessage>() {
+ @Override
+ public boolean apply(TrackerMessage message) {
+ try {
+ // Just enough data to see we're getting stuff
+ LOG.info("Sample count: " + message.sampleCount);
+ LOG.info("Sample 0: " + mapper.writeValueAsString(message.samples.get(0)));
+ } catch (Exception e) {
+ LOG.error("Failed to serialize sample data", e);
+ }
+ return true;
+ }
+ });
+ }
+
+ /**
+ * This is a tool I used to fix my display info report after I accidentally
+ * trashed it by runnig example code here:
+ * http://lxr.free-electrons.com/source/samples/hidraw/hid-example.c -- note
+ * the sample code writes to feature report 9 without actually doing any
+ * verification that that's a good idea.
+ *
+ * No guaratee that this will not destroy your device. No warranty is
+ * implied or provided.
+ *
+ * @param device
+ * @throws IOException
+ */
+ public static void fixDisplayInfo(HIDDevice device) throws IOException {
+ DisplayInfo di = new DisplayInfo();
+ // These values are from an earlier dump of my display Info. I have no
+ // idea if they're valid.
+ di.distortion = 1;
+ di.xres = 1280;
+ di.yres = 800;
+ di.xsize = 149760;
+ di.ysize = 93600;
+ di.center = 46800;
+ di.sep = 63500;
+ di.zeye = new int[] { 49800, 49800 };
+ di.distortionCoefficients = new float[] {
+ Float.NaN,
+ 1.5946803e-27f,
+ Float.NaN,
+ 3.4119901E16f,
+ 4.6665167E-38f,
+ -9.6494493E15f
+ };
+ di.write(device);
+ }
+}
diff --git a/Bindings/Java/src/test/java/log4j.properties b/Bindings/Java/src/test/java/log4j.properties
new file mode 100644
index 0000000..ec331d8
--- /dev/null
+++ b/Bindings/Java/src/test/java/log4j.properties
@@ -0,0 +1,6 @@
+log4j.rootLogger=INFO, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%-4r %-5p %c %x - %m%n
+ \ No newline at end of file