diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2012-03-05 11:29:35 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2012-03-05 11:29:35 +0100 |
commit | 881abcb70c5ac2f8e65b2d892b7bde3f5311e8b3 (patch) | |
tree | 0ccdb1c14551a1bc37025dc09c10a2f4f4bf020c /src/cameras | |
parent | 0010c60ac578e8d463b5948f5b2f137dde54abd9 (diff) | |
download | uca-881abcb70c5ac2f8e65b2d892b7bde3f5311e8b3.tar.gz uca-881abcb70c5ac2f8e65b2d892b7bde3f5311e8b3.tar.bz2 uca-881abcb70c5ac2f8e65b2d892b7bde3f5311e8b3.tar.xz uca-881abcb70c5ac2f8e65b2d892b7bde3f5311e8b3.zip |
Remove cruft
Diffstat (limited to 'src/cameras')
-rw-r--r-- | src/cameras/dummy.c | 327 | ||||
-rw-r--r-- | src/cameras/dummy.h | 23 | ||||
-rw-r--r-- | src/cameras/ipe.c | 240 | ||||
-rw-r--r-- | src/cameras/ipe.h | 23 | ||||
-rw-r--r-- | src/cameras/pco.c | 460 | ||||
-rw-r--r-- | src/cameras/pco.h | 23 | ||||
-rw-r--r-- | src/cameras/pf.c | 265 | ||||
-rw-r--r-- | src/cameras/pf.h | 23 | ||||
-rw-r--r-- | src/cameras/simple.c | 166 | ||||
-rw-r--r-- | src/cameras/simple.h | 23 |
10 files changed, 0 insertions, 1573 deletions
diff --git a/src/cameras/dummy.c b/src/cameras/dummy.c deleted file mode 100644 index 255a54b..0000000 --- a/src/cameras/dummy.c +++ /dev/null @@ -1,327 +0,0 @@ -/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu> - (Karlsruhe Institute of Technology) - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - - You should have received a copy of the GNU Lesser General Public License along - with this library; if not, write to the Free Software Foundation, Inc., 51 - Franklin St, Fifth Floor, Boston, MA 02110, USA */ - -#include <stdlib.h> -#include <string.h> -#define __USE_BSD -#include <unistd.h> -#undef __USE_BSD -#include <sys/time.h> -#include <assert.h> - -#include "config.h" -#include "uca.h" -#include "uca-cam.h" -#include "uca-grabber.h" - -#ifdef HAVE_PTHREADS -#include <pthread.h> -#endif - -/** - * User structure for the dummy camera. - */ -typedef struct dummy_cam { - uint32_t bitdepth; - uint32_t frame_rate; -#ifdef HAVE_PTHREADS - pthread_t grab_thread; - bool thread_running; - char *buffer; -#endif -} dummy_cam_t; - - -static const char g_digits[10][20] = { - /* 0 */ - { 0x00, 0xff, 0xff, 0x00, - 0xff, 0x00, 0x00, 0xff, - 0xff, 0x00, 0x00, 0xff, - 0xff, 0x00, 0x00, 0xff, - 0x00, 0xff, 0xff, 0x00 }, - /* 1 */ - { 0x00, 0x00, 0xff, 0x00, - 0x00, 0xff, 0xff, 0x00, - 0x00, 0x00, 0xff, 0x00, - 0x00, 0x00, 0xff, 0x00, - 0x00, 0x00, 0xff, 0x00 }, - /* 2 */ - { 0x00, 0xff, 0xff, 0x00, - 0xff, 0x00, 0x00, 0xff, - 0x00, 0x00, 0xff, 0x00, - 0x00, 0xff, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff }, - /* 3 */ - { 0x00, 0xff, 0xff, 0x00, - 0xff, 0x00, 0x00, 0xff, - 0x00, 0x00, 0xff, 0x00, - 0xff, 0x00, 0x00, 0xff, - 0x00, 0xff, 0xff, 0x00 }, - /* 4 */ - { 0xff, 0x00, 0x00, 0x00, - 0xff, 0x00, 0x00, 0xff, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0xff, - 0x00, 0x00, 0x00, 0xff }, - /* 5 */ - { 0xff, 0xff, 0xff, 0xff, - 0xff, 0x00, 0x00, 0x00, - 0x00, 0xff, 0xff, 0x00, - 0x00, 0x00, 0x00, 0xff, - 0xff, 0xff, 0xff, 0x00 }, - /* 6 */ - { 0x00, 0xff, 0xff, 0xff, - 0xff, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0x00, - 0xff, 0x00, 0x00, 0xff, - 0x00, 0xff, 0xff, 0x00 }, - /* 7 */ - { 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0xff, - 0x00, 0x00, 0xff, 0x00, - 0x00, 0xff, 0x00, 0x00, - 0xff, 0x00, 0x00, 0x00 }, - /* 8 */ - { 0x00, 0xff, 0xff, 0x00, - 0xff, 0x00, 0x00, 0xff, - 0x00, 0xff, 0xff, 0x00, - 0xff, 0x00, 0x00, 0xff, - 0x00, 0xff, 0xff, 0x00 }, - /* 9 */ - { 0x00, 0xff, 0xff, 0x00, - 0xff, 0x00, 0x00, 0xff, - 0x00, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0xff, - 0xff, 0xff, 0xff, 0x00 } -}; - -const int DIGIT_WIDTH = 4; -const int DIGIT_HEIGHT = 5; - -#define GET_DUMMY(uca) ((struct dummy_cam *)(uca->user)) - -static void uca_dummy_print_number(char *buffer, int number, int x, int y, int width) -{ - for (int i = 0; i < DIGIT_WIDTH; i++) { - for (int j = 0; j < DIGIT_HEIGHT; j++) { - buffer[(y+j)*width + (x+i)] = g_digits[number][j*DIGIT_WIDTH+i]; - } - } -} - -static void uca_dummy_memcpy(struct uca_camera_priv *cam, char *buffer) -{ - /* print current frame number */ - unsigned int number = cam->current_frame; - unsigned int divisor = 100000000; - int x = 10; - while (divisor > 1) { - uca_dummy_print_number(buffer, number / divisor, x, 10, cam->frame_width); - number = number % divisor; - divisor = divisor / 10; - x += 5; - } -} - -static __suseconds_t uca_dummy_time_diff(struct timeval *start, struct timeval *stop) -{ - return (stop->tv_sec - start->tv_sec)*1000000 + (stop->tv_usec - start->tv_usec); -} - -static void *uca_dummy_grab_thread(void *arg) -{ - struct uca_camera_priv *cam = ((struct uca_camera_priv *) arg); - struct dummy_cam *dc = GET_DUMMY(cam); - - assert(dc->frame_rate > 0); - const __useconds_t sleep_time = (unsigned int) 1000000.0f / dc->frame_rate; - __suseconds_t call_time; - struct timeval start, stop; - - while (dc->thread_running) { - uca_dummy_memcpy(cam, dc->buffer); - gettimeofday(&start, NULL); - cam->callback(cam->current_frame, dc->buffer, NULL, cam->callback_user); - gettimeofday(&stop, NULL); - - call_time = uca_dummy_time_diff(&start, &stop); - if (call_time < sleep_time) { - cam->current_frame++; - usleep(sleep_time - call_time); - } - else - cam->current_frame += call_time / sleep_time; - } - return NULL; -} - - -/* - * --- interface implementations ---------------------------------------------- - */ -static uint32_t uca_dummy_set_property(struct uca_camera_priv *cam, uca_property_ids property, void *data) -{ - uint32_t err = UCA_ERR_CAMERA | UCA_ERR_PROP; - - switch (property) { - case UCA_PROP_WIDTH: - cam->frame_width = *((uint32_t *) data); - break; - - case UCA_PROP_HEIGHT: - cam->frame_height = *((uint32_t *) data); - break; - - case UCA_PROP_FRAMERATE: - GET_DUMMY(cam)->frame_rate = *((uint32_t *) data); - break; - - default: - return err | UCA_ERR_INVALID; - } - - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_get_property(struct uca_camera_priv *cam, uca_property_ids property, void *data, size_t num) -{ - switch (property) { - case UCA_PROP_NAME: - strncpy((char *) data, "dummy", num); - break; - - case UCA_PROP_WIDTH: - uca_set_void(data, uint32_t, cam->frame_width); - break; - - case UCA_PROP_WIDTH_MIN: - uca_set_void(data, uint32_t, 1); - break; - - case UCA_PROP_WIDTH_MAX: - uca_set_void(data, uint32_t, 4096); - break; - - case UCA_PROP_HEIGHT: - uca_set_void(data, uint32_t, cam->frame_height); - break; - - case UCA_PROP_HEIGHT_MIN: - uca_set_void(data, uint32_t, 1); - break; - - case UCA_PROP_HEIGHT_MAX: - uca_set_void(data, uint32_t, 4096); - break; - - case UCA_PROP_BITDEPTH: - uca_set_void(data, uint32_t, 8); - break; - - default: - return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; - } - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_start_recording(struct uca_camera_priv *cam) -{ - if (cam->callback != NULL) { -#ifdef HAVE_PTHREADS - struct dummy_cam *dc = GET_DUMMY(cam); - /* FIXME: handle return value */ - dc->thread_running = true; - dc->buffer = (char *) malloc(cam->frame_width * cam->frame_height); - pthread_create(&dc->grab_thread, NULL, &uca_dummy_grab_thread, cam); -#endif - } - cam->current_frame = 0; - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_stop_recording(struct uca_camera_priv *cam) -{ - struct dummy_cam *dc = GET_DUMMY(cam); - if (cam->callback != NULL) { - dc->thread_running = false; - free(dc->buffer); - dc->buffer = NULL; - } - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_register_callback(struct uca_camera_priv *cam, uca_cam_grab_callback cb, void *user) -{ - if (cam->callback == NULL) { - cam->callback = cb; - cam->callback_user = user; - } - else - return UCA_ERR_CAMERA | UCA_ERR_CALLBACK | UCA_ERR_ALREADY_REGISTERED; - - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_grab(struct uca_camera_priv *cam, char *buffer, void *meta_data) -{ - if (cam->callback != NULL) - return UCA_ERR_CAMERA | UCA_ERR_CALLBACK | UCA_ERR_ALREADY_REGISTERED; - - uca_dummy_memcpy(cam, buffer); - cam->current_frame++; - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_destroy(struct uca_camera_priv *cam) -{ - struct dummy_cam *dc = GET_DUMMY(cam); - free(dc->buffer); - free(dc); - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_ignore(struct uca_camera_priv *cam) -{ - return UCA_NO_ERROR; -} - -uint32_t uca_dummy_init(struct uca_camera_priv **cam, struct uca_grabber_priv *grabber) -{ - struct uca_camera_priv *uca = uca_cam_new(); - - uca->destroy = &uca_dummy_destroy; - uca->set_property = &uca_dummy_set_property; - uca->get_property = &uca_dummy_get_property; - uca->start_recording = &uca_dummy_start_recording; - uca->stop_recording = &uca_dummy_stop_recording; - uca->trigger = &uca_dummy_ignore; - uca->grab = &uca_dummy_grab; - uca->register_callback = &uca_dummy_register_callback; - - uca->state = UCA_CAM_CONFIGURABLE; - uca->frame_width = 320; - uca->frame_height = 240; - - struct dummy_cam *dummy_cam = (struct dummy_cam *) malloc(sizeof(struct dummy_cam)); - dummy_cam->bitdepth = 8; - dummy_cam->frame_rate = 100; - uca->user = dummy_cam; - - *cam = uca; - - return UCA_NO_ERROR; -} diff --git a/src/cameras/dummy.h b/src/cameras/dummy.h deleted file mode 100644 index ba9a8d4..0000000 --- a/src/cameras/dummy.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu> - (Karlsruhe Institute of Technology) - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - - You should have received a copy of the GNU Lesser General Public License along - with this library; if not, write to the Free Software Foundation, Inc., 51 - Franklin St, Fifth Floor, Boston, MA 02110, USA */ - -#ifndef __UNIFIED_CAMERA_ACCESS_DUMMY_H -#define __UNIFIED_CAMERA_ACCESS_DUMMY_H - -uint32_t uca_dummy_init(struct uca_camera_priv **uca, struct uca_grabber_priv *grabber); - -#endif diff --git a/src/cameras/ipe.c b/src/cameras/ipe.c deleted file mode 100644 index b027d50..0000000 --- a/src/cameras/ipe.c +++ /dev/null @@ -1,240 +0,0 @@ -/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu> - (Karlsruhe Institute of Technology) - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - - You should have received a copy of the GNU Lesser General Public License along - with this library; if not, write to the Free Software Foundation, Inc., 51 - Franklin St, Fifth Floor, Boston, MA 02110, USA */ - -#include <stdlib.h> -#include <stdarg.h> -#include <stdio.h> -#include <string.h> -#include <assert.h> -#include <pcilib.h> -#include "uca.h" -#include "uca-cam.h" -#include "uca-grabber.h" - -#define set_void(p, type, value) { *((type *) p) = value; } -#define GET_HANDLE(cam) ((pcilib_t *) cam->user) - -static void uca_ipe_handle_error(const char *format, ...) -{ - if (format) { - va_list ap; - va_start(ap, format); - vprintf(format, ap); - printf("\n"); - va_end(ap); - } -} - -static uint32_t uca_ipe_set_property(struct uca_camera_priv *cam, uca_property_ids property, void *data) -{ - pcilib_t *handle = GET_HANDLE(cam); - pcilib_register_value_t value = *((pcilib_register_value_t *) data); - - switch (property) { - case UCA_PROP_EXPOSURE: - pcilib_write_register(handle, NULL, "exp_time", value); - break; - - default: - return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; - } - return UCA_NO_ERROR; -} - -static uint32_t uca_ipe_get_property(struct uca_camera_priv *cam, uca_property_ids property, void *data, size_t num) -{ - pcilib_t *handle = GET_HANDLE(cam); - pcilib_register_value_t value = 0; - - switch (property) { - case UCA_PROP_NAME: - strncpy((char *) data, "IPE PCIe based on CMOSIS CMV2000", num); - break; - - case UCA_PROP_BITDEPTH: - set_void(data, uint32_t, 16); - break; - - case UCA_PROP_WIDTH: - set_void(data, uint32_t, 2048); - break; - - case UCA_PROP_HEIGHT: - set_void(data, uint32_t, 1088); - break; - - case UCA_PROP_EXPOSURE: - pcilib_read_register(handle, NULL, "exp_time", &value); - set_void(data, uint32_t, (uint32_t) value); - - case UCA_PROP_TEMPERATURE_SENSOR: - pcilib_read_register(handle, NULL, "cmosis_temperature", &value); - set_void(data, uint32_t, (uint32_t) value); - break; - - case UCA_PROP_PGA_GAIN: - pcilib_read_register(handle, NULL, "pga", &value); - set_void(data, uint32_t, (uint32_t) value); - break; - - case UCA_PROP_PGA_GAIN_MIN: - set_void(data, uint32_t, 0); - break; - - case UCA_PROP_PGA_GAIN_MAX: - set_void(data, uint32_t, 3); - break; - - case UCA_PROP_ADC_GAIN: - pcilib_read_register(handle, NULL, "adc_gain", &value); - set_void(data, uint32_t, (uint32_t) value); - break; - - case UCA_PROP_ADC_GAIN_MIN: - set_void(data, uint32_t, 32); - break; - - case UCA_PROP_ADC_GAIN_MAX: - set_void(data, uint32_t, 55); - break; - - default: - return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; - } - return UCA_NO_ERROR; -} - -static uint32_t uca_ipe_start_recording(struct uca_camera_priv *cam) -{ - pcilib_t *handle = cam->user; - pcilib_start(handle, PCILIB_EVENT_DATA, PCILIB_EVENT_FLAGS_DEFAULT); - return UCA_NO_ERROR; -} - -static uint32_t uca_ipe_stop_recording(struct uca_camera_priv *cam) -{ - pcilib_t *handle = cam->user; - pcilib_stop(handle, PCILIB_EVENT_FLAGS_DEFAULT); - return UCA_NO_ERROR; -} - -static uint32_t uca_ipe_grab(struct uca_camera_priv *cam, char *buffer, void *meta_data) -{ - pcilib_t *handle = GET_HANDLE(cam); - size_t size = cam->frame_width * cam->frame_height * sizeof(uint16_t); - void *data = NULL; - pcilib_event_id_t event_id; - pcilib_event_info_t event_info; - - if (pcilib_trigger(handle, PCILIB_EVENT0, 0, NULL)) - return UCA_ERR_CAMERA; - - if (pcilib_get_next_event(handle, PCILIB_TIMEOUT_INFINITE, &event_id, sizeof(pcilib_event_info_t), &event_info)) - return UCA_ERR_CAMERA; - - size_t err = 0; - data = pcilib_get_data(handle, event_id, PCILIB_EVENT_DATA, &err); - - if (data == NULL) - return UCA_ERR_CAMERA; - - assert(err == size); - - memcpy(buffer, data, size); - pcilib_return_data(handle, event_id, PCILIB_EVENT_DATA, data); - return UCA_NO_ERROR; -} - -static int event_callback(pcilib_event_id_t event_id, pcilib_event_info_t *info, void *user) -{ - struct uca_camera_priv *cam = (struct uca_camera_priv *) user; - pcilib_t *handle = GET_HANDLE(cam); - size_t error = 0; - - void *buffer = pcilib_get_data(handle, event_id, PCILIB_EVENT_DATA, &error); - - if (buffer == NULL) { - pcilib_trigger(handle, PCILIB_EVENT0, 0, NULL); - return PCILIB_STREAMING_CONTINUE; - } - - uca_buffer_status status = cam->callback(info->seqnum, buffer, NULL, cam->callback_user); - - if (status == UCA_BUFFER_RELEASE) - pcilib_return_data(handle, event_id, PCILIB_EVENT_DATA, buffer); - - pcilib_trigger(handle, PCILIB_EVENT0, 0, NULL); - return PCILIB_STREAMING_CONTINUE; -} - -static uint32_t uca_ipe_register_callback(struct uca_camera_priv *cam, uca_cam_grab_callback cb, void *user) -{ - if (cam->callback == NULL) { - cam->callback = cb; - cam->callback_user = user; - pcilib_trigger(GET_HANDLE(cam), PCILIB_EVENT0, 0, NULL); - pcilib_stream(GET_HANDLE(cam), &event_callback, cam); - return UCA_NO_ERROR; - } - return UCA_ERR_CAMERA | UCA_ERR_CALLBACK | UCA_ERR_ALREADY_REGISTERED; -} - -static uint32_t uca_ipe_release_buffer(struct uca_camera_priv *cam, void *buffer) -{ - /* FIXME: call return_data */ - /* pcilib_t *handle = GET_HANDLE(cam); */ - /* pcilib_return_data(handle, event_id, PCILIB_EVENT_DATA, buffer); */ - return UCA_NO_ERROR; -} - -static uint32_t uca_ipe_destroy(struct uca_camera_priv *cam) -{ - pcilib_close(GET_HANDLE(cam)); - return UCA_NO_ERROR; -} - -uint32_t uca_ipe_init(struct uca_camera_priv **cam, struct uca_grabber_priv *grabber) -{ - pcilib_model_t model = PCILIB_MODEL_DETECT; - pcilib_set_error_handler(uca_ipe_handle_error, uca_ipe_handle_error); - pcilib_t *handle = pcilib_open("/dev/fpga0", model); - - if (handle == NULL) - return UCA_ERR_CAMERA | UCA_ERR_INIT | UCA_ERR_NOT_FOUND; - - pcilib_set_error_handler(&uca_ipe_handle_error, &uca_ipe_handle_error); - pcilib_reset(handle); - - struct uca_camera_priv *uca = uca_cam_new(); - - /* Camera found, set function pointers... */ - uca->destroy = &uca_ipe_destroy; - uca->set_property = &uca_ipe_set_property; - uca->get_property = &uca_ipe_get_property; - uca->start_recording = &uca_ipe_start_recording; - uca->stop_recording = &uca_ipe_stop_recording; - uca->grab = &uca_ipe_grab; - uca->register_callback = &uca_ipe_register_callback; - uca->release_buffer = &uca_ipe_release_buffer; - - uca->frame_width = 2048; - uca->frame_height = 1088; - uca->user = handle; - *cam = uca; - - return UCA_NO_ERROR; -} diff --git a/src/cameras/ipe.h b/src/cameras/ipe.h deleted file mode 100644 index 50bd5bd..0000000 --- a/src/cameras/ipe.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu> - (Karlsruhe Institute of Technology) - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - - You should have received a copy of the GNU Lesser General Public License along - with this library; if not, write to the Free Software Foundation, Inc., 51 - Franklin St, Fifth Floor, Boston, MA 02110, USA */ - -#ifndef __UNIFIED_CAMERA_ACCESS_IPE_H -#define __UNIFIED_CAMERA_ACCESS_IPE_H - -uint32_t uca_ipe_init(struct uca_camera_priv **uca, struct uca_grabber_priv *grabber); - -#endif diff --git a/src/cameras/pco.c b/src/cameras/pco.c deleted file mode 100644 index da4fd73..0000000 --- a/src/cameras/pco.c +++ /dev/null @@ -1,460 +0,0 @@ -/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu> - (Karlsruhe Institute of Technology) - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - - You should have received a copy of the GNU Lesser General Public License along - with this library; if not, write to the Free Software Foundation, Inc., 51 - Franklin St, Fifth Floor, Boston, MA 02110, USA */ - -#include <stdlib.h> -#include <string.h> -#include <libpco/libpco.h> -#include <libpco/sc2_defs.h> -#include "uca.h" -#include "uca-cam.h" -#include "uca-grabber.h" -#include "pco.h" - -typedef struct pco_desc { - pco_handle pco; - uint16_t type, subtype; - uint16_t roi[4]; - - uint16_t active_segment; - uint32_t current_image; - uint32_t num_recorded_images; -} pco_desc_t; - -#define GET_PCO_DESC(cam) ((struct pco_desc *) cam->user) -#define GET_PCO(cam) (((struct pco_desc *)(cam->user))->pco) - -#define uca_set_void(p, type, value) { *((type *) p) = (type) value; } - - -static uint32_t uca_pco_set_exposure(struct uca_camera_priv *cam, uint32_t *exposure) -{ - if (pco_set_exposure_time(GET_PCO(cam), *exposure) != PCO_NOERROR) - return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; - return UCA_NO_ERROR; -} - -static uint32_t uca_pco_set_delay(struct uca_camera_priv *cam, uint32_t *delay) -{ - if (pco_set_delay_time(GET_PCO(cam), *delay) != PCO_NOERROR) - return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; - return UCA_NO_ERROR; -} - -static uint32_t uca_pco_destroy(struct uca_camera_priv *cam) -{ - cam->grabber->stop_acquire(cam->grabber); - pco_stop_recording(GET_PCO(cam)); - pco_destroy(GET_PCO(cam)); - free(GET_PCO_DESC(cam)); - return UCA_NO_ERROR; -} - -static uint32_t uca_pco_set_property(struct uca_camera_priv *cam, uca_property_ids property, void *data) -{ - struct uca_grabber_priv *grabber = cam->grabber; - struct pco_desc *pco_d = GET_PCO_DESC(cam); - uint32_t err = UCA_ERR_CAMERA | UCA_ERR_PROP; - - /* We try to set the property on the grabber. If it returns "invalid", we - * also try it via the libpco. Else, there was a more serious error. */ - err = grabber->set_property(grabber, property, data); - if (((err & UCA_ERR_MASK_CODE) == UCA_ERR_INVALID) || (err == UCA_NO_ERROR)) - err = UCA_ERR_CAMERA | UCA_ERR_PROP; - else - return err; - - switch (property) { - case UCA_PROP_WIDTH: - cam->frame_width = *((uint32_t *) data); - pco_d->roi[2] = cam->frame_width; - if (pco_set_roi(pco_d->pco, pco_d->roi) != PCO_NOERROR) - return err | UCA_ERR_OUT_OF_RANGE; - - /* Twice the width because of 16 bits per pixel */ - uint32_t w = cam->frame_width * 2; - grabber->set_property(grabber, UCA_PROP_WIDTH, &w); - break; - - case UCA_PROP_HEIGHT: - cam->frame_height = *((uint32_t *) data); - pco_d->roi[3] = cam->frame_height; - if (pco_set_roi(pco_d->pco, pco_d->roi) == PCO_NOERROR) - return err | UCA_ERR_OUT_OF_RANGE; - break; - - case UCA_PROP_EXPOSURE: - return uca_pco_set_exposure(cam, (uint32_t *) data); - - case UCA_PROP_DELAY: - return uca_pco_set_delay(cam, (uint32_t *) data); - - case UCA_PROP_GRAB_AUTO: - return pco_set_auto_transfer(GET_PCO(cam), *(uint32_t *) data); - - case UCA_PROP_TRIGGER_MODE: - /* XXX: We have a 1:1 mapping between UCA_TRIGGER_* and - * TRIGGER_MODE_* - */ - return pco_set_trigger_mode(GET_PCO(cam), (uint16_t) *(uint32_t *) data); - - case UCA_PROP_TIMESTAMP_MODE: - { - uint32_t mode = *((uint32_t *) data); - if (mode & UCA_TIMESTAMP_ASCII) { - if (mode & UCA_TIMESTAMP_BINARY) - return pco_set_timestamp_mode(GET_PCO(cam), TIMESTAMP_MODE_BINARYANDASCII); - else - return pco_set_timestamp_mode(GET_PCO(cam), TIMESTAMP_MODE_ASCII); - } - else if (mode & UCA_TIMESTAMP_BINARY) - return pco_set_timestamp_mode(GET_PCO(cam), TIMESTAMP_MODE_BINARY); - else - return pco_set_timestamp_mode(GET_PCO(cam), TIMESTAMP_MODE_OFF); - } - - case UCA_PROP_HOTPIXEL_CORRECTION: - return pco_set_hotpixel_correction(GET_PCO(cam), *(uint32_t *) data); - - default: - return err | UCA_ERR_INVALID; - } - return UCA_NO_ERROR; -} - - -static uint32_t uca_pco_get_property(struct uca_camera_priv *cam, uca_property_ids property, void *data, size_t num) -{ - pco_handle pco = GET_PCO(cam); - struct uca_grabber_priv *grabber = cam->grabber; - - switch (property) { - case UCA_PROP_NAME: - { - char *name = NULL; - pco_get_name(pco, &name); - strncpy((char *) data, name, num); - free(name); - } - break; - - case UCA_PROP_TEMPERATURE_SENSOR: - { - uint32_t t1, t2, t3; - if (pco_get_temperature(pco, &t1, &t2, &t3) == PCO_NOERROR) { - uca_set_void(data, uint32_t, (t1 / 10)); - } - } - break; - - case UCA_PROP_TEMPERATURE_CAMERA: - { - uint32_t t1, t2, t3; - if (pco_get_temperature(pco, &t1, &t2, &t3) == PCO_NOERROR) - uca_set_void(data, uint32_t, t2); - } - break; - - case UCA_PROP_WIDTH: - uca_set_void(data, uint32_t, cam->frame_width); - break; - - case UCA_PROP_WIDTH_MIN: - uca_set_void(data, uint32_t, 1); - break; - - case UCA_PROP_HEIGHT: - uca_set_void(data, uint32_t, cam->frame_height); - break; - - case UCA_PROP_HEIGHT_MIN: - uca_set_void(data, uint32_t, 1); - break; - - case UCA_PROP_BINNING_X: - { - uint16_t hb, vb; - if (pco_get_binning(pco, &hb, &vb) == PCO_NOERROR) - uca_set_void(data, uint32_t, hb); - } - break; - - case UCA_PROP_BINNING_Y: - { - uint16_t hb, vb; - if (pco_get_binning(pco, &hb, &vb) == PCO_NOERROR) - uca_set_void(data, uint32_t, vb); - } - break; - - case UCA_PROP_X_OFFSET: - return grabber->get_property(grabber, UCA_PROP_X_OFFSET, (uint32_t *) data); - - case UCA_PROP_Y_OFFSET: - return grabber->get_property(grabber, UCA_PROP_Y_OFFSET, (uint32_t *) data); - - case UCA_PROP_DELAY: - pco_get_delay_time(pco, (uint32_t *) data); - break; - - case UCA_PROP_DELAY_MIN: - { - uint32_t dummy1, dummy2; - pco_get_delay_range(pco, (uint32_t *) data, &dummy1, &dummy2); - } - break; - - case UCA_PROP_DELAY_MAX: - { - uint32_t dummy1, dummy2; - pco_get_delay_range(pco, &dummy1, (uint32_t *) data, &dummy2); - } - break; - - case UCA_PROP_EXPOSURE: - pco_get_exposure_time(pco, (uint32_t *) data); - break; - - case UCA_PROP_EXPOSURE_MIN: - { - uint32_t dummy1, dummy2; - pco_get_exposure_range(pco, (uint32_t *) data, &dummy1, &dummy2); - } - break; - - case UCA_PROP_EXPOSURE_MAX: - { - uint32_t dummy1, dummy2; - pco_get_exposure_range(pco, &dummy1, (uint32_t *) data, &dummy2); - } - break; - - case UCA_PROP_BITDEPTH: - uca_set_void(data, uint32_t, 16); - break; - - case UCA_PROP_GRAB_AUTO: - { - int value = 0; - uint32_t err = pco_get_auto_transfer(pco, &value); - if (err != PCO_NOERROR) - return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; - uca_set_void(data, uint32_t, value); - } - break; - - case UCA_PROP_GRAB_TIMEOUT: - { - uint32_t timeout; - uint32_t err = cam->grabber->get_property(cam->grabber, UCA_PROP_GRAB_TIMEOUT, &timeout); - if (err != UCA_NO_ERROR) - return err; - uca_set_void(data, uint32_t, timeout); - } - break; - - default: - return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; - } - return UCA_NO_ERROR; -} - -static uint32_t uca_pco_start_recording(struct uca_camera_priv *cam) -{ - uint32_t err = UCA_ERR_CAMERA | UCA_ERR_INIT; - pco_handle pco = GET_PCO(cam); - - if (GET_PCO_DESC(cam)->type == CAMERATYPE_PCO_DIMAX_STD) - pco_clear_active_segment(pco); - - if (pco_arm_camera(pco) != PCO_NOERROR) - return err | UCA_ERR_UNCLASSIFIED; - - if (pco_start_recording(pco) != PCO_NOERROR) - return err | UCA_ERR_UNCLASSIFIED; - - return cam->grabber->acquire(cam->grabber, -1); -} - -static uint32_t uca_pco_stop_recording(struct uca_camera_priv *cam) -{ - if (pco_stop_recording(GET_PCO(cam)) != PCO_NOERROR) - return UCA_ERR_CAMERA | UCA_ERR_INIT | UCA_ERR_UNCLASSIFIED; - return UCA_NO_ERROR; -} - -static uint32_t uca_pco_trigger(struct uca_camera_priv *cam) -{ - /* TODO: is this correct? */ - uint32_t success = 0; - pco_force_trigger(GET_PCO(cam), &success); - return cam->grabber->trigger(cam->grabber); -} - -static uint32_t uca_pco_grab(struct uca_camera_priv *cam, char *buffer, void *meta_data) -{ - uint16_t *frame; - pco_desc_t *pco_d = GET_PCO_DESC(cam); - pco_handle pco = pco_d->pco; - - if (cam->state == UCA_CAM_READOUT) { - if (pco_d->current_image == pco_d->num_recorded_images) - return UCA_ERR_NO_MORE_IMAGES; - - /* Ok, this is pco's way of requesting multiple frames... you have to do - * it one by one :/ */ - pco_read_images(pco, pco_d->active_segment, pco_d->current_image, pco_d->current_image); - pco_d->current_image++; - } - - pco_request_image(GET_PCO(cam)); - uint32_t err = cam->grabber->grab(cam->grabber, (void **) &frame, &cam->current_frame); - if (err != UCA_NO_ERROR) - return err; - - /* Copy data into user buffer */ - if (pco_d->type == CAMERATYPE_PCO_EDGE) - pco_get_reorder_func(GET_PCO(cam))((uint16_t *) buffer, frame, cam->frame_width, cam->frame_height); - else - memcpy(buffer, (char *) frame, cam->frame_width * cam->frame_height * 2); - - return UCA_NO_ERROR; -} - -static uint32_t uca_pco_readout(struct uca_camera_priv *cam) -{ - pco_desc_t *pco_d = GET_PCO_DESC(cam); - /* TODO: error handling */ - pco_handle pco = GET_PCO(cam); - pco_get_active_segment(pco, &pco_d->active_segment); - pco_get_num_images(pco, pco_d->active_segment, &pco_d->num_recorded_images); - pco_d->current_image = 1; - return UCA_NO_ERROR; -} - -static uint32_t uca_pco_register_callback(struct uca_camera_priv *cam, uca_cam_grab_callback callback, void *user) -{ - if (cam->callback == NULL) { - cam->callback = callback; - cam->callback_user = user; - return cam->grabber->register_callback(cam->grabber, callback, NULL, user); - } - return UCA_ERR_CAMERA | UCA_ERR_CALLBACK | UCA_ERR_ALREADY_REGISTERED; -} - -uint32_t uca_pco_init(struct uca_camera_priv **cam, struct uca_grabber_priv *grabber) -{ - uint32_t err = UCA_ERR_CAMERA | UCA_ERR_INIT; - if (grabber == NULL) - return err | UCA_ERR_NOT_FOUND; - - pco_handle pco = pco_init(); - if (pco == NULL) - return err | UCA_ERR_NOT_FOUND; - - if (!pco_is_active(pco)) { - pco_destroy(pco); - return err | UCA_ERR_NOT_FOUND; - } - - struct uca_camera_priv *uca = uca_cam_new(); - - /* Prepare user data */ - struct pco_desc *pco_d = (struct pco_desc *) malloc(sizeof(struct pco_desc)); - uca->user = pco_d; - pco_d->pco = pco; - pco_get_camera_type(pco, &pco_d->type, &pco_d->subtype); - - uca->grabber = grabber; - uca->grabber->synchronous = true; - - /* Camera found, set function pointers... */ - uca->destroy = &uca_pco_destroy; - uca->set_property = &uca_pco_set_property; - uca->get_property = &uca_pco_get_property; - uca->start_recording = &uca_pco_start_recording; - uca->stop_recording = &uca_pco_stop_recording; - uca->trigger = &uca_pco_trigger; - uca->grab = &uca_pco_grab; - uca->readout = &uca_pco_readout; - uca->register_callback = &uca_pco_register_callback; - - /* Prepare camera for recording */ - if (pco_d->type == CAMERATYPE_PCO_EDGE) - pco_set_scan_mode(pco, PCO_SCANMODE_SLOW); - - pco_stop_recording(pco); - pco_set_timestamp_mode(pco, TIMESTAMP_MODE_ASCII); - /* pco_set_timebase(pco, 1, 1); */ - /* pco_arm_camera(pco); */ - - /* Prepare frame grabber for recording */ - int val = 0; - - switch (pco_d->type) { - case CAMERATYPE_PCO_EDGE: - val = UCA_CL_8BIT_FULL_10; - break; - case CAMERATYPE_PCO_DIMAX_STD: - val = UCA_CL_SINGLE_TAP_8; - break; - case CAMERATYPE_PCO4000: - val = UCA_CL_SINGLE_TAP_16; - break; - default: - break; - } - grabber->set_property(grabber, UCA_GRABBER_CAMERALINK_TYPE, &val); - - val = 0; - switch (pco_d->type) { - case CAMERATYPE_PCO_EDGE: - val = UCA_FORMAT_GRAY8; - break; - case CAMERATYPE_PCO_DIMAX_STD: - case CAMERATYPE_PCO4000: - val = UCA_FORMAT_GRAY16; - break; - default: - break; - } - grabber->set_property(grabber, UCA_GRABBER_FORMAT, &val); - - val = UCA_TRIGGER_AUTO; - grabber->set_property(grabber, UCA_GRABBER_TRIGGER_MODE, &val); - - uint16_t width_std, height_std, width_ex, height_ex; - pco_get_resolution(pco, &width_std, &height_std, &width_ex, &height_ex); - - uint32_t width = width_std, height = height_std; - uca->frame_width = width; - uca->frame_height = height; - pco_d->roi[0] = pco_d->roi[1] = 1; - pco_d->roi[2] = width; - pco_d->roi[3] = height; - - /* Yes, we really have to take an image twice as large because we set the - * CameraLink interface to 8-bit 10 Taps, but are actually using 5x16 bits. */ - if (pco_d->type == CAMERATYPE_PCO_EDGE) - width *= 2; - grabber->set_property(grabber, UCA_PROP_WIDTH, &width); - grabber->set_property(grabber, UCA_PROP_HEIGHT, &height); - - uca->state = UCA_CAM_CONFIGURABLE; - *cam = uca; - - return UCA_NO_ERROR; -} diff --git a/src/cameras/pco.h b/src/cameras/pco.h deleted file mode 100644 index 4d1a2b4..0000000 --- a/src/cameras/pco.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu> - (Karlsruhe Institute of Technology) - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - - You should have received a copy of the GNU Lesser General Public License along - with this library; if not, write to the Free Software Foundation, Inc., 51 - Franklin St, Fifth Floor, Boston, MA 02110, USA */ - -#ifndef __UNIFIED_CAMERA_ACCESS_PCO_H -#define __UNIFIED_CAMERA_ACCESS_PCO_H - -uint32_t uca_pco_init(struct uca_camera_priv **uca, struct uca_grabber_priv *grabber); - -#endif diff --git a/src/cameras/pf.c b/src/cameras/pf.c deleted file mode 100644 index 829b94a..0000000 --- a/src/cameras/pf.c +++ /dev/null @@ -1,265 +0,0 @@ -/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu> - (Karlsruhe Institute of Technology) - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - - You should have received a copy of the GNU Lesser General Public License along - with this library; if not, write to the Free Software Foundation, Inc., 51 - Franklin St, Fifth Floor, Boston, MA 02110, USA */ - -#include <math.h> -#include <stdlib.h> -#include <string.h> -#include <libpf/pfcam.h> -#include "uca.h" -#include "uca-cam.h" -#include "uca-grabber.h" - -struct uca_pf_map { - uca_property_ids uca_prop; - const char *pf_prop; -}; - -static struct uca_pf_map uca_to_pf[] = { - { UCA_PROP_NAME, "CameraName" }, - { UCA_PROP_WIDTH, "Window.W" }, - { UCA_PROP_WIDTH_MIN, "Window.W.Min" }, - { UCA_PROP_WIDTH_MAX, "Window.W.Max" }, - { UCA_PROP_HEIGHT, "Window.H" }, - { UCA_PROP_HEIGHT_MIN, "Window.H.Min" }, - { UCA_PROP_HEIGHT_MAX, "Window.H.Max" }, - { UCA_PROP_X_OFFSET, "Window.X" }, - { UCA_PROP_X_OFFSET_MIN,"Window.X.Min" }, - { UCA_PROP_X_OFFSET_MAX,"Window.X.Max" }, - { UCA_PROP_Y_OFFSET, "Window.Y" }, - { UCA_PROP_Y_OFFSET_MIN,"Window.Y.Min" }, - { UCA_PROP_Y_OFFSET_MAX,"Window.Y.Max" }, - { UCA_PROP_EXPOSURE, "ExposureTime" }, - { UCA_PROP_EXPOSURE_MIN,"ExposureTime.Min" }, - { UCA_PROP_EXPOSURE_MAX,"ExposureTime.Max" }, - { UCA_PROP_DELAY, "Trigger.Delay" }, - { UCA_PROP_DELAY_MIN, "Trigger.Delay.Min" }, - { UCA_PROP_DELAY_MAX, "Trigger.Delay.Max" }, - { UCA_PROP_FRAMERATE, "FrameRate" }, - { UCA_PROP_TRIGGER_MODE,"Trigger.Source" }, - { -1, NULL } -}; - -static int uca_pf_set_uint32_property(TOKEN token, void *data, uint32_t *update_var) -{ - PFValue value; - value.type = PF_INT; - value.value.i = *((uint32_t *) data); - if (update_var != NULL) - *update_var = value.value.i; - return pfDevice_SetProperty(0, token, &value); -} - -static uint32_t uca_pf_set_property(struct uca_camera_priv *cam, uca_property_ids property, void *data) -{ - struct uca_grabber_priv *grabber = cam->grabber; - TOKEN token = INVALID_TOKEN; - int i = 0; - int err = UCA_NO_ERROR; - - /* We try to set the property on the grabber. If it returns "invalid", we - * also try it via the PF SDK. Else, there was a more serious error. - * - * FIXME: This is actually not that good for cases where only the grabber - * should set a certain property and the camera itself is not able to do so. */ - err = grabber->set_property(grabber, property, data); - if (((err & UCA_ERR_MASK_CODE) == UCA_ERR_INVALID) || (err == UCA_NO_ERROR)) - err = UCA_ERR_CAMERA | UCA_ERR_PROP; - else - return err; - - /* Find a valid pf token for the property */ - while (uca_to_pf[i].uca_prop != -1) { - if (uca_to_pf[i].uca_prop == property) { - token = pfProperty_ParseName(0, uca_to_pf[i].pf_prop); - break; - } - i++; - } - if (token == INVALID_TOKEN) - return err | UCA_ERR_INVALID; - - PFValue value; - - switch (property) { - case UCA_PROP_WIDTH: - if (uca_pf_set_uint32_property(token, data, &cam->frame_width) < 0) - return err | UCA_ERR_OUT_OF_RANGE; - break; - - case UCA_PROP_HEIGHT: - if (uca_pf_set_uint32_property(token, data, &cam->frame_height) < 0) - return err | UCA_ERR_OUT_OF_RANGE; - break; - - case UCA_PROP_EXPOSURE: - /* I haven't found a specification but it looks like PF uses milli - * seconds. We also by-pass the frame grabber... */ - value.type = PF_FLOAT; - value.value.f = (float) *((uint32_t *) data) / 1000.0; - if (pfDevice_SetProperty(0, token, &value) < 0) - return err | UCA_ERR_OUT_OF_RANGE; - break; - - default: - return err | UCA_ERR_INVALID; - } - return UCA_NO_ERROR; -} - - -static uint32_t uca_pf_get_property(struct uca_camera_priv *cam, uca_property_ids property, void *data, size_t num) -{ - TOKEN t; /* You gotta love developers who name types capitalized... */ - PFValue value; - - /* Handle all special cases */ - switch (property) { - case UCA_PROP_BITDEPTH: - uca_set_void(data, uint32_t, 8); - return UCA_NO_ERROR; - - default: - break; - } - - int i = 0; - while (uca_to_pf[i].uca_prop != -1) { - if (uca_to_pf[i].uca_prop == property) { - t = pfProperty_ParseName(0, uca_to_pf[i].pf_prop); - if (t == INVALID_TOKEN || (pfDevice_GetProperty(0, t, &value) < 0)) - return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; - - switch (value.type) { - case PF_INT: - uca_set_void(data, uint32_t, value.value.i); - break; - - case PF_FLOAT: - uca_set_void(data, uint32_t, (uint32_t) floor((value.value.f * 1000.0)+0.5)); - break; - - case PF_STRING: - if (property == UCA_PROP_FRAMERATE) { - uca_set_void(data, uint32_t, (uint32_t) floor(atof(value.value.p)+0.5)); - } - else { - strncpy((char *) data, value.value.p, num); - } - break; - - case PF_MODE: - uca_set_void(data, uint32_t, (uint32_t) value.value.i); - break; - - default: - break; - } - return UCA_NO_ERROR; - } - i++; - } - - /* Try to get the property via frame grabber */ - return cam->grabber->get_property(cam->grabber, property, data); -} - -static uint32_t uca_pf_start_recording(struct uca_camera_priv *cam) -{ - return cam->grabber->acquire(cam->grabber, -1); -} - -static uint32_t uca_pf_stop_recording(struct uca_camera_priv *cam) -{ - return cam->grabber->stop_acquire(cam->grabber); -} - -static uint32_t uca_pf_trigger(struct uca_camera_priv *cam) -{ - return cam->grabber->trigger(cam->grabber); -} - -static uint32_t uca_pf_grab(struct uca_camera_priv *cam, char *buffer, void *metadata) -{ - uint16_t *frame; - uint32_t err = cam->grabber->grab(cam->grabber, (void **) &frame, &cam->current_frame); - if (err != UCA_NO_ERROR) - return err; - - memcpy(buffer, frame, cam->frame_width*cam->frame_height); - return UCA_NO_ERROR; -} - -static uint32_t uca_pf_register_callback(struct uca_camera_priv *cam, uca_cam_grab_callback callback, void *user) -{ - if (cam->callback == NULL) { - cam->callback = callback; - cam->callback_user = user; - return cam->grabber->register_callback(cam->grabber, callback, NULL, user); - } - return UCA_ERR_CAMERA | UCA_ERR_CALLBACK | UCA_ERR_ALREADY_REGISTERED; -} - -static uint32_t uca_pf_destroy(struct uca_camera_priv *cam) -{ - pfDeviceClose(0); - return UCA_NO_ERROR; -} - -uint32_t uca_pf_init(struct uca_camera_priv **cam, struct uca_grabber_priv *grabber) -{ - int num_ports; - if ((grabber == NULL) || (pfPortInit(&num_ports) < 0) || (pfDeviceOpen(0) < 0)) - return UCA_ERR_CAMERA | UCA_ERR_INIT | UCA_ERR_NOT_FOUND; - - /* We could check if a higher baud rate is supported, but... forget about - * it. We don't need high speed configuration. */ - - struct uca_camera_priv *uca = uca_cam_new(); - uca->grabber = grabber; - uca->grabber->synchronous = false; - - /* Camera found, set function pointers... */ - uca->destroy = &uca_pf_destroy; - uca->set_property = &uca_pf_set_property; - uca->get_property = &uca_pf_get_property; - uca->start_recording = &uca_pf_start_recording; - uca->stop_recording = &uca_pf_stop_recording; - uca->trigger = &uca_pf_trigger; - uca->grab = &uca_pf_grab; - uca->register_callback = &uca_pf_register_callback; - - /* Prepare frame grabber for recording */ - int val = UCA_CL_8BIT_FULL_8; - grabber->set_property(grabber, UCA_GRABBER_CAMERALINK_TYPE, &val); - - val = UCA_FORMAT_GRAY8; - grabber->set_property(grabber, UCA_GRABBER_FORMAT, &val); - - val = UCA_TRIGGER_AUTO; - grabber->set_property(grabber, UCA_GRABBER_TRIGGER_MODE, &val); - - uca_pf_get_property(uca, UCA_PROP_WIDTH, &uca->frame_width, 0); - uca_pf_get_property(uca, UCA_PROP_HEIGHT, &uca->frame_height, 0); - - grabber->set_property(grabber, UCA_PROP_WIDTH, &uca->frame_width); - grabber->set_property(grabber, UCA_PROP_HEIGHT, &uca->frame_height); - - uca->state = UCA_CAM_CONFIGURABLE; - *cam = uca; - - return UCA_NO_ERROR; -} diff --git a/src/cameras/pf.h b/src/cameras/pf.h deleted file mode 100644 index 74efbe5..0000000 --- a/src/cameras/pf.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu> - (Karlsruhe Institute of Technology) - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - - You should have received a copy of the GNU Lesser General Public License along - with this library; if not, write to the Free Software Foundation, Inc., 51 - Franklin St, Fifth Floor, Boston, MA 02110, USA */ - -#ifndef __UNIFIED_CAMERA_ACCESS_PHOTON_H -#define __UNIFIED_CAMERA_ACCESS_PHOTON_H - -uint32_t uca_pf_init(struct uca_camera_priv **uca, struct uca_grabber_priv *grabber); - -#endif diff --git a/src/cameras/simple.c b/src/cameras/simple.c deleted file mode 100644 index 9b8be9a..0000000 --- a/src/cameras/simple.c +++ /dev/null @@ -1,166 +0,0 @@ -/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu> - (Karlsruhe Institute of Technology) - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - - You should have received a copy of the GNU Lesser General Public License along - with this library; if not, write to the Free Software Foundation, Inc., 51 - Franklin St, Fifth Floor, Boston, MA 02110, USA */ - -#include <math.h> -#include <stdlib.h> -#include <string.h> -#include "uca.h" -#include "uca-cam.h" -#include "uca-grabber.h" - - -static uint32_t uca_simple_set_property(struct uca_camera_priv *cam, uca_property_ids property, void *data) -{ - struct uca_grabber_priv *grabber = cam->grabber; - int err = UCA_NO_ERROR; - - /* We try to set the property on the grabber. If it returns "invalid", we - * also try it via the PF SDK. Else, there was a more serious error. - * - * FIXME: This is actually not that good for cases where only the grabber - * should set a certain property and the camera itself is not able to do so. */ - err = grabber->set_property(grabber, property, data); - if (((err & UCA_ERR_MASK_CODE) == UCA_ERR_INVALID) || (err == UCA_NO_ERROR)) - err = UCA_ERR_CAMERA | UCA_ERR_PROP; - else - return err; - - return UCA_NO_ERROR; -} - - -static uint32_t uca_simple_get_property(struct uca_camera_priv *cam, uca_property_ids property, void *data, size_t num) -{ - struct uca_grabber_priv *grabber = cam->grabber; - uint32_t value32 = 0; - - /* Handle all special cases */ - switch (property) { - case UCA_PROP_NAME: - strncpy((char *) data, "Simple Framegrabber Access", num); - break; - - case UCA_PROP_WIDTH: - grabber->get_property(grabber, UCA_PROP_WIDTH, &value32); - uca_set_void(data, uint32_t, value32); - break; - - case UCA_PROP_HEIGHT: - grabber->get_property(grabber, UCA_PROP_HEIGHT, &value32); - uca_set_void(data, uint32_t, value32); - break; - - case UCA_PROP_X_OFFSET: - grabber->get_property(grabber, UCA_PROP_X_OFFSET, &value32); - uca_set_void(data, uint32_t, value32); - break; - - case UCA_PROP_Y_OFFSET: - grabber->get_property(grabber, UCA_PROP_Y_OFFSET, &value32); - uca_set_void(data, uint32_t, value32); - break; - - case UCA_PROP_BITDEPTH: - uca_set_void(data, uint32_t, 8); - return UCA_NO_ERROR; - - default: - break; - } - - /* Try to get the property via frame grabber */ - return cam->grabber->get_property(cam->grabber, property, data); -} - -static uint32_t uca_simple_start_recording(struct uca_camera_priv *cam) -{ - return cam->grabber->acquire(cam->grabber, -1); -} - -static uint32_t uca_simple_stop_recording(struct uca_camera_priv *cam) -{ - return cam->grabber->stop_acquire(cam->grabber); -} - -static uint32_t uca_simple_trigger(struct uca_camera_priv *cam) -{ - return cam->grabber->trigger(cam->grabber); -} - -static uint32_t uca_simple_grab(struct uca_camera_priv *cam, char *buffer, void *metadata) -{ - uint16_t *frame; - uint32_t err = cam->grabber->grab(cam->grabber, (void **) &frame, &cam->current_frame); - if (err != UCA_NO_ERROR) - return err; - - memcpy(buffer, frame, cam->frame_width*cam->frame_height); - return UCA_NO_ERROR; -} - -static uint32_t uca_simple_register_callback(struct uca_camera_priv *cam, uca_cam_grab_callback callback, void *user) -{ - if (cam->callback == NULL) { - cam->callback = callback; - cam->callback_user = user; - return cam->grabber->register_callback(cam->grabber, callback, NULL, user); - } - return UCA_ERR_CAMERA | UCA_ERR_CALLBACK | UCA_ERR_ALREADY_REGISTERED; -} - -static uint32_t uca_simple_destroy(struct uca_camera_priv *cam) -{ - return UCA_NO_ERROR; -} - -uint32_t uca_simple_init(struct uca_camera_priv **cam, struct uca_grabber_priv *grabber) -{ - if (grabber == NULL) - return UCA_ERR_CAMERA | UCA_ERR_INIT | UCA_ERR_NOT_FOUND; - - struct uca_camera_priv *uca = uca_cam_new(); - uca->grabber = grabber; - uca->grabber->synchronous = false; - - /* Camera found, set function pointers... */ - uca->destroy = &uca_simple_destroy; - uca->set_property = &uca_simple_set_property; - uca->get_property = &uca_simple_get_property; - uca->start_recording = &uca_simple_start_recording; - uca->stop_recording = &uca_simple_stop_recording; - uca->trigger = &uca_simple_trigger; - uca->grab = &uca_simple_grab; - uca->register_callback = &uca_simple_register_callback; - - /* Prepare frame grabber for recording */ - int val = UCA_CL_8BIT_FULL_8; - grabber->set_property(grabber, UCA_GRABBER_CAMERALINK_TYPE, &val); - - val = UCA_FORMAT_GRAY8; - grabber->set_property(grabber, UCA_GRABBER_FORMAT, &val); - - val = UCA_TRIGGER_AUTO; - grabber->set_property(grabber, UCA_GRABBER_TRIGGER_MODE, &val); - - grabber->get_property(grabber, UCA_PROP_WIDTH, &uca->frame_width); - grabber->get_property(grabber, UCA_PROP_HEIGHT, &uca->frame_height); - - uca->state = UCA_CAM_CONFIGURABLE; - *cam = uca; - - return UCA_NO_ERROR; -} diff --git a/src/cameras/simple.h b/src/cameras/simple.h deleted file mode 100644 index 6d8e45e..0000000 --- a/src/cameras/simple.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu> - (Karlsruhe Institute of Technology) - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - - You should have received a copy of the GNU Lesser General Public License along - with this library; if not, write to the Free Software Foundation, Inc., 51 - Franklin St, Fifth Floor, Boston, MA 02110, USA */ - -#ifndef __UNIFIED_CAMERA_ACCESS_SIMPLE_H -#define __UNIFIED_CAMERA_ACCESS_SIMPLE_H - -uint32_t uca_simple_init(struct uca_camera_priv **uca, struct uca_grabber_priv *grabber); - -#endif |