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
010/**
011 * This class is intended to be used within a program. The programmer can manually set its value.
012 * Also includes a setting for whether or not it should invert its value.
013 */
014public class InternalButton extends Button {
015
016  private boolean m_pressed;
017  private boolean m_inverted;
018
019  /**
020   * Creates an InternalButton that is not inverted.
021   */
022  public InternalButton() {
023    this(false);
024  }
025
026  /**
027   * Creates an InternalButton which is inverted depending on the input.
028   *
029   * @param inverted if false, then this button is pressed when set to true, otherwise it is pressed
030   *                 when set to false.
031   */
032  public InternalButton(boolean inverted) {
033    m_pressed = m_inverted = inverted;
034  }
035
036  public void setInverted(boolean inverted) {
037    m_inverted = inverted;
038  }
039
040  public void setPressed(boolean pressed) {
041    m_pressed = pressed;
042  }
043
044  public boolean get() {
045    return m_pressed ^ m_inverted;
046  }
047}