Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move RobotType and MAC address detection #1

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc.robot.util.MACAddress;
import frc.robot.util.RobotType;

public class Robot extends TimedRobot {
/** Singleton Stuff */
private static Robot instance = null;

public enum RobotType {
COMPETITION,
CRANE,
BONK;
}

public static Robot getInstance() {
if (instance == null) instance = new Robot();
return instance;
Expand All @@ -32,23 +26,10 @@ public static Robot getInstance() {
public final Controls controls;
public final Subsystems subsystems;

public static final MACAddress COMPETITION_ADDRESS = MACAddress.of(0x38, 0xd9, 0x9e);
public static final MACAddress BONK_ADDRESS = MACAddress.of(0x33, 0x9D, 0xE7);
public static final MACAddress CRANE_ADDRESS = MACAddress.of(0x22, 0xB0, 0x92);

private static RobotType getTypeFromAddress() {
if (CRANE_ADDRESS.exists()) return RobotType.CRANE;
if (BONK_ADDRESS.exists()) return RobotType.BONK;
if (!COMPETITION_ADDRESS.exists())
DriverStation.reportWarning(
"Code running on unknown MAC Address! Running competition code anyways", false);
return RobotType.COMPETITION;
}

protected Robot() {
// non public for singleton. Protected so test class can subclass
instance = this;
robotType = getTypeFromAddress();
robotType = RobotType.getCurrent();

LiveWindow.disableAllTelemetry();

Expand Down
36 changes: 36 additions & 0 deletions src/main/java/frc/robot/util/RobotType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package frc.robot.util;

import edu.wpi.first.wpilibj.DriverStation;

public enum RobotType {
COMPETITION(0x38, 0xd9, 0x93),
CRANE(0x22, 0xb0, 0x92),
BONK(0x33, 0x9d, 0xe7);

@SuppressWarnings("ImmutableEnumChecker")
private final MACAddress macAddress;

RobotType(int a, int b, int c) {
macAddress = MACAddress.of(a, b, c);
}

private static RobotType detectType() {
for (RobotType robotType : RobotType.values()) {
if (robotType.macAddress.exists()) {
return robotType;
}
}
DriverStation.reportWarning(
"Code running on unknown MAC Address! Running competition code anyways", false);
return COMPETITION;
}

private static RobotType currentRobotType;

public static RobotType getCurrent() {
if (currentRobotType == null) {
currentRobotType = detectType();
}
return currentRobotType;
}
}
Loading