diff --git a/util/findconfig.c b/util/findconfig.c index ee8f18a..9568eb1 100644 --- a/util/findconfig.c +++ b/util/findconfig.c @@ -31,7 +31,7 @@ main() if (j > 0) { printf(" "); } - libmegapixels_mode *mode = &config->cameras[i]->modes[j]; + libmegapixels_mode *mode = config->cameras[i]->modes[j]; printf("%dx%d@%d\n", mode->width, mode->height, mode->rate); } diff --git a/util/getframe.c b/util/getframe.c index e283ebf..9613fb5 100644 --- a/util/getframe.c +++ b/util/getframe.c @@ -6,9 +6,10 @@ #include #include #include -#include #include #include +#include +#include struct buffer { void *start; @@ -27,8 +28,38 @@ xioctl(int fd, int request, void *arg) } int -main() +main(int argc, char *argv[]) { + int c; + int camera_id = 0; + long res; + char *end; + + while ((c = getopt(argc, argv, "c:")) != -1) { + switch (c) { + case 'c': + res = strtol(optarg, &end, 10); + if (end == optarg || end == NULL || *end != '\0') { + fprintf(stderr, "Invalid number for -c\n"); + return 1; + } + camera_id = (int) res; + break; + case '?': + if (optopt == 'd' || optopt == 'l') { + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + } else if (isprint(optopt)) { + fprintf(stderr, "Unknown option '-%c'\n", optopt); + } else { + fprintf(stderr, "Unknown option character x%x\n", optopt); + } + return 1; + default: + return 1; + } + } + + char configpath[PATH_MAX]; int ret = libmegapixels_find_config(configpath); libmegapixels_devconfig *config = {0}; @@ -45,7 +76,11 @@ main() return 1; } - libmegapixels_camera *camera = config->cameras[0]; + if (camera_id > config->count) { + fprintf(stderr, "Camera id %d does not exist\n", camera_id); + } + + libmegapixels_camera *camera = config->cameras[camera_id]; if (libmegapixels_open(camera) != 0) { fprintf(stderr, "Could not open default camera\n"); return 1;