-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b98a40
commit 03413e5
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package frc.robot.commands; | ||
|
||
import edu.wpi.first.wpilibj.XboxController; | ||
import edu.wpi.first.wpilibj.GenericHID.RumbleType; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.Commands; | ||
|
||
public class HapticController { | ||
private final XboxController controller; | ||
|
||
/** | ||
* Creates a new HapticController | ||
* | ||
* @param controller | ||
* controller | ||
*/ | ||
public HapticController(XboxController controller) { | ||
this.controller = controller; | ||
} | ||
|
||
/** | ||
* Trigger rumble on the controller for a specified amount of time. | ||
* | ||
* @param type | ||
* rumble type | ||
* @param strength | ||
* rumble strength (0 to 1) | ||
* @param length | ||
* rumble time (seconds) | ||
*/ | ||
public Command HapticTap(RumbleType type, double strength, double length) { | ||
return Commands.runOnce(() -> controller.setRumble(type, strength)) | ||
.andThen(Commands.waitSeconds(length)) | ||
.finallyDo(() -> controller.setRumble(RumbleType.kBothRumble, 0)) | ||
.ignoringDisable(true); | ||
} | ||
} |