示例#1
0
char controls_enumerate(int fd)
{
  struct v4l2_queryctrl queryctrl;
  memset (&queryctrl, 0, sizeof (queryctrl));

  for (queryctrl.id = V4L2_CID_BASE; queryctrl.id < V4L2_CID_LASTP1; queryctrl.id++) 
  {
    if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl))
    {
      if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
        continue;

      fprintf(stderr,"Control %s (0x%x)\n", queryctrl.name, queryctrl.id);
      fprintf(stderr,"min=%d, max=%d, default=%d\n", queryctrl.minimum, queryctrl.maximum, queryctrl.default_value);

      if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
        enumerate_menu(fd, &queryctrl);
    }
    else 
    {
      if (errno == EINVAL)
        continue;

      perror ("VIDIOC_QUERYCTRL");
      return 0;
    }
  }

  for (queryctrl.id = V4L2_CID_PRIVATE_BASE;; queryctrl.id++) 
  {
    if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) 
    {
      if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
        continue;
      fprintf(stderr,"Custom control %s (0x%x)\n", queryctrl.name, queryctrl.id);
      fprintf(stderr,"min=%d, max=%d, default=%d\n", queryctrl.minimum, queryctrl.maximum, queryctrl.default_value);
      if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
        enumerate_menu(fd, &queryctrl);
    }
    else 
    {
      if (errno == EINVAL)
        break;
      perror ("VIDIOC_QUERYCTRL");
      return 0;
    }
  }
  return 1;
}
示例#2
0
void explain_control_type(const char * label, struct v4l2_queryctrl queryctrl, int fd) { 
    fprintf(stderr, "%s ", label);
    fprintf (stderr, "Control %s:", queryctrl.name);

    switch (queryctrl.type) {
        case V4L2_CTRL_TYPE_INTEGER:
            /* tell me the range  */
            fprintf (stderr, "integer %d to %d in increments of %d\n", queryctrl.minimum, queryctrl.maximum, queryctrl.step);
            break;
        case V4L2_CTRL_TYPE_BOOLEAN:
            fprintf (stderr, "boolean %d or %d\n", queryctrl.minimum,
            queryctrl.maximum);
            break;
        case V4L2_CTRL_TYPE_MENU:
            enumerate_menu((char *)queryctrl.name, fd, queryctrl);
            break;
        case V4L2_CTRL_TYPE_BUTTON:
            ; /* empty statement  */
            fprintf(stderr, "(button)\n");
            break;
        #ifdef V4L2_CTRL_TYPE_INTEGER64
        case V4L2_CTRL_TYPE_INTEGER64:
            fprintf(stderr, "value is a 64-bit integer\n");
            break;
        #endif /* V4L2_CTRL_TYPE_INTEGER64  */
        #ifdef V4L2_CTRL_TYPE_CTRL_CLASS
        case V4L2_CTRL_TYPE_CTRL_CLASS:
            ;/* empty statement  */
            break;
        #endif /* V4L2_CTRL_TYPE_CTRL_CLASS  */
    default:
        fprintf(stderr, "Warning: unknown control type in %s\n", __FUNCTION__);
        break;
    }
}
示例#3
0
void camera_v4l2<Tdata>::print_controls() {
    cout << "__V4l2 camera controls___________________________________" << endl;

    struct v4l2_queryctrl queryctrl;
    struct v4l2_querymenu querymenu;

    memset (&queryctrl, 0, sizeof (queryctrl));
    for (queryctrl.id = V4L2_CID_BASE;
            queryctrl.id < V4L2_CID_LASTP1;
            queryctrl.id++) {
        if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {
            if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
                continue;

            cout << queryctrl.name << " (" << queryctrl.id << "): "
                 << get_control(queryctrl.id) << endl;

            if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
                enumerate_menu (fd, queryctrl, querymenu);
        } else {
            if (errno == EINVAL)
                continue;
            eblerror ("VIDIOC_QUERYCTRL");
        }
    }

    for (queryctrl.id = V4L2_CID_PRIVATE_BASE;;
            queryctrl.id++) {
        if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {
            if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
                continue;

            printf ("Control %s\n", queryctrl.name);

            if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
                enumerate_menu (fd, queryctrl, querymenu);
        } else {
            if (errno == EINVAL)
                break;
            eblerror ("VIDIOC_QUERYCTRL");
        }
    }
    cout << "_________________________________________________________" << endl;
}
/**
 * Gets name of control, and value to set it to
 * Changes the value of control to given value.
 */
