Browse Source

Added device classes and flags.

Fredrik Hultin 8 years ago
parent
commit
2867db1a6d

+ 12 - 1
examples/simple/simple.c

@@ -49,10 +49,21 @@ int main(int argc, char** argv)
 
 	// Print device information
 	for(int i = 0; i < num_devices; i++){
+		int device_class = 0, device_flags = 0;
+		char* device_class_s[] = {"HMD", "Controller", "Generic Tracker", "Unknown"};
+
+		ohmd_list_geti(ctx, i, OHMD_DEVICE_CLASS, &device_class);
+		ohmd_list_geti(ctx, i, OHMD_DEVICE_FLAGS, &device_flags);
+
 		printf("device %d\n", i);
 		printf("  vendor:  %s\n", ohmd_list_gets(ctx, i, OHMD_VENDOR));
 		printf("  product: %s\n", ohmd_list_gets(ctx, i, OHMD_PRODUCT));
-		printf("  path:    %s\n\n", ohmd_list_gets(ctx, i, OHMD_PATH));
+		printf("  path:    %s\n", ohmd_list_gets(ctx, i, OHMD_PATH));
+		printf("  class:   %s\n", device_class_s[device_class > OHMD_DEVICE_CLASS_GENERIC_TRACKER ? 4 : device_class]);
+		printf("  flags:   %02x\n",  device_flags);
+		printf("    null device:         %s\n", device_flags & OHMD_DEVICE_FLAGS_NULL_DEVICE ? "yes" : "no");
+		printf("    rotational tracking: %s\n", device_flags & OHMD_DEVICE_FLAGS_ROTATIONAL_TRACKING ? "yes" : "no");
+		printf("    positional tracking: %s\n\n", device_flags & OHMD_DEVICE_FLAGS_POSITIONAL_TRACKING ? "yes" : "no");
 	}
 
 	// Open default device (0)

+ 47 - 7
include/openhmd.h

