001/*----------------------------------------------------------------------------*/
002/* Copyright (c) FIRST 2016. All Rights Reserved.                             */
003/* Open Source Software - may be modified and shared by FRC teams. The code   */
004/* must be accompanied by the FIRST BSD license file in the root directory of */
005/* the project.                                                               */
006/*----------------------------------------------------------------------------*/
007
008package edu.wpi.cscore;
009
010public class VideoProperty {
011  public enum Kind {
012    kNone(0), kBoolean(1), kInteger(2), kString(4), kEnum(8);
013    private int value;
014
015    private Kind(int value) {
016      this.value = value;
017    }
018
019    public int getValue() {
020      return value;
021    }
022  }
023
024  public static Kind getKindFromInt(int kind) {
025    switch (kind) {
026      case 1: return Kind.kBoolean;
027      case 2: return Kind.kInteger;
028      case 4: return Kind.kString;
029      case 8: return Kind.kEnum;
030      default: return Kind.kNone;
031    }
032  }
033
034  public String getName() {
035    return CameraServerJNI.getPropertyName(m_handle);
036  }
037
038  public Kind getKind() {
039    return m_kind;
040  }
041
042  public boolean isValid() {
043    return m_kind != Kind.kNone;
044  }
045
046  // Kind checkers
047  public boolean isBoolean() {
048    return m_kind == Kind.kBoolean;
049  }
050
051  public boolean isInteger() {
052    return m_kind == Kind.kInteger;
053  }
054
055  public boolean isString() {
056    return m_kind == Kind.kString;
057  }
058
059  public boolean isEnum() {
060    return m_kind == Kind.kEnum;
061  }
062
063  public int get() {
064    return CameraServerJNI.getProperty(m_handle);
065  }
066
067  public void set(int value) {
068    CameraServerJNI.setProperty(m_handle, value);
069  }
070
071  public int getMin() {
072    return CameraServerJNI.getPropertyMin(m_handle);
073  }
074
075  public int getMax() {
076    return CameraServerJNI.getPropertyMax(m_handle);
077  }
078
079  public int getStep() {
080    return CameraServerJNI.getPropertyStep(m_handle);
081  }
082
083  public int getDefault() {
084    return CameraServerJNI.getPropertyDefault(m_handle);
085  }
086
087  // String-specific functions
088  public String getString() {
089    return CameraServerJNI.getStringProperty(m_handle);
090  }
091
092  public void setString(String value) {
093    CameraServerJNI.setStringProperty(m_handle, value);
094  }
095
096  // Enum-specific functions
097  public String[] getChoices() {
098    return CameraServerJNI.getEnumPropertyChoices(m_handle);
099  }
100
101  VideoProperty(int handle) {
102    m_handle = handle;
103    m_kind = getKindFromInt(CameraServerJNI.getPropertyKind(handle));
104  }
105
106  VideoProperty(int handle, Kind kind) {
107    m_handle = handle;
108    m_kind = kind;
109  }
110
111  int m_handle;
112  private Kind m_kind;
113}