|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#4
|
||||
|
||||
|
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();
}
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|