- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package edu.wpi.first.wpilibj.templates;
- import edu.wpi.first.wpilibj.GenericHID;
- import edu.wpi.first.wpilibj.buttons.Button;
- import edu.wpi.first.wpilibj.buttons.Trigger;
- import edu.wpi.first.wpilibj.command.Command;
- /**
- *
- * @author Arhowk
- * Use as a normal JoystickButton. The exception is that the whileHeld() command will
- * replace the last issued command rather than stacking all instantiated commands
- * together
- */
- public class ChangeButton extends Button{
- Command runningCommand;
- buttonDummy dummy;
- GenericHID m_joystick;
- int m_buttonNumber;
- public ChangeButton(GenericHID joystick, int buttonNumber) {
- m_joystick = joystick;
- m_buttonNumber = buttonNumber;
- }
- /**
- * Gets the value of the joystick button
- * @return The value of the joystick button
- */
- public boolean get() {
- return m_joystick.getRawButton(m_buttonNumber);
- }
- public void whileHeld(final Command command){
- runningCommand = command;
- if(dummy == null){
- dummy = new buttonDummy();
- whileActive(dummy);
- }else if(command == null){
- dummy.cancel();
- }
- }
- private class buttonDummy extends Command{
- protected void initialize() {
- runningCommand.start();
- }
- // Called repeatedly when this Command is scheduled to run
- protected void execute() {
- }
- // Make this return true when this Command no longer needs to run execute()
- protected boolean isFinished() {
- return runningCommand.isCanceled();
- }
- // Called once after isFinished returns true
- protected void end() {
- }
- // Called when another command which requires one or more of the same
- // subsystems is scheduled to run
- protected void interrupted() {
- runningCommand.cancel();
- }
- }
- }
SHARE
TWEET
Untitled
a guest
Jan 25th, 2013
23
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
RAW Paste Data
