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 POV on a {@link GenericHID}. */ 010public class POVButton extends Button { 011 private final GenericHID m_joystick; 012 private final int m_angle; 013 private final int m_povNumber; 014 015 /** 016 * Creates a POV button for triggering commands. 017 * 018 * @param joystick The GenericHID object that has the POV 019 * @param angle The desired angle in degrees (e.g. 90, 270) 020 * @param povNumber The POV number (see {@link GenericHID#getPOV(int)}) 021 */ 022 public POVButton(GenericHID joystick, int angle, int povNumber) { 023 m_joystick = joystick; 024 m_angle = angle; 025 m_povNumber = povNumber; 026 } 027 028 /** 029 * Creates a POV button for triggering commands. By default, acts on POV 0 030 * 031 * @param joystick The GenericHID object that has the POV 032 * @param angle The desired angle (e.g. 90, 270) 033 */ 034 public POVButton(GenericHID joystick, int angle) { 035 this(joystick, angle, 0); 036 } 037 038 /** 039 * Checks whether the current value of the POV is the target angle. 040 * 041 * @return Whether the value of the POV matches the target angle 042 */ 043 @Override 044 public boolean get() { 045 return m_joystick.getPOV(m_povNumber) == m_angle; 046 } 047}