Replaced LED Commands with Inline Commands

This commit is contained in:
Keenan D. Buckley
2020-01-05 21:26:49 -07:00
parent 48e2e2238a
commit 1f35e8831a
5 changed files with 12 additions and 88 deletions
@@ -7,6 +7,8 @@
package frc4388.robot;
import frc4388.utility.LEDPatterns;
/**
* The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean
* constants. This class should not be used for any other purpose. All constants should be
@@ -25,6 +27,8 @@ public final class Constants {
public static final class LEDConstants {
public static final int LED_SPARK_ID = 0;
public static final LEDPatterns DEFAULT_PATTERN = LEDPatterns.FOREST_WAVES;
}
public static final class OIConstants {
@@ -13,9 +13,9 @@ import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import frc4388.robot.Constants.*;
import frc4388.robot.commands.LED.UpdateLED;
import frc4388.robot.subsystems.Drive;
import frc4388.robot.subsystems.LED;
import frc4388.utility.LEDPatterns;
import frc4388.utility.controller.IHandController;
import frc4388.utility.controller.XboxController;
@@ -47,7 +47,7 @@ public class RobotContainer {
getDriverController().getLeftYAxis(),
getDriverController().getRightXAxis())));
// continually sends updates to the Blinkin LED controller to keep the lights on
m_robotLED.setDefaultCommand(new UpdateLED(m_robotLED));
m_robotLED.setDefaultCommand(new RunCommand(() -> m_robotLED.updateLED()));
}
/**
@@ -58,11 +58,15 @@ public class RobotContainer {
*/
private void configureButtonBindings() {
/* Driver Buttons */
//Test command to spin the robot while pressing A on the driver controller
// test command to spin the robot while pressing A on the driver controller
new JoystickButton(getDriverJoystick(), XboxController.A_BUTTON)
.whileHeld(() -> m_robotDrive.driveWithInput(0, 1));
/* Operator Buttons */
// activates "Lit Mode"
new JoystickButton(getOperatorJoystick(), XboxController.A_BUTTON)
.whenPressed(() -> m_robotLED.setPattern(LEDPatterns.LAVA_RAINBOW))
.whenReleased(() -> m_robotLED.setPattern(LEDConstants.DEFAULT_PATTERN));
}
/**
@@ -1,37 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package frc4388.robot.commands.LED;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import frc4388.robot.subsystems.LED;
import frc4388.utility.LEDPatterns;
// NOTE: Consider using this command inline, rather than writing a subclass. For more
// information, see:
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
public class SetLEDPattern extends InstantCommand {
private final LED m_led;
public static LEDPatterns m_pattern;
/**
* Add your docs here.
*/
public SetLEDPattern(LED subsystem, LEDPatterns pattern) {
m_led = subsystem;
m_pattern = pattern;
addRequirements(m_led);
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
m_led.setPattern(m_pattern);
}
}
@@ -1,47 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package frc4388.robot.commands.LED;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc4388.robot.subsystems.LED;
public class UpdateLED extends CommandBase {
private final LED m_LED;
/**
* Creates a new UpdateLED that continually runs updateLED in the LED subsystem.
*/
public UpdateLED(LED subsystem) {
m_LED = subsystem;
addRequirements(m_LED);
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
m_LED.updateLED();
}
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
}
// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}
@@ -28,7 +28,7 @@ public class LED extends SubsystemBase {
*/
public LED(){
LEDController = new Spark(LEDConstants.LED_SPARK_ID);
setPattern(LEDPatterns.FOREST_WAVES);
setPattern(LEDConstants.DEFAULT_PATTERN);
LEDController.set(currentLED);
System.err.println("In the Beginning, there was Joe.\nAnd he said, 'Let there be LEDs.'\nAnd it was good.");
}