From f6f2bafe19fd57c56201e79be6b7692f16f16099 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Mon, 28 Feb 2011 16:53:29 +0100 Subject: Add grab example --- test/CMakeLists.txt | 6 +++-- test/enum.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ test/grab.c | 27 +++++++++++++++++++ test/test.c | 76 ----------------------------------------------------- 4 files changed, 107 insertions(+), 78 deletions(-) create mode 100644 test/enum.c create mode 100644 test/grab.c delete mode 100644 test/test.c (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b8dfce7..3f1e2a5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,6 +4,8 @@ add_definitions("--std=c99 -Wall") include_directories(${CMAKE_SOURCE_DIR}/src) -add_executable(test test.c) +add_executable(enum enum.c) +add_executable(grab grab.c) -target_link_libraries(test uca) +target_link_libraries(enum uca) +target_link_libraries(grab uca) diff --git a/test/enum.c b/test/enum.c new file mode 100644 index 0000000..0649c64 --- /dev/null +++ b/test/enum.c @@ -0,0 +1,76 @@ + +#include +#include "uca.h" +#include "uca-cam.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[]) +{ + struct uca_t *uca = uca_init(); + if (uca == NULL) { + printf("Couldn't find a camera\n"); + return 1; + } + + /* take first camera */ + struct uca_camera_t *cam = uca->cameras; + + char string_value[256]; + uint32_t uint32_value; + uint8_t uint8_value; + + const char *unit_map[] = { + "px", "bits", "ns", "µs", "ms", "s", "rows", "" + }; + + while (cam != NULL) { + for (int i = 0; i < UCA_PROP_LAST; i++) { + struct uca_property_t *prop = uca_get_full_property(i); + print_level(count_dots(prop->name)); + printf("%s = ", prop->name); + switch (prop->type) { + case uca_string: + if (cam->get_property(cam, i, string_value) != UCA_ERR_PROP_INVALID) { + printf("%s ", string_value); + } + else + printf("n/a"); + break; + case uca_uint32t: + if (cam->get_property(cam, i, &uint32_value) != UCA_ERR_PROP_INVALID) { + printf("%i %s", uint32_value, unit_map[prop->unit]); + } + else + printf("n/a"); + break; + case uca_uint8t: + if (cam->get_property(cam, i, &uint8_value) != UCA_ERR_PROP_INVALID) { + printf("%i %s", uint8_value, unit_map[prop->unit]); + } + else + printf("n/a"); + break; + } + printf("\n"); + } + cam = cam->next; + } + + uca_destroy(uca); + return 0; +} diff --git a/test/grab.c b/test/grab.c new file mode 100644 index 0000000..91a3cdc --- /dev/null +++ b/test/grab.c @@ -0,0 +1,27 @@ + +#include +#include "uca.h" +#include "uca-cam.h" + +int main(int argc, char *argv[]) +{ + struct uca_t *uca = uca_init(); + if (uca == NULL) { + printf("Couldn't find a camera\n"); + return 1; + } + + /* take first camera */ + struct uca_camera_t *cam = uca->cameras; + + uint32_t val = 5000; + cam->set_property(cam, UCA_PROP_EXPOSURE, &val); + val = 0; + cam->set_property(cam, UCA_PROP_DELAY, &val); + + if (uca_cam_alloc(cam, 20) != UCA_NO_ERROR) + printf("Couldn't allocate buffer memory\n"); + + uca_destroy(uca); + return 0; +} diff --git a/test/test.c b/test/test.c deleted file mode 100644 index 0649c64..0000000 --- a/test/test.c +++ /dev/null @@ -1,76 +0,0 @@ - -#include -#include "uca.h" -#include "uca-cam.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[]) -{ - struct uca_t *uca = uca_init(); - if (uca == NULL) { - printf("Couldn't find a camera\n"); - return 1; - } - - /* take first camera */ - struct uca_camera_t *cam = uca->cameras; - - char string_value[256]; - uint32_t uint32_value; - uint8_t uint8_value; - - const char *unit_map[] = { - "px", "bits", "ns", "µs", "ms", "s", "rows", "" - }; - - while (cam != NULL) { - for (int i = 0; i < UCA_PROP_LAST; i++) { - struct uca_property_t *prop = uca_get_full_property(i); - print_level(count_dots(prop->name)); - printf("%s = ", prop->name); - switch (prop->type) { - case uca_string: - if (cam->get_property(cam, i, string_value) != UCA_ERR_PROP_INVALID) { - printf("%s ", string_value); - } - else - printf("n/a"); - break; - case uca_uint32t: - if (cam->get_property(cam, i, &uint32_value) != UCA_ERR_PROP_INVALID) { - printf("%i %s", uint32_value, unit_map[prop->unit]); - } - else - printf("n/a"); - break; - case uca_uint8t: - if (cam->get_property(cam, i, &uint8_value) != UCA_ERR_PROP_INVALID) { - printf("%i %s", uint8_value, unit_map[prop->unit]); - } - else - printf("n/a"); - break; - } - printf("\n"); - } - cam = cam->next; - } - - uca_destroy(uca); - return 0; -} -- cgit v1.2.3