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