Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void initiateAddressableLED(int port, int totalAmountOfLEDs) {
}

/**
* Constructs a new AddressableLEDStrip. Before any commands are sent to the LED strip, the setAddressableLED and setAddressableLEDBuffer methods must be called.
* Constructs a new AddressableLEDStrip. Before any commands are sent to the LED strip, the {@link AddressableLEDStrip#initiateAddressableLED(int, int)} method must be called.
*
* @param inverted whether the LED strip is inverted
* @param numberOfLEDs the amount of LEDs in the strip
Expand All @@ -58,12 +58,12 @@ public void periodic() {
}

@Override
void clearLEDColors() {
staticColor(Color.kBlack);
protected void clearLEDColors() {
setStaticColor(Color.kBlack);
}

@Override
void blink(Color firstColor, double speed) {
protected void blink(Color color, double speed) {
final double correctedSpeed = 1 - speed;
final double currentTime = Timer.getTimestamp();

Expand All @@ -73,19 +73,19 @@ void blink(Color firstColor, double speed) {
}

if (isLEDAnimationChanged) {
staticColor(firstColor);
setStaticColor(color);
return;
}
clearLEDColors();
}

@Override
void staticColor(Color color) {
setLEDColors(color, 0, numberOfLEDs - 1);
protected void staticColor(Color color) {
setStaticColor(color);
}

@Override
void breathe(Color color, int breathingLEDs, double speed, boolean inverted, LarsonAnimation.BounceMode bounceMode) {
protected void breathe(Color color, int numberOfBreathingLEDs, double speed, boolean inverted, LarsonAnimation.BounceMode bounceMode) {
clearLEDColors();
final boolean correctedInverted = this.inverted != inverted;
final double moveLEDTimeSeconds = 1 - speed;
Expand All @@ -99,12 +99,12 @@ void breathe(Color color, int breathingLEDs, double speed, boolean inverted, Lar
lastBreatheLED++;
}

checkIfBreathingHasHitEnd(breathingLEDs, correctedInverted, bounceMode);
setBreathingLEDs(color, breathingLEDs, bounceMode);
checkIfBreathingHasHitEnd(numberOfBreathingLEDs, correctedInverted, bounceMode);
setBreathingLEDs(color, numberOfBreathingLEDs, bounceMode);
}

@Override
void colorFlow(Color color, double speed, boolean inverted) {
protected void colorFlow(Color color, double speed, boolean inverted) {
clearLEDColors();
final boolean correctedInverted = this.inverted != inverted;
final double moveLEDTimeSeconds = 1 - speed;
Expand All @@ -123,13 +123,13 @@ void colorFlow(Color color, double speed, boolean inverted) {
}

@Override
void alternateColor(Color firstColor, Color secondColor) {
protected void alternateColor(Color firstColor, Color secondColor) {
for (int i = 0; i < numberOfLEDs; i++)
LED_BUFFER.setLED(i + indexOffset, i % 2 == 0 ? firstColor : secondColor);
}

@Override
void rainbow(double brightness, double speed, boolean inverted) {
protected void rainbow(double brightness, double speed, boolean inverted) {
final boolean correctedInverted = this.inverted != inverted;
final int adjustedBrightness = (int) (brightness * 255);
final int hueIncrement = (int) (speed * 8);
Expand All @@ -150,9 +150,9 @@ void rainbow(double brightness, double speed, boolean inverted) {
}

@Override
void sectionColor(Supplier<Color>[] colors) {
protected void sectionColor(Supplier<Color>[] colors) {
final int amountOfSections = colors.length;
final int ledsPerSection = (int) Math.floor(numberOfLEDs / amountOfSections);
final int ledsPerSection = (int) Math.floor((double) numberOfLEDs / amountOfSections);

for (int i = 0; i < amountOfSections; i++)
setLEDColors(
Expand All @@ -163,14 +163,18 @@ void sectionColor(Supplier<Color>[] colors) {
}

@Override
void resetLEDSettings() {
protected void resetLEDSettings() {
lastBreatheLED = indexOffset;
lastLEDAnimationChangeTime = Timer.getTimestamp();
rainbowFirstPixelHue = 0;
isLEDAnimationChanged = false;
amountOfColorFlowLEDs = 0;
}

private void setStaticColor(Color color) {
setLEDColors(color, 0, numberOfLEDs - 1);
}

private void checkIfBreathingHasHitEnd(int amountOfBreathingLEDs, boolean inverted, LarsonAnimation.BounceMode bounceMode) {
final int bounceModeAddition = switch (bounceMode) {
case Back -> amountOfBreathingLEDs;
Expand Down
63 changes: 35 additions & 28 deletions src/main/java/org/trigon/hardware/misc/leds/CANdleLEDStrip.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CANdleLEDStrip extends LEDStrip {
* @param candle the CANdle instance to be used
*/
public static void setCANdle(CANdle candle) {
if (CANDLE == null)
if (CANDLE == null && !RobotHardwareStats.isSimulation())
CANDLE = candle;
}

Expand All @@ -37,7 +37,7 @@ public static void setTotalAmountOfLEDs(int totalAmountOfLEDs) {
}

