diff options
author | Matthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de> | 2011-02-23 09:24:44 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de> | 2011-02-23 09:24:44 +0100 |
commit | d69b1e834cc1558ff117688da7030dabd22099fa (patch) | |
tree | f2020a161aefc73b789386a1c38e5a260b600ee6 | |
parent | 29aec734715f7c4d6b8157ac514eff4fd8dd0242 (diff) | |
download | uca-d69b1e834cc1558ff117688da7030dabd22099fa.tar.gz uca-d69b1e834cc1558ff117688da7030dabd22099fa.tar.bz2 uca-d69b1e834cc1558ff117688da7030dabd22099fa.tar.xz uca-d69b1e834cc1558ff117688da7030dabd22099fa.zip |
Do something meaningful and check for frame grabber library
-rw-r--r-- | src/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/cameras/uca_pco.c | 82 | ||||
-rw-r--r-- | src/cameras/uca_pco.h | 2 | ||||
-rw-r--r-- | src/uca.c | 8 | ||||
-rw-r--r-- | src/uca.h | 35 | ||||
-rw-r--r-- | test/test.c | 7 |
6 files changed, 124 insertions, 15 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dde0a01..2167d7c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,10 +15,11 @@ set(uca_LIBS "") set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) find_package(PCO) +find_package(FgLib5) find_package(ClSerMe4) # --- Add sources if camera access sources are available ---------------------- -if(PCO_FOUND AND CLSERME4_FOUND) +if(PCO_FOUND AND CLSERME4_FOUND AND FGLIB5_FOUND) set(HAVE_PCO_EDGE TRUE) set(uca_SRCS @@ -29,12 +30,14 @@ if(PCO_FOUND AND CLSERME4_FOUND) set(uca_LIBS ${uca_LIBS} ${CLSERME4_LIBRARY} + ${FGLIB5_LIBRARY} ${PCO_LIBRARIES} ) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CLSERME4_INCLUDE_DIR} + ${FGLIB5_INCLUDE_DIR} ${PCO_INCLUDE_DIRS} ) endif() diff --git a/src/cameras/uca_pco.c b/src/cameras/uca_pco.c index 0359990..fd63139 100644 --- a/src/cameras/uca_pco.c +++ b/src/cameras/uca_pco.c @@ -1,30 +1,96 @@ +#include <stdlib.h> #include <clser.h> +#include <fgrab_struct.h> +#include <fgrab_prototyp.h> #include <libpco/libpco.h> #include "uca.h" #include "uca_pco.h" -struct pco_edge_t *pco; +struct pco_cam_t { + struct pco_edge_t *pco; + Fg_Struct *fg; +}; -static void uca_pco_destroy(struct uca_t *uca) +#define GET_PCO(uca) (((struct pco_cam_t *)(uca->user))->pco) +#define GET_FG(uca) (((struct pco_cam_t *)(uca->user))->fg) + + +static uint32_t uca_pco_set_dimensions(struct uca_t *uca, uint32_t *width, uint32_t *height) +{ + Fg_Struct *fg = GET_FG(uca); + Fg_setParameter(fg, FG_WIDTH, width, PORT_A); + Fg_setParameter(fg, FG_HEIGHT, height, PORT_A); + return 0; +} + +static uint32_t uca_pco_set_bitdepth(struct uca_t *uca, uint8_t *bitdepth) +{ + /* TODO: it's not possible via CameraLink so do it via frame grabber */ + return 0; +} + +static uint32_t uca_pco_set_exposure(struct uca_t *uca, uint32_t *exposure) +{ + uint32_t e, d; + pco_get_delay_exposure(GET_PCO(uca), &d, &e); + pco_set_delay_exposure(GET_PCO(uca), d, *exposure); + return 0; +} + +static uint32_t uca_pco_set_delay(struct uca_t *uca, uint32_t *delay) { - pco_destroy(pco); + uint32_t e, d; + pco_get_delay_exposure(GET_PCO(uca), &d, &e); + pco_set_delay_exposure(GET_PCO(uca), *delay, e); + return 0; } -int uca_pco_init(struct uca_t *uca) +static uint32_t uca_pco_acquire_image(struct uca_t *uca, void *buffer) { - pco = pco_init(); - if (!pco_active(pco)) { + return 0; +} + +static uint32_t uca_pco_destroy(struct uca_t *uca) +{ + Fg_FreeGrabber(GET_FG(uca)); + pco_destroy(GET_PCO(uca)); + free(uca->user); +} + +uint32_t uca_pco_init(struct uca_t *uca) +{ + uca->user = (struct pco_cam_t *) malloc(sizeof(struct pco_cam_t)); + + + struct pco_cam_t *pco_cam = uca->user; + struct pco_edge_t *pco = pco_cam->pco = pco_init(); + + if ((pco->serial_ref == NULL) || !pco_active(pco)) { pco_destroy(pco); - return 0; + return UCA_ERR_INIT_NOT_FOUND; } + pco_cam->fg = Fg_Init("libFullAreaGray8.so", 0); + pco_scan_and_set_baud_rate(pco); /* Camera found, set function pointers... */ uca->cam_destroy = &uca_pco_destroy; + uca->cam_set_dimensions = &uca_pco_set_dimensions; + uca->cam_set_bitdepth = &uca_pco_set_bitdepth; + uca->cam_set_exposure = &uca_pco_set_exposure; + uca->cam_set_delay = &uca_pco_set_delay; + uca->cam_acquire_image = &uca_pco_acquire_image; /* ... and some properties */ pco_get_actual_size(pco, &uca->image_width, &uca->image_height); - return 1; + + /* Prepare camera for recording. */ + pco_set_rec_state(pco, 0); + pco_set_timestamp_mode(pco, 2); + pco_set_timebase(pco, 1, 1); + pco_arm_camera(pco); + + return 0; } diff --git a/src/cameras/uca_pco.h b/src/cameras/uca_pco.h index f2e7174..07c3ef2 100644 --- a/src/cameras/uca_pco.h +++ b/src/cameras/uca_pco.h @@ -3,6 +3,6 @@ struct uca_t; -int uca_pco_init(struct uca_t *uca); +uint32_t uca_pco_init(struct uca_t *uca); #endif @@ -33,7 +33,7 @@ struct uca_t *uca_init() int i = 0; while (inits[i] != NULL) { uca_cam_init init = inits[i]; - if (init(uca)) + if (init(uca) != UCA_ERR_INIT_NOT_FOUND) return uca; i++; } @@ -45,6 +45,8 @@ struct uca_t *uca_init() void uca_destroy(struct uca_t *uca) { - uca->cam_destroy(uca); - free(uca); + if (uca != NULL) { + uca->cam_destroy(uca); + free(uca); + } } @@ -1,15 +1,36 @@ #ifndef __UNIFIED_CAMERA_ACCESS_H #define __UNIFIED_CAMERA_ACCESS_H +#include <stdint.h> + struct uca_t; /* * \brief Camera probing and initialization * \return 0 if camera is not found or could not be initialized */ -typedef int (*uca_cam_init) (struct uca_t *uca); +typedef uint32_t (*uca_cam_init) (struct uca_t *uca); + +typedef uint32_t (*uca_cam_destroy) (struct uca_t *uca); + +typedef uint32_t (*uca_cam_set_dimensions) (struct uca_t *uca, uint32_t *width, uint32_t *height); + +typedef uint32_t (*uca_cam_set_bitdepth) (struct uca_t *uca, uint8_t *bitdepth); + +typedef uint32_t (*uca_cam_set_exposure) (struct uca_t *uca, uint32_t *exposure); + +typedef uint32_t (*uca_cam_set_delay) (struct uca_t *uca, uint32_t *delay); + +typedef uint32_t (*uca_cam_acquire_image) (struct uca_t *uca, void *buffer); + + + +#define UCA_ERR_INIT_NOT_FOUND 1 /**< camera probing failed */ + +#define UCA_ERR_DIMENSION_NOT_SUPPORTED 1 + +#define UCA_ERR_BITDEPTH_NOT_SUPPORTED 1 -typedef void (*uca_cam_destroy) (struct uca_t *uca); #define UCA_BIG_ENDIAN 1 #define UCA_LITTLE_ENDIAN 2 @@ -22,7 +43,17 @@ struct uca_t { unsigned int image_flags; /* Function pointers to camera-specific methods */ + uca_cam_set_dimensions cam_set_dimensions; + uca_cam_set_bitdepth cam_set_bitdepth; + uca_cam_set_exposure cam_set_exposure; + uca_cam_set_delay cam_set_delay; + + uca_cam_acquire_image cam_acquire_image; + + /* Private */ uca_cam_destroy cam_destroy; + + void *user; /**< private user data to be used by the camera driver */ }; struct uca_t *uca_init(); diff --git a/test/test.c b/test/test.c index a1689ef..7e29a88 100644 --- a/test/test.c +++ b/test/test.c @@ -7,6 +7,13 @@ int main(int argc, char *argv[]) struct uca_t *uca = uca_init(); if (uca == NULL) { printf("Couldn't find a camera\n"); + return 1; } + + uint32_t width = 2560, height = 2160; + + uca->cam_set_dimensions(uca, &width, &height); + + uca_destroy(uca); return 0; } |