|
@@ -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
|
|
@@ -49,14 +55,28 @@ int main(int argc, char** argv)
|
|
|
|
|
|
// Print device information
|
|
|
for(int i = 0; i < num_devices; i++){
|
|
|
+ int device_class = 0, device_flags = 0;
|
|
|
+ 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);
|
|
|
+
|
|
|
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", device_flags & OHMD_DEVICE_FLAGS_POSITIONAL_TRACKING ? "yes" : "no");
|
|
|
+ printf(" left controller: %s\n", device_flags & OHMD_DEVICE_FLAGS_LEFT_CONTROLLER ? "yes" : "no");
|
|
|
+ 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));
|
|
@@ -80,18 +100,55 @@ 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, "control count: ", 1, OHMD_CONTROL_COUNT);
|
|
|
|
|
|
- printf("\n");
|
|
|
+ int control_count;
|
|
|
+ ohmd_device_geti(hmd, OHMD_CONTROL_COUNT, &control_count);
|
|
|
|
|
|
- // Ask for n rotation quaternions
|
|
|
+ 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 ? "" : ", ");
|
|
|
+ }
|
|
|
+
|
|
|
+ printf("\n\n");
|
|
|
+
|
|
|
+ // Ask for n rotation quaternions and position vectors
|
|
|
for(int i = 0; i < 10000; i++){
|
|
|
ohmd_ctx_update(ctx);
|
|
|
|
|
|
- float zero[] = {.0, .1, .2, 1};
|
|
|
- ohmd_device_setf(hmd, OHMD_ROTATION_QUAT, zero);
|
|
|
- ohmd_device_setf(hmd, OHMD_POSITION_VECTOR, zero);
|
|
|
+ // this can be used to set a different zero point
|
|
|
+ // for rotation and position, but is not required.
|
|
|
+ //float zero[] = {.0, .0, .0, 1};
|
|
|
+ //ohmd_device_setf(hmd, OHMD_ROTATION_QUAT, zero);
|
|
|
+ //ohmd_device_setf(hmd, OHMD_POSITION_VECTOR, zero);
|
|
|
|
|
|
+ // get rotation and postition
|
|
|
print_infof(hmd, "rotation quat:", 4, OHMD_ROTATION_QUAT);
|
|
|
+ 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]);
|
|
|
+ }
|
|
|
+ puts("");
|
|
|
+
|
|
|
+ // handle digital button events
|
|
|
print_infoi(hmd, "button event count:", 1, OHMD_BUTTON_EVENT_COUNT);
|
|
|
|
|
|
int event_count = 0;
|
|
@@ -103,7 +160,7 @@ int main(int argc, char** argv)
|
|
|
ohmd_device_geti(hmd, OHMD_BUTTON_POP_EVENT, event);
|
|
|
printf("button %d: %s", event[0], event[1] == OHMD_BUTTON_DOWN ? "down" : "up");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
ohmd_sleep(.01);
|
|
|
}
|
|
|
|