diff options
-rw-r--r-- | src/uca.c | 65 | ||||
-rw-r--r-- | src/uca.h | 27 | ||||
-rw-r--r-- | test/CMakeLists.txt | 3 | ||||
-rw-r--r-- | test/test.c | 76 |
4 files changed, 122 insertions, 49 deletions
@@ -59,48 +59,55 @@ void uca_destroy(struct uca_t *uca) } } -static const char* property_map[] = { - "name", - "width", - "width.min", - "width.max", - "height", - "height.min", - "height.max", - "offset.x", - "offset.y", - "bit-depth", - "exposure", - "exposure.min", - "exposure.max", - "delay", - "delay.min", - "delay.max", - "trigger-mode", - "frame-rate", - "timestamp-mode", - "scan-mode", - "interlace.sample-rate", - "interlace.threshold.pixel", - "interlace.threshold.row", - "correction-mode", - NULL +static struct uca_property_t property_map[UCA_PROP_LAST] = { + { "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 }, + { "bit-depth", uca_pixel, 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 }, + { "frame-rate", uca_na, uca_uint32t }, + { "trigger-mode", uca_na, uca_uint32t }, + { "timestamp-mode", uca_na, uca_uint32t }, + { "scan-mode", uca_na, uca_uint32t }, + { "interlace.sample-rate", uca_na, uca_uint32t }, + { "interlace.threshold.pixel", uca_na, uca_uint32t }, + { "interlace.threshold.row", uca_na, uca_uint32t }, + { "correction-mode", uca_na, uca_uint32t }, + { NULL, 0, 0 } }; int32_t uca_get_property_id(const char *property_name) { char *name; int i = 0; - while (property_map[i] != NULL) { - if (!strcmp(property_map[i], property_name)) + while (property_map[i].name != NULL) { + if (!strcmp(property_map[i].name, property_name)) return i; i++; } return UCA_PROP_INVALID; } +struct uca_property_t *uca_get_full_property(int32_t property_id) +{ + if ((property_id >= 0) && (property_id < UCA_PROP_LAST)) + return &property_map[property_id]; + return NULL; +} + const char* uca_get_property_name(int32_t property_id) { /* TODO: guard that thing */ - return property_map[property_id]; + return property_map[property_id].name; } @@ -14,6 +14,7 @@ #include <stdint.h> struct uca_t; +struct uca_property_t; /** * \brief Camera probing and initialization @@ -73,6 +74,7 @@ int32_t uca_get_property_id(const char *property_name); */ const char* uca_get_property_name(int32_t property_id); +struct uca_property_t *uca_get_full_property(int32_t property_id); #define UCA_NO_ERROR 0 #define UCA_ERR_INIT_NOT_FOUND 1 /**< camera probing or initialization failed */ @@ -115,7 +117,9 @@ const char* uca_get_property_name(int32_t property_id); #define UCA_PROP_INTERLACE_ROW_THRESH 24 /* Photon Focus specific */ -#define UCA_PROP_CORRECTION_MODE 21 +#define UCA_PROP_CORRECTION_MODE 25 + +#define UCA_PROP_LAST 26 /* Possible timestamp modes for UCA_PROP_TIMESTAMP_MODE */ #define UCA_TIMESTAMP_ASCII 0x01 @@ -131,6 +135,27 @@ const char* uca_get_property_name(int32_t property_id); #define UCA_CORRECT_HOTPIXEL 0x02 #define UCA_CORRECT_GAIN 0x04 +struct uca_property_t { + const char *name; + + enum uca_unit { + uca_pixel, + uca_bits, + uca_ns, + uca_us, + uca_ms, + uca_s, + uca_rows, + uca_na + } unit; + + enum uca_types { + uca_uint32t, + uca_uint8t, + uca_string + } type; +}; + struct uca_t { /* Function pointers to camera-specific methods */ uca_cam_set_property cam_set_property; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f560df3..b8dfce7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 2.8) +add_definitions("--std=c99 -Wall") + include_directories(${CMAKE_SOURCE_DIR}/src) + add_executable(test test.c) target_link_libraries(test uca) diff --git a/test/test.c b/test/test.c index 6537b6b..0f5b6fe 100644 --- a/test/test.c +++ b/test/test.c @@ -2,32 +2,70 @@ #include <stdio.h> #include "uca.h" +int count_dots(const char *s) +{ + int res = 0; + while (*(s++) != '\0') + if (*s == '.') + res++; + return res; +} + +void print_level(int depth) +{ + for (int i = 0; i < depth; i++) + printf("| "); + printf("`-- "); +} + int main(int argc, char *argv[]) { - if (argc < 2) { - printf("usage: uca <property-name>\n"); + struct uca_t *uca = uca_init(); + if (uca == NULL) { + printf("Couldn't find a camera\n"); return 1; } - else { - int property = uca_get_property_id(argv[1]); - if (property == UCA_PROP_INVALID) { - printf("Property invalid!\n"); - return 1; - } - struct uca_t *uca = uca_init(); - if (uca == NULL) { - printf("Couldn't find a camera\n"); - return 1; - } + char string_value[256]; + uint32_t uint32_value; + uint8_t uint8_value; - uint32_t value; /* this type should be right, most of the time */ - if (uca->cam_get_property(uca, property, &value) == UCA_PROP_INVALID) - printf("Property not supported on this camera\n"); - else - printf("%s = %u\n", argv[1], value); + const char *unit_map[] = { + "px", + "bits", + "ns", + "µs", + "ms", + "s", + "rows", + "" + }; - uca_destroy(uca); + for (int i = 0; i < UCA_PROP_LAST-2; i++) { + struct uca_property_t *prop = uca_get_full_property(i); + switch (prop->type) { + case uca_string: + if (uca->cam_get_property(uca, i, string_value) != UCA_PROP_INVALID) { + print_level(count_dots(prop->name)); + printf("%s = %s %s ", prop->name, string_value, unit_map[prop->unit]); + } + break; + case uca_uint32t: + if (uca->cam_get_property(uca, i, &uint32_value) != UCA_PROP_INVALID) { + print_level(count_dots(prop->name)); + printf("%s = %i %s ", prop->name, uint32_value, unit_map[prop->unit]); + } + break; + case uca_uint8t: + if (uca->cam_get_property(uca, i, &uint8_value) != UCA_PROP_INVALID) { + print_level(count_dots(prop->name)); + printf("%s = %i %s ", prop->name, uint8_value, unit_map[prop->unit]); + } + break; + } + printf("\n"); } + + uca_destroy(uca); return 0; } |