[Bf-blender-cvs] [b189710] HMD_viewport: - Fixed getting device information for the user preferences - Defaulting to device 0 in openhmd which is the last plugged in (will fallback on Dummy Device)

TheOnlyJoey noreply at git.blender.org
Wed Apr 6 16:42:03 CEST 2016


Commit: b189710cd874fcbeea75de8aad25fa78d8c7791a
Author: TheOnlyJoey
Date:   Wed Apr 6 16:41:24 2016 +0200
Branches: HMD_viewport
https://developer.blender.org/rBb189710cd874fcbeea75de8aad25fa78d8c7791a

- Fixed getting device information for the user preferences
- Defaulting to device 0 in openhmd which is the last plugged in (will fallback on Dummy Device)

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

M	intern/ghost/intern/GHOST_OpenHMDManager.cpp
M	intern/ghost/intern/GHOST_OpenHMDManager.h
M	source/blender/editors/interface/resources.c
M	source/blender/makesrna/intern/rna_userdef.c

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

diff --git a/intern/ghost/intern/GHOST_OpenHMDManager.cpp b/intern/ghost/intern/GHOST_OpenHMDManager.cpp
index 2d2549b..57d3793 100644
--- a/intern/ghost/intern/GHOST_OpenHMDManager.cpp
+++ b/intern/ghost/intern/GHOST_OpenHMDManager.cpp
@@ -160,12 +160,19 @@ void GHOST_OpenHMDManager::closeDevice()
 	m_available = false;
 }
 
-int GHOST_OpenHMDManager::getNumDevices() const
+int GHOST_OpenHMDManager::getNumDevices()
 {
-	if (!m_available)
-		return -1;
+	if (!m_context)
+		if (!createContext()) {
+			return false;
+		}
+
+	int numDevices = ohmd_ctx_probe(m_context);
+
+	ohmd_ctx_destroy(m_context);
+	m_context = NULL;
 
-	return ohmd_ctx_probe(m_context);
+	return numDevices;
 }
 
 const char *GHOST_OpenHMDManager::getError() const
@@ -185,12 +192,21 @@ const char *GHOST_OpenHMDManager::getDeviceName() const
 	return ohmd_list_gets(m_context, m_deviceIndex, OHMD_PRODUCT);
 }
 
-const char *GHOST_OpenHMDManager::getDeviceName(int index) const
+const char *GHOST_OpenHMDManager::getDeviceName(int index)
 {
-	if (!m_available)
-		return NULL;
+	if (!m_context)
+		if (!createContext()) {
+			return "";
+		}
+	//You need to probe to fetch the device information from the hardware
+	ohmd_ctx_probe(m_context);
+
+	const char* deviceName = ohmd_list_gets(m_context, index, OHMD_PRODUCT);
+
+	ohmd_ctx_destroy(m_context);
+	m_context = NULL;
 
-	return ohmd_list_gets(m_context, index, OHMD_PRODUCT);
+	return deviceName;
 }
 
 const char *GHOST_OpenHMDManager::getVendorName() const
diff --git a/intern/ghost/intern/GHOST_OpenHMDManager.h b/intern/ghost/intern/GHOST_OpenHMDManager.h
index 48b3f05..90541f2 100644
--- a/intern/ghost/intern/GHOST_OpenHMDManager.h
+++ b/intern/ghost/intern/GHOST_OpenHMDManager.h
@@ -75,7 +75,7 @@ public:
 	 *  \return The number of connected devices.
 	 *  -1 is returned if available() is false.
 	 */
-	int getNumDevices() const;
+	int getNumDevices();
 
 	///TODO add a function to retrieve a list of connected devices, or the data of a single device by index.
 	//the data should contain at least the device name and vendor name.
@@ -96,7 +96,7 @@ public:
 	 *  \return A c-style string with the human-readable name of the device at \a index.
 	 *  NULL is returned if available() is false.
 	 */
-	const char *getDeviceName(int index) const;
+	const char *getDeviceName(int index);
 
 	/**
 	 *  \return A c-style string with the human-readable name of the vendor of the the current device.
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index 4ad1446..b6861e1 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -2705,7 +2705,7 @@ void init_userdef_do_versions(void)
 	}
 
 	if (!USER_VERSION_ATLEAST(277, 1)) {
-		U.hmd_device = -1;
+		U.hmd_device = 0;
 	}
 
 	/**
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 42617da..4400a5a 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -655,6 +655,7 @@ static EnumPropertyItem *rna_userdef_hmd_device_itemf(
 
 	/* 'None' element */
 	RNA_enum_item_add(&item, &totitem, &hmd_device_items[0]);
+
 	/* add devices */
 	for (int i = 0; i < WM_device_HMD_num_devices_get(); i++) {
 		EnumPropertyItem tmp = {i, "", 0, "", ""};




More information about the Bf-blender-cvs mailing list