View Single Post
  #2   Spotlight this post!  
Unread 17-03-2013, 20:30
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: Reassigning button.whenPressed during teleop

I don't think it's possible. Button.whenPressed() calls Trigger.whenActive(), which adds a ButtonScheduler to the Scheduler's internal list of buttons. I don't think there's a way to remove it. I believe there is an alternative, though.

Custom buttons are pretty easy to make, they just need a get() method. So, if you want an easy way to disable a certain button binding, have a variable:
Code:
Button doubleBoundButton; // this is the button you want to trigger differently at different times
boolean initialBindingEnabled = true;
Button initialBinding = new Button() {
           public boolean get() {
               return initialBindingEnabled && doubleBoundButton.get();
           }
       },
       secondaryBinding = new Button() {
           public boolean get() {
               return !initialBindingEnabled && doubleBoundButton.get();
           }
       };
You can then bind different things to each:
Code:
initialBinding.whenPressed(new DoSomething());
secondaryBinding.whenPressed(new DoSomethingElse());
Then, to toggle which is enabled:
Code:
initialBindingEnabled = !initialBindingEnabled;
__________________
I code stuff.
Reply With Quote