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 java.util.concurrent.atomic.AtomicBoolean; 008 009/** 010 * This class is intended to be used within a program. The programmer can manually set its value. 011 * Also includes a setting for whether it should invert its value. 012 * 013 * <p>This class is provided by the NewCommands VendorDep 014 */ 015public class InternalButton extends Trigger { 016 // need to be references, so they can be mutated after being captured in the constructor. 017 private final AtomicBoolean m_pressed; 018 private final AtomicBoolean m_inverted; 019 020 /** Creates an InternalButton that is not inverted. */ 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 this(new AtomicBoolean(), new AtomicBoolean(inverted)); 033 } 034 035 /* 036 * Mock constructor so the AtomicBoolean objects can be constructed before the super 037 * constructor invocation. 038 */ 039 private InternalButton(AtomicBoolean state, AtomicBoolean inverted) { 040 super(() -> state.get() != inverted.get()); 041 this.m_pressed = state; 042 this.m_inverted = inverted; 043 } 044 045 public void setInverted(boolean inverted) { 046 m_inverted.set(inverted); 047 } 048 049 public void setPressed(boolean pressed) { 050 m_pressed.set(pressed); 051 } 052}