@@ -80,7 +80,7 @@ typedef enum {
 	    left eye of the HMD. */
 	OHMD_LEFT_EYE_GL_PROJECTION_MATRIX    =  4,
 	/** float[16] (get): A "ready to use" OpenGL style 4x4 matrix with a projection matrix for the
-	    right eye of the HMD. */
+	    right eye of the HMD. */	
 	OHMD_RIGHT_EYE_GL_PROJECTION_MATRIX   =  5,
 
 	/** float[3] (get): A 3-D vector representing the absolute position of the device, in space. */
@@ -133,19 +133,24 @@ typedef enum {
 
 /** A collection of int value information types used for getting information with ohmd_device_geti(). */
 typedef enum {
-	/** int[1] (get): Physical horizontal resolution of the device screen. */
+	/** int[1] (get, ohmd_geti()): Physical horizontal resolution of the device screen. */
 	OHMD_SCREEN_HORIZONTAL_RESOLUTION     =  0,
-	/** int[1] (get): Physical vertical resolution of the device screen. */
+	/** int[1] (get, ohmd_geti()): Physical vertical resolution of the device screen. */
 	OHMD_SCREEN_VERTICAL_RESOLUTION       =  1,
 
-	/** int[1] (get): Get number of events waiting in digital input event queue. */
+	/** int[1] (get, ohmd_geti()): Get number of events waiting in digital input event queue. */
 	OHMD_BUTTON_EVENT_COUNT               =  2,
-	/** int[1] (get): Get if the there was an overflow in the event queue causing events to be dropped. */
+	/** int[1] (get, ohmd_geti()): Get if the there was an overflow in the event queue causing events to be dropped. */
 	OHMD_BUTTON_EVENT_OVERFLOW            =  3,
-	/** int[1] (get): Get the number of physical digital input buttons on the device. */
+	/** int[1] (get, ohmd_geti()): Get the number of physical digital input buttons on the device. */
 	OHMD_BUTTON_COUNT                     =  4,
-	/** int[2] (get): Performs an event pop action. Format: [button_index, button_state], where button_state is either OHMD_BUTTON_DOWN or OHMD_BUTTON_UP */
+	/** int[2] (get, ohmd_geti()): Performs an event pop action. Format: [button_index, button_state], where button_state is either OHMD_BUTTON_DOWN or OHMD_BUTTON_UP */
 	OHMD_BUTTON_POP_EVENT                 =  5,
+
+	/** int[1] (get, ohmd_geti()/ohmd_list_geti()): Gets the class of the device. See: ohmd_device_class. */
+	OHMD_DEVICE_CLASS                     =  6,
+	/** int[1] (get, ohmd_geti()/ohmd_list_geti()): Gets the flags of the device. See: ohmd_device_flags. */
+	OHMD_DEVICE_FLAGS                     =  7,
 } ohmd_int_value;
 
 /** A collection of data information types used for setting information with ohmd_set_data(). */
@@ -175,6 +180,26 @@ typedef enum {
 	OHMD_BUTTON_UP   = 1
 } ohmd_button_state;
 
+/** Device classes. */
+typedef enum 
+{
+	/** HMD device. */
+	OHMD_DEVICE_CLASS_HMD        = 0,
+	/** Controller device. */
+	OHMD_DEVICE_CLASS_CONTROLLER = 1,
+	/** Generic tracker device. */
+	OHMD_DEVICE_CLASS_GENERIC_TRACKER = 2,
+} ohmd_device_class;
+
+/** Device flags. */
+typedef enum
+{
+	/** Device is a null (dummy) device. */
+	OHMD_DEVICE_FLAGS_NULL_DEVICE = 1,
+	OHMD_DEVICE_FLAGS_POSITIONAL_TRACKING = 2,
+	OHMD_DEVICE_FLAGS_ROTATIONAL_TRACKING = 4,
+} ohmd_device_flags;
+
 /** An opaque pointer to a context structure. */
 typedef struct ohmd_context ohmd_context;
 
@@ -267,6 +292,21 @@ OHMD_APIENTRYDLL int ohmd_gets(ohmd_string_description type, const char** out);
  **/
 OHMD_APIENTRYDLL const char* OHMD_APIENTRY ohmd_list_gets(ohmd_context* ctx, int index, ohmd_string_value type);
 
+
+/**
+ * Get integer value from enumeration list index.
+ *
+ * 
+ *
+ * ohmd_ctx_probe must be called before calling ohmd_list_gets.
+ *
+ * @param ctx A (probed) context.
+ * @param index An index, between 0 and the value returned from ohmd_ctx_probe.
+ * @param type What type of value to retrieve, ohmd_int_value section for more information.
+ * @return 0 on success, <0 on failure.
+ **/
+OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_list_geti(ohmd_context* ctx, int index, ohmd_int_value type, int* out);
+
 /**
  * Open a device.
  *

+ 3 - 0
src/drv_android/android.c

@@ -233,6 +233,9 @@ static void get_device_list(ohmd_driver* driver, ohmd_device_list* list)
 
 	strcpy(desc->path, "(none)");
 
+	desc->device_class = OHMD_DEVICE_CLASS_HMD;
+	desc->device_flags = OHMD_DEVICE_FLAGS_ROTATIONAL_TRACKING;
+
 	desc->driver_ptr = driver;
 }
 

+ 3 - 0
src/drv_deepoon/deepoon.c

@@ -301,6 +301,9 @@ static void get_device_list(ohmd_driver* driver, ohmd_device_list* list)
 		strcpy(desc->path, cur_dev->path);
 
 		desc->driver_ptr = driver;
+	
+		desc->device_class = OHMD_DEVICE_CLASS_HMD;
+		desc->device_flags = OHMD_DEVICE_FLAGS_ROTATIONAL_TRACKING;
 
 		cur_dev = cur_dev->next;
 	}

+ 3 - 0
src/drv_dummy/dummy.c

@@ -94,6 +94,9 @@ static void get_device_list(ohmd_driver* driver, ohmd_device_list* list)
 	strcpy(desc->path, "(none)");
 
 	desc->driver_ptr = driver;
+
+	desc->device_flags = OHMD_DEVICE_FLAGS_NULL_DEVICE | OHMD_DEVICE_FLAGS_ROTATIONAL_TRACKING;
+	desc->device_class = OHMD_DEVICE_CLASS_HMD;
 }
 
 static void destroy_driver(ohmd_driver* drv)

+ 3 - 0
src/drv_external/external.c

@@ -112,6 +112,9 @@ static void get_device_list(ohmd_driver* driver, ohmd_device_list* list)
 	strcpy(desc->product, "External Device");
 
 	strcpy(desc->path, "(none)");
+		
+	desc->device_class = OHMD_DEVICE_CLASS_HMD;
+	desc->device_flags = OHMD_DEVICE_FLAGS_ROTATIONAL_TRACKING | OHMD_DEVICE_FLAGS_POSITIONAL_TRACKING;
 
 	desc->driver_ptr = driver;
 }

+ 2 - 0
src/drv_htc_vive/vive.c

@@ -401,6 +401,8 @@ static void get_device_list(ohmd_driver* driver, ohmd_device_list* list)
 		snprintf(desc->path, OHMD_STR_SIZE, "%d", idx);
 
 		desc->driver_ptr = driver;
+		desc->device_class = OHMD_DEVICE_CLASS_HMD;
+		desc->device_flags = OHMD_DEVICE_FLAGS_ROTATIONAL_TRACKING;
 
 		cur_dev = cur_dev->next;
 		idx++;

+ 3 - 0
src/drv_oculus_rift/rift.c

@@ -408,6 +408,9 @@ static void get_device_list(ohmd_driver* driver, ohmd_device_list* list)
 				strcpy(desc->product, rd[i].name);
 
 				desc->revision = rd[i].rev;
+		
+				desc->device_class = OHMD_DEVICE_CLASS_HMD;
+				desc->device_flags = OHMD_DEVICE_FLAGS_ROTATIONAL_TRACKING;
 
 				strcpy(desc->path, cur_dev->path);
 

+ 3 - 0
src/drv_psvr/psvr.c

@@ -266,6 +266,9 @@ static void get_device_list(ohmd_driver* driver, ohmd_device_list* list)
 		snprintf(desc->path, OHMD_STR_SIZE, "%d", idx);
 
 		desc->driver_ptr = driver;
+		
+		desc->device_class = OHMD_DEVICE_CLASS_HMD;
+		desc->device_flags = OHMD_DEVICE_FLAGS_ROTATIONAL_TRACKING;
 
 		cur_dev = cur_dev->next;
 		idx++;

+ 19 - 0
src/openhmd.c

@@ -137,6 +137,25 @@ const char* OHMD_APIENTRY ohmd_list_gets(ohmd_context* ctx, int index, ohmd_stri
 	}
 }
 
+int OHMD_APIENTRY ohmd_list_geti(ohmd_context* ctx, int index, ohmd_int_value type, int* out)
+{
+	if(index >= ctx->list.num_devices)
+		return OHMD_S_INVALID_PARAMETER;
+
+	switch(type){
+	case OHMD_DEVICE_CLASS:
+		*out = ctx->list.devices[index].device_class;
+		return OHMD_S_OK;
+
+	case OHMD_DEVICE_FLAGS:
+		*out = ctx->list.devices[index].device_flags;
+		return OHMD_S_OK;
+
+	default:
+		return OHMD_S_INVALID_PARAMETER;
+	}
+}
+
 static unsigned int ohmd_update_thread(void* arg)
 {
 	ohmd_context* ctx = (ohmd_context*)arg;

+ 4 - 0
src/openhmdi.h

@@ -35,6 +35,8 @@ typedef struct {
 	char product[OHMD_STR_SIZE];
 	char path[OHMD_STR_SIZE];
 	int revision;
+	ohmd_device_flags device_flags;
+	ohmd_device_class device_class;
 	ohmd_driver* driver_ptr;
 } ohmd_device_desc;
 
@@ -79,6 +81,8 @@ typedef struct {
 		mat4x4f proj_right; // adjusted projection matrix for right screen
 		float universal_distortion_k[4]; //PanoTools lens distiorion model [a,b,c,d]
 		float universal_aberration_k[3]; //post-warp per channel scaling [r,g,b]
+
+
 } ohmd_device_properties;
 
 struct ohmd_device_settings