void change_controls(void)
{
  printf("chooose a control to change: ");
  scanf("%d", &queryctrl.id);
  queryctrl.id += V4L2_CID_BASE;
  if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {
    //Can we control this?
    if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED){
      printf("not valid!\n");
      return;
    }

    printf ("% 2d Control %20s", queryctrl.id - V4L2_CID_BASE,
            queryctrl.name);
    struct v4l2_control control;
    memset (&control, 0, sizeof (control));
    control.id = queryctrl.id;
    //Get the current value
    if (0 == ioctl (fd, VIDIOC_G_CTRL, &control)) {
      printf ("% 9d% 9d% 9d\n",
              queryctrl.minimum, control.value, queryctrl.maximum);
    } else if (errno != EINVAL) {
      perror ("VIDIOC_G_CTRL - the Nao said we could control this, but it "
	      "won't tell us what the current value is.");
      exit (EXIT_FAILURE);
    }
    if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
      enumerate_menu ();

    printf("value to set to: %d-%d: ", queryctrl.minimum, queryctrl.maximum);
    scanf("%d", &control.value);
    /* Errors ignored */
    if (-1 == ioctl (fd, VIDIOC_S_CTRL, &control)
        && errno != ERANGE) {
      perror ("VIDIOC_S_CTRL");
      exit (EXIT_FAILURE);
    }
  } else {
    if (errno == EINVAL){
      printf("not valid!\n");
      return;
    }
    perror ("VIDIOC_QUERYCTRL");
    exit (EXIT_FAILURE);
  }
}
/**
 * Reads current controls values
 * Prints current values as well as min and max of each control
 */
