Skip to content

Commit

Permalink
Compability and performance fixes for OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
thp committed Dec 2, 2012
1 parent a75a1c2 commit b18ec54
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 46 deletions.
49 changes: 4 additions & 45 deletions examples/c/test_tracker.c
Expand Up @@ -41,23 +41,6 @@
#include "psmove_tracker.h" #include "psmove_tracker.h"




void
wait_for_button(PSMove *move, int button)
{
/* Wait for press */
while ((psmove_get_buttons(move) & button) == 0) {
psmove_poll(move);
psmove_update_leds(move);
}

/* Wait for release */
while ((psmove_get_buttons(move) & button) != 0) {
psmove_poll(move);
psmove_update_leds(move);
}
}


int main(int arg, char** args) { int main(int arg, char** args) {
int i; int i;
int count = psmove_count_connected(); int count = psmove_count_connected();
Expand All @@ -71,40 +54,16 @@ int main(int arg, char** args) {
void *frame; void *frame;
int result; int result;


for (i=0; i<count; i++) {
printf("Opening controller %d\n", i);
controllers[i] = psmove_connect_by_id(i);
assert(controllers[i] != NULL);
}

#ifdef __APPLE__
PSMove *move = controllers[0];
psmove_set_leds(move, 255, 255, 255);
psmove_update_leds(move);
#endif

#ifdef __APPLE__
printf("Cover the iSight camera with the sphere and press the Move button\n");
wait_for_button(move, Btn_MOVE);
psmove_set_leds(move, 0, 0, 0);
psmove_update_leds(move);
psmove_set_leds(move, 255, 255, 255);
psmove_update_leds(move);
#endif

fprintf(stderr, "Trying to init PSMoveTracker..."); fprintf(stderr, "Trying to init PSMoveTracker...");
PSMoveTracker* tracker = psmove_tracker_new(); PSMoveTracker* tracker = psmove_tracker_new();
psmove_tracker_set_mirror(tracker, PSMove_True); psmove_tracker_set_mirror(tracker, PSMove_True);
fprintf(stderr, "OK\n"); fprintf(stderr, "OK\n");


#ifdef __APPLE__
printf("Move the controller away and press the Move button\n");
wait_for_button(move, Btn_MOVE);
psmove_set_leds(move, 0, 0, 0);
psmove_update_leds(move);
#endif

for (i=0; i<count; i++) { for (i=0; i<count; i++) {
printf("Opening controller %d\n", i);
controllers[i] = psmove_connect_by_id(i);
assert(controllers[i] != NULL);

while (1) { while (1) {
printf("Calibrating controller %d...", i); printf("Calibrating controller %d...", i);
fflush(stdout); fflush(stdout);
Expand Down
33 changes: 33 additions & 0 deletions src/psmove.c
Expand Up @@ -1769,6 +1769,23 @@ _psmove_normalize_btaddr(const char *addr, int lowercase, char separator)
return result; return result;
} }


#ifdef __APPLE__

#define CLOCK_MONOTONIC 0

static int
clock_gettime(int unused, struct timespec *ts)
{
struct timeval tv;
gettimeofday(&tv, NULL);

ts->tv_sec = tv.tv_sec;
ts->tv_nsec = tv.tv_usec * 1000;

return 0;
}
#endif /* __APPLE__ */

PSMove_timestamp PSMove_timestamp
_psmove_timestamp() _psmove_timestamp()
{ {
Expand Down Expand Up @@ -1797,3 +1814,19 @@ _psmove_timestamp_value(PSMove_timestamp ts)
return ts.tv_sec + ts.tv_nsec * 0.000000001; return ts.tv_sec + ts.tv_nsec * 0.000000001;
} }


void
_psmove_wait_for_button(PSMove *move, int button)
{
/* Wait for press */
while ((psmove_get_buttons(move) & button) == 0) {
psmove_poll(move);
psmove_update_leds(move);
}

/* Wait for release */
while ((psmove_get_buttons(move) & button) != 0) {
psmove_poll(move);
psmove_update_leds(move);
}
}

5 changes: 5 additions & 0 deletions src/psmove_private.h
Expand Up @@ -200,6 +200,11 @@ ADDAPI double
ADDCALL _psmove_timestamp_value(PSMove_timestamp ts); ADDCALL _psmove_timestamp_value(PSMove_timestamp ts);




/* Misc utility functions */
ADDAPI void
ADDCALL _psmove_wait_for_button(PSMove *move, int button);


#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
Expand Down
28 changes: 27 additions & 1 deletion src/tracker/psmove_tracker.c
Expand Up @@ -541,6 +541,19 @@ psmove_tracker_new_with_camera(int camera) {
tracker->color_t3 = COLOR_UPDATE_QUALITY_T3; tracker->color_t3 = COLOR_UPDATE_QUALITY_T3;
tracker->color_update_rate = COLOR_UPDATE_RATE; tracker->color_update_rate = COLOR_UPDATE_RATE;


#ifdef __APPLE__
PSMove *move = psmove_connect();
psmove_set_leds(move, 255, 255, 255);
psmove_update_leds(move);

printf("Cover the iSight camera with the sphere and press the Move button\n");
_psmove_wait_for_button(move, Btn_MOVE);
psmove_set_leds(move, 0, 0, 0);
psmove_update_leds(move);
psmove_set_leds(move, 255, 255, 255);
psmove_update_leds(move);
#endif

// start the video capture device for tracking // start the video capture device for tracking
tracker->cc = camera_control_new(camera); tracker->cc = camera_control_new(camera);


Expand Down Expand Up @@ -660,6 +673,15 @@ psmove_tracker_new_with_camera(int camera) {
int ks = 5; // Kernel Size int ks = 5; // Kernel Size
int kc = (ks + 1) / 2; // Kernel Center int kc = (ks + 1) / 2; // Kernel Center
tracker->kCalib = cvCreateStructuringElementEx(ks, ks, kc, kc, CV_SHAPE_RECT, NULL); tracker->kCalib = cvCreateStructuringElementEx(ks, ks, kc, kc, CV_SHAPE_RECT, NULL);

#ifdef __APPLE__
printf("Move the controller away and press the Move button\n");
_psmove_wait_for_button(move, Btn_MOVE);
psmove_set_leds(move, 0, 0, 0);
psmove_update_leds(move);
psmove_disconnect(move);
#endif

return tracker; return tracker;
} }


Expand All @@ -686,7 +708,11 @@ psmove_tracker_enable(PSMoveTracker *tracker, PSMove *move)
{0x00, 0xFF, 0xFF}, /* cyan */ {0x00, 0xFF, 0xFF}, /* cyan */
{0xFF, 0xFF, 0x00}, /* yellow */ {0xFF, 0xFF, 0x00}, /* yellow */
{0xFF, 0x00, 0x00}, /* red */ {0xFF, 0x00, 0x00}, /* red */
#ifdef __APPLE__
{0x00, 0xFF, 0x00}, /* green */
#else
{0x00, 0x00, 0xFF}, /* blue */ {0x00, 0x00, 0xFF}, /* blue */
#endif
}; };


for (i=0; i<ARRAY_LENGTH(preset_colors); i++) { for (i=0; i<ARRAY_LENGTH(preset_colors); i++) {
Expand Down Expand Up @@ -1367,7 +1393,7 @@ psmove_tracker_update_controller(PSMoveTracker *tracker, TrackedController *tc)
cvResetImageROI(tracker->frame); cvResetImageROI(tracker->frame);


if (sphere_found) { if (sphere_found) {
tc->search_tile = 0; //tc->search_tile = 0;
// the sphere was found // the sphere was found
break; break;
}else if(tc->roi_level>0){ }else if(tc->roi_level>0){
Expand Down

0 comments on commit b18ec54

Please sign in to comment.