Add camera selection in getframe
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
@@ -6,9 +6,10 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
#include <getopt.h>
|
||||
#include <ctype.h>
|
||||
|
||||
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;
|
||||
|
Reference in New Issue
Block a user