Created
December 20, 2023 21:07
-
-
Save tervay/b3fc777f8d430d389e6126e173d941ed to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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