diff --git a/src/main/java/org/team1540/robot2024/subsystems/led/LedPattern.java b/src/main/java/org/team1540/robot2024/subsystems/led/LedPattern.java index 8ee9c340..5da35421 100644 --- a/src/main/java/org/team1540/robot2024/subsystems/led/LedPattern.java +++ b/src/main/java/org/team1540/robot2024/subsystems/led/LedPattern.java @@ -1,34 +1,32 @@ package org.team1540.robot2024.subsystems.led; -import edu.wpi.first.wpilibj.AddressableLEDBuffer; import edu.wpi.first.wpilibj.util.Color; -import java.util.function.Consumer; +import java.util.function.BiConsumer; public class LedPattern { - private final Consumer applier; + private final BiConsumer applier; public final boolean isDynamic; - LedPattern(Consumer applier, boolean isDynamic) { + private LedPattern(BiConsumer applier, boolean isDynamic) { this.applier = applier; this.isDynamic = isDynamic; } + protected LedPattern(boolean isDynamic) { + this.applier = null; + this.isDynamic = isDynamic; + } void apply(ZonedAddressableLEDBuffer buffer) { - this.applier.accept(buffer); + assert this.applier != null; + for (int i = 0; i < buffer.getLength(); i++) { + this.applier.accept(buffer, i); + } } public static LedPattern solid(Color color) { - return new LedPattern((buffer) -> { - for (int i = 0; i buffer.setLED(i, color), false); } public static LedPattern alternating(Color a, Color b) { - return new LedPattern((buffer) -> { - for (int i = 0; i buffer.setLED(i, i % 2 == 0 ? a : b), false); } } diff --git a/src/main/java/org/team1540/robot2024/subsystems/led/LedPatternRainbow.java b/src/main/java/org/team1540/robot2024/subsystems/led/LedPatternRainbow.java index 6024aec4..38e2639b 100644 --- a/src/main/java/org/team1540/robot2024/subsystems/led/LedPatternRainbow.java +++ b/src/main/java/org/team1540/robot2024/subsystems/led/LedPatternRainbow.java @@ -1,12 +1,11 @@ package org.team1540.robot2024.subsystems.led; -import static java.lang.Math.round; - public class LedPatternRainbow extends LedPattern { private final int speed; - int initialHue = 0; + private int initialHue = 0; + public LedPatternRainbow(int speed) { - super(null, true); + super(true); this.speed = speed; }