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