summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de>2011-02-28 17:48:55 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de>2011-02-28 17:48:55 +0100
commit28873ccf3f3f32486049eb40cd639bbab86e09dc (patch)
tree1411086a03efeee7ce8051a362bc2f83ac2a929b
parentf6f2bafe19fd57c56201e79be6b7692f16f16099 (diff)
downloaduca-28873ccf3f3f32486049eb40cd639bbab86e09dc.tar.gz
uca-28873ccf3f3f32486049eb40cd639bbab86e09dc.tar.bz2
uca-28873ccf3f3f32486049eb40cd639bbab86e09dc.tar.xz
uca-28873ccf3f3f32486049eb40cd639bbab86e09dc.zip
Start grab interface
-rw-r--r--src/cameras/pco.c24
-rw-r--r--src/grabbers/me4.c18
-rw-r--r--src/uca-cam.h12
-rw-r--r--src/uca-grabber.h12
-rw-r--r--src/uca.c1
-rw-r--r--test/grab.c19
6 files changed, 79 insertions, 7 deletions
diff --git a/src/cameras/pco.c b/src/cameras/pco.c
index 2547387..f65eb14 100644
--- a/src/cameras/pco.c
+++ b/src/cameras/pco.c
@@ -83,6 +83,9 @@ static uint32_t uca_pco_set_property(struct uca_camera_t *cam, enum uca_property
case UCA_PROP_DELAY:
return uca_pco_set_delay(cam, (uint32_t *) data);
+ case UCA_PROP_TIMESTAMP_MODE:
+ return pco_set_timestamp_mode(GET_PCO(cam), *((uint16_t *) data));
+
default:
return UCA_ERR_PROP_INVALID;
}
@@ -173,6 +176,23 @@ static uint32_t uca_pco_get_property(struct uca_camera_t *cam, enum uca_property
return UCA_NO_ERROR;
}
+uint32_t uca_pco_start_recording(struct uca_camera_t *cam)
+{
+ struct pco_edge_t *pco = GET_PCO(cam);
+ pco_arm_camera(pco);
+ pco_set_rec_state(pco, 1);
+ cam->grabber->acquire(cam->grabber, -1, true);
+}
+
+uint32_t uca_pco_stop_recording(struct uca_camera_t *cam)
+{
+ pco_set_rec_state(GET_PCO(cam), 0);
+}
+
+uint32_t uca_pco_grab(struct uca_camera_t *cam, char *buffer, size_t n_bytes)
+{
+ cam->grabber->grab(cam->grabber, buffer, n_bytes);
+}
uint32_t uca_pco_init(struct uca_camera_t **cam, struct uca_grabber_t *grabber)
{
@@ -195,7 +215,9 @@ uint32_t uca_pco_init(struct uca_camera_t **cam, struct uca_grabber_t *grabber)
uca->destroy = &uca_pco_destroy;
uca->set_property = &uca_pco_set_property;
uca->get_property = &uca_pco_get_property;
- uca->acquire_image = &uca_pco_acquire_image;
+ uca->start_recording = &uca_pco_start_recording;
+ uca->stop_recording = &uca_pco_stop_recording;
+ uca->grab = &uca_pco_grab;
/* Prepare camera for recording */
pco_set_rec_state(pco, 0);
diff --git a/src/grabbers/me4.c b/src/grabbers/me4.c
index 5b46c79..2196172 100644
--- a/src/grabbers/me4.c
+++ b/src/grabbers/me4.c
@@ -1,5 +1,6 @@
#include <stdlib.h>
+#include <string.h>
#include <clser.h>
#include <fgrab_struct.h>
#include <fgrab_prototyp.h>
@@ -49,6 +50,21 @@ uint32_t uca_me4_alloc(struct uca_grabber_t *grabber, uint32_t n_buffers)
return UCA_ERR_PROP_GENERAL;
}
+uint32_t uca_me4_acquire(struct uca_grabber_t *grabber, int32_t n_frames, bool async)
+{
+ if (GET_MEM(grabber) != NULL) {
+ if (Fg_AcquireEx(GET_FG(grabber), 0, n_frames, ACQ_STANDARD, GET_MEM(grabber)) != FG_OK)
+ return UCA_NO_ERROR;
+ }
+ return UCA_ERR_PROP_GENERAL;
+}
+
+uint32_t uca_me4_grab(struct uca_grabber_t *grabber, char *buffer, size_t n_bytes)
+{
+ uint32_t last_frame = Fg_getLastPicNumber(GET_FG(grabber), PORT_A);
+ memcpy(buffer, Fg_getImagePtrEx(GET_FG(grabber), last_frame, PORT_A, GET_MEM(grabber)), n_bytes);
+}
+
uint32_t uca_me4_init(struct uca_grabber_t **grabber)
{
/* FIXME: find out if this board/grabber is running */
@@ -66,6 +82,8 @@ uint32_t uca_me4_init(struct uca_grabber_t **grabber)
uca->set_property = &uca_me4_set_property;
uca->get_property = &uca_me4_get_property;
uca->alloc = &uca_me4_alloc;
+ uca->acquire = &uca_me4_acquire;
+ uca->grab = &uca_me4_grab;
*grabber = uca;
return UCA_NO_ERROR;
diff --git a/src/uca-cam.h b/src/uca-cam.h
index 9f0c057..f9db0b7 100644
--- a/src/uca-cam.h
+++ b/src/uca-cam.h
@@ -47,11 +47,11 @@ typedef uint32_t (*uca_cam_set_property) (struct uca_camera_t *cam, enum uca_pro
*/
typedef uint32_t (*uca_cam_get_property) (struct uca_camera_t *cam, enum uca_property_ids property, void *data);
-/**
- * \brief Acquire one frame
- */
-typedef uint32_t (*uca_cam_acquire_image) (struct uca_camera_t *cam, void *buffer);
+typedef uint32_t (*uca_cam_start_recording) (struct uca_camera_t *cam);
+
+typedef uint32_t (*uca_cam_stop_recording) (struct uca_camera_t *cam);
+typedef uint32_t (*uca_cam_grab) (struct uca_camera_t *cam, char *buffer, size_t n_bytes);
enum uca_cam_state {
@@ -67,7 +67,9 @@ struct uca_camera_t {
/* Function pointers to camera-specific methods */
uca_cam_set_property set_property;
uca_cam_get_property get_property;
- uca_cam_acquire_image acquire_image;
+ uca_cam_start_recording start_recording;
+ uca_cam_stop_recording stop_recording;
+ uca_cam_grab grab;
/* Private */
uca_cam_destroy destroy;
diff --git a/src/uca-grabber.h b/src/uca-grabber.h
index 0ae229d..0e203e1 100644
--- a/src/uca-grabber.h
+++ b/src/uca-grabber.h
@@ -1,6 +1,8 @@
#ifndef __UNIFIED_CAMERA_ACCESS_GRABBER_H
#define __UNIFIED_CAMERA_ACCESS_GRABBER_H
+#include <stdbool.h>
+
/*
* --- virtual methods --------------------------------------------------------
*/
@@ -37,6 +39,14 @@ typedef uint32_t (*uca_grabber_get_property) (struct uca_grabber_t *grabber, enu
*/
typedef uint32_t (*uca_grabber_alloc) (struct uca_grabber_t *grabber, uint32_t n_buffers);
+/**
+ * \brief Begin acquiring frames
+ * \param[in] n_frames Number of frames to acquire, -1 means infinite number
+ * \param[in] async Grab asynchronous if true
+ */
+typedef uint32_t (*uca_grabber_acquire) (struct uca_grabber_t *grabber, int32_t n_frames, bool async);
+
+typedef uint32_t (*uca_grabber_grab) (struct uca_grabber_t *grabber, char *buffer, size_t n_bytes);
struct uca_grabber_t {
@@ -47,6 +57,8 @@ struct uca_grabber_t {
uca_grabber_set_property set_property;
uca_grabber_get_property get_property;
uca_grabber_alloc alloc;
+ uca_grabber_acquire acquire;
+ uca_grabber_grab grab;
/* Private */
void *user;
diff --git a/src/uca.c b/src/uca.c
index 7733411..39b45b4 100644
--- a/src/uca.c
+++ b/src/uca.c
@@ -91,6 +91,7 @@ struct uca_t *uca_init()
/* FIXME: we don't only want to take the first one */
if (init(&grabber) != UCA_ERR_INIT_NOT_FOUND)
break;
+ i++;
}
if (grabber == NULL) {
diff --git a/test/grab.c b/test/grab.c
index 91a3cdc..34453da 100644
--- a/test/grab.c
+++ b/test/grab.c
@@ -1,5 +1,6 @@
#include <stdio.h>
+#include <stdlib.h>
#include "uca.h"
#include "uca-cam.h"
@@ -19,9 +20,25 @@ int main(int argc, char *argv[])
val = 0;
cam->set_property(cam, UCA_PROP_DELAY, &val);
+ uint32_t width, height;
+ cam->get_property(cam, UCA_PROP_WIDTH, &width);
+ cam->get_property(cam, UCA_PROP_HEIGHT, &height);
+ printf("Image dimensions: %ix%i\n", width, height);
+
if (uca_cam_alloc(cam, 20) != UCA_NO_ERROR)
printf("Couldn't allocate buffer memory\n");
-
+
+ uint16_t *buffer = (uint16_t *) malloc(width * height * 2);
+
+ cam->start_recording(cam);
+ cam->grab(cam, (char *) buffer, width*height*2);
+ cam->stop_recording(cam);
uca_destroy(uca);
+
+ FILE *fp = fopen("out.raw", "wb");
+ fwrite(buffer, width*height, 2, fp);
+ fclose(fp);
+
+ free(buffer);
return 0;
}