Selaa lähdekoodia

Merge branch 'master' of https://github.com/OpenHMD/OpenHMD into android

Conflicts:
	CMakeLists.txt
	README.md
	configure.ac
	src/Makefile.am
	src/openhmd.c
	src/openhmdi.h
TheOnlyJoey 9 vuotta sitten
vanhempi
commit
ee375b7426
14 muutettua tiedostoa jossa 304 lisäystä ja 120 poistoa
  1. 17 0
      .travis.yml
  2. 22 9
      CMakeLists.txt
  3. 16 3
      README.md
  4. 47 0
      cmake/FindHIDAPI.cmake
  5. 0 94
      configure.ac
  6. 5 0
      examples/simple/simple.c
  7. 3 0
      include/openhmd.h
  8. 24 2
      src/Makefile.am
  9. 153 0
      src/drv_external/external.c
  10. 7 5
      src/fusion.c
  11. 2 1
      src/fusion.h
  12. 6 3
      src/openhmd.c
  13. 1 2
      src/openhmdi.h
  14. 1 1
      tests/unittests/tests.h

+ 17 - 0
.travis.yml

@@ -0,0 +1,17 @@
+# This is the project file for the automated build system travis (travis-ci.com).
+sudo: required
+
+dist: trusty
+
+language: c
+
+compiler: gcc
+
+before_install:
+  - sudo apt-get update -qq
+  - sudo apt-get install -qq libhidapi-dev
+  - ./autogen.sh
+
+install: true # skip install step
+
+script: ./configure && make

+ 22 - 9
CMakeLists.txt

@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8)
 project(openhmd C CXX)
 set(CMAKE_C_FLAGS "-std=c99")
 
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
 include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
 
 if (MSVC)
@@ -16,16 +17,17 @@ endif (MSVC)
 
 #source files set just for Android
 set(openhmd_source_files
-${CMAKE_CURRENT_LIST_DIR}/src/openhmd.c
-${CMAKE_CURRENT_LIST_DIR}/src/platform-win32.c
-${CMAKE_CURRENT_LIST_DIR}/src/drv_dummy/dummy.c
-${CMAKE_CURRENT_LIST_DIR}/src/omath.c
-${CMAKE_CURRENT_LIST_DIR}/src/platform-posix.c
-${CMAKE_CURRENT_LIST_DIR}/src/fusion.c
+	${CMAKE_CURRENT_LIST_DIR}/src/openhmd.c
+	${CMAKE_CURRENT_LIST_DIR}/src/platform-win32.c
+	${CMAKE_CURRENT_LIST_DIR}/src/drv_dummy/dummy.c
+	${CMAKE_CURRENT_LIST_DIR}/src/omath.c
+	${CMAKE_CURRENT_LIST_DIR}/src/platform-posix.c
+	${CMAKE_CURRENT_LIST_DIR}/src/fusion.c
 )
 
-OPTION(OPENHMD_DRIVER_OCULUS_RIFT "Oculus Rift DK1 and DK2" OFF)
-OPTION(OPENHMD_DRIVER_ANDROID "General Android driver" ON)
+OPTION(OPENHMD_DRIVER_OCULUS_RIFT "Oculus Rift DK1 and DK2" ON)
+OPTION(OPENHMD_DRIVER_EXTERNAL "External sensor driver" ON)
+OPTION(OPENHMD_DRIVER_ANDROID "General Android driver" OFF)
 
 if(OPENHMD_DRIVER_OCULUS_RIFT)
 	set(openhmd_source_files ${openhmd_source_files} 
@@ -33,8 +35,19 @@ if(OPENHMD_DRIVER_OCULUS_RIFT)
 	${CMAKE_CURRENT_LIST_DIR}/src/drv_oculus_rift/packet.c
 	)
 	add_definitions(-DDRIVER_OCULUS_RIFT)
+
+	find_package(HIDAPI REQUIRED)
+	include_directories(${HIDAPI_INCLUDE_DIRS})
+	set(LIBS ${LIBS} ${HIDAPI_LIBRARIES})
 endif(OPENHMD_DRIVER_OCULUS_RIFT)
 
