findconfig.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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(PATH_MAX, 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. if (config->cameras[i]->flash_type == LIBMEGAPIXELS_FLASH_SCREEN) {
  62. printf("Flash : screen\n");
  63. } else {
  64. if (config->cameras[i]->flash_path) {
  65. switch (config->cameras[i]->flash_type) {
  66. case LIBMEGAPIXELS_FLASH_LED:
  67. printf("Flash : LED (%s)\n", config->cameras[i]->flash_path);
  68. break;
  69. case LIBMEGAPIXELS_FLASH_V4L:
  70. printf("Flash : V4L flash entity (%s)\n", config->cameras[i]->flash_path);
  71. break;
  72. }
  73. }
  74. }
  75. if (config->cameras[i]->lens_path) {
  76. printf("Focus : %s\n", config->cameras[i]->lens_path);
  77. }
  78. printf("Modes : ");
  79. for (int j = 0; j < config->cameras[i]->num_modes; j++) {
  80. if (j > 0) {
  81. printf(" ");
  82. }
  83. libmegapixels_mode *mode = config->cameras[i]->modes[j];
  84. printf("%dx%d@%d [%s]\n", mode->width, mode->height, mode->rate, libmegapixels_format_name(mode->format));
  85. }
  86. }
  87. return 0;
  88. }