[wpilib] LEDPattern: Add usage reporting (#8452)

This commit is contained in:
Peter Johnson
2025-12-06 09:16:45 -08:00
committed by GitHub
parent a61866912b
commit 0d1dd84e86
2 changed files with 19 additions and 1 deletions

View File

@@ -9,6 +9,8 @@ import static edu.wpi.first.units.Units.Microsecond;
import static edu.wpi.first.units.Units.Microseconds;
import static edu.wpi.first.units.Units.Value;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.units.collections.LongToObjectHashMap;
import edu.wpi.first.units.measure.Dimensionless;
@@ -149,6 +151,7 @@ public interface LEDPattern {
* @return the mapped pattern
*/
default LEDPattern mapIndex(IndexMapper indexMapper) {
HAL.report(tResourceType.kResourceType_LEDPattern, 1);
return (reader, writer) -> {
int bufLen = reader.getLength();
applyTo(
@@ -294,6 +297,7 @@ public interface LEDPattern {
final long totalTimeMicros = (long) (onTime.in(Microseconds) + offTime.in(Microseconds));
final long onTimeMicros = (long) onTime.in(Microseconds);
HAL.report(tResourceType.kResourceType_LEDPattern, 1);
return (reader, writer) -> {
if (RobotController.getTime() % totalTimeMicros < onTimeMicros) {
applyTo(reader, writer);
@@ -323,6 +327,7 @@ public interface LEDPattern {
* @return the blinking pattern
*/
default LEDPattern synchronizedBlink(BooleanSupplier signal) {
HAL.report(tResourceType.kResourceType_LEDPattern, 1);
return (reader, writer) -> {
if (signal.getAsBoolean()) {
applyTo(reader, writer);
@@ -342,6 +347,7 @@ public interface LEDPattern {
default LEDPattern breathe(Time period) {
final long periodMicros = (long) period.in(Microseconds);
HAL.report(tResourceType.kResourceType_LEDPattern, 1);
return (reader, writer) -> {
applyTo(
reader,
@@ -373,6 +379,7 @@ public interface LEDPattern {
* @return the combined overlay pattern
*/
default LEDPattern overlayOn(LEDPattern base) {
HAL.report(tResourceType.kResourceType_LEDPattern, 1);
return (reader, writer) -> {
// write the base pattern down first...
base.applyTo(reader, writer);
@@ -400,6 +407,7 @@ public interface LEDPattern {
* @return the blended pattern
*/
default LEDPattern blend(LEDPattern other) {
HAL.report(tResourceType.kResourceType_LEDPattern, 1);
return (reader, writer) -> {
applyTo(reader, writer);
@@ -431,6 +439,7 @@ public interface LEDPattern {
* @return the masked pattern
*/
default LEDPattern mask(LEDPattern mask) {
HAL.report(tResourceType.kResourceType_LEDPattern, 1);
return (reader, writer) -> {
// Apply the current pattern down as normal...
applyTo(reader, writer);
@@ -470,6 +479,7 @@ public interface LEDPattern {
default LEDPattern atBrightness(Dimensionless relativeBrightness) {
double multiplier = relativeBrightness.in(Value);
HAL.report(tResourceType.kResourceType_LEDPattern, 1);
return (reader, writer) -> {
applyTo(
reader,
@@ -496,6 +506,7 @@ public interface LEDPattern {
* @return the pattern
*/
static LEDPattern solid(Color color) {
HAL.report(tResourceType.kResourceType_LEDPattern, 1);
return (reader, writer) -> {
int bufLen = reader.getLength();
for (int led = 0; led < bufLen; led++) {
@@ -525,6 +536,7 @@ public interface LEDPattern {
* @return the mask pattern
*/
static LEDPattern progressMaskLayer(DoubleSupplier progressSupplier) {
HAL.report(tResourceType.kResourceType_LEDPattern, 1);
return (reader, writer) -> {
double progress = MathUtil.clamp(progressSupplier.getAsDouble(), 0, 1);
@@ -561,6 +573,7 @@ public interface LEDPattern {
* @return a motionless step pattern
*/
static LEDPattern steps(Map<? extends Number, Color> steps) {
HAL.report(tResourceType.kResourceType_LEDPattern, 1);
if (steps.isEmpty()) {
// no colors specified
DriverStation.reportWarning("Creating LED steps with no colors!", false);
@@ -622,6 +635,7 @@ public interface LEDPattern {
* @return a motionless gradient pattern
*/
static LEDPattern gradient(GradientType type, Color... colors) {
HAL.report(tResourceType.kResourceType_LEDPattern, 1);
if (colors.length == 0) {
// Nothing to display
DriverStation.reportWarning("Creating a gradient with no colors!", false);
@@ -679,6 +693,7 @@ public interface LEDPattern {
* @return the rainbow pattern
*/
static LEDPattern rainbow(int saturation, int value) {
HAL.report(tResourceType.kResourceType_LEDPattern, 1);
return (reader, writer) -> {
int bufLen = reader.getLength();
for (int i = 0; i < bufLen; i++) {