// Path: library/src/main/java/com/jwoolston/android/uvc/interfaces/VideoClassInterface.java
// public abstract class VideoClassInterface extends UvcInterface {
// 
//     VideoClassInterface(UsbInterface usbInterface, byte[] descriptor) {
//         super(usbInterface, descriptor);
//     }
// 
//     public static enum VC_INF_SUBTYPE {
//         VC_DESCRIPTOR_UNDEFINED(0x00),
//         VC_HEADER(0x01),
//         VC_INPUT_TERMINAL(0x02),
//         VC_OUTPUT_TERMINAL(0x03),
//         VC_SELECTOR_UNIT(0x04),
//         VC_PROCESSING_UNIT(0x05),
//         VC_EXTENSION_UNIT(0x06),
//         VC_ENCODING_UNIT(0x07);
// 
//         public final byte subtype;
// 
//         private VC_INF_SUBTYPE(int subtype) {
//             this.subtype = (byte) (subtype & 0xFF);
//         }
// 
//         public static VC_INF_SUBTYPE getSubtype(byte subtype) {
//             for (VC_INF_SUBTYPE s : VC_INF_SUBTYPE.values()) {
//                 if (s.subtype == subtype) {
//                     return s;
//                 }
//             }
//             return null;
//         }
//     }
// }


import android.support.annotation.NonNull;
import com.jwoolston.android.uvc.interfaces.VideoClassInterface;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
package com.jwoolston.android.uvc.interfaces.terminals;




/**
 * The Camera Terminal (CT) controls mechanical (or equivalent digital) features of the device component that
 * transmits the video stream. As such, it is only applicable to video capture devices with controllable lens or
 * sensor characteristics. A Camera Terminal is always represented as an Input Terminal with a single output pin. It
 * provides support for the following features.
 *
 * <br>-Scanning Mode (Progressive or Interlaced)
 * <br>-Auto-Exposure Mode
 * <br>-Auto-Exposure Priority
 * <br>-Exposure Time
 * <br>-Focus
 * <br>-Auto-Focus
 * <br>-Simple Focus
 * <br>-Iris
 * <br>-Zoom
 * <br>-Pan
 * <br>-Roll
 * <br>-Tilt
 * <br>-Digital Windowing
 * <br>-Region of Interest
 *
 * Support for any particular control is optional. The Focus control can optionally provide support for an auto
 * setting (with an on/off state). If the auto setting is supported and set to the on state, the device will provide
 * automatic focus adjustment, and read requests will reflect the automatically set value. Attempts to
 * programmatically set the Focus control when in auto mode shall result in protocol STALL with an error code of
 * <b>bRequestErrorCode</b> = “Wrong State”. When leaving Auto-Focus mode (entering manual focus mode), the control
 * shall remain at the value that was in effect just before the transition.
 *
 * @author Jared Woolston (Jared.Woolston@gmail.com)
 * @see <a href=http://www.usb.org/developers/docs/devclass_docs/USB_Video_Class_1_5.zip>UVC 1.5 Class
 * Specification §2.3.3</a>
 */
public class CameraTerminal extends VideoInputTerminal {

    private static final int LENGTH_DESCRIPTOR = 18;

    private static final int wObjectiveFocalLengthMin = 8;
    private static final int wObjectiveFocalLengthMax = 10;
    private static final int wOcularFocalLength       = 12;
    private static final int bControlSize             = 14;
    private static final int bmControls               = 15;

    private final int objectiveFocalLengthMin;
    private final int objectiveFocalLengthMax;
    private final int objectiveFocalLength;
    private final int ocularFocalLength;

    private final Set<Control> controlSet;

    public static boolean isCameraTerminal(byte[] descriptor) {
        if (descriptor.length != LENGTH_DESCRIPTOR) {
            return false;
        }
// Path: library/src/main/java/com/jwoolston/android/uvc/interfaces/VideoClassInterface.java
// public abstract class VideoClassInterface extends UvcInterface {
// 
//     VideoClassInterface(UsbInterface usbInterface, byte[] descriptor) {
//         super(usbInterface, descriptor);
//     }
// 
//     public static enum VC_INF_SUBTYPE {
//         VC_DESCRIPTOR_UNDEFINED(0x00),
//         VC_HEADER(0x01),
//         VC_INPUT_TERMINAL(0x02),
//         VC_OUTPUT_TERMINAL(0x03),
//         VC_SELECTOR_UNIT(0x04),
//         VC_PROCESSING_UNIT(0x05),
//         VC_EXTENSION_UNIT(0x06),
//         VC_ENCODING_UNIT(0x07);
// 
//         public final byte subtype;
// 
//         private VC_INF_SUBTYPE(int subtype) {
//             this.subtype = (byte) (subtype & 0xFF);
//         }
// 
//         public static VC_INF_SUBTYPE getSubtype(byte subtype) {
//             for (VC_INF_SUBTYPE s : VC_INF_SUBTYPE.values()) {
//                 if (s.subtype == subtype) {
//                     return s;
//                 }
//             }
//             return null;
//         }
//     }
// }


// Path: library/src/main/java/com/jwoolston/android/uvc/interfaces/terminals/CameraTerminal.java
import android.support.annotation.NonNull;
import com.jwoolston.android.uvc.interfaces.VideoClassInterface;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

package com.jwoolston.android.uvc.interfaces.terminals;




/**
 * The Camera Terminal (CT) controls mechanical (or equivalent digital) features of the device component that
 * transmits the video stream. As such, it is only applicable to video capture devices with controllable lens or
 * sensor characteristics. A Camera Terminal is always represented as an Input Terminal with a single output pin. It
 * provides support for the following features.
 *
 * <br>-Scanning Mode (Progressive or Interlaced)
 * <br>-Auto-Exposure Mode
 * <br>-Auto-Exposure Priority
 * <br>-Exposure Time
 * <br>-Focus
 * <br>-Auto-Focus
 * <br>-Simple Focus
 * <br>-Iris
 * <br>-Zoom
 * <br>-Pan
 * <br>-Roll
 * <br>-Tilt
 * <br>-Digital Windowing
 * <br>-Region of Interest
 *
 * Support for any particular control is optional. The Focus control can optionally provide support for an auto
 * setting (with an on/off state). If the auto setting is supported and set to the on state, the device will provide
 * automatic focus adjustment, and read requests will reflect the automatically set value. Attempts to
 * programmatically set the Focus control when in auto mode shall result in protocol STALL with an error code of
 * <b>bRequestErrorCode</b> = “Wrong State”. When leaving Auto-Focus mode (entering manual focus mode), the control
 * shall remain at the value that was in effect just before the transition.
 *
 * @author Jared Woolston (Jared.Woolston@gmail.com)
 * @see <a href=http://www.usb.org/developers/docs/devclass_docs/USB_Video_Class_1_5.zip>UVC 1.5 Class
 * Specification §2.3.3</a>
 */
public class CameraTerminal extends VideoInputTerminal {

    private static final int LENGTH_DESCRIPTOR = 18;

    private static final int wObjectiveFocalLengthMin = 8;
    private static final int wObjectiveFocalLengthMax = 10;
    private static final int wOcularFocalLength       = 12;
    private static final int bControlSize             = 14;
    private static final int bmControls               = 15;

    private final int objectiveFocalLengthMin;
    private final int objectiveFocalLengthMax;
    private final int objectiveFocalLength;
    private final int ocularFocalLength;

    private final Set<Control> controlSet;

    public static boolean isCameraTerminal(byte[] descriptor) {
        if (descriptor.length != LENGTH_DESCRIPTOR) {
            return false;
        }
        if (descriptor[bDescriptorSubtype] != VideoClassInterface.VC_INF_SUBTYPE.VC_INPUT_TERMINAL.subtype) {