findconfig.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. if (!ret) {
  33. printf("No config found\n");
  34. return 1;
  35. }
  36. printf("Using config: %s\n", configpath);
  37. if (!libmegapixels_load_file(&config, configpath)) {
  38. return 1;
  39. }
  40. printf("Device: %s %s\n", config->make, config->model);
  41. printf("Found %d cameras\n", config->count);
  42. for (int i = 0; i < config->count; i++) {
  43. printf("\n----[ Camera %s (%d) ]----\n", config->cameras[i]->name, i);
  44. printf("Media : %s (%s)\n", config->cameras[i]->bridge_name, config->cameras[i]->media_path);
  45. printf("Sensor: %s (%s)\n", config->cameras[i]->sensor_name, config->cameras[i]->sensor_path);
  46. printf("Bridge: %s\n", config->cameras[i]->video_path);
  47. printf("Modes : ");
  48. for (int j = 0; j < config->cameras[i]->num_modes; j++) {
  49. if (j > 0) {
  50. printf(" ");
  51. }
  52. libmegapixels_mode *mode = config->cameras[i]->modes[j];
  53. printf("%dx%d@%d\n", mode->width, mode->height, mode->rate);
  54. }
  55. }
  56. return 0;
  57. }