001/*----------------------------------------------------------------------------*/
002/* Copyright (c) FIRST 2008-2017. 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.first.wpilibj;
009
010/**
011 * GenericHID Interface.
012 */
013public abstract class GenericHID {
014  /**
015   * Represents a rumble output on the JoyStick.
016   */
017  public enum RumbleType {
018    kLeftRumble, kRightRumble
019  }
020
021  public enum HIDType {
022    kUnknown(-1),
023    kXInputUnknown(0),
024    kXInputGamepad(1),
025    kXInputWheel(2),
026    kXInputArcadeStick(3),
027    kXInputFlightStick(4),
028    kXInputDancePad(5),
029    kXInputGuitar(6),
030    kXInputGuitar2(7),
031    kXInputDrumKit(8),
032    kXInputGuitar3(11),
033    kXInputArcadePad(19),
034    kHIDJoystick(20),
035    kHIDGamepad(21),
036    kHIDDriving(22),
037    kHIDFlight(23),
038    kHID1stPerson(24);
039
040    @SuppressWarnings("MemberName")
041    public final int value;
042
043    private HIDType(int value) {
044      this.value = value;
045    }
046  }
047
048  /**
049   * Which hand the Human Interface Device is associated with.
050   */
051  public enum Hand {
052    kLeft(0), kRight(1);
053
054    @SuppressWarnings("MemberName")
055    public final int value;
056
057    private Hand(int value) {
058      this.value = value;
059    }
060  }
061
062  private final int m_port;
063
064  public GenericHID(int port) {
065    m_port = port;
066  }
067
068  /**
069   * Get the x position of the HID.
070   *
071   * @return the x position of the HID
072   */
073  public final double getX() {
074    return getX(Hand.kRight);
075  }
076
077  /**
078   * Get the x position of HID.
079   *
080   * @param hand which hand, left or right
081   * @return the x position
082   */
083  public abstract double getX(Hand hand);
084
085  /**
086   * Get the y position of the HID.
087   *
088   * @return the y position
089   */
090  public final double getY() {
091    return getY(Hand.kRight);
092  }
093
094  /**
095   * Get the y position of the HID.
096   *
097   * @param hand which hand, left or right
098   * @return the y position
099   */
100  public abstract double getY(Hand hand);
101
102  /**
103   * Get the raw axis.
104   *
105   * @param which index of the axis
106   * @return the raw value of the selected axis
107   */
108  public abstract double getRawAxis(int which);
109
110  /**
111   * Is the given button pressed.
112   *
113   * @param button which button number
114   * @return true if the button is pressed
115   */
116  public abstract boolean getRawButton(int button);
117
118  /**
119   * Get the angle in degrees of a POV on the HID.
120   *
121   * <p>The POV angles start at 0 in the up direction, and increase clockwise (eg right is 90,
122   * upper-left is 315).
123   *
124   * @param pov The index of the POV to read (starting at 0)
125   * @return the angle of the POV in degrees, or -1 if the POV is not pressed.
126   */
127  public abstract int getPOV(int pov);
128
129  public int getPOV() {
130    return getPOV(0);
131  }
132
133  /**
134   * For the current HID, return the number of POVs.
135   */
136  public abstract int getPOVCount();
137
138  /**
139   * Get the port number of the HID.
140   *
141   * @return The port number of the HID.
142   */
143  public int getPort() {
144    return m_port;
145  }
146
147  /**
148   * Get the type of the HID.
149   *
150   * @return the type of the HID.
151   */
152  public abstract HIDType getType();
153
154  /**
155   * Get the name of the HID.
156   *
157   * @return the name of the HID.
158   */
159  public abstract String getName();
160
161  /**
162   * Set a single HID output value for the HID.
163   *
164   * @param outputNumber The index of the output to set (1-32)
165   * @param value        The value to set the output to
166   */
167  public abstract void setOutput(int outputNumber, boolean value);
168
169  /**
170   * Set all HID output values for the HID.
171   *
172   * @param value The 32 bit output value (1 bit for each output)
173   */
174  public abstract void setOutputs(int value);
175
176  /**
177   * Set the rumble output for the HID. The DS currently supports 2 rumble values, left rumble and
178   * right rumble.
179   *
180   * @param type  Which rumble value to set
181   * @param value The normalized value (0 to 1) to set the rumble to
182   */
183  public abstract void setRumble(RumbleType type, double value);
184}