Skip to content

Commit

Permalink
Userland issue raspberrypi#76
Browse files Browse the repository at this point in the history
Added  option to set the exposure/shutter time.

Needs a change on GPU binary, Brcm ref: 425060 and
a consequent change to
userland/interface/mmal/mmal_parameters_camera.h

There is currently a limitation of about 350ms beyond which
the camera will lock (depending on other settings). This
is being investigated, but is unrelated to this change
i.e. You can get the fault in other ways, not just by setting
the shutter speed.
  • Loading branch information
JamesH65 committed Oct 4, 2013
1 parent 77d32cd commit a48694c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 26 additions & 1 deletion host_applications/linux/apps/raspicam/RaspiCamControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ static const int metering_mode_map_size = sizeof(metering_mode_map)/sizeof(meter
#define CommandHFlip 13
#define CommandVFlip 14
#define CommandROI 15
#define CommandShutterSpeed 16

static COMMAND_LIST cmdline_commands[] =
{
Expand All @@ -149,7 +150,8 @@ static COMMAND_LIST cmdline_commands[] =
{CommandRotation, "-rotation", "rot","Set image rotation (0-359)", 1},
{CommandHFlip, "-hflip", "hf", "Set horizontal flip", 0},
{CommandVFlip, "-vflip", "vf", "Set vertical flip", 0},
{CommandROI, "-roi", "roi","Set region of interest (x,y,w,d as normalised coordinates [0.0-1.0])", 1}
{CommandROI, "-roi", "roi","Set region of interest (x,y,w,d as normalised coordinates [0.0-1.0])", 1},
{CommandShutterSpeed,"-shutter", "ss", "Set shutter speed in microseconds", 1}
};

static int cmdline_commands_size = sizeof(cmdline_commands) / sizeof(cmdline_commands[0]);
Expand Down Expand Up @@ -573,6 +575,12 @@ int raspicamcontrol_parse_cmdline(RASPICAM_CAMERA_PARAMETERS *params, const char
break;
}

case CommandShutterSpeed : // Shutter speed needs single number parameter
sscanf(arg2, "%d", &params->shutter_speed);
used = 2;
break;


}

return used;
Expand Down Expand Up @@ -704,6 +712,7 @@ void raspicamcontrol_set_defaults(RASPICAM_CAMERA_PARAMETERS *params)
params->hflip = params->vflip = 0;
params->roi.x = params->roi.y = 0.0;
params->roi.w = params->roi.h = 1.0;
params->shutter_speed = 0; // 0 = auto
}

/**
Expand Down Expand Up @@ -763,6 +772,7 @@ int raspicamcontrol_set_all_parameters(MMAL_COMPONENT_T *camera, const RASPICAM_
result += raspicamcontrol_set_rotation(camera, params->rotation);
result += raspicamcontrol_set_flips(camera, params->hflip, params->vflip);
result += raspicamcontrol_set_ROI(camera, params->roi);
result += raspicamcontrol_set_shutter_speed(camera, params->shutter_speed);

return result;
}
Expand Down Expand Up @@ -1125,6 +1135,21 @@ int raspicamcontrol_set_ROI(MMAL_COMPONENT_T *camera, PARAM_FLOAT_RECT_T rect)
return mmal_port_parameter_set(camera->control, &crop.hdr);
}

/**
* Adjust the exposure time used for images
* @param camera Pointer to camera component
* @param shutter speed in microseconds
* @return 0 if successful, non-zero if any parameters out of range
*/
int raspicamcontrol_set_shutter_speed(MMAL_COMPONENT_T *camera, int speed)
{
if (!camera)
return 1;

return mmal_status_to_int(mmal_port_parameter_set_uint32(camera->control, MMAL_PARAMETER_SHUTTER_SPEED, speed));
}



/**
* Asked GPU how much memory it has allocated
Expand Down
2 changes: 2 additions & 0 deletions host_applications/linux/apps/raspicam/RaspiCamControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ typedef struct
int hflip; /// 0 or 1
int vflip; /// 0 or 1
PARAM_FLOAT_RECT_T roi; /// region of interest to use on the sensor. Normalised [0,1] values in the rect
int shutter_speed; /// 0 = auto, otherwise the shutter speed in ms
} RASPICAM_CAMERA_PARAMETERS;


Expand Down Expand Up @@ -162,6 +163,7 @@ int raspicamcontrol_set_colourFX(MMAL_COMPONENT_T *camera, const MMAL_PARAM_COLO
int raspicamcontrol_set_rotation(MMAL_COMPONENT_T *camera, int rotation);
int raspicamcontrol_set_flips(MMAL_COMPONENT_T *camera, int hflip, int vflip);
int raspicamcontrol_set_ROI(MMAL_COMPONENT_T *camera, PARAM_FLOAT_RECT_T rect);
int raspicamcontrol_set_shutter_speed(MMAL_COMPONENT_T *camera, int speed_ms);

//Individual getting functions
int raspicamcontrol_get_saturation(MMAL_COMPONENT_T *camera);
Expand Down

0 comments on commit a48694c

Please sign in to comment.