noname пре 7 година
родитељ
комит
5156d310e9
5 измењених фајлова са 87 додато и 20 уклоњено
  1. 33 10
      examples/simple/simple.c
  2. 34 4
      include/openhmd.h
  3. 7 3
      src/drv_dummy/dummy.c
  4. 10 2
      src/openhmd.c
  5. 3 1
      src/openhmdi.h

+ 33 - 10
examples/simple/simple.c

@@ -9,6 +9,7 @@
 
 #include <openhmd.h>
 #include <stdio.h>
+#include <stdlib.h>
 
 void ohmd_sleep(double);
 
@@ -36,6 +37,11 @@ void print_infoi(ohmd_device* hmd, const char* name, int len, ohmd_int_value val
 
 int main(int argc, char** argv)
 {
+	int device_idx = 0;
+
+	if(argc > 1)
+		device_idx = atoi(argv[1]);
+
 	ohmd_context* ctx = ohmd_ctx_create();
 
 	// Probe for devices
@@ -50,7 +56,7 @@ 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"};
+		const 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);
@@ -68,8 +74,9 @@ int main(int argc, char** argv)
 		printf("    right controller:    %s\n\n", device_flags & OHMD_DEVICE_FLAGS_RIGHT_CONTROLLER ? "yes" : "no");
 	}
 
