Bladeren bron

Merge pull request #59 from lubosz/riftfixes

Fix some Oculus DK2 problems. Rev 2.
Fredrik Hultin 9 jaren geleden
bovenliggende
commit
a4103568b1
2 gewijzigde bestanden met toevoegingen van 24 en 2 verwijderingen
  1. 22 1
      src/drv_oculus_rift/rift.c
  2. 2 1
      src/openhmd.c

+ 22 - 1
src/drv_oculus_rift/rift.c

@@ -185,6 +185,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,8 +212,13 @@ 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");

+ 2 - 1
src/openhmd.c

@@ -158,10 +158,11 @@ ohmd_device* OHMD_APIENTRY ohmd_list_open_device_s(ohmd_context* ctx, int index,
 		device->active_device_idx = ctx->num_active_devices;
 		ctx->active_devices[ctx->num_active_devices++] = device;
 
+		ohmd_unlock_mutex(ctx->update_mutex);
+
 		if(device->settings.automatic_update)
 			ohmd_set_up_update_thread(ctx);
 
-		ohmd_unlock_mutex(ctx->update_mutex);
 		return device;
 	}