summaryrefslogtreecommitdiffstats
path: root/ipecamera
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2011-04-14 04:21:38 +0200
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2011-04-14 04:21:38 +0200
commitb70ed8b6ccf17a7c5b4339f05a33471eaf3b33e5 (patch)
treea608941197e4ea1fa87a47cad013e3a7c768ca41 /ipecamera
parent0d9e1cfca235f68e55a4d81e60409110b8ccde41 (diff)
downloadpcitool-b70ed8b6ccf17a7c5b4339f05a33471eaf3b33e5.tar.gz
pcitool-b70ed8b6ccf17a7c5b4339f05a33471eaf3b33e5.tar.bz2
pcitool-b70ed8b6ccf17a7c5b4339f05a33471eaf3b33e5.tar.xz
pcitool-b70ed8b6ccf17a7c5b4339f05a33471eaf3b33e5.zip
Support non-callback way of getting events
Diffstat (limited to 'ipecamera')
-rw-r--r--ipecamera/image.c40
-rw-r--r--ipecamera/image.h2
-rw-r--r--ipecamera/model.h1
3 files changed, 42 insertions, 1 deletions
diff --git a/ipecamera/image.c b/ipecamera/image.c
index 8ad6953..3e320cd 100644
--- a/ipecamera/image.c
+++ b/ipecamera/image.c
@@ -37,6 +37,7 @@ struct ipecamera_s {
void *cb_user;
pcilib_event_id_t event_id;
+ pcilib_event_id_t reported_id;
pcilib_register_t control_reg, status_reg;
pcilib_register_t start_reg, end_reg;
@@ -253,6 +254,7 @@ int ipecamera_start(void *vctx, pcilib_event_t event_mask, pcilib_callback_t cb,
ctx->cb_user = user;
ctx->event_id = 0;
+ ctx->reported_id = 0;
ctx->buf_ptr = 0;
ctx->dim.width = 1270;
@@ -303,6 +305,7 @@ int ipecamera_stop(void *vctx) {
ctx->event_id = 0;
+ ctx->reported_id = 0;
ctx->buf_ptr = 0;
return 0;
@@ -504,7 +507,12 @@ int ipecamera_trigger(void *vctx, pcilib_event_t event, size_t trigger_size, voi
}
err = ipecamera_get_image(ctx);
- if (!err) err = ctx->cb(event, ctx->event_id, ctx->cb_user);
+ if (!err) {
+ if (ctx->cb) {
+ err = ctx->cb(event, ctx->event_id, ctx->cb_user);
+ ctx->reported_id = ctx->event_id;
+ }
+ }
return err;
}
@@ -524,6 +532,36 @@ static int ipecamera_resolve_event_id(ipecamera_t *ctx, pcilib_event_id_t evid)
return buf_ptr;
}
+pcilib_event_id_t ipecamera_next_event(void *vctx, pcilib_event_t event_mask) {
+ int buf_ptr;
+ pcilib_event_id_t reported;
+ ipecamera_t *ctx = (ipecamera_t*)vctx;
+
+ if (!ctx) {
+ pcilib_error("IPECamera imaging is not initialized");
+ return PCILIB_EVENT_ID_INVALID;
+ }
+
+ if (!ctx->started) {
+ pcilib_error("IPECamera is not in grabbing state");
+ return PCILIB_EVENT_ID_INVALID;
+ }
+
+ if ((!ctx->event_id)||(ctx->reported_id == ctx->event_id)) return PCILIB_EVENT_ID_INVALID;
+
+ // We had an overflow in event counting
+ if (ctx->reported_id > ctx->event_id) {
+ do {
+ if (++ctx->reported_id == 0) ctx->reported_id = 1;
+ } while (ipecamera_resolve_event_id(ctx, ctx->reported_id) < 0);
+ } else {
+ if ((ctx->event_id - ctx->reported_id) > ctx->buffer_size) ctx->reported_id = ctx->event_id - (ctx->buffer_size - 1);
+ else ++ctx->reported_id;
+ }
+
+ return ctx->reported_id;
+}
+
void* ipecamera_get(void *vctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t arg_size, void *arg, size_t *size) {
int buf_ptr;
ipecamera_t *ctx = (ipecamera_t*)vctx;
diff --git a/ipecamera/image.h b/ipecamera/image.h
index 6b92524..513449f 100644
--- a/ipecamera/image.h
+++ b/ipecamera/image.h
@@ -13,9 +13,11 @@ int ipecamera_reset(void *ctx);
int ipecamera_start(void *ctx, pcilib_event_t event_mask, pcilib_callback_t cb, void *user);
int ipecamera_stop(void *ctx);
int ipecamera_trigger(void *ctx, pcilib_event_t event, size_t trigger_size, void *trigger_data);
+pcilib_event_id_t ipecamera_next_event(void *ctx, pcilib_event_t event_mask);
void* ipecamera_get(void *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t arg_size, void *arg, size_t *size);
int ipecamera_return(void *ctx, pcilib_event_id_t event_id);
+
#endif /* _IPECAMERA_IMAGE_H */
diff --git a/ipecamera/model.h b/ipecamera/model.h
index 07f405a..c3d82e3 100644
--- a/ipecamera/model.h
+++ b/ipecamera/model.h
@@ -105,6 +105,7 @@ pcilib_event_api_description_t ipecamera_image_api = {
ipecamera_stop,
ipecamera_trigger,
+ ipecamera_next_event,
ipecamera_get,
ipecamera_return
};