-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to camera handling and swerve
- Loading branch information
1 parent
04cef6c
commit 2ecca04
Showing
9 changed files
with
182 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/techhounds/houndutil/houndlib/TriConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.techhounds.houndutil.houndlib; | ||
|
||
import java.util.Objects; | ||
|
||
@FunctionalInterface | ||
public interface TriConsumer<A, B, C> { | ||
void accept(A a, B b, C c); | ||
|
||
default TriConsumer<A, B, C> andThen(TriConsumer<? super A, ? super B, ? super C> after) { | ||
Objects.requireNonNull(after); | ||
|
||
return (a, b, c) -> { | ||
accept(a, b, c); | ||
after.accept(a, b, c); | ||
}; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/techhounds/houndutil/houndlib/ValueContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.techhounds.houndutil.houndlib; | ||
|
||
public class ValueContainer { | ||
public int value; | ||
|
||
public ValueContainer(int value) { | ||
this.value = value; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/techhounds/houndutil/houndlib/leds/Patterns.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.techhounds.houndutil.houndlib.leds; | ||
|
||
import com.techhounds.houndutil.houndlib.ValueContainer; | ||
|
||
import edu.wpi.first.wpilibj.AddressableLEDBuffer; | ||
import edu.wpi.first.wpilibj.Timer; | ||
import edu.wpi.first.wpilibj.util.Color; | ||
import edu.wpi.first.wpilibj.util.Color8Bit; | ||
|
||
public class Patterns { | ||
/** | ||
* Changes the contents of the AddressableLEDBuffer to the rainbow state. | ||
*/ | ||
|
||
public static Runnable rainbow(double firstIndex, double lastIndex, AddressableLEDBuffer buffer) { | ||
ValueContainer firstPixelHue = new ValueContainer(0); | ||
|
||
return () -> { | ||
for (int i = 0; i < buffer.getLength(); i++) { | ||
// Calculate the hue - hue is easier for rainbows because the color | ||
// shape is a circle so only one value needs to change | ||
final var hue = (firstPixelHue.value + (i * 180 / buffer.getLength())) % 180; | ||
// Set the value | ||
buffer.setHSV(i, hue, 255, 255); // max brightness until adjusted later | ||
|
||
} | ||
// Increase by 3 to make the rainbow "move" | ||
firstPixelHue.value += 3; | ||
// Check bounds | ||
firstPixelHue.value %= 180; | ||
}; | ||
} | ||
|
||
public static Runnable solid(Color color, double firstIndex, double lastIndex, AddressableLEDBuffer buffer) { | ||
return () -> { | ||
for (int i = 0; i < buffer.getLength(); i++) { | ||
buffer.setLED(i, color); | ||
} | ||
}; | ||
} | ||
|
||
public static Runnable flash(Color color, double onDuration, double firstIndex, double lastIndex, | ||
AddressableLEDBuffer buffer) { | ||
return () -> { | ||
|
||
for (int i = 0; i < buffer.getLength(); i++) { | ||
if (Timer.getFPGATimestamp() % (onDuration * 2) > onDuration) { | ||
buffer.setLED(i, color); | ||
} else { | ||
buffer.setLED(i, Color.kBlack); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Changes the contents of the AddressableLEDBuffer to the TechHOUNDS state. | ||
*/ | ||
private static void techHounds(AddressableLEDBuffer buffer) { | ||
ValueContainer timeStep = new ValueContainer(0); | ||
|
||
for (int i = 0; i < buffer.getLength(); i++) { | ||
if (((i + timeStep.value) / 8) % 2 == 0) { // shifts back and forth every 8 pixels | ||
buffer.setHSV(i, 15, 250, 255); // gold | ||
} else { | ||
buffer.setHSV(i, 109, 240, 255); // blue | ||
} | ||
} | ||
timeStep.value += 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters