findconfig.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <libmegapixels.h>
  2. #include <stdio.h>
  3. #include <limits.h>
  4. #include <getopt.h>
  5. #include <ctype.h>
  6. int
  7. main(int argc, char *argv[])
  8. {
  9. int c;
  10. char configpath[PATH_MAX];
  11. int ret;
  12. int verbose = 0;
  13. while ((c = getopt(argc, argv, "c:v")) != -1) {
  14. switch (c) {
  15. case 'c':
  16. sprintf(configpath, "%s", optarg);
  17. ret = 1;
  18. break;
  19. case 'v':
  20. verbose = 1;
  21. break;
  22. case '?':
  23. if (optopt == 'd' || optopt == 'l') {
  24. fprintf(stderr, "Option -%c requires an argument.\n", optopt);
  25. } else if (isprint(optopt)) {
  26. fprintf(stderr, "Unknown option '-%c'\n", optopt);
  27. } else {
  28. fprintf(stderr, "Unknown option character x%x\n", optopt);
  29. }
  30. return 1;
  31. default:
  32. return 1;
  33. }
  34. }
  35. ret = libmegapixels_find_config_verbose(configpath, verbose);
  36. libmegapixels_devconfig *config = {0};
  37. libmegapixels_init(&config);
  38. if (!ret) {
  39. printf("No config found\n");
  40. } else {
  41. printf("Using config: %s\n", configpath);
  42. if (!libmegapixels_load_file(config, configpath)) {
  43. printf("Could not load config\n");
  44. }
  45. }
  46. libmegapixels_load_uvc(config);
  47. if (config->count == 0) {
  48. return 1;
  49. }
  50. printf("Device: %s %s\n", config->make, config->model);
  51. printf("Found %d cameras\n", config->count);
  52. for (int i = 0; i < config->count; i++) {
  53. printf("\n----[ Camera %s (%d) ]----\n", config->cameras[i]->name, config->cameras[i]->index);
  54. if (config->cameras[i]->bridge_name) {
  55. printf("Media : %s (%s)\n", config->cameras[i]->bridge_name, config->cameras[i]->media_path);
  56. }
  57. if (config->cameras[i]->sensor_name) {
  58. printf("Sensor: %s (%s)\n", config->cameras[i]->sensor_name, config->cameras[i]->sensor_path);
  59. }
  60. printf("Video : %s\n", config->cameras[i]->video_path);
  61. printf("Modes : ");
  62. for (int j = 0; j < config->cameras[i]->num_modes; j++) {
  63. if (j > 0) {
  64. printf(" ");
  65. }
  66. libmegapixels_mode *mode = config->cameras[i]->modes[j];
  67. printf("%dx%d@%d [%s]\n", mode->width, mode->height, mode->rate, libmegapixels_format_name(mode->format));
  68. }
  69. }
  70. return 0;
  71. }