+if (OPENHMD_DRIVER_EXTERNAL)
+	set(openhmd_source_files ${openhmd_source_files} 
+	${CMAKE_CURRENT_LIST_DIR}/src/drv_external/external.c
+	)
+	add_definitions(-DDRIVER_EXTERNAL)
+endif(OPENHMD_DRIVER_EXTERNAL)
+
 if (OPENHMD_DRIVER_ANDROID)
 	set(openhmd_source_files ${openhmd_source_files} 
 	${CMAKE_CURRENT_LIST_DIR}/src/drv_android/android.c
@@ -42,5 +55,5 @@ if (OPENHMD_DRIVER_ANDROID)
 	add_definitions(-DDRIVER_ANDROID)
 endif(OPENHMD_DRIVER_ANDROID)
 
-add_library(openhmd ${openhmd_source_files})
+add_library(openhmd ${openhmd_source_files} ${LIBS})
 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_DIR}/)

+ 16 - 3
README.md

@@ -7,12 +7,14 @@ OpenHMD is released under the permissive Boost Software License (see LICENSE for
 ## Supported Devices
   * Oculus Rift DK1 and DK2 (rotation only)
   * Android based devices
+  * External Sensor (passthrough for external sensors)
 
 ## Supported Platforms
   * Linux
   * Windows
   * OS X
   * Android
+  * FreeBSD
 
 ## Requirements
   * Option 1: GNU Autotools (if you're building from the git repository)
@@ -22,8 +24,10 @@ OpenHMD is released under the permissive Boost Software License (see LICENSE for
     * https://github.com/signal11/hidapi/
 
 ## Language Bindings
+  * Java bindings by Joey Ferwerda and Koen Mertens
+    * https://github.com/OpenHMD/OpenHMD-Java
   * Perl bindings by CandyAngel
-    * https://bitbucket.org/CandyAngel/perl-openhmd
+    * https://github.com/CandyAngel/perl-openhmd
   * Python bindings by Lubosz Sarnecki
     * https://github.com/lubosz/python-rift
   
@@ -41,9 +45,10 @@ Using make:
 Using CMake:
 
 With CMake, you can enable and disable drivers to compile OpenHMD with.
-Current Available drivers are: OPENHMD_DRIVER_OCULUS_RIFT and OPENHMD_DRIVER_ANDROID
+Current Available drivers are: OPENHMD_DRIVER_OCULUS_RIFT, OPENHMD_DRIVER_EXTERNAL and OPENHMD_DRIVER_ANDROID.
+These can be enabled or disabled adding -DDRIVER_OF_CHOICE=ON after the cmake command (or using cmake-gui).
 
-    cmake -DOPENHMD_DRIVER_ANDROID=ON .
+    cmake .
     make
 
 ### Configuring udev on Linux
@@ -58,11 +63,19 @@ After this you have to unplug your Rift and plug it back in. You should now be a
 
 
 ### Cross compiling for windows using mingw
+Using Make:
+
     export PREFIX=/usr/i686-w64-mingw32/ (or whatever your mingw path is)
     PKG_CONFIG_LIBDIR=$PREFIX/lib/pkgconfig ./configure --build=`gcc -dumpmachine` --host=i686-w64-mingw32 --prefix=$PREFIX
     make
 the library will end up in the .lib directory, you can use microsoft's lib.exe to make a .lib file for it
 
+Using CMake:
+
+For MinGW cross compiling, toolchain files tend to be the best solucion.
+Please check the CMake documentation on how to do this.
+A starting point might be the CMake wiki: http://www.vtk.org/Wiki/CmakeMingw
+
 ### Static linking on windows
 If you're linking statically with OpenHMD using windows/mingw you have to make sure the macro OHMD_STATIC is set before including openhmd.h. In GCC this can be done by adding the compiler flag -DOHMD_STATIC, and with msvc it can be done using /DOHMD_STATIC.
 

+ 47 - 0
cmake/FindHIDAPI.cmake

@@ -0,0 +1,47 @@
+# - try to find HIDAPI library
+# from http://www.signal11.us/oss/hidapi/
+#
+# Cache Variables: (probably not for direct use in your scripts)
+#  HIDAPI_INCLUDE_DIR
+#  HIDAPI_LIBRARY
+#
+# Non-cache variables you might use in your CMakeLists.txt:
+#  HIDAPI_FOUND
+#  HIDAPI_INCLUDE_DIRS
+#  HIDAPI_LIBRARIES
+#
+# Requires these CMake modules:
+#  FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
+#
+# Original Author:
+# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
+# http://academic.cleardefinition.com
+# Iowa State University HCI Graduate Program/VRAC
+#
+# Copyright Iowa State University 2009-2010.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+find_library(HIDAPI_LIBRARY
+	NAMES hidapi hidapi-libusb)
+
+find_path(HIDAPI_INCLUDE_DIR
+	NAMES hidapi.h
+	PATH_SUFFIXES
+	hidapi)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(HIDAPI
+	DEFAULT_MSG
+	HIDAPI_LIBRARY
+	HIDAPI_INCLUDE_DIR)
+
+if(HIDAPI_FOUND)
+	set(HIDAPI_LIBRARIES "${HIDAPI_LIBRARY}")
+
+	set(HIDAPI_INCLUDE_DIRS "${HIDAPI_INCLUDE_DIR}")
+endif()
+
+mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_LIBRARY)
+

+ 0 - 94
configure.ac

@@ -1,94 +0,0 @@
-name='openhmd'
-version='0.1.1'
-library_interface_version='0:0:0'
-email='noname@nurd.se'
-
-m4_define([OH_VERSION_STRING], [0.0.1])
-m4_define([OH_NAME], [openhmd])
-
-AC_PREREQ([2.13])
-AC_INIT([OH_NAME], [OH_VERSION_STRING], [noname@nurd.se])
-AM_INIT_AUTOMAKE([foreign -Wall])
-m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
-LT_INIT
-AC_CANONICAL_HOST
-
-m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
-
-hidapi="hidapi"
-
-AC_SUBST(PKG_CONFIG_EXTRA_PATH, "")
-AC_SUBST(EXTRA_LD_FLAGS, "")
-
-AC_MSG_CHECKING([operating system])
-case "$host" in
-*-linux*)
-	AC_MSG_RESULT([$host (Linux)])
-	hidapi="hidapi-libusb"
-
-	#link with realtime lib on linux for clock_gettime
-	AC_SUBST(EXTRA_LD_FLAGS, "-lrt -lpthread")
-	;;
-*-freebsd*)
-	AC_SUBST(PKG_CONFIG_EXTRA_PATH, "libdata/")
-	;;
-esac
-
-# Oculus Rift Driver
-AC_ARG_ENABLE([driver-oculus-rift],
-        [AS_HELP_STRING([--enable-driver-oculus-rift],
-                [enable building of Oculus Rift driver (default y)])],
-        [driver_oculus_rift_enabled=$enableval],
-        [driver_oculus_rift_enabled='yes'])
-
-AM_CONDITIONAL([BUILD_DRIVER_OCULUS_RIFT], [test "x$driver_oculus_rift_enabled" != "xno"])
-
-# Libs required by Oculus Rift Driver
-if test "x$driver_oculus_rift_enabled" != "xno"; then
-	PKG_CHECK_MODULES([hidapi], [$hidapi] >= 0.0.5)
-fi
-
-# Do we build OpenGL example?
-AC_ARG_ENABLE([openglexample],
-        [AS_HELP_STRING([--enable-openglexample],
-                [enable building of OpenGL example (default n)])],
-        [openglexample_enabled=$enableval],
-        [openglexample_enabled='no'])
-
-AM_CONDITIONAL([BUILD_OPENGL_EXAMPLE], [test "x$openglexample_enabled" != "xno"])
-
-# Libs required by OpenGL test
-if test "x$openglexample_enabled" != "xno"; then
-	PKG_CHECK_MODULES([sdl], [sdl])
-
-	# Try to find OpenGL with pkg-config
-	PKG_CHECK_MODULES([GL], [gl], [], 
-			# and try to find which lib to link to, -lGL first
-			[AC_CHECK_LIB(GL, glBegin, [GL_LIBS=-lGL], 
-
-				# if that fails, try -lopengl32 (win32)
-				[AC_CHECK_LIB(opengl32, main, [GL_LIBS=-lopengl32], 
-					AC_MSG_ERROR([GL not found])
-				)]
-			)]
-	)
-
-	AC_SUBST(GL_LIBS)
-
-	# Try to find GLEW with pkg-config
-	PKG_CHECK_MODULES([GLEW], [glew], [],
-		# if that fails, check if there's a glew header
-		[AC_CHECK_HEADER([GL/glew.h], [GLEW_LIBS=-lGLEW; GLEW_CFLAGS=-DGLEW_STATIC], AC_MSG_ERROR([GLEW not found]))]
-	)
-
-	AC_SUBST(GLEW_LIBS)
-	AC_SUBST(GLEW_CFLAGS)
-fi
-
-AC_PROG_CC
-AC_PROG_CC_C99
-
-AC_CONFIG_HEADERS([config.h])
-
-AC_OUTPUT([Makefile src/Makefile tests/Makefile tests/unittests/Makefile examples/Makefile examples/opengl/Makefile examples/simple/Makefile])
-AC_OUTPUT 

