-
Notifications
You must be signed in to change notification settings - Fork 0
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
9665517
commit 3627526
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/frc/robot/commands/IntakeControllerSignal.java
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,49 @@ | ||
package frc.robot.commands; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
import edu.wpi.first.wpilibj.TimedRobot; | ||
import edu.wpi.first.wpilibj.XboxController; | ||
import edu.wpi.first.wpilibj.GenericHID.RumbleType; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
|
||
public class IntakeControllerSignal extends Command { | ||
private final XboxController controller; | ||
private final BooleanSupplier signal; | ||
private final double rumbleValue; | ||
|
||
private final double rumbleTimeMax = 0.2 / TimedRobot.kDefaultPeriod; | ||
private double rumbleTime = 0; | ||
|
||
public IntakeControllerSignal(XboxController controller, BooleanSupplier signal, double rumbleValue) { | ||
this.controller = controller; | ||
this.signal = signal; | ||
this.rumbleValue = rumbleValue; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
boolean value = signal.getAsBoolean(); | ||
|
||
if (value) { | ||
if (rumbleTime < rumbleTimeMax) { | ||
rumbleTime++; | ||
controller.setRumble(RumbleType.kBothRumble, rumbleValue); | ||
} | ||
} | ||
else { | ||
rumbleTime = 0; | ||
controller.setRumble(RumbleType.kBothRumble, 0); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
controller.setRumble(RumbleType.kBothRumble, 0); | ||
} | ||
} |