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.buttons;
009
010import edu.wpi.first.wpilibj.GenericHID;
011
012/**
013 * A {@link Button} that gets its state from a {@link GenericHID}.
014 */
015public class JoystickButton extends Button {
016
017  private final GenericHID m_joystick;
018  private final int m_buttonNumber;
019
020  /**
021   * Create a joystick button for triggering commands.
022   *
023   * @param joystick     The GenericHID object that has the button (e.g. Joystick, KinectStick,
024   *                     etc)
025   * @param buttonNumber The button number (see {@link GenericHID#getRawButton(int) }
026   */
027  public JoystickButton(GenericHID joystick, int buttonNumber) {
028    m_joystick = joystick;
029    m_buttonNumber = buttonNumber;
030  }
031
032  /**
033   * Gets the value of the joystick button.
034   *
035   * @return The value of the joystick button
036   */
037  public boolean get() {
038    return m_joystick.getRawButton(m_buttonNumber);
039  }
040}