summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2015-03-17 17:59:59 +0100
committerFlorian Jung <flo@windfisch.org>2015-03-17 17:59:59 +0100
commitd7457ddebb80941745ec73b564e9e9cc77dd6c31 (patch)
treebae0f9df70135b8057f52dbab6e7e7cd1696ed27
parentf09318781835617bb73b3f0c601cd0e4c1c7017b (diff)
cleanup
-rw-r--r--simple.c63
1 files changed, 26 insertions, 37 deletions
diff --git a/simple.c b/simple.c
index 538d536..813b8fe 100644
--- a/simple.c
+++ b/simple.c
@@ -12,43 +12,26 @@
void ohmd_sleep(double);
-// gets float values from the device and prints them
-void print_infof(ohmd_device* hmd, const char* name, int len, ohmd_float_value val)
-{
- float f[len];
- ohmd_device_getf(hmd, val, f);
- printf("%-20s", name);
- for(int i = 0; i < len; i++)
- printf("%f ", f[i]);
- printf("\n");
-}
-int main(int argc, char** argv)
+int init_ohmd(ohmd_context** ctx_, ohmd_device** hmd_)
{
ohmd_context* ctx = ohmd_ctx_create();
- // Probe for devices
+ // Probe
int num_devices = ohmd_ctx_probe(ctx);
- if(num_devices < 0){
- printf("failed to probe devices: %s\n", ohmd_ctx_get_error(ctx));
+ if(num_devices < 0)
+ {
+ printf("device probing failed: %s\n", ohmd_ctx_get_error(ctx));
return -1;
}
- printf("num devices: %d\n\n", num_devices);
+ printf("i've got %d devices\n\n", num_devices);
- // Print device information
- for(int i = 0; i < num_devices; i++){
- 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));
- }
-
- // Open default device (0)
ohmd_device* hmd = ohmd_list_open_device(ctx, 0);
- if(!hmd){
- printf("failed to open device: %s\n", ohmd_ctx_get_error(ctx));
+ if(!hmd)
+ {
+ printf("open failed! %s\n", ohmd_ctx_get_error(ctx));
return -1;
}
@@ -58,22 +41,26 @@ int main(int argc, char** argv)
ohmd_device_geti(hmd, OHMD_SCREEN_VERTICAL_RESOLUTION, ivals + 1);
printf("resolution: %i x %i\n", ivals[0], ivals[1]);
- print_infof(hmd, "hsize:", 1, OHMD_SCREEN_HORIZONTAL_SIZE);
- print_infof(hmd, "vsize:", 1, OHMD_SCREEN_VERTICAL_SIZE);
- print_infof(hmd, "lens separation:", 1, OHMD_LENS_HORIZONTAL_SEPARATION);
- print_infof(hmd, "lens vcenter:", 1, OHMD_LENS_VERTICAL_POSITION);
- print_infof(hmd, "left eye fov:", 1, OHMD_LEFT_EYE_FOV);
- print_infof(hmd, "right eye fov:", 1, OHMD_RIGHT_EYE_FOV);
- print_infof(hmd, "left eye aspect:", 1, OHMD_LEFT_EYE_ASPECT_RATIO);
- print_infof(hmd, "right eye aspect:", 1, OHMD_RIGHT_EYE_ASPECT_RATIO);
- print_infof(hmd, "distortion k:", 6, OHMD_DISTORTION_K);
+ *ctx_=ctx;
+ *hmd_=hmd;
+}
+
+int main(int argc, char** argv)
+{
+ ohmd_context* ctx;
+ ohmd_device* hmd;
- printf("\n");
+ init_ohmd(&ctx,&hmd);
// Ask for n rotation quaternions
for(int i = 0; i < 10000; i++){
ohmd_ctx_update(ctx);
- print_infof(hmd, "rotation quat:", 4, OHMD_ROTATION_QUAT);
+
+ float quat[4];
+ ohmd_device_getf(hmd, OHMD_ROTATION_QUAT, quat);
+ printf("quat:\t %f\t%f\t%f\t%f\n", quat[0],quat[1],quat[2],quat[3]);
+
+
ohmd_sleep(.01);
}
@@ -81,3 +68,5 @@ int main(int argc, char** argv)
return 0;
}
+
+