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