From 363f67a56e012c2f55ba1225e58c4a956da41f41 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Tue, 7 Aug 2012 16:21:31 +0200 Subject: [PATCH] Tracker: Environment variable to choose camera --- README | 12 ++++++++++++ include/psmove_tracker.h | 4 ++++ src/psmove_tracker.c | 13 +++++++++++++ 3 files changed, 29 insertions(+) diff --git a/README b/README index eb9c038f..ed4ea404 100644 --- a/README +++ b/README @@ -19,6 +19,18 @@ Advanced features: * Orientation: Rotation tracking using gyro and accelerometer +Environment variables: + + PSMOVE_TRACKER_CAMERA + + If set, this is the camera that will be used when using + psmove_tracker_new() instead of using auto-detection + + Example: export PSMOVE_TRACKER_CAMERA=2 # Will use the 3rd camera + + + + |- Windows notes ----------- -- - - | If you are using MinGW from the Qt SDK, you have to replace the file | libbthprops.a in mingw\lib\ with the file of the same name from the diff --git a/include/psmove_tracker.h b/include/psmove_tracker.h index 96f41d9d..0d1ae0cb 100644 --- a/include/psmove_tracker.h +++ b/include/psmove_tracker.h @@ -42,6 +42,10 @@ extern "C" { /* For now, we only allow 1 controller to be tracked */ #define PSMOVE_TRACKER_MAX_CONTROLLERS 2 +/* Name of the environment variable used to pick a camera */ +#define PSMOVE_TRACKER_CAMERA_ENV "PSMOVE_TRACKER_CAMERA" + + /* Opaque data structure, defined only in psmove_tracker.c */ struct _PSMoveTracker; typedef struct _PSMoveTracker PSMoveTracker; diff --git a/src/psmove_tracker.c b/src/psmove_tracker.c index 529fe7d6..c199e5fc 100644 --- a/src/psmove_tracker.c +++ b/src/psmove_tracker.c @@ -263,6 +263,19 @@ PSMoveTracker *psmove_tracker_new() { } #endif + char *camera_env = getenv(PSMOVE_TRACKER_CAMERA_ENV); + if (camera_env) { + char *end; + long camera_env_id = strtol(camera_env, &end, 10); + if (*end == '\0' && *camera_env != '\0') { + camera = (int)camera_env_id; +#ifdef PSMOVE_DEBUG + fprintf(stderr, "[PSMOVE] Using camera %d (%s is set)\n", + camera, PSMOVE_TRACKER_CAMERA_ENV); +#endif + } + } + return psmove_tracker_new_with_camera(camera); }