summaryrefslogtreecommitdiffstats
path: root/src/uca.c
blob: f86864c377b9fcaebf8b2ed63be8782a32df9eed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <stdlib.h>

#include "config.h"
#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

#ifdef HAVE_PHOTRON_FASTCAM
#include "cameras/uca_photron.h"
#endif


struct uca_t *uca_init()
{
    struct uca_t *uca = (struct uca_t *) malloc(sizeof(struct uca_t));
    uca->cameras = NULL;

    uca_cam_init inits[] = {
#ifdef HAVE_PCO_EDGE
        uca_pco_init,
#endif
#ifdef HAVE_PHOTON_FOCUS
        uca_pf_init,
#endif
#ifdef HAVE_IPE_CAM
        uca_ipe_init,
#endif
#ifdef HAVE_PH
        uca_photron_init,
#endif
    NULL };

    int i = 0;
    struct uca_camera_t* current = NULL;

    while (inits[i] != NULL) {
        struct uca_camera_t *cam = NULL;
        uca_cam_init init = inits[i];
        if (init(&cam) != UCA_ERR_INIT_NOT_FOUND) {
            if (current == NULL) 
                uca->cameras = current = cam;
            else {
                current->next = cam;
                current = cam;
            }
            current->next = NULL;
        }
        i++;
    }

    if (uca->cameras == NULL) {
        free(uca);
        return NULL;
    }
    return uca;
}

void uca_destroy(struct uca_t *uca)
{
    if (uca != NULL) {
        struct uca_camera_t *current = uca->cameras, *tmp;
        while (current != NULL) {
            tmp = current;
            current->destroy(current);
            current = current->next;
            free(tmp);
        }
        free(uca);
    }
}

enum uca_cam_state uca_get_camera_state(struct uca_camera_t *cam)
{
    return cam->state;
}

static struct uca_property_t property_map[UCA_PROP_LAST+1] = {
    { "name",           uca_na,     uca_string }, 
    { "width",          uca_pixel,  uca_uint32t }, 
    { "width.min",      uca_pixel,  uca_uint32t }, 
    { "width.max",      uca_pixel,  uca_uint32t }, 
    { "height",         uca_pixel,  uca_uint32t }, 
    { "height.min",     uca_pixel,  uca_uint32t }, 
    { "height.max",     uca_pixel,  uca_uint32t }, 
    { "offset.x",       uca_pixel,  uca_uint32t }, 
    { "offset.y",       uca_pixel,  uca_uint32t }, 
    { "bitdepth",       uca_bits,   uca_uint8t }, 
    { "exposure",       uca_us,     uca_uint32t }, 
    { "exposure.min",   uca_ns,     uca_uint32t }, 
    { "exposure.max",   uca_ms,     uca_uint32t }, 
    { "delay",          uca_us,     uca_uint32t }, 
    { "delay.min",      uca_ns,     uca_uint32t }, 
    { "delay.max",      uca_ms,     uca_uint32t }, 
    { "framerate",      uca_na,     uca_uint32t }, 
    { "triggermode",    uca_na,     uca_uint32t }, 
    { "timestampmode",  uca_na,     uca_uint32t }, 
    { "scan-mode",      uca_na,     uca_uint32t }, 
    { "interlace.samplerate", uca_na, uca_uint32t }, 
    { "interlace.threshold.pixel", uca_na, uca_uint32t }, 
    { "interlace.threshold.row", uca_na, uca_uint32t }, 
    { "correctionmode", uca_na, uca_uint32t }, 
    { NULL, 0, 0 }
};

enum uca_property_ids uca_get_property_id(const char *property_name)
{
    char *name;
    int i = 0;
    while (property_map[i].name != NULL) {
        if (!strcmp(property_map[i].name, property_name))
            return i;
        i++;
    }
    return UCA_ERR_PROP_INVALID;
}

struct uca_property_t *uca_get_full_property(enum uca_property_ids property_id)
{
    if ((property_id >= 0) && (property_id < UCA_PROP_LAST))
        return &property_map[property_id];
    return NULL;
}

const char* uca_get_property_name(enum uca_property_ids property_id)
{
    if ((property_id >= 0) && (property_id < UCA_PROP_LAST))
        return property_map[property_id].name;
}