+ 5 - 0
examples/simple/simple.c

@@ -73,6 +73,11 @@ int main(int argc, char** argv)
 	// Ask for n rotation quaternions
 	for(int i = 0; i < 10000; i++){
 		ohmd_ctx_update(ctx);
+
+		float zero[] = {.0, .1, .2, 1};
+		ohmd_device_setf(hmd, OHMD_ROTATION_QUAT, zero);
+		ohmd_device_setf(hmd, OHMD_POSITION_VECTOR, zero);
+
 		print_infof(hmd, "rotation quat:", 4, OHMD_ROTATION_QUAT);
 		ohmd_sleep(.01);
 	}

+ 3 - 0
include/openhmd.h

@@ -110,6 +110,9 @@ typedef enum {
 
 	/** float[6], get - Device specifc distortion value. */
 	OHMD_DISTORTION_K                     = 18,
+	
+	/** float[10], set - Perform sensor fusion on values from external sensors. Values are: dt (time since last update, in seconds) X, Y, Z gyro, X, Y, Z accelerometer and X, Y, Z magnetometer. */
+	OHMD_EXTERNAL_SENSOR_FUSION           = 19,
 
 	/** float[10], set - Perform sensor fusion on values from external sensors. Values are: dt (time since last update, in seconds) X, Y, Z gyro, X, Y, Z accelerometer and X, Y, Z magnetometer. */
 	OHMD_EXTERNAL_SENSOR_FUSION           = 19,

+ 24 - 2
src/Makefile.am

@@ -6,13 +6,35 @@ lib_LTLIBRARIES = libopenhmd.la
 libopenhmd_la_SOURCES = \
 	openhmd.c \
 	platform-win32.c \
+<<<<<<< HEAD
 	drv_oculus_rift/rift.c \
 	drv_oculus_rift/packet.c \
 	drv_android/android.c \
+=======
+>>>>>>> 7015410d4a059a252c20ee4abeb46adad0fe5fb1
 	drv_dummy/dummy.c \
 	omath.c \
 	platform-posix.c \
 	fusion.c
 
-libopenhmd_la_LDFLAGS = $(hidapi_LIBS) -no-undefined -version-info 0:0:0 $(EXTRA_LD_FLAGS)
-libopenhmd_la_CPPFLAGS = -fPIC -I$(top_srcdir)/include $(hidapi_CFLAGS) -Wall 
+libopenhmd_la_LDFLAGS = -no-undefined -version-info 0:0:0
+libopenhmd_la_CPPFLAGS = -fPIC -I$(top_srcdir)/include -Wall 
+
+if BUILD_DRIVER_OCULUS_RIFT
+
+libopenhmd_la_SOURCES += \
+	drv_oculus_rift/rift.c \
+	drv_oculus_rift/packet.c
+
+libopenhmd_la_CPPFLAGS += $(hidapi_CFLAGS) -DDRIVER_OCULUS_RIFT
+libopenhmd_la_LDFLAGS += $(hidapi_LIBS)
+
+endif
+
+if BUILD_DRIVER_EXTERNAL
+
+libopenhmd_la_SOURCES += \
+	drv_external/external.c
+endif
+
+libopenhmd_la_LDFLAGS += $(EXTRA_LD_FLAGS)

+ 153 - 0
src/drv_external/external.c

@@ -0,0 +1,153 @@
+/*
+ * OpenHMD - Free and Open Source API and drivers for immersive technology.
+ * Copyright (C) 2013 Fredrik Hultin.
+ * Copyright (C) 2013 Jakob Bornecrantz.
+ * Copyright (C) 2015 Joey Ferwerda
+ * Distributed under the Boost 1.0 licence, see LICENSE for full text.
+ */
+
+/* External Driver */
+
+#include "../openhmdi.h"
+#include "string.h"
+
+typedef struct {
+	ohmd_device base;
+	fusion sensor_fusion;
+} external_priv;
+
+static void update_device(ohmd_device* device)
+{
+}
+
+static int getf(ohmd_device* device, ohmd_float_value type, float* out)
+{
+	external_priv* priv = (external_priv*)device;
+
+	switch(type){
+		case OHMD_ROTATION_QUAT: {
+				*(quatf*)out = priv->sensor_fusion.orient;
+				break;
+			}
+
+		case OHMD_POSITION_VECTOR:
+			out[0] = out[1] = out[2] = 0;
+			break;
+
+		default:
+			ohmd_set_error(priv->base.ctx, "invalid type given to getf (%d)", type);
+			return -1;
+			break;
+	}
+
+	return 0;
+}
+
+static int setf(ohmd_device* device, ohmd_float_value type, float* in)
+{
+	external_priv* priv = (external_priv*)device;
+
+	switch(type){
+		case OHMD_EXTERNAL_SENSOR_FUSION: {
+				ofusion_update(&priv->sensor_fusion, *in, (vec3f*)(in + 1), (vec3f*)(in + 4), (vec3f*)(in + 7));
+			}
+			break;
+
+		default:
+			ohmd_set_error(priv->base.ctx, "invalid type given to setf (%d)", type);
+			return -1;
+			break;
+	}
+
+	return 0;
+}
+
+static void close_device(ohmd_device* device)
+{
+	LOGD("closing external device");
+	free(device);
+}
+
+static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
+{
+	external_priv* priv = ohmd_alloc(driver->ctx, sizeof(external_priv));
+	if(!priv)
+		return NULL;
+
+	// Set default device properties
+	ohmd_set_default_device_properties(&priv->base.properties);
+
+	// Set device properties
+	//TODO: Get information from external device using set_external_properties?
+	//Using 'dummy' settings for now
+	priv->base.properties.hsize = 0.149760f;
+	priv->base.properties.vsize = 0.093600f;
+	priv->base.properties.hres = 1280;
+	priv->base.properties.vres = 800;
+	priv->base.properties.lens_sep = 0.063500;
+	priv->base.properties.lens_vpos = 0.046800;
+	priv->base.properties.fov = DEG_TO_RAD(125.5144f);
+	priv->base.properties.ratio = (1280.0f / 800.0f) / 2.0f;
+
+	// calculate projection eye projection matrices from the device properties
+	ohmd_calc_default_proj_matrices(&priv->base.properties);
+
+	// set up device callbacks
+	priv->base.update = update_device;
+	priv->base.close = close_device;
+	priv->base.getf = getf;
+	priv->base.setf = setf;
+	
+	ofusion_init(&priv->sensor_fusion);
+
+	return (ohmd_device*)priv;
+}
+
+static void get_device_list(ohmd_driver* driver, ohmd_device_list* list)
+{
+	ohmd_device_desc* desc = &list->devices[list->num_devices++];
+
+	strcpy(desc->driver, "OpenHMD Generic External Driver");
+	strcpy(desc->vendor, "OpenHMD");
+	strcpy(desc->product, "External Device");
+
+	strcpy(desc->path, "(none)");
+
+	desc->driver_ptr = driver;
+}
+
+static void destroy_driver(ohmd_driver* drv)
+{
+	LOGD("shutting down external driver");
+	free(drv);
+}
+
+ohmd_driver* ohmd_create_external_drv(ohmd_context* ctx)
+{
+	ohmd_driver* drv = ohmd_alloc(ctx, sizeof(ohmd_driver));
+	if(!drv)
+		return NULL;
+
+	drv->get_device_list = get_device_list;
+	drv->open_device = open_device;
+	drv->get_device_list = get_device_list;
+	drv->open_device = open_device;
+	drv->destroy = destroy_driver;
+
+	return drv;
+}
+
+/* external specific functions */
+static void set_external_properties(ohmd_device* device, ohmd_device_properties* props)
+{
+    external_priv* priv = (external_priv*)device;
+
+	priv->base.properties.hsize = props->hsize;
+	priv->base.properties.vsize = props->vsize;
+	priv->base.properties.hres = props->hres;
+	priv->base.properties.vres = props->vres;
+	priv->base.properties.lens_sep = props->lens_sep;
+	priv->base.properties.lens_vpos = props->lens_vpos;
+	priv->base.properties.fov = DEG_TO_RAD(props->fov);
+	priv->base.properties.ratio = props->ratio;
+}

+ 7 - 5
src/fusion.c

@@ -23,7 +23,7 @@ void ofusion_init(fusion* me)
 	me->grav_gain = 0.05f;
 }
 
