From a10b4d2abbb2aafbcb398f659975d673b0181e8c Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Fri, 25 Feb 2011 17:44:23 +0100 Subject: Make the properties complete and build even better test app --- test/test.c | 76 +++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 19 deletions(-) (limited to 'test/test.c') 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 #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 \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; } -- cgit v1.2.3