From 28619821bc90ed4c15844b2e6b6a5a2971ef5f2e Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Mon, 21 Feb 2011 15:06:42 +0100 Subject: Initial commit --- src/CMakeLists.txt | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/cameras/uca_pco.c | 30 ++++++++++++++++++++++++++++++ src/cameras/uca_pco.h | 8 ++++++++ src/config.h.in | 4 ++++ src/uca.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/uca.h | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 172 insertions(+) create mode 100644 src/CMakeLists.txt create mode 100644 src/cameras/uca_pco.c create mode 100644 src/cameras/uca_pco.h create mode 100644 src/config.h.in create mode 100644 src/uca.c create mode 100644 src/uca.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..0d6ce94 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,49 @@ +cmake_minimum_required(VERSION 2.8) + +# --- Set sources ------------------------------------------------------------- +set(uca_SRCS + uca.c + ) + +set(uca_HDRS + uca.h + ) + +set(uca_LIBS "") + +# --- Find packages and libraries --------------------------------------------- +set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) + +find_package(PCO) +find_package(ClSerMe4) + +# --- Add sources if camera access sources are available ---------------------- +if(PCO_FOUND AND CLSERME4_FOUND) + set(HAVE_PCO_EDGE TRUE) + + set(uca_SRCS + ${uca_SRCS} + cameras/uca_pco.c + ) + + set(uca_LIBS + ${uca_LIBS} + ${CLSERME4_LIBRARY} + ${PCO_LIBRARIES} + ) + + include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${CLSERME4_INCLUDE_DIR} + ${PCO_INCLUDE_DIRS} + ) +endif() + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/config.h) + + +# --- Build target ------------------------------------------------------------ +add_library(uca SHARED ${uca_SRCS}) + +target_link_libraries(uca ${uca_LIBS}) diff --git a/src/cameras/uca_pco.c b/src/cameras/uca_pco.c new file mode 100644 index 0000000..daba6f6 --- /dev/null +++ b/src/cameras/uca_pco.c @@ -0,0 +1,30 @@ + +#include +#include +#include "uca.h" +#include "uca_pco.h" + +struct pco_edge_t *pco; + +static void uca_pco_destroy(struct uca_t *uca) +{ + pco_destroy(pco); +} + +uint8_t uca_pco_init(struct uca_t *uca) +{ + pco = pco_init(); + if (!pco_active(pco)) { + pco_destroy(pco); + return 0; + } + + pco_scan_and_set_baud_rate(pco); + + /* Camera found, set function pointers... */ + uca->cam_destroy = &uca_pco_destroy; + + /* ... and some properties */ + pco_get_actual_size(pco, &uca->image_width, &uca->image_height); + return 1; +} diff --git a/src/cameras/uca_pco.h b/src/cameras/uca_pco.h new file mode 100644 index 0000000..c314ffe --- /dev/null +++ b/src/cameras/uca_pco.h @@ -0,0 +1,8 @@ +#ifndef __UNIFIED_CAMERA_ACCESS_PCO_H +#define __UNIFIED_CAMERA_ACCESS_PCO_H + +struct uca_t; + +uint8_t uca_pco_init(struct uca_t *uca); + +#endif diff --git a/src/config.h.in b/src/config.h.in new file mode 100644 index 0000000..2a4abbb --- /dev/null +++ b/src/config.h.in @@ -0,0 +1,4 @@ + +#cmakedefine HAVE_PCO_EDGE +#cmakedefine HAVE_PHOTON_FOCUS +#cmakedefine HAVE_IPE_CAMERA diff --git a/src/uca.c b/src/uca.c new file mode 100644 index 0000000..7889fe2 --- /dev/null +++ b/src/uca.c @@ -0,0 +1,49 @@ +#include + +#include "uca.h" + +#ifdef HAVE_PCO_EDGE +#include "cameras/uca_pco.h" +#endif + +#ifdef HAVE_PHOTON_FOCUS +#include "cameras/uca_pf.h" +#endif + +#ifdef HAVE_IPE_CAM +#include "cameras/uca_ipe.h" +#endif + + +struct uca_t *uca_init() +{ + struct uca_t *uca = (struct uca_t *) malloc(sizeof(struct uca_t)); + + uca_cam_init inits[] = { +#ifdef HAVE_PCO_EDGE + uca_pco_init, +#elif HAVE_PHOTON_FOCUS + uca_pf_init, +#elif HAVE_IPE_CAM + uca_ipe_init, +#endif + NULL }; + + int i = 0; + while (inits[i] != NULL) { + uca_cam_init init = inits[i]; + if (init(uca)) + return uca; + i++; + } + + /* No camera found then return nothing */ + free(uca); + return NULL; +} + +void uca_destroy(struct uca_t *uca) +{ + uca->cam_destroy(uca); + free(uca); +} diff --git a/src/uca.h b/src/uca.h new file mode 100644 index 0000000..2f93093 --- /dev/null +++ b/src/uca.h @@ -0,0 +1,32 @@ +#ifndef __UNIFIED_CAMERA_ACCESS_H +#define __UNIFIED_CAMERA_ACCESS_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 void (*uca_cam_destroy) (struct uca_t *uca); + +#define UCA_BIG_ENDIAN 1 +#define UCA_LITTLE_ENDIAN 2 + +struct uca_t { + /* These must be written by uca_cam_init() */ + unsigned int image_width; + unsigned int image_height; + unsigned int image_bitdepth; + unsigned int image_flags; + + /* Function pointers to camera-specific methods */ + uca_cam_destroy cam_destroy; +}; + +struct uca_t *uca_init(); +void uca_destroy(struct uca_t *uca); + + +#endif -- cgit v1.2.3