-void ofusion_update(fusion* me, float dt, const vec3f* ang_vel, const vec3f* accel, const vec3f* mag)
+void ofusion_update(fusion* me, float dt, const vec3f* ang_vel, const vec3f* accel, const vec3f* mag, const float prox)
 {
 	me->ang_vel = *ang_vel;
 	me->accel = *accel;
@@ -34,6 +34,8 @@ void ofusion_update(fusion* me, float dt, const vec3f* ang_vel, const vec3f* acc
 	vec3f world_accel;
 	oquatf_get_rotated(&me->orient, accel, &world_accel);
 
+	me->prox = prox;
+
 	me->iterations += 1;
 	me->time += dt;
 
@@ -44,7 +46,7 @@ void ofusion_update(fusion* me, float dt, const vec3f* ang_vel, const vec3f* acc
 	float ang_vel_length = ovec3f_get_length(ang_vel);
 
 	if(ang_vel_length > 0.0001f){
-		vec3f rot_axis = 
+		vec3f rot_axis =
 			{{ ang_vel->x / ang_vel_length, ang_vel->y / ang_vel_length, ang_vel->z / ang_vel_length }};
 
 		float rot_angle = ang_vel_length * dt;
@@ -63,7 +65,7 @@ void ofusion_update(fusion* me, float dt, const vec3f* ang_vel, const vec3f* acc
 		// if the device is within tolerance levels, count this as the device is level and add to the counter
 		// otherwise reset the counter and start over
 
-		me->device_level_count = 
+		me->device_level_count =
 			fabsf(ovec3f_get_length(accel) - 9.82f) < gravity_tolerance && ang_vel_length < ang_vel_tolerance
 			? me->device_level_count + 1 : 0;
 
@@ -74,7 +76,7 @@ void ofusion_update(fusion* me, float dt, const vec3f* ang_vel, const vec3f* acc
 			me->device_level_count = 0;
 
 			vec3f accel_mean;
-			ofq_get_mean(&me->accel_fq, &accel_mean);	
+			ofq_get_mean(&me->accel_fq, &accel_mean);
 
 			// Calculate a cross product between what the device
 			// thinks is up and what gravity indicates is down.
@@ -105,7 +107,7 @@ void ofusion_update(fusion* me, float dt, const vec3f* ang_vel, const vec3f* acc
 
 			// otherwise try to correct
 			else {
-				use_angle = -me->grav_gain * me->grav_error_angle * 0.005f * (5.0f * ang_vel_length + 1.0f); 
+				use_angle = -me->grav_gain * me->grav_error_angle * 0.005f * (5.0f * ang_vel_length + 1.0f);
 				me->grav_error_angle += use_angle;
 			}
 

+ 2 - 1
src/fusion.h

@@ -22,6 +22,7 @@ typedef struct {
 	vec3f ang_vel;  // angular velocity
 	vec3f mag;      // magnetometer
 	vec3f raw_mag;  // raw magnetometer values
+	float prox;     // proximity sensor
 
 	int iterations;
 	float time;
@@ -39,6 +40,6 @@ typedef struct {
 } fusion;
 
 void ofusion_init(fusion* me);
-void ofusion_update(fusion* me, float dt, const vec3f* ang_vel, const vec3f* accel, const vec3f* mag_field);
+void ofusion_update(fusion* me, float dt, const vec3f* ang_vel, const vec3f* accel, const vec3f* mag_field, const float prox);
 
 #endif

+ 6 - 3
src/openhmd.c

@@ -24,10 +24,13 @@ ohmd_context* OHMD_APIENTRY ohmd_ctx_create()
 	ctx->drivers[ctx->num_drivers++] = ohmd_create_oculus_rift_drv(ctx);
 #endif
 
+#if DRIVER_EXTERNAL
+	ctx->drivers[ctx->num_drivers++] = ohmd_create_external_drv(ctx);
+#endif
+
 #if DRIVER_ANDROID
 	ctx->drivers[ctx->num_drivers++] = ohmd_create_android_drv(ctx);
 #endif
-
 	// add dummy driver last to make it the lowest priority
 	ctx->drivers[ctx->num_drivers++] = ohmd_create_dummy_drv(ctx);
 
@@ -93,11 +96,11 @@ ohmd_device* OHMD_APIENTRY ohmd_list_open_device(ohmd_context* ctx, int index)
 		ohmd_driver* driver = (ohmd_driver*)desc->driver_ptr;
 		ohmd_device* device = driver->open_device(driver, desc);
 
-		device->rotation_correction.w = 1;
-
 		if (device == NULL)
 			return NULL;
 
+		device->rotation_correction.w = 1;
+
 		device->ctx = ctx;
 		device->active_device_idx = ctx->num_active_devices;
 		ctx->active_devices[ctx->num_active_devices++] = device;

+ 1 - 2
src/openhmdi.h

@@ -79,9 +79,7 @@ struct ohmd_device {
 
 	int (*getf)(ohmd_device* device, ohmd_float_value type, float* out);
 	int (*setf)(ohmd_device* device, ohmd_float_value type, float* in);
-
 	int (*seti)(ohmd_device* device, ohmd_int_value type, int* in);
-
 	int (*set_data)(ohmd_device* device, ohmd_data_value type, void* in);
 
 	void (*update)(ohmd_device* device);
@@ -110,6 +108,7 @@ void ohmd_calc_default_proj_matrices(ohmd_device_properties* props);
 // drivers
 ohmd_driver* ohmd_create_dummy_drv(ohmd_context* ctx);
 ohmd_driver* ohmd_create_oculus_rift_drv(ohmd_context* ctx);
+ohmd_driver* ohmd_create_external_drv(ohmd_context* ctx);
 ohmd_driver* ohmd_create_android_drv(ohmd_context* ctx);
 
 #include "log.h"

+ 1 - 1
tests/unittests/tests.h

@@ -16,7 +16,7 @@
 
 #include "openhmdi.h"
 
-#define TAssert(_v) if((!_v)){ printf("\ntest failed: %s @ %s:%d\n", __func__, __FILE__, __LINE__); exit(1); }
+#define TAssert(_v) if(!(_v)){ printf("\ntest failed: %s @ %s:%d\n", __func__, __FILE__, __LINE__); exit(1); }
 
 bool float_eq(float a, float b, float t);
 bool vec3f_eq(vec3f v1, vec3f v2, float t);