Jelajahi Sumber

Merge branch 'master' of https://github.com/OpenHMD/OpenHMD into device-class-and-flags

TheOnlyJoey 8 tahun lalu
induk
melakukan
7a06b42e0c
5 mengubah file dengan 39 tambahan dan 10 penghapusan
  1. 9 6
      src/drv_oculus_rift/rift.c
  2. 3 3
      src/drv_psvr/psvr.c
  3. 12 1
      src/platform-posix.c
  4. 12 0
      src/platform-win32.c
  5. 3 0
      src/platform.h

+ 9 - 6
src/drv_oculus_rift/rift.c

@@ -212,12 +212,12 @@ static void close_device(ohmd_device* device)
 
 static char* _hid_to_unix_path(char* path)
 {
-	char bus [4];
-	char dev [4];
+	char bus [5];
+	char dev [5];
 	char *result = malloc( sizeof(char) * ( 20 + 1 ) );
 
-	sprintf (bus, "%.*s\n", 4, path);
-	sprintf (dev, "%.*s\n", 4, path + 5);
+	sprintf (bus, "%.*s", 4, path);
+	sprintf (dev, "%.*s", 4, path + 5);
 
 	sprintf (result, "/dev/bus/usb/%03d/%03d",
 		(int)strtol(bus, NULL, 16),
@@ -225,6 +225,8 @@ static char* _hid_to_unix_path(char* path)
 	return result;
 }
 
+#define UDEV_WIKI_URL "https://github.com/OpenHMD/OpenHMD/wiki/Udev-rules-list"
+
 static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 {
 	rift_priv* priv = ohmd_alloc(driver->ctx, sizeof(rift_priv));
@@ -240,8 +242,9 @@ static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 
 	if(!priv->handle) {
 		char* path = _hid_to_unix_path(desc->path);
-		ohmd_set_error(driver->ctx, "Could not open %s. "
-		                            "Check your rights.", path);
+		ohmd_set_error(driver->ctx, "Could not open %s.\n"
+		                            "Check your rights: "
+		                            UDEV_WIKI_URL, path);
 		free(path);
 		goto cleanup;
 	}

+ 3 - 3
src/drv_psvr/psvr.c

@@ -158,7 +158,7 @@ static hid_device* open_device_idx(int manufacturer, int product, int iface, int
 	while (cur_dev) {
 		printf("%04x:%04x %s\n", manufacturer, product, cur_dev->path);
 
-		if(idx == device_index && iface == iface_cur){
+		if(findEndPoint(cur_dev->path, device_index) > 0 && iface == iface_cur){
 			ret = hid_open_path(cur_dev->path);
 			printf("opening\n");
 		}
@@ -190,7 +190,7 @@ static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 	int idx = atoi(desc->path);
 
 	// Open the HMD device
-	priv->hmd_handle = open_device_idx(SONY_ID, PSVR_HMD, 0, 0, idx);
+	priv->hmd_handle = open_device_idx(SONY_ID, PSVR_HMD, 0, 0, 4);
 
 	if(!priv->hmd_handle)
 		goto cleanup;
@@ -201,7 +201,7 @@ static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 	}
 
 	// Open the HMD Control device
-	priv->hmd_control = open_device_idx(SONY_ID, PSVR_HMD, 0, 0, 1);
+	priv->hmd_control = open_device_idx(SONY_ID, PSVR_HMD, 0, 0, 5);
 
 	if(!priv->hmd_control)
 		goto cleanup;

+ 12 - 1
src/platform-posix.c

@@ -19,6 +19,7 @@
 #include <sys/time.h>
 #include <stdio.h>
 #include <pthread.h>
+#include <string.h>
 
 #include "platform.h"
 #include "openhmdi.h"
@@ -127,6 +128,16 @@ void ohmd_unlock_mutex(ohmd_mutex* mutex)
 /// Handling ovr service
 void ohmd_toggle_ovr_service(int state) //State is 0 for Disable, 1 for Enable
 {
-	//Empty implementation	
+	//Empty implementation
+}
+
+int findEndPoint(char* path, int endpoint)
+{
+	char comp[6];
+	sprintf(comp,":0%d",endpoint);
+	if (strstr(path, comp) != NULL) {
+		return 1;
+	}
+	return 0;
 }
 #endif

+ 12 - 0
src/platform-win32.c

@@ -105,6 +105,18 @@ void ohmd_unlock_mutex(ohmd_mutex* mutex)
 		ReleaseMutex(mutex->handle);
 }
 
+int findEndPoint(char* path, int endpoint)
+{
+	char comp[8];
+	sprintf(comp,"mi_0%d",endpoint);
+
+	if (strstr(path, comp) != NULL) {
+		return 1;
+	}
+
+	return 0;
+}
+
 /// Handling ovr service
 static int _enable_ovr_service = 0;
 

+ 3 - 0
src/platform.h

@@ -28,5 +28,8 @@ void ohmd_unlock_mutex(ohmd_mutex* mutex);
 ohmd_thread* ohmd_create_thread(ohmd_context* ctx, unsigned int (*routine)(void* arg), void* arg);
 void ohmd_destroy_thread(ohmd_thread* thread);
 
+/* String functions */
+
+int findEndPoint(char* path, int endpoint);
 
 #endif