[Bf-blender-cvs] [459f922] HMD_viewport: Updated OpenHMD to match their latest master (1c984fb) Adds support for Oculus Rift CV1 and Deepoon E2

TheOnlyJoey noreply at git.blender.org
Fri Oct 28 23:41:42 CEST 2016


Commit: 459f92248454d8a973f6a95ed2501dee16e557e3
Author: TheOnlyJoey
Date:   Fri Oct 28 23:28:41 2016 +0200
Branches: HMD_viewport
https://developer.blender.org/rB459f92248454d8a973f6a95ed2501dee16e557e3

Updated OpenHMD to match their latest master (1c984fb)
Adds support for Oculus Rift CV1 and Deepoon E2

===================================================================

M	extern/openhmd/CMakeLists.txt
M	extern/openhmd/src/drv_android/android.c
A	extern/openhmd/src/drv_deepoon/deepoon.c
A	extern/openhmd/src/drv_deepoon/deepoon.h
A	extern/openhmd/src/drv_deepoon/packet.c
M	extern/openhmd/src/drv_oculus_rift/packet.c
M	extern/openhmd/src/drv_oculus_rift/rift.c
M	extern/openhmd/src/drv_oculus_rift/rift.h
M	extern/openhmd/src/fusion.c
M	extern/openhmd/src/openhmd.c
M	extern/openhmd/src/openhmdi.h
M	extern/openhmd/src/platform-win32.c

===================================================================

diff --git a/extern/openhmd/CMakeLists.txt b/extern/openhmd/CMakeLists.txt
index 20ef8e0..32dfc28 100644
--- a/extern/openhmd/CMakeLists.txt
+++ b/extern/openhmd/CMakeLists.txt
@@ -36,7 +36,8 @@ set(SRC
 )
 
 # TODO: Either remove this or move to main CMakeLists.txt
-OPTION(OPENHMD_DRIVER_OCULUS_RIFT "Oculus Rift DK1 and DK2" ON)
+OPTION(OPENHMD_DRIVER_OCULUS_RIFT "Oculus Rift DK1, DK2 and CV1" ON)
+OPTION(OPENHMD_DRIVER_DEEPOON "Deepoon E2 support" ON)
 OPTION(OPENHMD_DRIVER_EXTERNAL "External sensor driver" OFF)
 OPTION(OPENHMD_DRIVER_ANDROID "General Android driver" OFF)
 
@@ -56,6 +57,17 @@ if(OPENHMD_DRIVER_OCULUS_RIFT)
 	list(APPEND INC_SYS ${HIDAPI_INCLUDE_DIRS})
 endif()
 
+if(OPENHMD_DRIVER_DEEPOON)
+	list(APPEND SRC
+		src/drv_deepoon/deepoon.c
+		src/drv_deepoon/packet.c
+	)
+	add_definitions(-DDRIVER_DEEPOON)
+
+	find_package(HIDAPI REQUIRED)
+	list(APPEND INC_SYS ${HIDAPI_INCLUDE_DIRS})
+endif()
+
 if(OPENHMD_DRIVER_EXTERNAL)
 	list(APPEND SRC
 		src/drv_external/external.c
diff --git a/extern/openhmd/src/drv_android/android.c b/extern/openhmd/src/drv_android/android.c
index b6e2a99..d021a21 100644
--- a/extern/openhmd/src/drv_android/android.c
+++ b/extern/openhmd/src/drv_android/android.c
@@ -250,9 +250,8 @@ ohmd_driver* ohmd_create_android_drv(ohmd_context* ctx)
 
 	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;
+	drv->ctx = ctx;
 
 	return drv;
 }
diff --git a/extern/openhmd/src/drv_oculus_rift/rift.c b/extern/openhmd/src/drv_deepoon/deepoon.c
similarity index 66%
copy from extern/openhmd/src/drv_oculus_rift/rift.c
copy to extern/openhmd/src/drv_deepoon/deepoon.c
index aa98def..7104332 100644
--- a/extern/openhmd/src/drv_oculus_rift/rift.c
+++ b/extern/openhmd/src/drv_deepoon/deepoon.c
@@ -5,7 +5,7 @@
  * Distributed under the Boost 1.0 licence, see LICENSE for full text.
  */
 
-/* Oculus Rift Driver - HID/USB Driver Implementation */
+/* Deepoon Driver - HID/USB Driver Implementation */
 
 #include <stdlib.h>
 #include <hidapi.h>
@@ -14,12 +14,15 @@
 #include <time.h>
 #include <assert.h>
 
-#include "rift.h"
+#include "deepoon.h"
 
-#define TICK_LEN (1.0f / 1000.0f) // 1000 Hz ticks
+#define TICK_LEN (1.0f / 1000000.0f) // 1000 Hz ticks
 #define KEEP_ALIVE_VALUE (10 * 1000)
 #define SETFLAG(_s, _flag, _val) (_s) = ((_s) & ~(_flag)) | ((_val) ? (_flag) : 0)
 
+#define DEEPOON_ID					0x0483
+#define DEEPOON_HMD					0x5750
+
 typedef struct {
 	ohmd_device base;
 
@@ -58,9 +61,9 @@ static void set_coordinate_frame(rift_priv* priv, rift_coordinate_frame coordfra
 	// set the RIFT_SCF_SENSOR_COORDINATES in the sensor config to match whether coordframe is hmd or sensor
 	SETFLAG(priv->sensor_config.flags, RIFT_SCF_SENSOR_COORDINATES, coordframe == RIFT_CF_SENSOR);
 
-	// encode send the new config to the Rift 
+	// encode send the new config to the Rift
 	unsigned char buf[FEATURE_BUFFER_SIZE];
-	int size = encode_sensor_config(buf, &priv->sensor_config);
+	int size = dp_encode_sensor_config(buf, &priv->sensor_config);
 	if(send_feature_report(priv, buf, size) == -1){
 		ohmd_set_error(priv->base.ctx, "send_feature_report failed in set_coordinate frame");
 		return;
@@ -75,7 +78,6 @@ static void set_coordinate_frame(rift_priv* priv, rift_coordinate_frame coordfra
 		return;
 	}
 
-	decode_sensor_config(&priv->sensor_config, buf, size);
 	priv->hw_coordinate_frame = (priv->sensor_config.flags & RIFT_SCF_SENSOR_COORDINATES) ? RIFT_CF_SENSOR : RIFT_CF_HMD;
 
 	if(priv->hw_coordinate_frame != coordframe) {
@@ -85,26 +87,28 @@ static void set_coordinate_frame(rift_priv* priv, rift_coordinate_frame coordfra
 
 static void handle_tracker_sensor_msg(rift_priv* priv, unsigned char* buffer, int size)
 {
-	if(!decode_tracker_sensor_msg(&priv->sensor, buffer, size)){
+	uint32_t last_sample_tick = priv->sensor.tick;
+
+	if(!dp_decode_tracker_sensor_msg(&priv->sensor, buffer, size)){
 		LOGE("couldn't decode tracker sensor message");
 	}
 
 	pkt_tracker_sensor* s = &priv->sensor;
 
-	dump_packet_tracker_sensor(s);
-
-	// TODO handle missed samples etc.
+	dp_dump_packet_tracker_sensor(s);
 
-	float dt = s->num_samples > 3 ? (s->num_samples - 2) * TICK_LEN : TICK_LEN;
+	uint32_t tick_delta = 1000;
+	if(last_sample_tick > 0) //startup correction
+		tick_delta = s->tick - last_sample_tick;
 
-	int32_t mag32[] = { s->mag[0], s->mag[1], s->mag[2] };
-	vec3f_from_rift_vec(mag32, &priv->raw_mag);
+	float dt = tick_delta * TICK_LEN;
+	vec3f mag = {{0.0f, 0.0f, 0.0f}};
 
-	for(int i = 0; i < OHMD_MIN(s->num_samples, 3); i++){
-		vec3f_from_rift_vec(s->samples[i].accel, &priv->raw_accel);
-		vec3f_from_rift_vec(s->samples[i].gyro, &priv->raw_gyro);
+	for(int i = 0; i < 1; i++){ //just use 1 sample since we don't have sample order for this frame
+		vec3f_from_dp_vec(s->samples[i].accel, &priv->raw_accel);
+		vec3f_from_dp_vec(s->samples[i].gyro, &priv->raw_gyro);
 
-		ofusion_update(&priv->sensor_fusion, dt, &priv->raw_gyro, &priv->raw_accel, &priv->raw_mag);
+		ofusion_update(&priv->sensor_fusion, dt, &priv->raw_gyro, &priv->raw_accel, &mag);
 
 		// reset dt to tick_len for the last samples if there were more than one sample
 		dt = TICK_LEN;
@@ -121,7 +125,7 @@ static void update_device(ohmd_device* device)
 	if(t - priv->last_keep_alive >= (double)priv->sensor_config.keep_alive_interval / 1000.0 - .2){
 		// send keep alive message
 		pkt_keep_alive keep_alive = { 0, priv->sensor_config.keep_alive_interval };
-		int ka_size = encode_keep_alive(buffer, &keep_alive);
+		int ka_size = dp_encode_keep_alive(buffer, &keep_alive);
 		send_feature_report(priv, buffer, ka_size);
 
 		// Update the time of the last keep alive we have sent.
@@ -139,7 +143,7 @@ static void update_device(ohmd_device* device)
 		}
 
 		// currently the only message type the hardware supports (I think)
-		if(buffer[0] == RIFT_IRQ_SENSORS){
+		if(buffer[0] == RIFT_IRQ_SENSORS || buffer[0] == 11){
 			handle_tracker_sensor_msg(priv, buffer, size);
 		}else{
 			LOGE("unknown message type: %u", buffer[0]);
@@ -185,6 +189,22 @@ static void close_device(ohmd_device* device)
 	free(priv);
 }
 
+static char* _hid_to_unix_path(char* path)
+{
+	const int len = 4;
+	char bus [len];
+	char dev [len];
+	char *result = malloc( sizeof(char) * ( 20 + 1 ) );
+
+	sprintf (bus, "%.*s\n", len, path);
+	sprintf (dev, "%.*s\n", len, path + 5);
+
+	sprintf (result, "/dev/bus/usb/%03d/%03d",
+		(int)strtol(bus, NULL, 16),
+		(int)strtol(dev, NULL, 16));
+	return result;
+}
+
 static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 {
 	rift_priv* priv = ohmd_alloc(driver->ctx, sizeof(rift_priv));
@@ -196,32 +216,22 @@ static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 	// Open the HID device
 	priv->handle = hid_open_path(desc->path);
 
-	if(!priv->handle)
+	if(!priv->handle) {
+		char* path = _hid_to_unix_path(desc->path);
+		ohmd_set_error(driver->ctx, "Could not open %s. "
+		                            "Check your rights.", path);
+		free(path);
 		goto cleanup;
-	
+	}
+
 	if(hid_set_nonblocking(priv->handle, 1) == -1){
 		ohmd_set_error(driver->ctx, "failed to set non-blocking on device");
 		goto cleanup;
 	}
 
 	unsigned char buf[FEATURE_BUFFER_SIZE];
-	
-	int size;
-
-	// Read and decode the sensor range
-	size = get_feature_report(priv, RIFT_CMD_RANGE, buf);
-	decode_sensor_range(&priv->sensor_range, buf, size);
-	dump_packet_sensor_range(&priv->sensor_range);
-
-	// Read and decode display information
-	size = get_feature_report(priv, RIFT_CMD_DISPLAY_INFO, buf);
-	decode_sensor_display_info(&priv->display_info, buf, size);
-	dump_packet_sensor_display_info(&priv->display_info);
 
-	// Read and decode the sensor config
-	size = get_feature_report(priv, RIFT_CMD_SENSOR_CONFIG, buf);
-	decode_sensor_config(&priv->sensor_config, buf, size);
-	dump_packet_sensor_config(&priv->sensor_config);
+	int size;
 
 	// if the sensor has display info data, use HMD coordinate frame
 	priv->coordinate_frame = priv->display_info.distortion_type != RIFT_DT_NONE ? RIFT_CF_HMD : RIFT_CF_SENSOR;
@@ -235,30 +245,25 @@ static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 
 	// set keep alive interval to n seconds
 	pkt_keep_alive keep_alive = { 0, KEEP_ALIVE_VALUE };
-	size = encode_keep_alive(buf, &keep_alive);
+	size = dp_encode_keep_alive(buf, &keep_alive);
 	send_feature_report(priv, buf, size);
 
 	// Update the time of the last keep alive we have sent.
 	priv->last_keep_alive = ohmd_get_tick();
 
-	// update sensor settings with new keep alive value
-	// (which will have been ignored in favor of the default 1000 ms one)
-	size = get_feature_report(priv, RIFT_CMD_SENSOR_CONFIG, buf);
-	decode_sensor_config(&priv->sensor_config, buf, size);
-	dump_packet_sensor_config(&priv->sensor_config);
-
 	// Set default device properties
 	ohmd_set_default_device_properties(&priv->base.properties);
 
 	// Set device properties
-	priv->base.properties.hsize = priv->display_info.h_screen_size;
-	priv->base.properties.vsize = priv->display_info.v_screen_size;
-	priv->base.properties.hres = priv->display_info.h_resolution;
-	priv->base.properties.vres = priv->display_info.v_resolution;
-	priv->base.properties.lens_sep = priv->display_info.lens_separation;
-	priv->base.properties.lens_vpos = priv->display_info.v_center;
-	priv->base.properties.fov = DEG_TO_RAD(125.5144f); // TODO calculate.
-	priv->base.properties.ratio = ((float)priv->display_info.h_resolution / (float)priv->display_info.v_resolution) / 2.0f;
+	//NOTE: These values are estimations, no one has taken one appart to check
+	priv->base.properties.hsize = 0.1698f;
+	priv->base.properties.vsize = 0.0936f;
+	priv->base.properties.hres = 1920;
+	priv->base.properties.vres = 1080;
+	priv->base.properties.lens_sep = 0.0849f;
+	priv->base.properties.lens_vpos = 0.0468f;;
+	priv->base.properties.fov = DEG_TO_RAD(110.0); // TODO calculate.
+	priv->base.properties.ratio = ((float)1920 / (float)1080) / 2.0f;
 
 	// calculate projection eye projection matrices from the device properties
 	ohmd_calc_default_proj_matrices(&priv->base.properties);
@@ -280,44 +285,28 @@ cleanup:

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list