findconfig.c 1.8 KB

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