Skip to content

Instantly share code, notes, and snippets.

@tervay
Created December 20, 2023 21:07
Show Gist options
  • Select an option

  • Save tervay/b3fc777f8d430d389e6126e173d941ed to your computer and use it in GitHub Desktop.

Select an option

Save tervay/b3fc777f8d430d389e6126e173d941ed to your computer and use it in GitHub Desktop.
package frc.robot.util;
import com.revrobotics.CANSparkMax;
import com.revrobotics.REVLibError;
import java.util.function.Function;
public class SparkConfigurator {
private CANSparkMax spark;
private int uniqueConfigs = 0, totalCalls = 0;
public SparkConfigurator(CANSparkMax spark) {
this.spark = spark;
}
public SparkConfigurator checkOK(Function<CANSparkMax, REVLibError> setConfigCall) {
uniqueConfigs++;
REVLibError maybeError = REVLibError.kOk;
do {
maybeError = setConfigCall.apply(spark);
totalCalls++;
if (maybeError != REVLibError.kOk) {
System.out.println(
String.format(
"[%s] %s setting #%s not OK! (%s)",
maybeError.name(), spark.getDeviceId(), uniqueConfigs, totalCalls));
}
} while (maybeError != REVLibError.kOk);
return this;
}
public SparkConfigurator setInverted(boolean inverted, int times) {
for (int i = 0; i < times; i++) {
spark.setInverted(inverted);
}
return this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment