Permalink
Browse files

Tracker: Auto-update LEDs by default (switchable)

By default, we now auto-update the LEDs of the controller
directly from the tracker - this avoids some boilerplace
code necessary in the user application. If desired, the
user of the library can disable the auto-updating and do
the updates manually (e.g. to switch colors, etc...).
  • Loading branch information...
1 parent 59a05bb commit fcb25df2c434becd2114b32ec809d7c569de66da @thp committed Oct 9, 2012
@@ -75,12 +75,6 @@ namespace ot {
* so we don't need to call them here
**/
- // Update the LEDs of the controller to keep it lit
- unsigned char r, g, b;
- psmove_tracker_get_color(tracker, move, &r, &g, &b);
- psmove_set_leds(move, r, g, b);
- psmove_update_leds(move);
-
// Read the latest input reports from the controller
while (psmove_poll(move));
View
@@ -233,6 +233,14 @@ void reinit();
psmove_tracker_disable($self, move);
}
+ void set_auto_update_leds(PSMove *move, int auto_update_leds) {
+ psmove_tracker_set_auto_update_leds($self, move, auto_update_leds);
+ }
+
+ int get_auto_update_leds(PSMove *move) {
+ return psmove_tracker_get_auto_update_leds($self, move);
+ }
+
void get_color(PSMove *move, unsigned char *OUTPUT,
unsigned char *OUTPUT, unsigned char *OUTPUT);
@@ -90,11 +90,6 @@ main(int arg, char** args)
void *frame = psmove_tracker_get_frame(tracker);
cvShowImage("Camera", frame);
- unsigned char r, g, b;
- psmove_tracker_get_color(tracker, move, &r, &g, &b);
- psmove_set_leds(move, r, g, b);
- psmove_update_leds(move);
-
float x, y, radius;
psmove_tracker_get_position(tracker, move, &x, &y, &radius);
@@ -69,7 +69,6 @@ int main(int arg, char** args) {
}
void *frame;
- unsigned char r, g, b;
int result;
for (i=0; i<count; i++) {
@@ -110,8 +109,11 @@ int main(int arg, char** args) {
fflush(stdout);
result = psmove_tracker_enable(tracker, controllers[i]);
+ enum PSMove_Bool auto_update_leds =
+ psmove_tracker_get_auto_update_leds(tracker, controllers[i]);
if (result == Tracker_CALIBRATED) {
- printf("OK\n");
+ printf("OK, auto_update_leds is %s\n",
+ (auto_update_leds == PSMove_True)?"enabled":"disabled");
break;
} else {
printf("ERROR - retrying\n");
@@ -129,9 +131,12 @@ int main(int arg, char** args) {
}
for (i=0; i<count; i++) {
+ /* Optional and not required by default (see auto_update_leds above)
+ unsigned char r, g, b;
psmove_tracker_get_color(tracker, controllers[i], &r, &g, &b);
psmove_set_leds(controllers[i], r, g, b);
psmove_update_leds(controllers[i]);
+ */
float x, y, r;
psmove_tracker_get_position(tracker, controllers[i], &x, &y, &r);
@@ -503,7 +503,6 @@ main(int argc, const char **argv) {
PSMoveTracker* tracker = psmove_tracker_new();
- unsigned char r, g, b;
int width, height;
bool show_debug_window = false;
bool did_show_debug_window_once = false;
@@ -621,9 +620,7 @@ main(int argc, const char **argv) {
float x, y;
for (int i=0; i<count; i++) {
- psmove_tracker_get_color(tracker, moves[i], &r, &g, &b);
psmove_set_rumble(moves[i], 0);
- psmove_set_leds(moves[i], r, g, b);
psmove_update_leds(moves[i]);
if (event_sender) {
@@ -16,11 +16,12 @@ public class Tracker {
/* Track controllers in the camera picture */
tracker.update();
- /* Update the LEDs so they don't turn dark */
+ /* Optional and not required by default
byte r, g, b;
tracker.get_color(move, out r, out g, out b);
move.set_leds(r, g, b);
move.update_leds();
+ */
/* If we're tracking, output the position */
if (tracker.get_status(move) == Status.Tracker_TRACKING) {
@@ -43,12 +43,14 @@ public static void main(String [] args) {
tracker.update_image();
tracker.update();
+ /* Optional and not required by default
short [] r = {0};
short [] g = {0};
short [] b = {0};
tracker.get_color(move, r, g, b);
move.set_leds(r[0], g[0], b[0]);
move.update_leds();
+ */
if (tracker.get_status(move) == Status.Tracker_TRACKING) {
float [] x = { 0.f };
@@ -160,13 +160,6 @@ class MovetyTouch : public QThread
psmove_tracker_update_image(tracker);
psmove_tracker_update(tracker, NULL);
-
- for (i=0; i<count; i++) {
- unsigned char r, g, b;
- psmove_tracker_get_color(tracker, moves[i], &r, &g, &b);
- psmove_set_leds(moves[i], r, g, b);
- psmove_update_leds(moves[i]);
- }
}
psmove_tracker_free(tracker);
@@ -100,11 +100,6 @@ class Orientation : public QThread
psmove_tracker_update(tracker, NULL);
cvShowImage("asdf", psmove_tracker_get_frame(tracker));
-
- unsigned char r, g, b;
- psmove_tracker_get_color(tracker, move, &r, &g, &b);
- psmove_set_leds(move, r, g, b);
- psmove_update_leds(move);
}
psmove_tracker_free(tracker);
@@ -142,15 +142,6 @@ class Orientation : public QThread
}
} while (again);
- for (i=0; i<count; i++) {
- PSMove *move = moves[i];
-
- unsigned char r, g, b;
- psmove_tracker_get_color(tracker, move, &r, &g, &b);
- psmove_set_leds(move, r, g, b);
- psmove_update_leds(move);
- }
-
psmove_tracker_update_image(tracker);
psmove_tracker_update(tracker, NULL);
emit newimage(psmove_tracker_get_frame(tracker));
@@ -99,11 +99,6 @@ MainWindow::~MainWindow()
void MainWindow::timeout()
{
- unsigned char r, g, b;
- psmove_tracker_get_color(m_tracker, m_move, &r, &g, &b);
- psmove_set_leds(m_move, r, g, b);
- psmove_update_leds(m_move);
-
psmove_tracker_update_image(m_tracker);
psmove_tracker_update(m_tracker, m_move);
@@ -22,14 +22,7 @@ void setup() {
void draw() {
tracker.update_image();
tracker.update();
-
- short r[] = new short[1];
- short g[] = new short[1];
- short b[] = new short[1];
- tracker.get_color(move, r, g, b);
- move.set_leds(r[0], g[0], b[0]);
- move.update_leds();
-
+
PSMoveTrackerRGBImage image = tracker.get_image();
if (pixels == null) {
pixels = new byte[image.getSize()];
@@ -43,6 +43,9 @@
print 'Trying to calibrate...'
result = tracker.enable(move)
+auto_update_leds = tracker.get_auto_update_leds(move)
+print 'Auto-update LEDs is', ('enabled' if auto_update_leds else 'disabled')
+
# Loop and update the controller
while True:
# Get the latest input report from the controller
@@ -53,10 +56,10 @@
# Update all tracked controllers
tracker.update()
- # Need to set the LEDs of the controller regulary
- r, g, b = tracker.get_color(move)
- move.set_leds(r, g, b)
- move.update_leds()
+ # Optional and not required by default (see auto_update_leds above)
+ #r, g, b = tracker.get_color(move)
+ #move.set_leds(r, g, b)
+ #move.update_leds()
# Check the tracking status
status = tracker.get_status(move)
@@ -75,11 +75,6 @@
display.blit(surface, (0, 0))
pygame.display.flip()
- # Need to set the LEDs of the controller regulary
- r, g, b = tracker.get_color(move)
- move.set_leds(r, g, b)
- move.update_leds()
-
# Check the tracking status
status = tracker.get_status(move)
if status == psmove.Tracker_TRACKING:
View
@@ -107,6 +107,13 @@ ADDAPI PSMoveTracker *
ADDCALL psmove_tracker_new_with_camera(int camera);
ADDAPI void
+ADDCALL psmove_tracker_set_auto_update_leds(PSMoveTracker *tracker, PSMove *move,
+ enum PSMove_Bool auto_update_leds);
+
+ADDAPI enum PSMove_Bool
+ADDCALL psmove_tracker_get_auto_update_leds(PSMoveTracker *tracker, PSMove *move);
+
+ADDAPI void
ADDCALL psmove_tracker_set_dimming(PSMoveTracker *tracker, float dimming);
ADDAPI float
@@ -132,6 +132,7 @@ struct _TrackedController {
int is_tracked; // 1 if tracked 0 otherwise
long last_color_update; // the timestamp when the last color adaption has been performed
+ enum PSMove_Bool auto_update_leds;
};
typedef struct _TrackedController TrackedController;
@@ -416,6 +417,30 @@ PSMoveTracker *psmove_tracker_new() {
}
void
+psmove_tracker_set_auto_update_leds(PSMoveTracker *tracker, PSMove *move,
+ enum PSMove_Bool auto_update_leds)
+{
+ psmove_return_if_fail(tracker != NULL);
+ psmove_return_if_fail(move != NULL);
+ TrackedController *tc = psmove_tracker_find_controller(tracker, move);
+ psmove_return_if_fail(tc != NULL);
+ tc->auto_update_leds = auto_update_leds;
+}
+
+
+enum PSMove_Bool
+psmove_tracker_get_auto_update_leds(PSMoveTracker *tracker, PSMove *move)
+{
+ psmove_return_val_if_fail(tracker != NULL, PSMove_False);
+ psmove_return_val_if_fail(move != NULL, PSMove_False);
+
+ TrackedController *tc = psmove_tracker_find_controller(tracker, move);
+ psmove_return_val_if_fail(tc != NULL, PSMove_False);
+ return tc->auto_update_leds;
+}
+
+
+void
psmove_tracker_set_dimming(PSMoveTracker *tracker, float dimming)
{
psmove_return_if_fail(tracker != NULL);
@@ -631,6 +656,7 @@ psmove_tracker_old_color_is_tracked(PSMoveTracker* tracker, PSMove* move, struct
tc->move = move;
tc->color = rgb;
+ tc->auto_update_leds = PSMove_True;
tc->eColor = tc->eFColor = color;
tc->eColorHSV = tc->eFColorHSV = th_brg2hsv(tc->eFColor);
@@ -914,6 +940,7 @@ psmove_tracker_enable_with_color_internal(PSMoveTracker *tracker, PSMove *move,
tc->move = move;
tc->color = rgb;
+ tc->auto_update_leds = PSMove_True;
psmove_tracker_remember_color(tracker, rgb, color);
tc->eColor = tc->eFColor = color;
@@ -1053,7 +1080,8 @@ psmove_tracker_get_image(PSMoveTracker *tracker)
}
void psmove_tracker_update_image(PSMoveTracker *tracker) {
- tracker->frame = camera_control_query_frame(tracker->cc);
+ psmove_return_if_fail(tracker != NULL);
+ tracker->frame = camera_control_query_frame(tracker->cc);
}
int
@@ -1063,6 +1091,13 @@ psmove_tracker_update_controller(PSMoveTracker *tracker, TrackedController *tc)
int i = 0;
int sphere_found = 0;
+ if (tc->auto_update_leds) {
+ unsigned char r, g, b;
+ psmove_tracker_get_color(tracker, tc->move, &r, &g, &b);
+ psmove_set_leds(tc->move, r, g, b);
+ psmove_update_leds(tc->move);
+ }
+
// calculate upper & lower bounds for the color filter
CvScalar min = th_scalar_sub(tc->eColorHSV, tracker->rHSV);
CvScalar max = th_scalar_add(tc->eColorHSV, tracker->rHSV);

0 comments on commit fcb25df

Please sign in to comment.