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