View Single Post
  #1   Spotlight this post!  
Unread 08-02-2014, 23:49
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Toggle When Pressed Option

The implementation may make things clearer (from Toggle.java in WPILibJ):
Code:
   /**
     * Toggles a command when the trigger becomes active
     * @param command the command to toggle
     */
    public void toggleWhenActive(final Command command) {
         new ButtonScheduler() {

            boolean pressedLast = grab();

            public void execute() {
                if (grab()) {
                    if (!pressedLast) {
                        pressedLast = true;
                        if (command.isRunning()){
                            command.cancel();
                        } else{
                            command.start();
                        }
                    }
                } else {
                    pressedLast = false;
                }
            }
        }.start();
    }
__________________
I code stuff.
Reply With Quote