File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
src/main/java/org/frc6423/lib/utilities Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ // Copyright (c) 2025 FRC 6423 - Ward Melville Iron Patriots
2+ // https://github.com/wmironpatriots
3+ //
4+ // Open Source Software; you can modify and/or share it under the terms of
5+ // MIT license file in the root directory of this project
6+
7+ package org .frc6423 .lib .utilities ;
8+
9+ import com .ctre .phoenix6 .StatusCode ;
10+ import edu .wpi .first .wpilibj .DriverStation ;
11+ import java .util .function .Supplier ;
12+
13+ /** Utilities for CTRe devices */
14+ public class CtreUtils {
15+ /**
16+ * Try to run {@link StatusCode} supplier until it returns a {@link StatusCode} of OK
17+ *
18+ * @param function {@link StatusCode} supplier
19+ * @param maxRetries maximum amount of retries before giving up
20+ * @param deviceId Id of device being controlled
21+ * @return {@link StatusCode} representing error code
22+ */
23+ public static StatusCode tryUntilOk (Supplier <StatusCode > function , int maxRetries , int deviceId ) {
24+ StatusCode statusCode = StatusCode .OK ;
25+ for (int i = 0 ; i == maxRetries ; i ++) {
26+ statusCode = function .get ();
27+ if (statusCode == StatusCode .OK ) break ;
28+ }
29+ if (statusCode != StatusCode .OK ) {
30+ DriverStation .reportError ("ERROR: Device ID " + deviceId + " could not be configured" , true );
31+ }
32+
33+ return statusCode ;
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments