Skip to content

Commit

Permalink
Static Map in Ports.java
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahk17 authored and jonahk17 committed Sep 18, 2024
1 parent e7e4625 commit 6b6e19f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/org/sciborgs1155/lib/FaultLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
import edu.wpi.first.wpilibj.DutyCycleEncoder;
import edu.wpi.first.wpilibj.PowerDistribution;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import org.photonvision.PhotonCamera;
import org.sciborgs1155.robot.Ports;

/**
* FaultLogger allows for faults to be logged and displayed.
Expand Down Expand Up @@ -191,7 +190,12 @@ public static void register(CANSparkBase spark) {
() -> {
for (FaultID fault : FaultID.values()) {
if (spark.getFault(fault)) {
report(SparkUtils.name(spark), fault.name(), FaultType.ERROR);
report(
String.format(
"Name - %s ID- %s",
Ports.idToName.get(spark.getDeviceId()), String.valueOf(spark.getDeviceId())),
fault.name(),
FaultType.ERROR);
}
}
});
Expand Down Expand Up @@ -282,15 +286,12 @@ public static boolean check(CANSparkBase spark) {
* @return If the spark is working without errors.
*/
public static boolean check(CANSparkBase spark, REVLibError error) {
Map<Integer, String> nickname = new HashMap<>();
// nicknames for motors with corresponding ids
// ...

if (error != REVLibError.kOk) {
report(
String.format(
"Name - %s ID- %s",
nickname.get(spark.getDeviceId()), String.valueOf(spark.getDeviceId())),
Ports.idToName.get(spark.getDeviceId()), String.valueOf(spark.getDeviceId())),
error.name(),
FaultType.ERROR);
return false;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/sciborgs1155/robot/Ports.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
package org.sciborgs1155.robot;

import java.util.HashMap;
import java.util.Map;

public final class Ports {

public static Map<Integer, String> idToName;

static {
idToName = new HashMap();
// idToName.put(id, name);
}

public static final class OI {
public static final int OPERATOR = 0;
public static final int DRIVER = 1;
Expand Down

0 comments on commit 6b6e19f

Please sign in to comment.