mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[hal] Update runtime enum to allow selecting roborio 2 (#3565)
In some cases, knowing roborio 2 might be useful. This also creates a higher level enum that might be usable later for the discussion on more complex runtime types.
This commit is contained in:
@@ -160,6 +160,15 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
@Override
|
||||
public void close() {}
|
||||
|
||||
/**
|
||||
* Get the current runtime type.
|
||||
*
|
||||
* @return Current runtime type.
|
||||
*/
|
||||
public static RuntimeType getRuntimeType() {
|
||||
return RuntimeType.getValue(HALUtil.getHALRuntimeType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the robot is a simulation.
|
||||
*
|
||||
@@ -175,7 +184,8 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
* @return If the robot is running in the real world.
|
||||
*/
|
||||
public static boolean isReal() {
|
||||
return HALUtil.getHALRuntimeType() == 0;
|
||||
RuntimeType runtimeType = getRuntimeType();
|
||||
return runtimeType == RuntimeType.kRoboRIO || runtimeType == RuntimeType.kRoboRIO2;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
34
wpilibj/src/main/java/edu/wpi/first/wpilibj/RuntimeType.java
Normal file
34
wpilibj/src/main/java/edu/wpi/first/wpilibj/RuntimeType.java
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.hal.HALUtil;
|
||||
|
||||
public enum RuntimeType {
|
||||
kRoboRIO(HALUtil.RUNTIME_ROBORIO),
|
||||
kRoboRIO2(HALUtil.RUNTIME_ROBORIO2),
|
||||
kSimulation(HALUtil.RUNTIME_SIMULATION);
|
||||
|
||||
public final int value;
|
||||
|
||||
RuntimeType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a runtime type from an int value.
|
||||
*
|
||||
* @param type Runtime type as int
|
||||
* @return Matching runtime type
|
||||
*/
|
||||
public static RuntimeType getValue(int type) {
|
||||
if (type == HALUtil.RUNTIME_ROBORIO) {
|
||||
return RuntimeType.kRoboRIO;
|
||||
} else if (type == HALUtil.RUNTIME_ROBORIO2) {
|
||||
return RuntimeType.kRoboRIO2;
|
||||
}
|
||||
return RuntimeType.kSimulation;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user