[wpilib] DriverStation: Change alliance station to use optional (#5229)

Many teams have issues trying to read the DS too early. By switching to an optional, we cause teams to check 2 things. Either 1) they explicitly check, and their code is correct, or 2) they just read .value() and their code reboots in a loop. However, because the DS will eventually connect, this 2nd case is ok, and should theoretically be undetectable on the field.
This commit is contained in:
Thad House
2023-07-22 15:19:28 -07:00
committed by GitHub
parent ef155438bd
commit fc56f8049a
17 changed files with 179 additions and 86 deletions

View File

@@ -5,6 +5,7 @@
package edu.wpi.first.hal;
public enum AllianceStationID {
Unknown,
Red1,
Red2,
Red3,

View File

@@ -147,12 +147,13 @@ public class DriverStationJNI extends JNIWrapper {
*/
private static native int nativeGetAllianceStation();
public static final int kRed1AllianceStation = 0;
public static final int kRed2AllianceStation = 1;
public static final int kRed3AllianceStation = 2;
public static final int kBlue1AllianceStation = 3;
public static final int kBlue2AllianceStation = 4;
public static final int kBlue3AllianceStation = 5;
public static final int kUnknownAllianceStation = 0;
public static final int kRed1AllianceStation = 1;
public static final int kRed2AllianceStation = 2;
public static final int kRed3AllianceStation = 3;
public static final int kBlue1AllianceStation = 4;
public static final int kBlue2AllianceStation = 5;
public static final int kBlue3AllianceStation = 6;
/**
* Gets the current alliance station ID.
@@ -162,6 +163,8 @@ public class DriverStationJNI extends JNIWrapper {
*/
public static AllianceStationID getAllianceStation() {
switch (nativeGetAllianceStation()) {
case kUnknownAllianceStation:
return AllianceStationID.Unknown;
case kRed1AllianceStation:
return AllianceStationID.Red1;
case kRed2AllianceStation: