Skip to content

Commit

Permalink
implementing this was soooooooooooooooooo annoying
Browse files Browse the repository at this point in the history
  • Loading branch information
Nummun14 committed Nov 13, 2024
1 parent 40ba58d commit f10e39c
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ void staticColor(Color color) {

@Override
void breathe(Color color, int breathingLEDs, double cycleTimeSeconds, boolean shouldLoop, boolean inverted, LarsonAnimation.BounceMode bounceMode) {
clearLEDColors();
inverted = this.inverted != inverted;
clearLEDColors();
double moveLEDTimeSeconds = cycleTimeSeconds / numberOfLEDs;
double currentTime = Timer.getFPGATimestamp();

if (currentTime - lastLEDAnimationChangeTime > moveLEDTimeSeconds) {
lastLEDAnimationChangeTime = currentTime;
if (inverted)
lastBreatheLED--;
else
lastBreatheLED++;
}
setBreathingLEDs(color, breathingLEDs, shouldLoop);
checkIfBreathingHasHitEnd(breathingLEDs, shouldLoop, inverted, bounceMode);
setBreathingLEDs(color, breathingLEDs, bounceMode);
}

@Override
Expand Down Expand Up @@ -167,20 +167,30 @@ void resetLEDSettings() {
amountOfColorFlowLEDs = 0;
}

private void setBreathingLEDs(Color color, int breathingLEDs, boolean shouldLoop) {
if (inverted ? (lastBreatheLED < indexOffset) : (lastBreatheLED >= numberOfLEDs + indexOffset)) {
private void checkIfBreathingHasHitEnd(int amountOfBreathingLEDs, boolean shouldLoop, boolean inverted, LarsonAnimation.BounceMode bounceMode) {
int bounceModeThing = switch (bounceMode) {
case Back -> amountOfBreathingLEDs;
case Center -> amountOfBreathingLEDs / 2;
default -> 0;
};
if (inverted ? (lastBreatheLED < indexOffset + bounceModeThing) : (lastBreatheLED >= numberOfLEDs + indexOffset + bounceModeThing)) {
if (!shouldLoop) {
getDefaultCommand().schedule();
return;
}
lastBreatheLED = inverted ? indexOffset + numberOfLEDs : indexOffset;
}
}

private void setBreathingLEDs(Color color, int breathingLEDs, LarsonAnimation.BounceMode bounceMode) {
for (int i = 0; i < breathingLEDs; i++) {
if (lastBreatheLED - i >= indexOffset && lastBreatheLED - i < indexOffset + numberOfLEDs)
LED_BUFFER.setLED(lastBreatheLED - i, color);
else if (lastBreatheLED - i < indexOffset + numberOfLEDs)
else if (lastBreatheLED - i < indexOffset + numberOfLEDs) {
if (bounceMode.equals(LarsonAnimation.BounceMode.Back) || bounceMode.equals(LarsonAnimation.BounceMode.Center) && i > breathingLEDs / 2)
return;
LED_BUFFER.setLED(lastBreatheLED - i + numberOfLEDs, color);
}
}
}

Expand Down

0 comments on commit f10e39c

Please sign in to comment.