Skip to content

Commit

Permalink
Add ability to control IR projector brightness - fixes #433
Browse files Browse the repository at this point in the history
Signed-off-by: Benn Snyder <benn.snyder@gmail.com>
  • Loading branch information
piedar committed Feb 11, 2015
1 parent b2043d0 commit b6c2eb3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
13 changes: 12 additions & 1 deletion examples/glview.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ void keyPressed(unsigned char key, int x, int y)
freenect_set_flag(f_dev, FREENECT_NEAR_MODE, near_mode);
near_mode = near_mode ? FREENECT_OFF : FREENECT_ON;
}

if (key == '+') {
uint16_t brightness = freenect_get_ir_brightness(f_dev) + 2;
freenect_set_ir_brightness(f_dev, brightness);
}
if (key == '-') {
uint16_t brightness = freenect_get_ir_brightness(f_dev) - 2;
freenect_set_ir_brightness(f_dev, brightness);
}

if (key == '1') {
freenect_set_led(f_dev,LED_GREEN);
}
Expand All @@ -259,6 +269,7 @@ void keyPressed(unsigned char key, int x, int y)
if (key == '0') {
freenect_set_led(f_dev,LED_OFF);
}

if (key == 'o') {
if (camera_rotate) {
camera_rotate = 0;
Expand Down Expand Up @@ -420,7 +431,7 @@ void *freenect_threadfunc(void *arg)
freenect_start_depth(f_dev);
freenect_start_video(f_dev);

printf("'w' - tilt up, 's' - level, 'x' - tilt down, '0'-'6' - select LED mode \n");
printf("'w' - tilt up, 's' - level, 'x' - tilt down, '0'-'6' - select LED mode, '+' & '-' - change IR intensity \n");
printf("'f' - change video format, 'm' - mirror video, 'o' - rotate video with accelerometer \n");
printf("'e' - auto exposure, 'b' - white balance, 'r' - raw color, 'n' - near mode (K4W only) \n");

Expand Down
18 changes: 18 additions & 0 deletions include/libfreenect.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,24 @@ FREENECTAPI int freenect_set_depth_mode(freenect_device* dev, const freenect_fra
*/
FREENECTAPI int freenect_set_flag(freenect_device *dev, freenect_flag flag, freenect_flag_value value);

/**
* Returns the brightness of the IR projector
*
* @param dev Device to get IR brightness
*
* @return IR brightness, UINT16_MAX if error
*/
FREENECTAPI uint16_t freenect_get_ir_brightness(freenect_device *dev);

/**
* Sets the brightness of the IR projector
*
* @param dev Device to set IR brightness
* @param brighness Brightness value in range 1 - 50
*
* @return 0 on success, < 0 if error
*/
FREENECTAPI int freenect_set_ir_brightness(freenect_device *dev, uint16_t brightness);

/**
* Allows the user to specify a pointer to the audio firmware in memory for the Xbox 360 Kinect
Expand Down
38 changes: 35 additions & 3 deletions src/flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
#include "flags.h"


// freenect_set_flag is the only function exposed in libfreenect.h
// The rest are available internally via #include flags.h

FN_INTERNAL int register_for_flag(int flag)
{
switch(flag)
Expand Down Expand Up @@ -96,6 +93,41 @@ int freenect_set_flag(freenect_device *dev, freenect_flag flag, freenect_flag_va
return write_cmos_register(dev, 0x0106, cmos_value);
}

uint16_t freenect_get_ir_brightness(freenect_device *dev)
{
freenect_context *ctx = dev->parent;

const uint16_t brightness = read_register(dev, 0x15);
if (brightness == UINT16_MAX)
{
FN_WARNING("Failed to get IR brightness!");
}

return brightness;
}

int freenect_set_ir_brightness(freenect_device *dev, uint16_t brightness)
{
freenect_context *ctx = dev->parent;

if (brightness < 1)
{
brightness = 1;
}
if (brightness > 50)
{
brightness = 50;
}

const int ret = write_register(dev, 0x15, brightness);
if (ret < 0)
{
FN_WARNING("Failed to set IR brightness");
}

return ret;
}

typedef struct {
uint8_t magic[2];
uint16_t len;
Expand Down

2 comments on commit b6c2eb3

@yizziy
Copy link

@yizziy yizziy commented on b6c2eb3 Sep 7, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

freenect_set_ir_brightness does not change the brightness of emitted light. However, it does change the brightness of the detected light ( hardware or software based ).

The current name might lead to the assumption, that the emitted light is changed. This leads to problems when using multiple kinects ( can't set the brightness to zero, in order to reduce noise from other kinects)

@zhumxcq
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the function changes the gain on the IR sensor on hardware and does not change the brightness of the IR projector at all.

Please sign in to comment.