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 base class for single image providing sources. */ 008public abstract class ImageSource extends VideoSource { 009 /** 010 * Constructs an ImageSource. 011 * 012 * @param handle The image source handle. 013 */ 014 protected ImageSource(int handle) { 015 super(handle); 016 } 017 018 /** 019 * Signal sinks that an error has occurred. This should be called instead of NotifyFrame when an 020 * error occurs. 021 * 022 * @param msg Error message. 023 */ 024 public void notifyError(String msg) { 025 CameraServerJNI.notifySourceError(m_handle, msg); 026 } 027 028 /** 029 * Set source connection status. Defaults to true. 030 * 031 * @param connected True for connected, false for disconnected 032 */ 033 public void setConnected(boolean connected) { 034 CameraServerJNI.setSourceConnected(m_handle, connected); 035 } 036 037 /** 038 * Set source description. 039 * 040 * @param description Description 041 */ 042 public void setDescription(String description) { 043 CameraServerJNI.setSourceDescription(m_handle, description); 044 } 045 046 /** 047 * Create a property. 048 * 049 * @param name Property name 050 * @param kind Property kind 051 * @param minimum Minimum value 052 * @param maximum Maximum value 053 * @param step Step value 054 * @param defaultValue Default value 055 * @param value Current value 056 * @return Property 057 */ 058 public VideoProperty createProperty( 059 String name, 060 VideoProperty.Kind kind, 061 int minimum, 062 int maximum, 063 int step, 064 int defaultValue, 065 int value) { 066 return new VideoProperty( 067 CameraServerJNI.createSourceProperty( 068 m_handle, name, kind.getValue(), minimum, maximum, step, defaultValue, value)); 069 } 070 071 /** 072 * Create an integer property. 073 * 074 * @param name Property name 075 * @param minimum Minimum value 076 * @param maximum Maximum value 077 * @param step Step value 078 * @param defaultValue Default value 079 * @param value Current value 080 * @return Property 081 */ 082 public VideoProperty createIntegerProperty( 083 String name, int minimum, int maximum, int step, int defaultValue, int value) { 084 return new VideoProperty( 085 CameraServerJNI.createSourceProperty( 086 m_handle, 087 name, 088 VideoProperty.Kind.kInteger.getValue(), 089 minimum, 090 maximum, 091 step, 092 defaultValue, 093 value)); 094 } 095 096 /** 097 * Create a boolean property. 098 * 099 * @param name Property name 100 * @param defaultValue Default value 101 * @param value Current value 102 * @return Property 103 */ 104 public VideoProperty createBooleanProperty(String name, boolean defaultValue, boolean value) { 105 return new VideoProperty( 106 CameraServerJNI.createSourceProperty( 107 m_handle, 108 name, 109 VideoProperty.Kind.kBoolean.getValue(), 110 0, 111 1, 112 1, 113 defaultValue ? 1 : 0, 114 value ? 1 : 0)); 115 } 116 117 /** 118 * Create a string property. 119 * 120 * @param name Property name 121 * @param value Current value 122 * @return Property 123 */ 124 public VideoProperty createStringProperty(String name, String value) { 125 VideoProperty prop = 126 new VideoProperty( 127 CameraServerJNI.createSourceProperty( 128 m_handle, name, VideoProperty.Kind.kString.getValue(), 0, 0, 0, 0, 0)); 129 prop.setString(value); 130 return prop; 131 } 132 133 /** 134 * Configure enum property choices. 135 * 136 * @param property Property 137 * @param choices Choices 138 */ 139 public void setEnumPropertyChoices(VideoProperty property, String[] choices) { 140 CameraServerJNI.setSourceEnumPropertyChoices(m_handle, property.m_handle, choices); 141 } 142}