/**
* Constructs a new CANdleLEDStrip. Before any commands are sent to the LED strip, the setCANdle method must be called.
* Constructs a new CANdleLEDStrip. Before any commands are sent to the LED strip, the {@link CANdleLEDStrip#setCANdle(CANdle)} method must be called.
*
* @param inverted whether the LED strip is inverted
* @param numberOfLEDs the amount of LEDs in the strip
Expand All @@ -50,17 +50,17 @@ public static void setTotalAmountOfLEDs(int totalAmountOfLEDs) {
}

@Override
void clearLEDColors() {
protected void clearLEDColors() {
CANDLE.clearAnimation(animationSlot);
}

@Override
void blink(Color firstColor, double speed) {
protected void blink(Color color, double speed) {
CANDLE.animate(
new SingleFadeAnimation(
(int) firstColor.red,
(int) firstColor.green,
(int) firstColor.blue,
(int) (color.red * 255),
(int) (color.green * 255),
(int) (color.blue * 255),
0,
speed,
this.numberOfLEDs,
Expand All @@ -71,49 +71,56 @@ void blink(Color firstColor, double speed) {
}

@Override
void staticColor(Color color) {
CANDLE.setLEDs((int) color.red, (int) color.green, (int) color.blue, 0, indexOffset, numberOfLEDs);
protected void staticColor(Color color) {
CANDLE.setLEDs(
((int) color.red * 255),
((int) color.green * 255),
((int) color.blue * 255),
0,
indexOffset,
numberOfLEDs
);
}

@Override
void breathe(Color color, int amountOfBreathingLEDs, double speed, boolean inverted, LarsonAnimation.BounceMode bounceMode) {
protected void breathe(Color color, int numberOfBreathingLEDs, double speed, boolean inverted, LarsonAnimation.BounceMode bounceMode) {
CANDLE.animate(
new LarsonAnimation(
(int) color.red,
(int) color.green,
(int) color.blue,
(int) (color.red * 255),
(int) (color.green * 255),
(int) (color.blue * 255),
0,
speed,
this.numberOfLEDs,
bounceMode,
amountOfBreathingLEDs,
numberOfBreathingLEDs,
indexOffset
),
animationSlot
);
}

@Override
void alternateColor(Color firstColor, Color secondColor) {
protected void alternateColor(Color firstColor, Color secondColor) {
for (int i = 0; i < numberOfLEDs; i++)
CANDLE.setLEDs(
(int) (isEven(i) ? firstColor.red : secondColor.red),
(int) (isEven(i) ? firstColor.green : secondColor.green),
(int) (isEven(i) ? firstColor.blue : secondColor.blue),
(int) ((isEven(i) ? firstColor.red : secondColor.red) * 255),
(int) ((isEven(i) ? firstColor.green : secondColor.green) * 255),
(int) ((isEven(i) ? firstColor.blue : secondColor.blue) * 255),
0,
i + indexOffset,
1
);
}

@Override
void colorFlow(Color color, double speed, boolean inverted) {
protected void colorFlow(Color color, double speed, boolean inverted) {
final boolean correctedInverted = this.inverted != inverted;
CANDLE.animate(
new ColorFlowAnimation(
(int) color.red,
(int) color.green,
(int) color.blue,
(int) (color.red * 255),
(int) (color.green * 255),
(int) (color.blue * 255),
0,
speed,
this.numberOfLEDs,
Expand All @@ -125,7 +132,7 @@ void colorFlow(Color color, double speed, boolean inverted) {
}

@Override
void rainbow(double brightness, double speed, boolean inverted) {
protected void rainbow(double brightness, double speed, boolean inverted) {
final boolean correctedInverted = this.inverted != inverted;
CANDLE.animate(
new RainbowAnimation(
Expand All @@ -140,17 +147,17 @@ void rainbow(double brightness, double speed, boolean inverted) {
}

@Override
void sectionColor(Supplier<Color>[] colors) {
final int ledsPerSection = (int) Math.floor(numberOfLEDs / colors.length);
protected void sectionColor(Supplier<Color>[] colors) {
final int ledsPerSection = (int) Math.floor((double) numberOfLEDs / colors.length);
setSectionColor(colors.length, ledsPerSection, colors);
}

private void setSectionColor(int amountOfSections, int ledsPerSection, Supplier<Color>[] colors) {
for (int i = 0; i < amountOfSections; i++) {
CANDLE.setLEDs(
(int) (inverted ? colors[amountOfSections - i - 1].get().red : colors[i].get().red),
(int) (inverted ? colors[amountOfSections - i - 1].get().green : colors[i].get().green),
(int) (inverted ? colors[amountOfSections - i - 1].get().blue : colors[i].get().blue),
(int) ((inverted ? colors[amountOfSections - i - 1].get().red : colors[i].get().red) * 255),
(int) ((inverted ? colors[amountOfSections - i - 1].get().green : colors[i].get().green) * 255),
(int) ((inverted ? colors[amountOfSections - i - 1].get().blue : colors[i].get().blue) * 255),
0,
ledsPerSection * i + indexOffset,
i == amountOfSections - 1 ? numberOfLEDs - 1 : ledsPerSection * (i + 1) - 1
Expand Down
Loading
Loading