Commit 407a5483 authored by Éric Thiébaut's avatar Éric Thiébaut
Browse files

Rename dev to fcam

parent 551ef720
......@@ -30,7 +30,7 @@ tao_mutex mutex = TAO_MUTEX_INITIALIZER;
// Retrieve list of connected devices. Caller must have locked the resource.
static tao_status update_device_list();
// A handle fo a camera (see <libfipro.h>).
// A handle fo a camera (see <libflipro.h>).
typedef int32_t flipro_handle;
// Number of acquisition buffers.
......@@ -62,32 +62,32 @@ static void flipro_error(const char* func, int code);
// Update exposure time and frame rate from current settings.
static tao_status update_exposure(
flipro_camera* dev);
flipro_camera* fcam);
// Set the exposure time (in seconds) and the frame rate (in frames per
// second).
static tao_status set_exposure(
flipro_camera* dev,
flipro_camera* fcam,
double exposuretime,
double framerate);
// Update the pixel binning from current settings.
static tao_status update_binning(
flipro_camera* dev);
flipro_camera* fcam);
// Set the pixel binning to given settings.
static tao_status set_binning(
flipro_camera* dev,
flipro_camera* fcam,
long xbin,
long ybin);
// Update the image area from current settings.
static tao_status update_image_area(
flipro_camera* dev);
flipro_camera* fcam);
// Set the the image area to given settings.
static tao_status set_image_area(
flipro_camera* dev,
flipro_camera* fcam,
long xoff,
long yoff,
long width,
......@@ -95,7 +95,7 @@ static tao_status set_image_area(
// Free all acquisition buffers.
static void free_buffers(
flipro_camera* dev);
flipro_camera* fcam);
//-----------------------------------------------------------------------------
// Declaration of private methods and of the table grouping these methods for
......@@ -197,21 +197,21 @@ static tao_status on_initialize(
tao_camera* cam)
{
// The camera is a FLIPRO camera.
flipro_camera* dev = (flipro_camera*)cam;
flipro_camera* fcam = (flipro_camera*)cam;
// The contextual data is the device information.
FPRODEVICEINFO* devinfo = cam->ctx;
// No acquisition buffers yet.
dev->bufsiz = 0;
fcam->bufsiz = 0;
for (int i = 0; i < NBUFS; ++i) {
dev->bufs[i] = NULL;
fcam->bufs[i] = NULL;
}
// Open the camera.
dev->handle = -1;
FLIPRO_CALL(FPROCam_Open,(devinfo, &dev->handle), return TAO_ERROR);
if (dev->handle < 0) {
fcam->handle = -1;
FLIPRO_CALL(FPROCam_Open,(devinfo, &fcam->handle), return TAO_ERROR);
if (fcam->handle < 0) {
tao_store_error(__func__, TAO_BAD_DEVICE);
return TAO_ERROR;
}
......@@ -219,7 +219,7 @@ static tao_status on_initialize(
// Retrieve camera capabilities.
FPROCAP cap;
uint32_t size = sizeof(cap);
FLIPRO_CALL(FPROSensor_GetCapabilities,(dev->handle, &cap, &size),
FLIPRO_CALL(FPROSensor_GetCapabilities,(fcam->handle, &cap, &size),
return TAO_ERROR);
cam->info.sensorwidth = cap.uiMaxPixelImageWidth;
......@@ -231,15 +231,15 @@ static tao_status on_finalize(
tao_camera* cam)
{
// The camera is a FLIPRO camera.
flipro_camera* dev = (flipro_camera*)cam;
flipro_camera* fcam = (flipro_camera*)cam;
// Free all acquisition buffers.
free_buffers(dev);
free_buffers(fcam);
// Close the device.
if (dev->handle >= 0) {
flipro_handle handle = dev->handle;
dev->handle = -1; // never close more than once
if (fcam->handle >= 0) {
flipro_handle handle = fcam->handle;
fcam->handle = -1; // never close more than once
FLIPRO_CALL(FPROCam_Close,(handle), return TAO_ERROR);
}
return TAO_OK;
......@@ -256,11 +256,11 @@ static tao_status on_update_config(
tao_camera* cam)
{
// The camera is a FLIPRO camera.
flipro_camera* dev = (flipro_camera*)cam;
flipro_camera* fcam = (flipro_camera*)cam;
if (update_binning(dev) != TAO_OK ||
update_image_area(dev) != TAO_OK ||
update_exposure(dev) != TAO_OK) {
if (update_binning(fcam) != TAO_OK ||
update_image_area(fcam) != TAO_OK ||
update_exposure(fcam) != TAO_OK) {
return TAO_ERROR;
}
return TAO_OK;
......@@ -311,7 +311,7 @@ static tao_status on_set_config(
const tao_camera_config* cfg)
{
// The camera is a FLIPRO camera.
flipro_camera* dev = (flipro_camera*)cam;
flipro_camera* fcam = (flipro_camera*)cam;
// Do we need to change the frame rate?
bool reduce_fps = (cfg->framerate < cam->info.config.framerate);
......@@ -320,7 +320,7 @@ static tao_status on_set_config(
// Reduce frame rate if possible before changing ROI.
if (reduce_fps) {
if (set_exposure(dev, cfg->exposuretime, cfg->framerate) != TAO_OK) {
if (set_exposure(fcam, cfg->exposuretime, cfg->framerate) != TAO_OK) {
return TAO_ERROR;
}
change_exposure = false;
......@@ -329,7 +329,7 @@ static tao_status on_set_config(
// Set binning.
if (cfg->roi.xbin != cam->info.config.roi.xbin ||
cfg->roi.ybin != cam->info.config.roi.ybin) {
if (set_binning(dev, cfg->roi.xbin, cfg->roi.ybin) != TAO_OK) {
if (set_binning(fcam, cfg->roi.xbin, cfg->roi.ybin) != TAO_OK) {
return TAO_ERROR;
}
}
......@@ -339,7 +339,7 @@ static tao_status on_set_config(
cfg->roi.yoff != cam->info.config.roi.yoff ||
cfg->roi.width != cam->info.config.roi.width ||
cfg->roi.height != cam->info.config.roi.height) {
if (set_image_area(dev, cfg->roi.xoff, cfg->roi.yoff,
if (set_image_area(fcam, cfg->roi.xoff, cfg->roi.yoff,
cfg->roi.width, cfg->roi.height) != TAO_OK) {
return TAO_ERROR;
}
......@@ -347,7 +347,7 @@ static tao_status on_set_config(
// Augment frame rate after changing image area.
if (augment_fps || change_exposure) {
if (set_exposure(dev, cfg->exposuretime, cfg->framerate) != TAO_OK) {
if (set_exposure(fcam, cfg->exposuretime, cfg->framerate) != TAO_OK) {
return TAO_ERROR;
}
}
......@@ -358,33 +358,33 @@ static tao_status on_start(
tao_camera* cam)
{
// The camera is a FLIPRO camera.
flipro_camera* dev = (flipro_camera*)cam;
flipro_camera* fcam = (flipro_camera*)cam;
// Compute image size in bytes.
int size = FPROFrame_ComputeFrameSize(dev->handle);
int size = FPROFrame_ComputeFrameSize(fcam->handle);
if (size < 0) {
flipro_error("FPROFrame_ComputeFrameSize", size);
return TAO_ERROR;
}
// Allocates acquisition buffers.
if (size != dev->bufsiz) {
if (size != fcam->bufsiz) {
// Free all acquisition buffers.
free_buffers(dev);
dev->bufsiz = size;
free_buffers(fcam);
fcam->bufsiz = size;
}
for (int i = 0; i < NBUFS; ++i) {
if (dev->bufs[i] == NULL) {
dev->bufs[i] = tao_malloc(size);
if (dev->bufs[i] == NULL) {
if (fcam->bufs[i] == NULL) {
fcam->bufs[i] = tao_malloc(size);
if (fcam->bufs[i] == NULL) {
return TAO_ERROR;
}
}
}
dev->lastbuf = NBUFS - 1;
fcam->lastbuf = NBUFS - 1;
// Start image capture.
FLIPRO_CALL(FPROFrame_CaptureStart,(dev->handle, 0), return TAO_ERROR);
FLIPRO_CALL(FPROFrame_CaptureStart,(fcam->handle, 0), return TAO_ERROR);
return TAO_OK;
}
......@@ -392,10 +392,10 @@ static tao_status on_stop(
tao_camera* cam)
{
// The camera is a FLIPRO camera.
flipro_camera* dev = (flipro_camera*)cam;
flipro_camera* fcam = (flipro_camera*)cam;
// Start image capture.
FLIPRO_CALL(FPROFrame_CaptureStop,(dev->handle), return TAO_ERROR);
FLIPRO_CALL(FPROFrame_CaptureStop,(fcam->handle), return TAO_ERROR);
return TAO_OK;
}
......@@ -434,31 +434,31 @@ static tao_status update_device_list()
#define NANOSECONDS_PER_SECOND 1e9
static void store_exposure(
flipro_camera* dev,
flipro_camera* fcam,
uint64_t exposuretime_ns,
uint64_t framedelay_ns)
{
dev->base.info.config.exposuretime =
fcam->base.info.config.exposuretime =
exposuretime_ns/NANOSECONDS_PER_SECOND;
dev->base.info.config.framerate =
fcam->base.info.config.framerate =
NANOSECONDS_PER_SECOND/(exposuretime_ns
+ framedelay_ns);
}
// Update exposure time and frame rate from current settings.
static tao_status update_exposure(
flipro_camera* dev)
flipro_camera* fcam)
{
uint64_t exposuretime_ns, framedelay_ns;
bool immediate;
for (int pass = 1; pass <= 2; ++pass) {
FLIPRO_CALL(FPROCtrl_GetExposure,(dev->handle, &exposuretime_ns,
FLIPRO_CALL(FPROCtrl_GetExposure,(fcam->handle, &exposuretime_ns,
&framedelay_ns, &immediate),
return TAO_ERROR);
if (pass == 2 || !immediate) {
break;
}
FLIPRO_CALL(FPROCtrl_SetExposure,(dev->handle, exposuretime_ns,
FLIPRO_CALL(FPROCtrl_SetExposure,(fcam->handle, exposuretime_ns,
framedelay_ns, false),
return TAO_ERROR);
}
......@@ -466,14 +466,14 @@ static tao_status update_exposure(
fputs("Warning: Failed to set `immediate` to `false` in "
"FPROCtrl_SetExposure.\n", stderr);
}
store_exposure(dev, exposuretime_ns, framedelay_ns);
store_exposure(fcam, exposuretime_ns, framedelay_ns);
return TAO_OK;
}
// Set the exposure time (in seconds) and the frame rate (in frames per
// second).
static tao_status set_exposure(
flipro_camera* dev,
flipro_camera* fcam,
double exposuretime,
double framerate)
{
......@@ -484,73 +484,74 @@ static tao_status set_exposure(
uint64_t actual_exposuretime_ns;
uint64_t actual_framedelay_ns;
FLIPRO_CALL(FPROCtrl_SetExposureEx,
(dev->handle, exposuretime_ns, framedelay_ns, false,
(fcam->handle, exposuretime_ns, framedelay_ns, false,
&actual_exposuretime_ns, &actual_framedelay_ns),
return TAO_ERROR);
store_exposure(dev, actual_exposuretime_ns, actual_framedelay_ns);
store_exposure(fcam, actual_exposuretime_ns, actual_framedelay_ns);
return TAO_OK;
}
// Update the pixel binning from current settings.
static tao_status update_binning(
flipro_camera* dev)
flipro_camera* fcam)
{
uint32_t xbin, ybin;
FLIPRO_CALL(FPROSensor_GetBinning,(dev->handle, &xbin, &ybin),
FLIPRO_CALL(FPROSensor_GetBinning,(fcam->handle, &xbin, &ybin),
return TAO_ERROR);
dev->base.info.config.roi.xbin = xbin;
dev->base.info.config.roi.ybin = ybin;
fcam->base.info.config.roi.xbin = xbin;
fcam->base.info.config.roi.ybin = ybin;
return TAO_OK;
}
// Set the pixel binning to given current settings.
static tao_status set_binning(
flipro_camera* dev,
flipro_camera* fcam,
long xbin,
long ybin)
{
FLIPRO_CALL(FPROSensor_SetBinning,(dev->handle, xbin, ybin),
FLIPRO_CALL(FPROSensor_SetBinning,(fcam->handle, xbin, ybin),
return TAO_ERROR);
return update_binning(dev);
return update_binning(fcam);
}
// Update the image area from current settings.
static tao_status update_image_area(
flipro_camera* dev)
flipro_camera* fcam)
{
uint32_t xoff, yoff, width, height;
FLIPRO_CALL(FPROFrame_GetImageArea,
(dev->handle, &xoff, &yoff, &width, &height), return TAO_ERROR);
dev->base.info.config.roi.xoff = xoff;
dev->base.info.config.roi.yoff = yoff;
dev->base.info.config.roi.width = width;
dev->base.info.config.roi.height = height;
(fcam->handle, &xoff, &yoff, &width, &height),
return TAO_ERROR);
fcam->base.info.config.roi.xoff = xoff;
fcam->base.info.config.roi.yoff = yoff;
fcam->base.info.config.roi.width = width;
fcam->base.info.config.roi.height = height;
return TAO_OK;
}
// Set the image area to given current settings.
static tao_status set_image_area(
flipro_camera* dev,
flipro_camera* fcam,
long xoff,
long yoff,
long width,
long height)
{
FLIPRO_CALL(FPROFrame_SetImageArea,
(dev->handle, xoff, yoff, width, height), return TAO_ERROR);
return update_image_area(dev);
(fcam->handle, xoff, yoff, width, height), return TAO_ERROR);
return update_image_area(fcam);
}
// Free all acquisition buffers.
static void free_buffers(
flipro_camera* dev)
flipro_camera* fcam)
{
for (int i = 0; i < NBUFS; ++i) {
void* buf = dev->bufs[i];
dev->bufs[i] = NULL;
void* buf = fcam->bufs[i];
fcam->bufs[i] = NULL;
free(buf);
}
dev->bufsiz = 0;
fcam->bufsiz = 0;
}
//-----------------------------------------------------------------------------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment