Skip to content

Commit

Permalink
Add support for enabling near mode with new K4W.
Browse files Browse the repository at this point in the history
Thanks to dxli and nneonneo for their initial work on this:

OpenKinect#274

Signed-off-by: Rene Wagner <rwagner@informatik.uni-bremen.de>
  • Loading branch information
renewagner committed Mar 26, 2012
1 parent 2f02393 commit 34f4c1a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
13 changes: 13 additions & 0 deletions examples/glview.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ freenect_video_format current_format = FREENECT_VIDEO_RGB;
freenect_smoothing_mode requested_smoothing = FREENECT_SMOOTHING_HOLE_FILLING_DEPTH_SMOOTHING_ENABLED;
freenect_smoothing_mode current_smoothing = FREENECT_SMOOTHING_HOLE_FILLING_DEPTH_SMOOTHING_ENABLED;

freenect_range_mode requested_range = FREENECT_RANGE_DEFAULT;
freenect_range_mode current_range = FREENECT_RANGE_DEFAULT;

pthread_cond_t gl_frame_cond = PTHREAD_COND_INITIALIZER;
int got_rgb = 0;
int got_depth = 0;
Expand Down Expand Up @@ -187,6 +190,12 @@ void keyPressed(unsigned char key, int x, int y)
else
requested_smoothing = FREENECT_SMOOTHING_DISABLED;
}
if (key == 'n') {
if (requested_range == FREENECT_RANGE_DEFAULT)
requested_range = FREENECT_RANGE_NEAR_MODE;
else
requested_range = FREENECT_RANGE_DEFAULT;
}
}

void ReSizeGLScene(int Width, int Height)
Expand Down Expand Up @@ -340,6 +349,10 @@ void *freenect_threadfunc(void *arg)
freenect_set_smoothing_mode(f_dev, requested_smoothing);
current_smoothing = requested_smoothing;
}
if (requested_range != current_range){
freenect_set_range_mode(f_dev, requested_range);
current_range = requested_range;
}
}

printf("\nshutting down streams...\n");
Expand Down
20 changes: 19 additions & 1 deletion include/libfreenect.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ typedef enum {
FREENECT_SMOOTHING_HOLE_FILLING_DEPTH_SMOOTHING_ENABLED = 1,
} freenect_smoothing_mode;

/// Enumeration of range modes
typedef enum {
FREENECT_RANGE_DEFAULT = 0, /**< default range */
FREENECT_RANGE_NEAR_MODE = 1, /**< near mode. Supported by Kinect for Windows only */
} freenect_range_mode;

/// Enumeration of LED states
/// See http://openkinect.org/wiki/Protocol_Documentation#Setting_LED for more information.
typedef enum {
Expand Down Expand Up @@ -630,7 +636,19 @@ FREENECTAPI int freenect_set_depth_mode(freenect_device* dev, const freenect_fra
* @return 0 on success, < 0 on error
*/
FREENECTAPI int freenect_set_smoothing_mode(freenect_device* dev, const freenect_smoothing_mode mode);


/**
* Set the range mode. The near mode introduced with the Kinect for
* Windows device allows the sensor to see objects closer to it. The
* depth stream must be active as this appears to be reset when it is
* started.
*
* @param mode New range mode
*
* @return 0 on success, < 0 on error
*/
FREENECTAPI int freenect_set_range_mode(freenect_device* dev, const freenect_range_mode mode);

#ifdef __cplusplus
}
#endif
Expand Down
25 changes: 25 additions & 0 deletions src/cameras.c
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,31 @@ int freenect_set_smoothing_mode(freenect_device* dev, const freenect_smoothing_m
}
}

int freenect_set_range_mode(freenect_device* dev, const freenect_range_mode mode)
{
if (dev->hwrev != HWREV_K4W_0)
return -1;

int retval = 0;
switch(mode) {
case FREENECT_RANGE_DEFAULT:
retval = write_register(dev, 0x0015, 0x001E);
if (retval != 0)
return retval;
usleep(100000);
retval = write_register(dev, 0x02EF, 0x0190);
break;
case FREENECT_RANGE_NEAR_MODE:
retval = write_register(dev, 0x0015, 0x0007);
if (retval != 0)
return retval;
usleep(100000);
retval = write_register(dev, 0x02EF, 0x0000);
break;
}
return retval;
}

int freenect_set_depth_buffer(freenect_device *dev, void *buf)
{
return stream_setbuf(dev->parent, &dev->depth, buf);
Expand Down

0 comments on commit 34f4c1a

Please sign in to comment.