void read_controls(void)
{
  __u32 id;

  memset (&queryctrl, 0, sizeof (queryctrl));

  for (id = V4L2_CID_BASE;
       // +32 to catch 'hidden' controls
       id < V4L2_CID_LASTP1 + 32;
       id++) {
    queryctrl.id = id;
    if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {
      //Can we control this?
      if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
        continue;

      printf ("%2d Control %22s", queryctrl.id - V4L2_CID_BASE,
              queryctrl.name);
      struct v4l2_control control;
      control.id = queryctrl.id;
      if(id != V4L2_CID_BASE + 33){ //causes a SIGKILL
         //Get the current value
         if (0 == ioctl (fd, VIDIOC_G_CTRL, &control)) {
            printf ("% 9d% 9d% 9d\n",
                    queryctrl.minimum, control.value, queryctrl.maximum);
         } else if (errno != EINVAL) {
            perror ("VIDIOC_G_CTRL - the Nao said we could control this, but "
                    "it won't tell us what the current value is.");
            exit (EXIT_FAILURE);
         }
      }
      else
         printf ("\n");
      if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
         enumerate_menu ();
    } else {
       if (errno == EINVAL)
          continue;

      perror ("VIDIOC_QUERYCTRL");
      exit (EXIT_FAILURE);
    }
  }

  for (queryctrl.id = V4L2_CID_PRIVATE_BASE;; ++queryctrl.id) {
    if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {
      if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
        continue;

      printf ("%d Control %s\n", queryctrl.id - V4L2_CID_PRIVATE_BASE,
              queryctrl.name);

      if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
        enumerate_menu ();
    } else {
      if (errno == EINVAL)
        break;

      perror ("VIDIOC_QUERYCTRL");
      exit (EXIT_FAILURE);
    }
  }
}
int main(int argc, char *argv[]) {

	if (argc >= 1 && NULL != argv[0]) {
		size_t n = strlen(argv[0]) + 1;
		program_name = allocate(n);
		strlcpy(program_name, argv[0], n);
	}

	static const char short_options[] = "hvd:";

	static const struct option
		long_options[] = {
		{ "help",    no_argument,       NULL, 'h' },
		{ "verbose", no_argument,       NULL, 'v' },
		{ "device",  required_argument, NULL, 'd' },
		{ 0, 0, 0, 0 }
	};

	device_name = "/dev/video0";

	int verbose = 0;

	for (;;) {
		int idx;
		int c;

		c = getopt_long(argc, argv, short_options, long_options, &idx);

		if (-1 == c) {
			break;
		}

		switch (c) {
		case 0: // getopt_long() flag
			break;

		case 'v':
			++verbose;
			break;

		case 'd':
			device_name = optarg;
			break;

		case 'h':
			usage(NULL);
			return 0;

		default:
			usage("invalid option: %c", c);
		}
	}

	int fd = open_device(device_name);

	// iterate through all controls and display their data
	struct v4l2_queryctrl queryctrl;
	memset(&queryctrl, 0, sizeof(queryctrl));

	for (queryctrl.id = V4L2_CID_BASE; queryctrl.id < V4L2_CID_LASTP1; ++queryctrl.id) {
		if (0 == ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
			if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
				continue;
			}

			struct v4l2_control control;
			memset (&control, 0, sizeof (control));
			control.id = queryctrl.id;

			if (0 != ioctl(fd, VIDIOC_G_CTRL, &control)) {
				usage("VIDIOC_G_CTRL error: (%d) '%s'", errno, strerror(errno));
			}

			printf("Control %s type: 0x%08x:\n"
			       "  value:   0x%08x  %10d\n"
			       "  minimum: 0x%08x  %10d\n"
			       "  maximum: 0x%08x  %10d\n"
			       "  step :   0x%08x  %10d\n"
			       "  default: 0x%08x  %10d\n"
			       "  flags:   0x%08x  %10d\n"
			       "",
			       queryctrl.name, queryctrl.type,
			       control.value, control.value,
			       queryctrl.minimum, queryctrl.minimum,
			       queryctrl.maximum, queryctrl.maximum,
			       queryctrl.step, queryctrl.step,
			       queryctrl.default_value, queryctrl.default_value,
			       queryctrl.flags, queryctrl.flags);

			if (queryctrl.type == V4L2_CTRL_TYPE_MENU) {
				enumerate_menu(fd, &queryctrl);
			}
		} else {
			if (errno == EINVAL) {
				continue;
			}
			usage("VIDIOC_QUERYCTRL error: (%d) '%s'", errno, strerror(errno));
		}
	}

	// check for any private controls
	for (queryctrl.id = V4L2_CID_PRIVATE_BASE; ; ++queryctrl.id) {
		if (0 == ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
			if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
				continue;
			}
			printf("Private Control %s type: 0x%08x:\n"
			       "  minimum: 0x%08x  %10d\n"
			       "  maximum: 0x%08x  %10d\n"
			       "  step :   0x%08x  %10d\n"
			       "  default: 0x%08x  %10d\n"
			       "  flags:   0x%08x  %10d\n"
			       "",
			       queryctrl.name, queryctrl.type,
			       queryctrl.minimum, queryctrl.minimum,
			       queryctrl.maximum, queryctrl.maximum,
			       queryctrl.step, queryctrl.step,
			       queryctrl.default_value, queryctrl.default_value,
			       queryctrl.flags, queryctrl.flags);

			if (queryctrl.type == V4L2_CTRL_TYPE_MENU) {
				enumerate_menu(fd, &queryctrl);
			}
		} else {
			if (errno == EINVAL) {
				break;
			}
			usage("VIDIOC_QUERYCTRL error: (%d) '%s'", errno, strerror(errno));
		}
	}

	close(fd);
	return 0;
}