/alps/ipecamera

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/ipecamera

« back to all changes in this revision

Viewing changes to apps/grab.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-04-29 02:50:52 UTC
  • Revision ID: csa@suren.me-20150429025052-2ivr7bkemzj7svzi
Added a small grabbing example

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
 
 
3
#include <pcilib.h>
 
4
#include <pcilib/error.h>
 
5
 
 
6
#include <ipecamera.h>
 
7
 
 
8
int main() {
 
9
    int err;
 
10
    pcilib_event_id_t evid;
 
11
    ipecamera_event_info_t info;
 
12
    ipecamera_t *ipecamera;
 
13
    size_t size;
 
14
    void *data;
 
15
    FILE *f;
 
16
 
 
17
    pcilib_t *pcilib = pcilib_open("/dev/fpga0", "ipecamera");
 
18
    if (!pcilib) pcilib_error("Error opening device");
 
19
 
 
20
    ipecamera = (ipecamera_t*)pcilib_get_event_engine(pcilib);
 
21
    if (!ipecamera) pcilib_error("Failed to get ipecamera event engine");
 
22
 
 
23
    err = ipecamera_set_buffer_size(ipecamera, 8);
 
24
    if (err) pcilib_error("Error (%i) setting buffer size", err);
 
25
 
 
26
    err = pcilib_start(pcilib, PCILIB_EVENTS_ALL, PCILIB_EVENT_FLAGS_DEFAULT);
 
27
    if (err) pcilib_error("Error (%i) starting event engine", err);
 
28
 
 
29
    err = pcilib_trigger(pcilib, PCILIB_EVENT0, 0, NULL);
 
30
    if (err) pcilib_error("Error (%i) triggering event", err);
 
31
 
 
32
    err = pcilib_get_next_event(pcilib, 100000, &evid, sizeof(info), (pcilib_event_info_t*)&info);
 
33
    if (err) pcilib_error("Error (%i) while waiting for event", err);
 
34
 
 
35
    data = pcilib_get_data(pcilib, evid, PCILIB_EVENT_DATA, &size);
 
36
    if (!data) pcilib_error("Error getting event data");
 
37
 
 
38
    printf("Writting %zu bytes to /dev/null\n", size);
 
39
    f = fopen("/dev/null", "w");
 
40
    if (f) {
 
41
        fwrite(data, 1, size, f);
 
42
        fclose(f);
 
43
    }
 
44
 
 
45
    err = pcilib_return_data(pcilib, evid, PCILIB_EVENT_DATA, data);
 
46
    if (err) pcilib_error("Error returning data, data is possibly corrupted");
 
47
 
 
48
    pcilib_stop(pcilib, PCILIB_EVENT_FLAGS_DEFAULT);
 
49
}