Permalink
Browse files

Compability and performance fixes for OS X

  • Loading branch information...
1 parent a75a1c2 commit b18ec54e1896480a380e0efc70dc0748344738a4 @thp committed Dec 2, 2012
Showing with 69 additions and 46 deletions.
  1. +4 −45 examples/c/test_tracker.c
  2. +33 −0 src/psmove.c
  3. +5 −0 src/psmove_private.h
  4. +27 −1 src/tracker/psmove_tracker.c
View
@@ -41,23 +41,6 @@
#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 i;
int count = psmove_count_connected();
@@ -71,40 +54,16 @@ int main(int arg, char** args) {
void *frame;
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...");
PSMoveTracker* tracker = psmove_tracker_new();
psmove_tracker_set_mirror(tracker, PSMove_True);
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++) {
+ printf("Opening controller %d\n", i);
+ controllers[i] = psmove_connect_by_id(i);
+ assert(controllers[i] != NULL);
+
while (1) {
printf("Calibrating controller %d...", i);
fflush(stdout);
View
@@ -1769,6 +1769,23 @@ _psmove_normalize_btaddr(const char *addr, int lowercase, char separator)
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()
{
@@ -1797,3 +1814,19 @@ _psmove_timestamp_value(PSMove_timestamp ts)
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);
+ }
+}
+
View
@@ -200,6 +200,11 @@ ADDAPI double
ADDCALL _psmove_timestamp_value(PSMove_timestamp ts);
+/* Misc utility functions */
+ADDAPI void
+ADDCALL _psmove_wait_for_button(PSMove *move, int button);
+
+
#ifdef __cplusplus
}
#endif
@@ -541,6 +541,19 @@ psmove_tracker_new_with_camera(int camera) {
tracker->color_t3 = COLOR_UPDATE_QUALITY_T3;
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
tracker->cc = camera_control_new(camera);
@@ -660,6 +673,15 @@ psmove_tracker_new_with_camera(int camera) {
int ks = 5; // Kernel Size
int kc = (ks + 1) / 2; // Kernel Center
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;
}
@@ -686,7 +708,11 @@ psmove_tracker_enable(PSMoveTracker *tracker, PSMove *move)
{0x00, 0xFF, 0xFF}, /* cyan */
{0xFF, 0xFF, 0x00}, /* yellow */
{0xFF, 0x00, 0x00}, /* red */
+#ifdef __APPLE__
+ {0x00, 0xFF, 0x00}, /* green */
+#else
{0x00, 0x00, 0xFF}, /* blue */
+#endif
};
for (i=0; i<ARRAY_LENGTH(preset_colors); i++) {
@@ -1367,7 +1393,7 @@ psmove_tracker_update_controller(PSMoveTracker *tracker, TrackedController *tc)
cvResetImageROI(tracker->frame);
if (sphere_found) {
- tc->search_tile = 0;
+ //tc->search_tile = 0;
// the sphere was found
break;
}else if(tc->roi_level>0){

0 comments on commit b18ec54

Please sign in to comment.