From 5ccdcb53a36ed95f08a99863164dc2151e47c2af Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Tue, 12 Apr 2011 21:18:13 +0200 Subject: Allow access to implementation context and provide call to set size of internal buffer for IPECamera --- error.h | 1 + ipecamera/image.c | 28 ++++++++++++++++++++++++++++ ipecamera/image.h | 2 -- ipecamera/ipecamera.h | 5 +++++ pci.c | 3 +++ pcilib.h | 1 + 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/error.h b/error.h index bf78a8a..fcdbe68 100644 --- a/error.h +++ b/error.h @@ -4,6 +4,7 @@ enum { PCILIB_ERROR_SUCCESS = 0, PCILIB_ERROR_MEMORY, + PCILIB_ERROR_INVALID_REQUEST, PCILIB_ERROR_INVALID_ADDRESS, PCILIB_ERROR_INVALID_BANK, PCILIB_ERROR_INVALID_DATA, diff --git a/ipecamera/image.c b/ipecamera/image.c index 8899627..969071d 100644 --- a/ipecamera/image.c +++ b/ipecamera/image.c @@ -38,6 +38,7 @@ struct ipecamera_s { pcilib_register_t n_lines_reg, line_reg; pcilib_register_t exposure_reg; + int started; int buffer_size; int buf_ptr; @@ -140,6 +141,23 @@ void ipecamera_free(void *vctx) { } } +int ipecamera_set_buffer_size(ipecamera_t *ctx, int size) { + if (ctx->started) { + pcilib_error("Can't change buffer size while grabbing"); + return PCILIB_ERROR_INVALID_REQUEST; + } + + if (ctx->size < 1) { + pcilib_error("The buffer size is too small"); + return PCILIB_ERROR_INVALID_REQUEST; + } + + ctx->buffer_size = size; + + return 0; +} + + int ipecamera_reset(void *vctx) { int err; pcilib_t *pcilib; @@ -222,6 +240,11 @@ int ipecamera_start(void *vctx, pcilib_event_t event_mask, pcilib_callback_t cb, return PCILIB_ERROR_NOTINITIALIZED; } + if (ctx->started) { + pcilib_error("IPECamera grabbing is already started"); + return PCILIB_ERROR_INVALID_REQUEST; + } + ctx->cb = cb; ctx->cb_user = user; @@ -429,6 +452,11 @@ int ipecamera_trigger(void *vctx, pcilib_event_t event, size_t trigger_size, voi pcilib_error("IPECamera imaging is not initialized"); return PCILIB_ERROR_NOTINITIALIZED; } + + if (!ctx->started) { + pcilib_error("Can't trigger while not grabbing is not started"); + return PCILIB_ERROR_INVALID_REQUEST; + } err = ipecamera_get_image(ctx); if (!err) err = ctx->cb(event, ctx->event_id, ctx->cb_user); diff --git a/ipecamera/image.h b/ipecamera/image.h index ede964c..6b92524 100644 --- a/ipecamera/image.h +++ b/ipecamera/image.h @@ -6,8 +6,6 @@ #include "ipecamera.h" #include "pcilib.h" -typedef struct ipecamera_s ipecamera_t; - void *ipecamera_init(pcilib_t *pcilib); void ipecamera_free(void *ctx); diff --git a/ipecamera/ipecamera.h b/ipecamera/ipecamera.h index d54dda2..49afe0c 100644 --- a/ipecamera/ipecamera.h +++ b/ipecamera/ipecamera.h @@ -1,6 +1,8 @@ #ifndef _IPECAMERA_H #define _IPECAMERA_H +typedef struct ipecamera_s ipecamera_t; + typedef struct { int bpp; /*<< Bits per pixel (8, 16, or 32) as returned by IPECAMERA_IMAGE_DATA */ int real_bpp; /*<< Bits per pixel as returned by camera and IPECAMERA_PACKED_IMAGE */ @@ -20,4 +22,7 @@ typedef enum { typedef uint16_t ipecamera_change_mask_t; typedef uint16_t ipecamera_pixel_t; + +int ipecamera_set_buffer_size(ipecamera_t *ctx, int size); + #endif /* _IPECAMERA_H */ diff --git a/pci.c b/pci.c index 0e81992..5fae55c 100644 --- a/pci.c +++ b/pci.c @@ -98,6 +98,9 @@ const pci_board_info *pcilib_get_board_info(pcilib_t *ctx) { return &ctx->board_info; } +void *pcilib_get_implementation_context(pcilib_t *ctx) { + return ctx->event_ctx; +} pcilib_model_t pcilib_get_model(pcilib_t *ctx) { if (ctx->model == PCILIB_MODEL_DETECT) { diff --git a/pcilib.h b/pcilib.h index 7542131..cde33d3 100644 --- a/pcilib.h +++ b/pcilib.h @@ -155,6 +155,7 @@ extern pcilib_model_description_t pcilib_model[]; int pcilib_set_error_handler(void (*err)(const char *msg, ...), void (*warn)(const char *msg, ...)); pcilib_model_t pcilib_get_model(pcilib_t *ctx); +void *pcilib_get_implementation_context(pcilib_t *ctx); pcilib_t *pcilib_open(const char *device, pcilib_model_t model); void pcilib_close(pcilib_t *ctx); -- cgit v1.2.3