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 or sink property. */ 008public class VideoProperty { 009 /** VideoProperty property types. */ 010 public enum Kind { 011 /** No specific property. */ 012 kNone(0), 013 /** Boolean property. */ 014 kBoolean(1), 015 /** Integer property. */ 016 kInteger(2), 017 /** String property. */ 018 kString(4), 019 /** Enum property. */ 020 kEnum(8); 021 022 private final int value; 023 024 Kind(int value) { 025 this.value = value; 026 } 027 028 /** 029 * Returns the Kind value. 030 * 031 * @return The Kind value. 032 */ 033 public int getValue() { 034 return value; 035 } 036 } 037 038 /** 039 * Convert from the numerical representation of kind to an enum type. 040 * 041 * @param kind The numerical representation of kind 042 * @return The kind 043 */ 044 public static Kind getKindFromInt(int kind) { 045 switch (kind) { 046 case 1: 047 return Kind.kBoolean; 048 case 2: 049 return Kind.kInteger; 050 case 4: 051 return Kind.kString; 052 case 8: 053 return Kind.kEnum; 054 default: 055 return Kind.kNone; 056 } 057 } 058 059 /** 060 * Returns property name. 061 * 062 * @return Property name. 063 */ 064 public String getName() { 065 return CameraServerJNI.getPropertyName(m_handle); 066 } 067 068 /** 069 * Returns property kind. 070 * 071 * @return Property kind. 072 */ 073 public Kind getKind() { 074 return m_kind; 075 } 076 077 /** 078 * Returns true if property is valid. 079 * 080 * @return True if property is valid. 081 */ 082 public boolean isValid() { 083 return m_kind != Kind.kNone; 084 } 085 086 /** 087 * Returns true if property is a boolean. 088 * 089 * @return True if property is a boolean. 090 */ 091 public boolean isBoolean() { 092 return m_kind == Kind.kBoolean; 093 } 094 095 /** 096 * Returns true if property is an integer. 097 * 098 * @return True if property is an integer. 099 */ 100 public boolean isInteger() { 101 return m_kind == Kind.kInteger; 102 } 103 104 /** 105 * Returns true if property is a string. 106 * 107 * @return True if property is a string. 108 */ 109 public boolean isString() { 110 return m_kind == Kind.kString; 111 } 112 113 /** 114 * Returns true if property is an enum. 115 * 116 * @return True if property is an enum. 117 */ 118 public boolean isEnum() { 119 return m_kind == Kind.kEnum; 120 } 121 122 /** 123 * Returns property value. 124 * 125 * @return Property value. 126 */ 127 public int get() { 128 return CameraServerJNI.getProperty(m_handle); 129 } 130 131 /** 132 * Sets property value. 133 * 134 * @param value Property value. 135 */ 136 public void set(int value) { 137 CameraServerJNI.setProperty(m_handle, value); 138 } 139 140 /** 141 * Returns property minimum value. 142 * 143 * @return Property minimum value. 144 */ 145 public int getMin() { 146 return CameraServerJNI.getPropertyMin(m_handle); 147 } 148 149 /** 150 * Returns property maximum value. 151 * 152 * @return Property maximum value. 153 */ 154 public int getMax() { 155 return CameraServerJNI.getPropertyMax(m_handle); 156 } 157 158 /** 159 * Returns property step size. 160 * 161 * @return Property step size. 162 */ 163 public int getStep() { 164 return CameraServerJNI.getPropertyStep(m_handle); 165 } 166 167 /** 168 * Returns property default value. 169 * 170 * @return Property default value. 171 */ 172 public int getDefault() { 173 return CameraServerJNI.getPropertyDefault(m_handle); 174 } 175 176 /** 177 * Returns the string property value. 178 * 179 * <p>This function is string-specific. 180 * 181 * @return The string property value. 182 */ 183 public String getString() { 184 return CameraServerJNI.getStringProperty(m_handle); 185 } 186 187 /** 188 * Sets the string property value. 189 * 190 * <p>This function is string-specific. 191 * 192 * @param value String property value. 193 */ 194 public void setString(String value) { 195 CameraServerJNI.setStringProperty(m_handle, value); 196 } 197 198 /** 199 * Returns the possible values for the enum property value. 200 * 201 * <p>This function is enum-specific. 202 * 203 * @return The possible values for the enum property value. 204 */ 205 public String[] getChoices() { 206 return CameraServerJNI.getEnumPropertyChoices(m_handle); 207 } 208 209 VideoProperty(int handle) { 210 m_handle = handle; 211 m_kind = getKindFromInt(CameraServerJNI.getPropertyKind(handle)); 212 } 213 214 VideoProperty(int handle, Kind kind) { 215 m_handle = handle; 216 m_kind = kind; 217 } 218 219 int m_handle; 220 private Kind m_kind; 221}