001/*----------------------------------------------------------------------------*/
002/* Copyright (c) 2008-2018 FIRST. 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  private final GenericHID m_joystick;
017  private final int m_buttonNumber;
018
019  /**
020   * Create a joystick button for triggering commands.
021   *
022   * @param joystick     The GenericHID object that has the button (e.g. Joystick, KinectStick,
023   *                     etc)
024   * @param buttonNumber The button number (see {@link GenericHID#getRawButton(int) }
025   */
026  public JoystickButton(GenericHID joystick, int buttonNumber) {
027    m_joystick = joystick;
028    m_buttonNumber = buttonNumber;
029  }
030
031  /**
032   * Gets the value of the joystick button.
033   *
034   * @return The value of the joystick button
035   */
036  public boolean get() {
037    return m_joystick.getRawButton(m_buttonNumber);
038  }
039}