001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.cscore;
006
007/** A source that represents a USB camera. */
008public class UsbCamera extends VideoCamera {
009  /**
010   * Create a source for a USB camera based on device number.
011   *
012   * @param name Source name (arbitrary unique identifier)
013   * @param dev Device number (e.g. 0 for /dev/video0)
014   */
015  public UsbCamera(String name, int dev) {
016    super(CameraServerJNI.createUsbCameraDev(name, dev));
017  }
018
019  /**
020   * Create a source for a USB camera based on device path.
021   *
022   * @param name Source name (arbitrary unique identifier)
023   * @param path Path to device (e.g. "/dev/video0" on Linux)
024   */
025  public UsbCamera(String name, String path) {
026    super(CameraServerJNI.createUsbCameraPath(name, path));
027  }
028
029  /**
030   * Enumerate USB cameras on the local system.
031   *
032   * @return Vector of USB camera information (one for each camera)
033   */
034  public static UsbCameraInfo[] enumerateUsbCameras() {
035    return CameraServerJNI.enumerateUsbCameras();
036  }
037
038  /**
039   * Change the path to the device.
040   *
041   * @param path New device path.
042   */
043  void setPath(String path) {
044    CameraServerJNI.setUsbCameraPath(m_handle, path);
045  }
046
047  /**
048   * Get the path to the device.
049   *
050   * @return The device path.
051   */
052  public String getPath() {
053    return CameraServerJNI.getUsbCameraPath(m_handle);
054  }
055
056  /**
057   * Get the full camera information for the device.
058   *
059   * @return The camera information.
060   */
061  public UsbCameraInfo getInfo() {
062    return CameraServerJNI.getUsbCameraInfo(m_handle);
063  }
064
065  /**
066   * Set how verbose the camera connection messages are.
067   *
068   * @param level 0=don't display Connecting message, 1=do display message
069   */
070  public void setConnectVerbose(int level) {
071    CameraServerJNI.setProperty(
072        CameraServerJNI.getSourceProperty(m_handle, "connect_verbose"), level);
073  }
074}