-	// Open default device (0)
-	ohmd_device* hmd = ohmd_list_open_device(ctx, 0);
+	// Open specified device idx or 0 (default) if nothing specified
+	printf("opening device: %d\n", device_idx);
+	ohmd_device* hmd = ohmd_list_open_device(ctx, device_idx);
 	
 	if(!hmd){
 		printf("failed to open device: %s\n", ohmd_ctx_get_error(ctx));
@@ -93,12 +100,28 @@ int main(int argc, char** argv)
 	print_infof(hmd, "distortion k:",     6, OHMD_DISTORTION_K);
 	
 	print_infoi(hmd, "digital button count:", 1, OHMD_BUTTON_COUNT);
-	print_infoi(hmd, "analog axis count:   ", 1, OHMD_ANALOG_AXIS_COUNT);
+	print_infoi(hmd, "control count:   ", 1, OHMD_CONTROL_COUNT);
 
-	printf("\n");
+	int control_count;
+	ohmd_device_geti(hmd, OHMD_CONTROL_COUNT, &control_count);
+
+	const char* controls_fn_str[] = { "generic", "trigger", "trigger_click", "squeeze", "menu", "home",
+		"analog-x", "analog-y", "anlog_press", "button-a", "button-b", "button-x", "button-y"};
+
+	const char* controls_type_str[] = {"digital", "analog"};
+
+	int controls_fn[64];
+	int controls_types[64];
+
+	ohmd_device_geti(hmd, OHMD_CONTROLS_FUNCTIONS, controls_fn);
+	ohmd_device_geti(hmd, OHMD_CONTROLS_TYPES, controls_types);
+	
+	printf("%-25s", "controls:");
+	for(int i = 0; i < control_count; i++){
+		printf("%s (%s)%s", controls_fn_str[controls_fn[i]], controls_type_str[controls_types[i]], i == control_count - 1 ? "" : ", ");
+	}
 
-	int analog_axis_count;
-	ohmd_device_geti(hmd, OHMD_ANALOG_AXIS_COUNT, &analog_axis_count);
+	printf("\n\n");
 
 	// Ask for n rotation quaternions and position vectors
 	for(int i = 0; i < 10000; i++){
@@ -116,10 +139,10 @@ int main(int argc, char** argv)
 
 		// read analog axes
 		float axes[256];
-		ohmd_device_getf(hmd, OHMD_ANALOG_AXES_STATE, axes);
+		ohmd_device_getf(hmd, OHMD_CONTROLS_STATE, axes);
 
-		printf("%-25s", "axes:");
-		for(int i = 0; i < analog_axis_count; i++)
+		printf("%-25s", "controls:");
+		for(int i = 0; i < control_count; i++)
 		{
 			printf("%f ", axes[i]);
 		}

+ 34 - 4
include/openhmd.h

@@ -63,6 +63,30 @@ typedef enum {
 	OHMD_GLSL_DISTORTION_FRAG_SRC = 1,
 } ohmd_string_description;
 
+/** Standard controls. Note that this is not an index into the control state. 
+	Use OHMD_CONTROL_TYPES to determine what function a control serves at a given index. */
+typedef enum {
+	OHMD_GENERIC        = 0,
+	OHMD_TRIGGER        = 1,
+	OHMD_TRIGGER_CLICK  = 2,
+	OHMD_SQUEEZE        = 3,
+	OHMD_MENU           = 4,
+	OHMD_HOME           = 5,
+	OHMD_ANALOG_X       = 6,
+	OHMD_ANALOG_Y       = 7,
+	OHMD_ANALOG_PRESS   = 8,
+	OHMD_BUTTON_A       = 9,
+	OHMD_BUTTON_B       = 10,
+	OHMD_BUTTON_X       = 11,
+	OHMD_BUTTON_Y       = 12,
+} ohmd_control_function;
+
+/** Control type. Indicates whether controls are digital or analog. */
+typedef enum {
+	OHMD_DIGITAL = 0,
+	OHMD_ANALOG = 1
+} ohmd_control_type;
+
 /** A collection of float value information types, used for getting and setting information with
     ohmd_device_getf() and ohmd_device_setf(). */
 typedef enum {
@@ -129,8 +153,8 @@ typedef enum {
 	/** float[3] (get): Universal shader aberration coefficients (post warp scaling <r,g,b>. */
 	OHMD_UNIVERSAL_ABERRATION_K           = 21,
 
-	/** float[OHMD_ANALOG_AXIS_COUNT] (get): Get the state of the analog axes on the device. */
-	OHMD_ANALOG_AXES_STATE                = 22,
+	/** float[OHMD_CONTROL_COUNT] (get): Get the state of the device's controls. */
+	OHMD_CONTROLS_STATE                = 22,
 
 } ohmd_float_value;
 
@@ -155,8 +179,14 @@ typedef enum {
 	/** int[1] (get, ohmd_geti()/ohmd_list_geti()): Gets the flags of the device. See: ohmd_device_flags. */
 	OHMD_DEVICE_FLAGS                     =  7,
 
-	/** int[1] (get, ohmd_geti()): Get the number of analog axes on the device. */
-	OHMD_ANALOG_AXIS_COUNT                =  8,
+	/** int[1] (get, ohmd_geti()): Get the number of analog and digital controls of the device. */
+	OHMD_CONTROL_COUNT                    =  8,
+
+	/** int[OHMD_CONTROL_COUNT] (get, ohmd_geti()): Get whether controls are digital or analog. */
+	OHMD_CONTROLS_FUNCTIONS               =  9,
+	
+	/** int[OHMD_CONTROL_COUNT] (get, ohmd_geti()): Get what function controls serve. */
+	OHMD_CONTROLS_TYPES                   =  10,
 } ohmd_int_value;
 
 /** A collection of data information types used for setting information with ohmd_set_data(). */

+ 7 - 3
src/drv_dummy/dummy.c

@@ -53,9 +53,9 @@ static int getf(ohmd_device* device, ohmd_float_value type, float* out)
 		memset(out, 0, sizeof(float) * 6);
 		break;
 	
-	case OHMD_ANALOG_AXES_STATE:
+	case OHMD_CONTROLS_STATE:
 		out[0] = .1f;
-		out[1] = .2f;
+		out[1] = 1.0f;
 		break;
 
 	default:
@@ -96,7 +96,11 @@ static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 	
 	// Some buttons and axes
 	priv->base.properties.digital_button_count = 4;
-	priv->base.properties.analog_axis_count = 2;
+	priv->base.properties.control_count = 2;
+	priv->base.properties.controls_functions[0] = OHMD_BUTTON_A;
+	priv->base.properties.controls_functions[1] = OHMD_MENU;
+	priv->base.properties.controls_types[0] = OHMD_ANALOG;
+	priv->base.properties.controls_types[1] = OHMD_DIGITAL;
 
 	// calculate projection eye projection matrices from the device properties
 	ohmd_calc_default_proj_matrices(&priv->base.properties);

+ 10 - 2
src/openhmd.c

@@ -475,8 +475,16 @@ int OHMD_APIENTRY ohmd_device_geti(ohmd_device* device, ohmd_int_value type, int
 				return OHMD_S_OK;
 			}
 		
-		case OHMD_ANALOG_AXIS_COUNT:
-			*out = device->properties.analog_axis_count;
+		case OHMD_CONTROL_COUNT:
+			*out = device->properties.control_count;
+			return OHMD_S_OK;
+
+		case OHMD_CONTROLS_TYPES:
+			memcpy(out, device->properties.controls_types, device->properties.control_count * sizeof(int));
+			return OHMD_S_OK;
+		
+		case OHMD_CONTROLS_FUNCTIONS:
+			memcpy(out, device->properties.controls_functions, device->properties.control_count * sizeof(int));
 			return OHMD_S_OK;
 
 		default:

+ 3 - 1
src/openhmdi.h

@@ -62,7 +62,9 @@ typedef struct {
 		int hres;
 		int vres;
 		int digital_button_count;
-		int analog_axis_count;
+		int control_count;
+		int controls_functions[64];
+		int controls_types[64];
 
 		float hsize;
 		float vsize;