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
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  private boolean m_pressed;
016  private boolean m_inverted;
017
018  /**
019   * Creates an InternalButton that is not inverted.
020   */
021  public InternalButton() {
022    this(false);
023  }
024
025  /**
026   * Creates an InternalButton which is inverted depending on the input.
027   *
028   * @param inverted if false, then this button is pressed when set to true, otherwise it is pressed
029   *                 when set to false.
030   */
031  public InternalButton(boolean inverted) {
032    m_pressed = m_inverted = inverted;
033  }
034
035  public void setInverted(boolean inverted) {
036    m_inverted = inverted;
037  }
038
039  public void setPressed(boolean pressed) {
040    m_pressed = pressed;
041  }
042
043  public boolean get() {
044    return m_pressed ^ m_inverted;
045  }
046}