瀏覽代碼

Merge pull request #136 from ChristophHaag/simple_controller

examples/simple: Only query controller state if device is controller
TheOnlyJoey 7 年之前
父節點
當前提交
5bf4831acb
共有 1 個文件被更改,包括 11 次插入7 次删除
  1. 11 7
      examples/simple/simple.c

+ 11 - 7
examples/simple/simple.c

@@ -122,6 +122,8 @@ int main(int argc, char** argv)
 
 	printf("\n\n");
 
+	int device_class = 0;
+	ohmd_device_geti(hmd, OHMD_DEVICE_CLASS, &device_class);
 	// Ask for n rotation quaternions and position vectors
 	for(int i = 0; i < 10000; i++){
 		ohmd_ctx_update(ctx);
@@ -137,13 +139,15 @@ int main(int argc, char** argv)
 		print_infof(hmd, "position vec: ", 3, OHMD_POSITION_VECTOR);
 
 		// read controls
-		float control_state[256];
-		ohmd_device_getf(hmd, OHMD_CONTROLS_STATE, control_state);
-
-		printf("%-25s", "controls state:");
-		for(int i = 0; i < control_count; i++)
-		{
-			printf("%f ", control_state[i]);
+		if (device_class & OHMD_DEVICE_CLASS_CONTROLLER) {
+			float control_state[256];
+			ohmd_device_getf(hmd, OHMD_CONTROLS_STATE, control_state);
+
+			printf("%-25s", "controls state:");
+			for(int i = 0; i < control_count; i++)
+			{
+				printf("%f ", control_state[i]);
+			}
 		}
 		puts("");