Add camera selection in getframe

This commit is contained in:
Martijn Braam
2023-07-08 21:06:56 +02:00
parent 2ee1da5bfe
commit a01f25f2d7
2 changed files with 39 additions and 4 deletions

View File

@@ -31,7 +31,7 @@ main()
if (j > 0) { if (j > 0) {
printf(" "); 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); printf("%dx%d@%d\n", mode->width, mode->height, mode->rate);
} }

View File

@@ -6,9 +6,10 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h>
#include <errno.h> #include <errno.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <getopt.h>
#include <ctype.h>
struct buffer { struct buffer {
void *start; void *start;
@@ -27,8 +28,38 @@ xioctl(int fd, int request, void *arg)
} }
int 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]; char configpath[PATH_MAX];
int ret = libmegapixels_find_config(configpath); int ret = libmegapixels_find_config(configpath);
libmegapixels_devconfig *config = {0}; libmegapixels_devconfig *config = {0};
@@ -45,7 +76,11 @@ main()
return 1; 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) { if (libmegapixels_open(camera) != 0) {
fprintf(stderr, "Could not open default camera\n"); fprintf(stderr, "Could not open default camera\n");
return 1; return 1;