summaryrefslogtreecommitdiffstats
path: root/src/uca.c
blob: 3e016d1390c195c858c123fbcbffbe2da937c45d (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include <stdlib.h>

#include "config.h"
#include "uca.h"
#include "uca-cam.h"
#include "uca-grabber.h"

#ifdef HAVE_ME4
#include "grabbers/me4.h"
#endif

#ifdef HAVE_PCO_EDGE
#include "cameras/pco.h"
#endif

#ifdef HAVE_PHOTON_FOCUS
#include "cameras/pf.h"
#endif

#ifdef HAVE_IPE_CAM
#include "cameras/ipe.h"
#endif

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

const char *uca_unit_map[] = {
    "px",
    "bits",
    "ns",
    "µs",
    "ms",
    "s",
    "rows",
    "fps",
    "°C",
    "" 
};

static struct uca_property_t property_map[UCA_PROP_LAST+1] = {
    { "General.Name",           uca_na,     uca_string,  uca_read }, 
    { "Image.Width",            uca_pixel,  uca_uint32t, uca_readwrite }, 
    { "Image.Width.Min",        uca_pixel,  uca_uint32t, uca_read }, 
    { "Image.Width.Max",        uca_pixel,  uca_uint32t, uca_read }, 
    { "Image.Height",           uca_pixel,  uca_uint32t, uca_readwrite }, 
    { "Image.Height.Min",       uca_pixel,  uca_uint32t, uca_read }, 
    { "Image.Height.Max",       uca_pixel,  uca_uint32t, uca_read }, 
    { "Image.Offset.x",         uca_pixel,  uca_uint32t, uca_readwrite }, 
    { "Image.Offset.x.Min",     uca_pixel,  uca_uint32t, uca_read }, 
    { "Image.Offset.x.Max",     uca_pixel,  uca_uint32t, uca_read }, 
    { "Image.Offset.y",         uca_pixel,  uca_uint32t, uca_readwrite }, 
    { "Image.Offset.y.Min",     uca_pixel,  uca_uint32t, uca_read }, 
    { "Image.Offset.y.Max",     uca_pixel,  uca_uint32t, uca_read }, 
    { "Image.Bitdepth",         uca_bits,   uca_uint32t, uca_read}, 
    { "Time.Exposure",          uca_us,     uca_uint32t, uca_readwrite }, 
    { "Time.Exposure.Min",      uca_us,     uca_uint32t, uca_read }, 
    { "Time.Exposure.Max",      uca_us,     uca_uint32t, uca_read }, 
    { "Time.Delay",             uca_us,     uca_uint32t, uca_readwrite }, 
    { "Time.Delay.Min",         uca_us,     uca_uint32t, uca_read }, 
    { "Time.Delay.Max",         uca_us,     uca_uint32t, uca_read }, 
    { "Time.Framerate",         uca_fps,    uca_uint32t, uca_read }, 
    { "Temperature.Sensor",     uca_dc,     uca_uint32t, uca_read },
    { "Temperature.Camera",     uca_dc,     uca_uint32t, uca_read },
    { "Trigger.Mode",           uca_na,     uca_uint32t, uca_readwrite }, 
    { "Trigger.Exposure",       uca_na,     uca_uint32t, uca_readwrite },
    { "Mode.Timestamp",         uca_na,     uca_uint32t, uca_readwrite }, 
    { "Mode.Scan",              uca_na,     uca_uint32t, uca_readwrite }, 
    { "Interlace.Samplerate",   uca_na,     uca_uint32t, uca_readwrite }, 
    { "Interlace.Threshold.Pixel", uca_na,  uca_uint32t, uca_readwrite }, 
    { "Interlace.Threshold.Row", uca_na,    uca_uint32t, uca_readwrite },
    { "Mode.correction",        uca_na,     uca_uint32t, uca_readwrite }, 
    { NULL, 0, 0, 0 }
};

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

    uca_grabber_init grabber_inits[] = {
#ifdef HAVE_ME4
        uca_me4_init,
#endif
        NULL
    };

    uca_cam_init cam_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;

    /* Probe each frame grabber that is configured */
    struct uca_grabber_t *grabber = NULL;
    while (grabber_inits[i] != NULL) {
        uca_grabber_init init = grabber_inits[i];
        /* FIXME: we don't only want to take the first one */
        if (init(&grabber) != UCA_ERR_GRABBER_NOT_FOUND)
            break;
        i++;
    }

    if (grabber == NULL) {
        free(uca);
        return NULL;
    }
    uca->grabbers = grabber;
    grabber->next = NULL;

    /* Probe each camera that is configured */
    i = 0;
    while (cam_inits[i] != NULL) {
        struct uca_camera_t *cam = NULL;
        uca_cam_init init = cam_inits[i];
        if (init(&cam, grabber) != UCA_ERR_CAM_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 *cam = uca->cameras, *tmp;
        while (cam != NULL) {
            tmp = cam;
            cam->destroy(cam);
            cam = cam->next;
            free(tmp);
        }

        struct uca_grabber_t *grabber = uca->grabbers, *tmpg;
        while (grabber != NULL) {
            tmpg = grabber;
            grabber->destroy(grabber);
            grabber = grabber->next;
            free(grabber);
        }

        free(uca);
    }
}

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;
}