Skip to content

Commit

Permalink
Raspicam: Add option to force the sensor mode.
Browse files Browse the repository at this point in the history
Useful in some odd situations to force field of view
or binning modes.
Select with -md or --mode on the command line.
  • Loading branch information
Dave Stevenson committed Sep 19, 2014
1 parent aab4344 commit bd58d9a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
26 changes: 25 additions & 1 deletion host_applications/linux/apps/raspicam/RaspiStill.c
Expand Up @@ -136,6 +136,7 @@ typedef struct
int settings; /// Request settings from the camera
int cameraNum; /// Camera number
int burstCaptureMode; /// Enable burst mode
int sensor_mode; /// Sensor mode. 0=auto. Check docs/forum for modes selected by other values.

RASPIPREVIEW_PARAMETERS preview_parameters; /// Preview setup parameters
RASPICAM_CAMERA_PARAMETERS camera_parameters; /// Camera setup parameters
Expand Down Expand Up @@ -187,6 +188,7 @@ static void store_exif_tag(RASPISTILL_STATE *state, const char *exif_tag);
#define CommandSettings 19
#define CommandCamSelect 20
#define CommandBurstMode 21
#define CommandSensorMode 22

static COMMAND_LIST cmdline_commands[] =
{
Expand All @@ -211,7 +213,8 @@ static COMMAND_LIST cmdline_commands[] =
{ CommandGLCapture, "-glcapture","gc", "Capture the GL frame-buffer instead of the camera image", 0},
{ CommandSettings, "-settings", "set","Retrieve camera settings and write to stdout", 0},
{ CommandCamSelect, "-camselect","cs", "Select camera <number>. Default 0", 1 },
{ CommandBurstMode, "-burst", "bm", "Enable 'burst capture mode'", 0},
{ CommandBurstMode, "-burst", "bm", "Enable 'burst capture mode'", 0},
{ CommandSensorMode,"-mode", "md", "Force sensor mode. 0=auto. See docs for other modes available", 1},
};

static int cmdline_commands_size = sizeof(cmdline_commands) / sizeof(cmdline_commands[0]);
Expand Down Expand Up @@ -290,6 +293,7 @@ static void default_status(RASPISTILL_STATE *state)
state->settings = 0;
state->cameraNum = 0;
state->burstCaptureMode=0;
state->sensor_mode = 0;

// Setup preview window defaults
raspipreview_set_defaults(&state->preview_parameters);
Expand Down Expand Up @@ -622,6 +626,18 @@ static int parse_cmdline(int argc, const char **argv, RASPISTILL_STATE *state)
state->burstCaptureMode=1;
break;

case CommandSensorMode:
{
if (sscanf(argv[i + 1], "%u", &state->sensor_mode) == 1)
{
i++;
}
else
valid = 0;
break;
}


default:
{
// Try parsing for any image specific parameters
Expand Down Expand Up @@ -848,6 +864,14 @@ static MMAL_STATUS_T create_camera_component(RASPISTILL_STATE *state)
goto error;
}

status = mmal_port_parameter_set_uint32(camera->control, MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG, state->sensor_mode);

if (status != MMAL_SUCCESS)
{
vcos_log_error("Could not set sensor mode : error %d", status);
goto error;
}

preview_port = camera->output[MMAL_CAMERA_PREVIEW_PORT];
video_port = camera->output[MMAL_CAMERA_VIDEO_PORT];
still_port = camera->output[MMAL_CAMERA_CAPTURE_PORT];
Expand Down
30 changes: 26 additions & 4 deletions host_applications/linux/apps/raspicam/RaspiVid.c
Expand Up @@ -186,7 +186,7 @@ struct RASPIVID_STATE_S

int cameraNum; /// Camera number
int settings; /// Request settings from the camera

int sensor_mode; /// Sensor mode. 0=auto. Check docs/forum for modes selected by other values.
};


Expand Down Expand Up @@ -239,6 +239,7 @@ static void display_valid_parameters(char *app_name);
#define CommandIMV 23
#define CommandCamSelect 24
#define CommandSettings 25
#define CommandSensorMode 26

static COMMAND_LIST cmdline_commands[] =
{
Expand Down Expand Up @@ -267,7 +268,8 @@ static COMMAND_LIST cmdline_commands[] =
{ CommandCircular, "-circular", "c", "Run encoded data through circular buffer until triggered then save", 0},
{ CommandIMV, "-vectors", "x", "Output filename <filename> for inline motion vectors", 1 },
{ CommandCamSelect, "-camselect", "cs", "Select camera <number>. Default 0", 1 },
{ CommandSettings, "-settings", "set","Retrieve camera settings and write to stdout", 0},
{ CommandSettings, "-settings", "set","Retrieve camera settings and write to stdout", 0},
{ CommandSensorMode, "-mode", "md", "Force sensor mode. 0=auto. See docs for other modes available", 1},
};

static int cmdline_commands_size = sizeof(cmdline_commands) / sizeof(cmdline_commands[0]);
Expand Down Expand Up @@ -335,6 +337,7 @@ static void default_status(RASPIVID_STATE *state)

state->cameraNum = 0;
state->settings = 0;
state->sensor_mode = 0;

// Setup preview window defaults
raspipreview_set_defaults(&state->preview_parameters);
Expand Down Expand Up @@ -675,13 +678,24 @@ static int parse_cmdline(int argc, const char **argv, RASPIVID_STATE *state)
}
else
valid = 0;
break;
}
break;
}

case CommandSettings:
state->settings = 1;
break;

case CommandSensorMode:
{
if (sscanf(argv[i + 1], "%u", &state->sensor_mode) == 1)
{
i++;
}
else
valid = 0;
break;
}

default:
{
// Try parsing for any image specific parameters
Expand Down Expand Up @@ -1115,6 +1129,14 @@ static MMAL_STATUS_T create_camera_component(RASPIVID_STATE *state)
goto error;
}

status = mmal_port_parameter_set_uint32(camera->control, MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG, state->sensor_mode);

if (status != MMAL_SUCCESS)
{
vcos_log_error("Could not set sensor mode : error %d", status);
goto error;
}

preview_port = camera->output[MMAL_CAMERA_PREVIEW_PORT];
video_port = camera->output[MMAL_CAMERA_VIDEO_PORT];
still_port = camera->output[MMAL_CAMERA_CAPTURE_PORT];
Expand Down

0 comments on commit bd58d9a

Please sign in to comment.