mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
[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:
@@ -533,7 +533,7 @@ int DriverStation::GetReplayNumber() {
|
||||
return info.replayNumber;
|
||||
}
|
||||
|
||||
DriverStation::Alliance DriverStation::GetAlliance() {
|
||||
std::optional<DriverStation::Alliance> DriverStation::GetAlliance() {
|
||||
int32_t status = 0;
|
||||
auto allianceStationID = HAL_GetAllianceStation(&status);
|
||||
switch (allianceStationID) {
|
||||
@@ -546,11 +546,11 @@ DriverStation::Alliance DriverStation::GetAlliance() {
|
||||
case HAL_AllianceStationID_kBlue3:
|
||||
return kBlue;
|
||||
default:
|
||||
return kInvalid;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
int DriverStation::GetLocation() {
|
||||
std::optional<int> DriverStation::GetLocation() {
|
||||
int32_t status = 0;
|
||||
auto allianceStationID = HAL_GetAllianceStation(&status);
|
||||
switch (allianceStationID) {
|
||||
@@ -564,7 +564,7 @@ int DriverStation::GetLocation() {
|
||||
case HAL_AllianceStationID_kBlue3:
|
||||
return 3;
|
||||
default:
|
||||
return 0;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include <units/time.h>
|
||||
@@ -21,7 +22,7 @@ namespace frc {
|
||||
*/
|
||||
class DriverStation final {
|
||||
public:
|
||||
enum Alliance { kRed, kBlue, kInvalid };
|
||||
enum Alliance { kRed, kBlue };
|
||||
enum MatchType { kNone, kPractice, kQualification, kElimination };
|
||||
|
||||
static constexpr int kJoystickPorts = 6;
|
||||
@@ -282,7 +283,7 @@ class DriverStation final {
|
||||
*
|
||||
* @return The Alliance enum (kRed, kBlue or kInvalid)
|
||||
*/
|
||||
static Alliance GetAlliance();
|
||||
static std::optional<Alliance> GetAlliance();
|
||||
|
||||
/**
|
||||
* Return the driver station location from the FMS.
|
||||
@@ -294,7 +295,7 @@ class DriverStation final {
|
||||
*
|
||||
* @return The location of the driver station (1-3, 0 for invalid)
|
||||
*/
|
||||
static int GetLocation();
|
||||
static std::optional<int> GetLocation();
|
||||
|
||||
/**
|
||||
* Wait for a DS connection.
|
||||
|
||||
Reference in New Issue
Block a user