Skip to content

Commit

Permalink
more fixes and refactoring pt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
quackitsquinn committed Apr 4, 2024
1 parent f2c6976 commit 754d20a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ public static final class Camera {

/** The constants for the light strips */
public static class LightStrips {
/** The PWM ID for the underglow light strip */
/** The PWM ID for the lights */
public static final int PWM_ID = 0;

/** The count of LEDs for the underglow light strip. */
/** The count of LEDs for the lights. */
public static final int LED_COUNT = 150;

/** The speed of the fade animation. [0, 1] */
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/frc/robot/subsystems/AddressableLightStrip.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public AddressableLightStrip(int pwmPort, int lightCount) {
* @param color
*/
public void setColorLight(int lightNumber, Color color) {
if (lightNumber > this.buffer.getLength()) {
throw new ArrayIndexOutOfBoundsException(lightNumber);
}
this.targetStripColor = null;
this.buffer.setLED(lightNumber, color);
}
Expand All @@ -74,7 +77,7 @@ public void setStripColorRaw(Color color) {
}
}

private static double lerp(double v0, double v1, double amount) {
private static double interpolate(double v0, double v1, double amount) {
if (v0 == v1) {
return v0;
}
Expand All @@ -92,11 +95,11 @@ private static double lerp(double v0, double v1, double amount) {
* @param amount The amount to interpolate. [0, 1]
* @return The interpolated color.
*/
public static Color lerpColors(Color color1, Color color2, double amount) {
public static Color interpolateColors(Color color1, Color color2, double amount) {
return new Color(
lerp(color1.red, color2.red, amount),
lerp(color1.blue, color2.blue, amount),
lerp(color1.green, color2.green, amount));
interpolate(color1.red, color2.red, amount),
interpolate(color1.blue, color2.blue, amount),
interpolate(color1.green, color2.green, amount));
}

/**
Expand Down Expand Up @@ -158,7 +161,7 @@ public void periodic() {
this.targetLightEntry.setBoolean(atTarget);
if (!atTarget) {
for (int led = 0; led < this.buffer.getLength(); led++) {
Color c = lerpColors(this.buffer.getLED(led), targetStripColor, fadeSpeed);
Color c = interpolateColors(this.buffer.getLED(led), targetStripColor, fadeSpeed);
this.buffer.setLED(led, c);
}
this.flush();
Expand Down

0 comments on commit 754d20a

Please sign in to comment.