Fix main function initialization (#1176)

I don't have a good way to ensure this always works, so this is going to be a documentation issue.
But initializeHardwareConfiguration is now reentrant, so we can just have all tests call it.
This commit is contained in:
Thad House
2018-07-08 15:41:31 -07:00
committed by Peter Johnson
parent f5b1028b5a
commit 89d15f061b
27 changed files with 86 additions and 729 deletions

View File

@@ -21,8 +21,6 @@ import edu.wpi.first.wpilibj.hal.FRCNetComm.tInstances;
import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
import edu.wpi.first.wpilibj.hal.HAL;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.internal.HardwareHLUsageReporting;
import edu.wpi.first.wpilibj.internal.HardwareTimer;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.util.WPILibVersion;
@@ -84,7 +82,6 @@ public abstract class RobotBase implements AutoCloseable {
* to put this code into it's own task that loads on boot so ensure that it runs.
*/
protected RobotBase() {
initializeHardwareConfiguration();
NetworkTableInstance inst = NetworkTableInstance.getDefault();
setupCameraServerShared();
inst.setNetworkIdentity("Robot");
@@ -198,24 +195,6 @@ public abstract class RobotBase implements AutoCloseable {
}
}
/**
* Common initialization for all robot programs.
*/
public static void initializeHardwareConfiguration() {
if (!HAL.initialize(500, 0)) {
throw new IllegalStateException("Failed to initialize. Terminating");
}
// Set some implementations so that the static methods work properly
Timer.SetImplementation(new HardwareTimer());
HLUsageReporting.SetImplementation(new HardwareHLUsageReporting());
RobotState.SetImplementation(DriverStation.getInstance());
// Call a CameraServer JNI function to force OpenCV native library loading
// Needed because all the OpenCV JNI functions don't have built in loading
CameraServerJNI.enumerateSinks();
}
/**
* Starting point for the applications.
*/
@@ -226,6 +205,10 @@ public abstract class RobotBase implements AutoCloseable {
throw new IllegalStateException("Failed to initialize. Terminating");
}
// Call a CameraServer JNI function to force OpenCV native library loading
// Needed because all the OpenCV JNI functions don't have built in loading
CameraServerJNI.enumerateSinks();
HAL.report(tResourceType.kResourceType_Language, tInstances.kLanguage_Java);
String robotName = "";