[hal,wpilib] Rename DriverStation constants to all caps

This commit is contained in:
Peter Johnson
2026-03-13 01:04:29 -07:00
parent 614eb1db18
commit 227f01f3bd
51 changed files with 555 additions and 550 deletions

View File

@@ -106,7 +106,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the up direction of a POV on the HID.
*/
public Trigger povUp() {
return pov(POVDirection.Up);
return pov(POVDirection.UP);
}
/**
@@ -117,7 +117,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the up right direction of a POV on the HID.
*/
public Trigger povUpRight() {
return pov(POVDirection.UpRight);
return pov(POVDirection.UP_RIGHT);
}
/**
@@ -128,7 +128,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the right direction of a POV on the HID.
*/
public Trigger povRight() {
return pov(POVDirection.Right);
return pov(POVDirection.RIGHT);
}
/**
@@ -139,7 +139,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the down right direction of a POV on the HID.
*/
public Trigger povDownRight() {
return pov(POVDirection.DownRight);
return pov(POVDirection.DOWN_RIGHT);
}
/**
@@ -150,7 +150,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the down direction of a POV on the HID.
*/
public Trigger povDown() {
return pov(POVDirection.Down);
return pov(POVDirection.DOWN);
}
/**
@@ -161,7 +161,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the down left POV direction of a POV on the HID.
*/
public Trigger povDownLeft() {
return pov(POVDirection.DownLeft);
return pov(POVDirection.DOWN_LEFT);
}
/**
@@ -172,7 +172,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the left direction of a POV on the HID.
*/
public Trigger povLeft() {
return pov(POVDirection.Left);
return pov(POVDirection.LEFT);
}
/**
@@ -183,7 +183,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the up left direction of a POV on the HID.
*/
public Trigger povUpLeft() {
return pov(POVDirection.UpLeft);
return pov(POVDirection.UP_LEFT);
}
/**
@@ -194,7 +194,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the center position of a POV on the HID.
*/
public Trigger povCenter() {
return pov(POVDirection.Center);
return pov(POVDirection.CENTER);
}
/**

View File

@@ -28,39 +28,39 @@ Trigger CommandGenericHID::POV(int pov, wpi::DriverStation::POVDirection angle,
}
Trigger CommandGenericHID::POVUp(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kUp, loop);
return POV(wpi::DriverStation::POVDirection::UP, loop);
}
Trigger CommandGenericHID::POVUpRight(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kUpRight, loop);
return POV(wpi::DriverStation::POVDirection::UP_RIGHT, loop);
}
Trigger CommandGenericHID::POVRight(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kRight, loop);
return POV(wpi::DriverStation::POVDirection::RIGHT, loop);
}
Trigger CommandGenericHID::POVDownRight(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kDownRight, loop);
return POV(wpi::DriverStation::POVDirection::DOWN_RIGHT, loop);
}
Trigger CommandGenericHID::POVDown(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kDown, loop);
return POV(wpi::DriverStation::POVDirection::DOWN, loop);
}
Trigger CommandGenericHID::POVDownLeft(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kDownLeft, loop);
return POV(wpi::DriverStation::POVDirection::DOWN_LEFT, loop);
}
Trigger CommandGenericHID::POVLeft(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kLeft, loop);
return POV(wpi::DriverStation::POVDirection::LEFT, loop);
}
Trigger CommandGenericHID::POVUpLeft(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kUpLeft, loop);
return POV(wpi::DriverStation::POVDirection::UP_LEFT, loop);
}
Trigger CommandGenericHID::POVCenter(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kCenter, loop);
return POV(wpi::DriverStation::POVDirection::CENTER, loop);
}
Trigger CommandGenericHID::AxisLessThan(int axis, double threshold,

View File

@@ -19,7 +19,7 @@ class POVButtonTest : public CommandTestBase {};
TEST_F(POVButtonTest, SetPOV) {
wpi::sim::JoystickSim joysim(1);
joysim.SetPOV(wpi::DriverStation::kUp);
joysim.SetPOV(wpi::DriverStation::POVDirection::UP);
joysim.NotifyNewData();
auto& scheduler = CommandScheduler::GetInstance();
@@ -28,11 +28,11 @@ TEST_F(POVButtonTest, SetPOV) {
WaitUntilCommand command([&finished] { return finished; });
wpi::Joystick joy(1);
POVButton(&joy, wpi::DriverStation::kRight).OnTrue(&command);
POVButton(&joy, wpi::DriverStation::POVDirection::RIGHT).OnTrue(&command);
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&command));
joysim.SetPOV(wpi::DriverStation::kRight);
joysim.SetPOV(wpi::DriverStation::POVDirection::RIGHT);
joysim.NotifyNewData();
scheduler.Run();

View File

@@ -16,7 +16,7 @@ class RobotModeTriggersTest : public CommandTestBase {};
TEST(RobotModeTriggersTest, Autonomous) {
DriverStationSim::ResetData();
DriverStationSim::SetRobotMode(HAL_ROBOTMODE_AUTONOMOUS);
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_AUTONOMOUS);
DriverStationSim::SetEnabled(true);
DriverStationSim::NotifyNewData();
Trigger autonomous = RobotModeTriggers::Autonomous();
@@ -25,7 +25,7 @@ TEST(RobotModeTriggersTest, Autonomous) {
TEST(RobotModeTriggersTest, Teleop) {
DriverStationSim::ResetData();
DriverStationSim::SetRobotMode(HAL_ROBOTMODE_TELEOPERATED);
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TELEOPERATED);
DriverStationSim::SetEnabled(true);
DriverStationSim::NotifyNewData();
Trigger teleop = RobotModeTriggers::Teleop();
@@ -42,7 +42,7 @@ TEST(RobotModeTriggersTest, Disabled) {
TEST(RobotModeTriggersTest, TestMode) {
DriverStationSim::ResetData();
DriverStationSim::SetRobotMode(HAL_ROBOTMODE_TEST);
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TEST);
DriverStationSim::SetEnabled(true);
DriverStationSim::NotifyNewData();
Trigger test = RobotModeTriggers::Test();

View File

@@ -120,7 +120,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the 0 degree angle of a POV on the HID.
*/
public Trigger povUp() {
return pov(POVDirection.Up);
return pov(POVDirection.UP);
}
/**
@@ -131,7 +131,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the 45 degree angle of a POV on the HID.
*/
public Trigger povUpRight() {
return pov(POVDirection.UpRight);
return pov(POVDirection.UP_RIGHT);
}
/**
@@ -142,7 +142,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the 90 degree angle of a POV on the HID.
*/
public Trigger povRight() {
return pov(POVDirection.Right);
return pov(POVDirection.RIGHT);
}
/**
@@ -153,7 +153,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the 135 degree angle of a POV on the HID.
*/
public Trigger povDownRight() {
return pov(POVDirection.DownRight);
return pov(POVDirection.DOWN_RIGHT);
}
/**
@@ -164,7 +164,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the 180 degree angle of a POV on the HID.
*/
public Trigger povDown() {
return pov(POVDirection.Down);
return pov(POVDirection.DOWN);
}
/**
@@ -175,7 +175,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the 225 degree angle of a POV on the HID.
*/
public Trigger povDownLeft() {
return pov(POVDirection.DownLeft);
return pov(POVDirection.DOWN_LEFT);
}
/**
@@ -186,7 +186,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the 270 degree angle of a POV on the HID.
*/
public Trigger povLeft() {
return pov(POVDirection.Left);
return pov(POVDirection.LEFT);
}
/**
@@ -197,7 +197,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the 315 degree angle of a POV on the HID.
*/
public Trigger povUpLeft() {
return pov(POVDirection.UpLeft);
return pov(POVDirection.UP_LEFT);
}
/**
@@ -208,7 +208,7 @@ public class CommandGenericHID {
* @return a Trigger instance based around the center position of a POV on the HID.
*/
public Trigger povCenter() {
return pov(POVDirection.Center);
return pov(POVDirection.CENTER);
}
/**

View File

@@ -7,17 +7,17 @@ package org.wpilib.hardware.hal;
/** Alliance station ID. */
public enum AllianceStationID {
/** Unknown. */
Unknown,
UNKNOWN,
/** Red 1. */
Red1,
RED_1,
/** Red 2. */
Red2,
RED_2,
/** Red 3. */
Red3,
RED_3,
/** Blue 1. */
Blue1,
BLUE_1,
/** Blue 2. */
Blue2,
BLUE_2,
/** Blue 3. */
Blue3
BLUE_3
}

View File

@@ -93,25 +93,25 @@ public class DriverStationJNI extends JNIWrapper {
private static native int nativeGetAllianceStation();
/** Unknown Alliance Station ID. */
public static final int kUnknownAllianceStation = 0;
public static final int ALLIANCE_STATION_UNKNOWN = 0;
/** Red Alliance Station 1 ID. */
public static final int kRed1AllianceStation = 1;
public static final int ALLIANCE_STATION_RED_1 = 1;
/** Red Alliance Station 2 ID. */
public static final int kRed2AllianceStation = 2;
public static final int ALLIANCE_STATION_RED_2 = 2;
/** Red Alliance Station 3 ID. */
public static final int kRed3AllianceStation = 3;
public static final int ALLIANCE_STATION_RED_3 = 3;
/** Blue Alliance Station 1 ID. */
public static final int kBlue1AllianceStation = 4;
public static final int ALLIANCE_STATION_BLUE_1 = 4;
/** Blue Alliance Station 2 ID. */
public static final int kBlue2AllianceStation = 5;
public static final int ALLIANCE_STATION_BLUE_2 = 5;
/** Blue Alliance Station 3 ID. */
public static final int kBlue3AllianceStation = 6;
public static final int ALLIANCE_STATION_BLUE_3 = 6;
/**
* Gets the current alliance station ID.
@@ -121,33 +121,33 @@ public class DriverStationJNI extends JNIWrapper {
*/
public static AllianceStationID getAllianceStation() {
return switch (nativeGetAllianceStation()) {
case kUnknownAllianceStation -> AllianceStationID.Unknown;
case kRed1AllianceStation -> AllianceStationID.Red1;
case kRed2AllianceStation -> AllianceStationID.Red2;
case kRed3AllianceStation -> AllianceStationID.Red3;
case kBlue1AllianceStation -> AllianceStationID.Blue1;
case kBlue2AllianceStation -> AllianceStationID.Blue2;
case kBlue3AllianceStation -> AllianceStationID.Blue3;
case ALLIANCE_STATION_UNKNOWN -> AllianceStationID.UNKNOWN;
case ALLIANCE_STATION_RED_1 -> AllianceStationID.RED_1;
case ALLIANCE_STATION_RED_2 -> AllianceStationID.RED_2;
case ALLIANCE_STATION_RED_3 -> AllianceStationID.RED_3;
case ALLIANCE_STATION_BLUE_1 -> AllianceStationID.BLUE_1;
case ALLIANCE_STATION_BLUE_2 -> AllianceStationID.BLUE_2;
case ALLIANCE_STATION_BLUE_3 -> AllianceStationID.BLUE_3;
default -> null;
};
}
/** The maximum number of axes. */
public static final int kMaxJoystickAxes = 12;
public static final int MAX_JOYSTICK_AXES = 12;
public static final int kMaxJoystickButtons = 64;
public static final int MAX_JOYSTICK_BUTTONS = 64;
/** The maximum number of POVs. */
public static final int kMaxJoystickPOVs = 8;
public static final int MAX_JOYSTICK_POVS = 8;
/** The maximum number of joysticks. */
public static final int kMaxJoysticks = 6;
public static final int MAX_JOYSTICKS = 6;
/** The maximum number of touchpads. */
public static final int kMaxJoystickTouchpads = 2;
public static final int MAX_JOYSTICK_TOUCHPADS = 2;
/** The maximum number of fingers per touchpad. */
public static final int kMaxJoystickTouchpadFingers = 2;
public static final int MAX_JOYSTICK_TOUCHPAD_FINGERS = 2;
/**
* Get all joystick data.

View File

@@ -120,9 +120,9 @@ void hal::InitializeDashboardOpMode() {
void hal::SetDashboardOpModeOptions(std::span<const HAL_OpModeOption> options) {
std::scoped_lock lock{gInstance->mutex};
gInstance->autoOpModes.SetOptions(options, HAL_ROBOTMODE_AUTONOMOUS);
gInstance->teleopOpModes.SetOptions(options, HAL_ROBOTMODE_TELEOPERATED);
gInstance->testOpModes.SetOptions(options, HAL_ROBOTMODE_TEST);
gInstance->autoOpModes.SetOptions(options, HAL_ROBOT_MODE_AUTONOMOUS);
gInstance->teleopOpModes.SetOptions(options, HAL_ROBOT_MODE_TELEOPERATED);
gInstance->testOpModes.SetOptions(options, HAL_ROBOT_MODE_TEST);
}
void hal::StartDashboardOpMode() {
@@ -150,11 +150,11 @@ int64_t hal::GetDashboardSelectedOpMode(HAL_RobotMode robotMode) {
}
std::scoped_lock lock{gInstance->mutex};
switch (robotMode) {
case HAL_ROBOTMODE_AUTONOMOUS:
case HAL_ROBOT_MODE_AUTONOMOUS:
return gInstance->autoOpModes.GetSelected();
case HAL_ROBOTMODE_TELEOPERATED:
case HAL_ROBOT_MODE_TELEOPERATED:
return gInstance->teleopOpModes.GetSelected();
case HAL_ROBOTMODE_TEST:
case HAL_ROBOT_MODE_TEST:
return gInstance->testOpModes.GetSelected();
default:
return 0;

View File

@@ -17,32 +17,35 @@
#include "wpi/util/jni_util.hpp"
static_assert(
org_wpilib_hardware_hal_DriverStationJNI_kUnknownAllianceStation ==
HAL_AllianceStationID_kUnknown);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_kRed1AllianceStation ==
HAL_AllianceStationID_kRed1);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_kRed2AllianceStation ==
HAL_AllianceStationID_kRed2);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_kRed3AllianceStation ==
HAL_AllianceStationID_kRed3);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_kBlue1AllianceStation ==
HAL_AllianceStationID_kBlue1);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_kBlue2AllianceStation ==
HAL_AllianceStationID_kBlue2);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_kBlue3AllianceStation ==
HAL_AllianceStationID_kBlue3);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_kMaxJoystickAxes ==
HAL_kMaxJoystickAxes);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_kMaxJoystickPOVs ==
HAL_kMaxJoystickPOVs);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_kMaxJoysticks ==
HAL_kMaxJoysticks);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_kMaxJoystickTouchpads ==
HAL_kMaxJoystickTouchpads);
org_wpilib_hardware_hal_DriverStationJNI_ALLIANCE_STATION_UNKNOWN ==
HAL_ALLIANCE_STATION_UNKNOWN);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_ALLIANCE_STATION_RED_1 ==
HAL_ALLIANCE_STATION_RED_1);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_ALLIANCE_STATION_RED_2 ==
HAL_ALLIANCE_STATION_RED_2);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_ALLIANCE_STATION_RED_3 ==
HAL_ALLIANCE_STATION_RED_3);
static_assert(
org_wpilib_hardware_hal_DriverStationJNI_kMaxJoystickTouchpadFingers ==
HAL_kMaxJoystickTouchpadFingers);
org_wpilib_hardware_hal_DriverStationJNI_ALLIANCE_STATION_BLUE_1 ==
HAL_ALLIANCE_STATION_BLUE_1);
static_assert(
org_wpilib_hardware_hal_DriverStationJNI_ALLIANCE_STATION_BLUE_2 ==
HAL_ALLIANCE_STATION_BLUE_2);
static_assert(
org_wpilib_hardware_hal_DriverStationJNI_ALLIANCE_STATION_BLUE_3 ==
HAL_ALLIANCE_STATION_BLUE_3);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_MAX_JOYSTICK_AXES ==
HAL_MAX_JOYSTICK_AXES);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_MAX_JOYSTICK_POVS ==
HAL_MAX_JOYSTICK_POVS);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_MAX_JOYSTICKS ==
HAL_MAX_JOYSTICKS);
static_assert(org_wpilib_hardware_hal_DriverStationJNI_MAX_JOYSTICK_TOUCHPADS ==
HAL_MAX_JOYSTICK_TOUCHPADS);
static_assert(
org_wpilib_hardware_hal_DriverStationJNI_MAX_JOYSTICK_TOUCHPAD_FINGERS ==
HAL_MAX_JOYSTICK_TOUCHPAD_FINGERS);
using namespace wpi::hal;
using namespace wpi::util::java;

View File

@@ -485,7 +485,7 @@ Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickAxes
auto arrayRef = jArrayRef.array();
auto arraySize = arrayRef.size();
int maxCount =
arraySize < HAL_kMaxJoystickAxes ? arraySize : HAL_kMaxJoystickAxes;
arraySize < HAL_MAX_JOYSTICK_AXES ? arraySize : HAL_MAX_JOYSTICK_AXES;
axes.available = availableAxes;
for (int i = 0; i < maxCount; i++) {
axes.axes[i] = arrayRef[i];
@@ -511,7 +511,7 @@ Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickPOVs
auto arrayRef = jArrayRef.array();
auto arraySize = arrayRef.size();
int maxCount =
arraySize < HAL_kMaxJoystickPOVs ? arraySize : HAL_kMaxJoystickPOVs;
arraySize < HAL_MAX_JOYSTICK_POVS ? arraySize : HAL_MAX_JOYSTICK_POVS;
povs.available = availablePovs;
for (int i = 0; i < maxCount; i++) {
povs.povs[i] = static_cast<HAL_JoystickPOV>(arrayRef[i]);

View File

@@ -30,33 +30,33 @@ typedef struct HAL_ControlWord HAL_ControlWord;
HAL_ENUM(HAL_AllianceStationID) {
/** Unknown Alliance Station */
HAL_AllianceStationID_kUnknown = 0,
HAL_ALLIANCE_STATION_UNKNOWN = 0,
/** Red Alliance Station 1 */
HAL_AllianceStationID_kRed1,
HAL_ALLIANCE_STATION_RED_1,
/** Red Alliance Station 2 */
HAL_AllianceStationID_kRed2,
HAL_ALLIANCE_STATION_RED_2,
/** Red Alliance Station 3 */
HAL_AllianceStationID_kRed3,
HAL_ALLIANCE_STATION_RED_3,
/** Blue Alliance Station 1 */
HAL_AllianceStationID_kBlue1,
HAL_ALLIANCE_STATION_BLUE_1,
/** Blue Alliance Station 2 */
HAL_AllianceStationID_kBlue2,
HAL_ALLIANCE_STATION_BLUE_2,
/** Blue Alliance Station 3 */
HAL_AllianceStationID_kBlue3,
HAL_ALLIANCE_STATION_BLUE_3,
};
HAL_ENUM(HAL_MatchType) {
HAL_kMatchType_none = 0,
HAL_kMatchType_practice,
HAL_kMatchType_qualification,
HAL_kMatchType_elimination,
HAL_MATCH_TYPE_NONE = 0,
HAL_MATCH_TYPE_PRACTICE,
HAL_MATCH_TYPE_QUALIFICATION,
HAL_MATCH_TYPE_ELIMINATION,
};
HAL_ENUM(HAL_RobotMode) {
HAL_ROBOTMODE_UNKNOWN = 0,
HAL_ROBOTMODE_AUTONOMOUS,
HAL_ROBOTMODE_TELEOPERATED,
HAL_ROBOTMODE_TEST,
HAL_ROBOT_MODE_UNKNOWN = 0,
HAL_ROBOT_MODE_AUTONOMOUS,
HAL_ROBOT_MODE_TELEOPERATED,
HAL_ROBOT_MODE_TEST,
};
/**
@@ -64,63 +64,64 @@ HAL_ENUM(HAL_RobotMode) {
* HAL_JoystickTouchpads struct. This is used for allocating buffers, not
* bounds checking, since there are usually less touchpads in practice.
*/
#define HAL_kMaxJoystickTouchpads 2
#define HAL_MAX_JOYSTICK_TOUCHPADS 2
/**
* The maximum number of fingers that will be stored in a single
* HAL_JoystickTouchpad struct. This is used for allocating buffers, not
* bounds checking, since there are usually less fingers in practice.
*/
#define HAL_kMaxJoystickTouchpadFingers 2
#define HAL_MAX_JOYSTICK_TOUCHPAD_FINGERS 2
/**
* The maximum number of axes that will be stored in a single HAL_JoystickAxes
* struct. This is used for allocating buffers, not bounds checking, since there
* are usually less axes in practice.
*/
#define HAL_kMaxJoystickAxes 12
#define HAL_MAX_JOYSTICK_AXES 12
/**
* The maximum number of POVs that will be stored in a single HAL_JoystickPOVs
* struct. This is used for allocating buffers, not bounds checking, since there
* are usually less POVs in practice.
*/
#define HAL_kMaxJoystickPOVs 8
#define HAL_MAX_JOYSTICK_POVS 8
/**
* The maximum number of joysticks.
*/
#define HAL_kMaxJoysticks 6
#define HAL_MAX_JOYSTICKS 6
struct HAL_JoystickAxes {
uint16_t available;
float axes[HAL_kMaxJoystickAxes];
int16_t raw[HAL_kMaxJoystickAxes];
float axes[HAL_MAX_JOYSTICK_AXES];
int16_t raw[HAL_MAX_JOYSTICK_AXES];
};
typedef struct HAL_JoystickAxes HAL_JoystickAxes;
HAL_ENUM_WITH_UNDERLYING_TYPE(HAL_JoystickPOV, uint8_t){
/** Centered */
HAL_JoystickPOV_kCentered = 0x00u,
HAL_JOYSTICK_POV_CENTERED = 0x00u,
/** Up */
HAL_JoystickPOV_kUp = 0x01u,
HAL_JOYSTICK_POV_UP = 0x01u,
/** Right */
HAL_JoystickPOV_kRight = 0x02u,
HAL_JOYSTICK_POV_RIGHT = 0x02u,
/** Down */
HAL_JoystickPOV_kDown = 0x04u,
HAL_JOYSTICK_POV_DOWN = 0x04u,
/** Left */
HAL_JoystickPOV_kLeft = 0x08u,
HAL_JOYSTICK_POV_LEFT = 0x08u,
/** Right-Up */
HAL_JoystickPOV_kRightUp = HAL_JoystickPOV_kRight | HAL_JoystickPOV_kUp,
HAL_JOYSTICK_POV_RIGHT_UP = HAL_JOYSTICK_POV_RIGHT | HAL_JOYSTICK_POV_UP,
/** Right-Down */
HAL_JoystickPOV_kRightDown = HAL_JoystickPOV_kRight | HAL_JoystickPOV_kDown,
HAL_JOYSTICK_POV_RIGHT_DOWN = HAL_JOYSTICK_POV_RIGHT |
HAL_JOYSTICK_POV_DOWN,
/** Left-Up */
HAL_JoystickPOV_kLeftUp = HAL_JoystickPOV_kLeft | HAL_JoystickPOV_kUp,
HAL_JOYSTICK_POV_LEFT_UP = HAL_JOYSTICK_POV_LEFT | HAL_JOYSTICK_POV_UP,
/** Left-Down */
HAL_JoystickPOV_kLeftDown = HAL_JoystickPOV_kLeft | HAL_JoystickPOV_kDown,
HAL_JOYSTICK_POV_LEFT_DOWN = HAL_JOYSTICK_POV_LEFT | HAL_JOYSTICK_POV_DOWN,
};
struct HAL_JoystickPOVs {
uint8_t available;
HAL_JoystickPOV povs[HAL_kMaxJoystickPOVs];
HAL_JoystickPOV povs[HAL_MAX_JOYSTICK_POVS];
};
typedef struct HAL_JoystickPOVs HAL_JoystickPOVs;
@@ -139,13 +140,13 @@ typedef struct HAL_JoystickTouchpadFinger HAL_JoystickTouchpadFinger;
struct HAL_JoystickTouchpad {
uint8_t count;
HAL_JoystickTouchpadFinger fingers[HAL_kMaxJoystickTouchpadFingers];
HAL_JoystickTouchpadFinger fingers[HAL_MAX_JOYSTICK_TOUCHPAD_FINGERS];
};
typedef struct HAL_JoystickTouchpad HAL_JoystickTouchpad;
struct HAL_JoystickTouchpads {
uint8_t count;
HAL_JoystickTouchpad touchpads[HAL_kMaxJoystickTouchpads];
HAL_JoystickTouchpad touchpads[HAL_MAX_JOYSTICK_TOUCHPADS];
};
typedef struct HAL_JoystickTouchpads HAL_JoystickTouchpads;

View File

@@ -14,13 +14,13 @@ namespace wpi::hal {
*/
enum class RobotMode {
/// Unknown.
UNKNOWN = HAL_ROBOTMODE_UNKNOWN,
UNKNOWN = HAL_ROBOT_MODE_UNKNOWN,
/// Autonomous.
AUTONOMOUS = HAL_ROBOTMODE_AUTONOMOUS,
AUTONOMOUS = HAL_ROBOT_MODE_AUTONOMOUS,
/// Teleoperated.
TELEOPERATED = HAL_ROBOTMODE_TELEOPERATED,
TELEOPERATED = HAL_ROBOT_MODE_TELEOPERATED,
/// Test.
TEST = HAL_ROBOTMODE_TEST
TEST = HAL_ROBOT_MODE_TEST
};
/**

View File

@@ -80,7 +80,7 @@ void JoystickDataCache::Update() {
}
#define CHECK_JOYSTICK_NUMBER(stickNum) \
if ((stickNum) < 0 || (stickNum) >= HAL_kMaxJoysticks) \
if ((stickNum) < 0 || (stickNum) >= HAL_MAX_JOYSTICKS) \
return PARAMETER_OUT_OF_RANGE
static HAL_ControlWord newestControlWord;
@@ -98,7 +98,7 @@ struct TcpCache {
void CloneTo(TcpCache* other) { std::memcpy(other, this, sizeof(*this)); }
HAL_MatchInfo matchInfo;
HAL_JoystickDescriptor descriptors[HAL_kMaxJoysticks];
HAL_JoystickDescriptor descriptors[HAL_MAX_JOYSTICKS];
};
static_assert(std::is_standard_layout_v<TcpCache>);
} // namespace
@@ -109,7 +109,7 @@ static TcpCache tcpCurrent;
void TcpCache::Update() {
SimDriverStationData->GetMatchInfo(&matchInfo);
for (int i = 0; i < HAL_kMaxJoysticks; i++) {
for (int i = 0; i < HAL_MAX_JOYSTICKS; i++) {
SimDriverStationData->GetJoystickDescriptor(i, &descriptors[i]);
}
}
@@ -259,7 +259,7 @@ int32_t HAL_SetOpModeOptions(const struct HAL_OpModeOption* options,
HAL_AllianceStationID HAL_GetAllianceStation(int32_t* status) {
if (gShutdown) {
return HAL_AllianceStationID_kUnknown;
return HAL_ALLIANCE_STATION_UNKNOWN;
}
std::scoped_lock lock{driverStation->cacheMutex};
return currentRead->allianceStation;

View File

@@ -46,7 +46,7 @@ DriverStationData::~DriverStationData() {
void DriverStationData::ResetData() {
enabled.Reset(false);
robotMode.Reset(HAL_ROBOTMODE_UNKNOWN);
robotMode.Reset(HAL_ROBOT_MODE_UNKNOWN);
eStop.Reset(false);
fmsAttached.Reset(false);
dsAttached.Reset(false);
@@ -413,7 +413,7 @@ void DriverStationData::SetJoystickAxis(int32_t stick, int32_t axis,
if (stick < 0 || stick >= kNumJoysticks) {
return;
}
if (axis < 0 || axis >= HAL_kMaxJoystickAxes) {
if (axis < 0 || axis >= HAL_MAX_JOYSTICK_AXES) {
return;
}
std::scoped_lock lock(m_joystickDataMutex);
@@ -426,7 +426,7 @@ void DriverStationData::SetJoystickPOV(int32_t stick, int32_t pov,
if (stick < 0 || stick >= kNumJoysticks) {
return;
}
if (pov < 0 || pov >= HAL_kMaxJoystickPOVs) {
if (pov < 0 || pov >= HAL_MAX_JOYSTICK_POVS) {
return;
}
std::scoped_lock lock(m_joystickDataMutex);
@@ -510,10 +510,10 @@ void DriverStationData::SetJoystickTouchpadFinger(int32_t stick,
if (stick < 0 || stick >= kNumJoysticks) {
return;
}
if (touchpad < 0 || touchpad >= HAL_kMaxJoystickTouchpads) {
if (touchpad < 0 || touchpad >= HAL_MAX_JOYSTICK_TOUCHPADS) {
return;
}
if (finger < 0 || finger >= HAL_kMaxJoystickTouchpadFingers) {
if (finger < 0 || finger >= HAL_MAX_JOYSTICK_TOUCHPAD_FINGERS) {
return;
}
std::scoped_lock lock(m_joystickDataMutex);

View File

@@ -168,7 +168,7 @@ class DriverStationData {
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetEnabledName> enabled{false};
SimDataValue<HAL_RobotMode, MakeRobotModeValue, GetRobotModeName> robotMode{
HAL_ROBOTMODE_UNKNOWN};
HAL_ROBOT_MODE_UNKNOWN};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetEStopName> eStop{false};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetFmsAttachedName> fmsAttached{
false};

View File

@@ -45,21 +45,22 @@
static_assert(sizeof(int32_t) >= sizeof(int),
"WPILIB_NetworkComm status variable is larger than 32 bits");
static_assert(MRC_MAX_NUM_AXES == HAL_kMaxJoystickAxes);
static_assert(MRC_MAX_NUM_POVS == HAL_kMaxJoystickPOVs);
static_assert(MRC_MAX_NUM_JOYSTICKS == HAL_kMaxJoysticks);
static_assert(MRC_MAX_NUM_TOUCHPADS == HAL_kMaxJoystickTouchpads);
static_assert(MRC_MAX_NUM_TOUCHPAD_FINGERS == HAL_kMaxJoystickTouchpadFingers);
static_assert(MRC_MAX_NUM_AXES == HAL_MAX_JOYSTICK_AXES);
static_assert(MRC_MAX_NUM_POVS == HAL_MAX_JOYSTICK_POVS);
static_assert(MRC_MAX_NUM_JOYSTICKS == HAL_MAX_JOYSTICKS);
static_assert(MRC_MAX_NUM_TOUCHPADS == HAL_MAX_JOYSTICK_TOUCHPADS);
static_assert(MRC_MAX_NUM_TOUCHPAD_FINGERS ==
HAL_MAX_JOYSTICK_TOUCHPAD_FINGERS);
namespace {
struct JoystickDataCache {
JoystickDataCache() { std::memset(this, 0, sizeof(*this)); }
void Update(const mrc::ControlData& data);
HAL_JoystickAxes axes[HAL_kMaxJoysticks];
HAL_JoystickPOVs povs[HAL_kMaxJoysticks];
HAL_JoystickButtons buttons[HAL_kMaxJoysticks];
HAL_JoystickTouchpads touchpads[HAL_kMaxJoysticks];
HAL_JoystickAxes axes[HAL_MAX_JOYSTICKS];
HAL_JoystickPOVs povs[HAL_MAX_JOYSTICKS];
HAL_JoystickButtons buttons[HAL_MAX_JOYSTICKS];
HAL_JoystickTouchpads touchpads[HAL_MAX_JOYSTICKS];
HAL_AllianceStationID allianceStation;
float matchTime;
HAL_ControlWord controlWord;
@@ -301,7 +302,7 @@ void JoystickDataCache::Update(const mrc::ControlData& data) {
}
}
// Mark remaining sticks as unavailable
for (size_t i = sticks.size(); i < HAL_kMaxJoysticks; i++) {
for (size_t i = sticks.size(); i < HAL_MAX_JOYSTICKS; i++) {
axes[i].available = 0;
povs[i].available = 0;
buttons[i].available = 0;
@@ -310,7 +311,7 @@ void JoystickDataCache::Update(const mrc::ControlData& data) {
}
#define CHECK_JOYSTICK_NUMBER(stickNum) \
if ((stickNum) < 0 || (stickNum) >= HAL_kMaxJoysticks) \
if ((stickNum) < 0 || (stickNum) >= HAL_MAX_JOYSTICKS) \
return PARAMETER_OUT_OF_RANGE
static HAL_ControlWord newestControlWord;
@@ -327,7 +328,7 @@ struct TcpCache {
void CloneTo(TcpCache* other) { std::memcpy(other, this, sizeof(*this)); }
HAL_MatchInfo matchInfo;
HAL_JoystickDescriptor descriptors[HAL_kMaxJoysticks];
HAL_JoystickDescriptor descriptors[HAL_MAX_JOYSTICKS];
};
static_assert(std::is_standard_layout_v<TcpCache>);
} // namespace

View File

@@ -15,12 +15,12 @@ void HALSIM_ResetDriverStationData(void) {}
RETURN)
DEFINE_CAPI(HAL_Bool, Enabled, false)
DEFINE_CAPI(HAL_RobotMode, RobotMode, HAL_ROBOTMODE_UNKNOWN)
DEFINE_CAPI(HAL_RobotMode, RobotMode, HAL_ROBOT_MODE_UNKNOWN)
DEFINE_CAPI(HAL_Bool, EStop, false)
DEFINE_CAPI(HAL_Bool, FmsAttached, false)
DEFINE_CAPI(HAL_Bool, DsAttached, false)
DEFINE_CAPI(HAL_AllianceStationID, AllianceStationId,
HAL_AllianceStationID_kRed1)
HAL_ALLIANCE_STATION_RED_1)
DEFINE_CAPI(double, MatchTime, 0)
DEFINE_CAPI(int64_t, OpMode, 0)

View File

@@ -6,14 +6,14 @@ extra_includes:
enums:
HAL_AllianceStationID:
value_prefix: HAL_AllianceStationID
value_prefix: HAL_ALLIANCE_STATION
HAL_JoystickPOV:
value_prefix: HAL_JoystickPOV
value_prefix: HAL_JOYSTICK_POV
HAL_MatchType:
value_prefix: HAL_kMatchType
value_prefix: HAL_MATCH_TYPE
HAL_RobotMode:
rename: _RobotMode
value_prefix: HAL_ROBOTMODE
value_prefix: HAL_ROBOT_MODE
classes:
HAL_ControlWord:
rename: _ControlWord

View File

@@ -25,12 +25,12 @@ TEST(DriverStationTest, Joystick) {
HAL_GetJoystickButtons(joystickNum, &buttons);
EXPECT_EQ(0, axes.available);
for (int i = 0; i < HAL_kMaxJoystickAxes; ++i) {
for (int i = 0; i < HAL_MAX_JOYSTICK_AXES; ++i) {
EXPECT_EQ(0, axes.axes[i]);
}
EXPECT_EQ(0, povs.available);
for (int i = 0; i < HAL_kMaxJoystickPOVs; ++i) {
for (int i = 0; i < HAL_MAX_JOYSTICK_POVS; ++i) {
EXPECT_EQ(0, povs.povs[i]);
}
@@ -53,9 +53,9 @@ TEST(DriverStationTest, Joystick) {
}
set_povs.available = 0x7;
set_povs.povs[0] = HAL_JoystickPOV_kUp;
set_povs.povs[1] = HAL_JoystickPOV_kRight;
set_povs.povs[2] = HAL_JoystickPOV_kDown;
set_povs.povs[0] = HAL_JOYSTICK_POV_UP;
set_povs.povs[1] = HAL_JOYSTICK_POV_RIGHT;
set_povs.povs[2] = HAL_JOYSTICK_POV_DOWN;
set_buttons.available = 0xFF;
set_buttons.buttons = 0xDEADBEEF;
@@ -82,9 +82,9 @@ TEST(DriverStationTest, Joystick) {
EXPECT_NEAR(0, axes.axes[6], 0.000001); // Should not have been set, still 0
EXPECT_EQ(0x7, povs.available);
EXPECT_EQ(HAL_JoystickPOV_kUp, povs.povs[0]);
EXPECT_EQ(HAL_JoystickPOV_kRight, povs.povs[1]);
EXPECT_EQ(HAL_JoystickPOV_kDown, povs.povs[2]);
EXPECT_EQ(HAL_JOYSTICK_POV_UP, povs.povs[0]);
EXPECT_EQ(HAL_JOYSTICK_POV_RIGHT, povs.povs[1]);
EXPECT_EQ(HAL_JOYSTICK_POV_DOWN, povs.povs[2]);
EXPECT_EQ(0, povs.povs[3]); // Should not have been set, still 0
EXPECT_EQ(0, povs.povs[4]); // Should not have been set, still 0
EXPECT_EQ(0, povs.povs[5]); // Should not have been set, still 0
@@ -104,12 +104,12 @@ TEST(DriverStationTest, Joystick) {
HAL_GetJoystickButtons(joystickNum, &buttons);
EXPECT_EQ(0, axes.available);
for (int i = 0; i < HAL_kMaxJoystickAxes; ++i) {
for (int i = 0; i < HAL_MAX_JOYSTICK_AXES; ++i) {
EXPECT_EQ(0, axes.axes[i]);
}
EXPECT_EQ(0, povs.available);
for (int i = 0; i < HAL_kMaxJoystickPOVs; ++i) {
for (int i = 0; i < HAL_MAX_JOYSTICK_POVS; ++i) {
EXPECT_EQ(0, povs.povs[i]);
}
@@ -124,7 +124,7 @@ TEST(DriverStationTest, EventInfo) {
wpi::util::format_to_n_c_str(info.eventName, sizeof(info.eventName),
eventName);
info.matchNumber = 5;
info.matchType = HAL_MatchType::HAL_kMatchType_qualification;
info.matchType = HAL_MatchType::HAL_MATCH_TYPE_QUALIFICATION;
info.replayNumber = 42;
HALSIM_SetMatchInfo(&info);
@@ -135,7 +135,7 @@ TEST(DriverStationTest, EventInfo) {
EXPECT_EQ(eventName, dataBack.eventName);
EXPECT_EQ(5, dataBack.matchNumber);
EXPECT_EQ(HAL_MatchType::HAL_kMatchType_qualification, dataBack.matchType);
EXPECT_EQ(HAL_MatchType::HAL_MATCH_TYPE_QUALIFICATION, dataBack.matchType);
EXPECT_EQ(42, dataBack.replayNumber);
}

View File

@@ -33,7 +33,7 @@ class MyRobot(wpilib.TimedRobot):
setAlliance = False
alliance = wpilib.DriverStation.getAlliance()
if alliance:
setAlliance = alliance == wpilib.DriverStation.Alliance.kRed
setAlliance = alliance == wpilib.DriverStation.Alliance.RED
# pull alliance port high if on red alliance, pull low if on blue alliance
self.allianceOutput.set(setAlliance)

View File

@@ -44,7 +44,7 @@ class MyRobot(wpilib.TimedRobot):
alliance = wpilib.DriverStation.getAlliance()
if alliance is not None:
allianceString = (
"R" if alliance == wpilib.DriverStation.Alliance.kRed else "B"
"R" if alliance == wpilib.DriverStation.Alliance.RED else "B"
)
enabledString = "E" if wpilib.DriverStation.isEnabled() else "D"

View File

@@ -18,24 +18,24 @@ using namespace halsim;
HAL_JoystickPOV DegreesToPOV(int degrees) {
switch (degrees) {
case 0:
return HAL_JoystickPOV_kUp;
return HAL_JOYSTICK_POV_UP;
case 45:
return HAL_JoystickPOV_kRightUp;
return HAL_JOYSTICK_POV_RIGHT_UP;
case 90:
return HAL_JoystickPOV_kRight;
return HAL_JOYSTICK_POV_RIGHT;
case 135:
return HAL_JoystickPOV_kRightDown;
return HAL_JOYSTICK_POV_RIGHT_DOWN;
case 180:
return HAL_JoystickPOV_kDown;
return HAL_JOYSTICK_POV_DOWN;
case 225:
return HAL_JoystickPOV_kLeftDown;
return HAL_JOYSTICK_POV_LEFT_DOWN;
case 270:
return HAL_JoystickPOV_kLeft;
return HAL_JOYSTICK_POV_LEFT;
case 315:
return HAL_JoystickPOV_kLeftUp;
return HAL_JOYSTICK_POV_LEFT_UP;
case -1:
default:
return HAL_JoystickPOV_kCentered;
return HAL_JOYSTICK_POV_CENTERED;
}
}
@@ -54,11 +54,11 @@ DSCommPacket::DSCommPacket() {
void DSCommPacket::SetControl(uint8_t control, uint8_t request) {
HAL_RobotMode robotMode;
if ((control & kAutonomous) != 0) {
robotMode = HAL_ROBOTMODE_AUTONOMOUS;
robotMode = HAL_ROBOT_MODE_AUTONOMOUS;
} else if ((control & kTest) != 0) {
robotMode = HAL_ROBOTMODE_TEST;
robotMode = HAL_ROBOT_MODE_TEST;
} else {
robotMode = HAL_ROBOTMODE_TELEOPERATED;
robotMode = HAL_ROBOT_MODE_TELEOPERATED;
}
m_control_word = HAL_MakeControlWord(
wpi::hal::GetDashboardSelectedOpMode(robotMode), robotMode,
@@ -256,7 +256,7 @@ void DSCommPacket::ReadJoystickDescriptionTag(std::span<const uint8_t> data) {
}
void DSCommPacket::SendJoysticks(void) {
for (int i = 0; i < HAL_kMaxJoysticks; i++) {
for (int i = 0; i < HAL_MAX_JOYSTICKS; i++) {
DSCommJoystickPacket& packet = m_joystick_packets[i];
HALSIM_SetJoystickAxes(i, &packet.axes);
HALSIM_SetJoystickPOVs(i, &packet.povs);

View File

@@ -63,7 +63,7 @@ class DSCommPacket {
HAL_ControlWord m_control_word;
HAL_AllianceStationID m_alliance_station;
HAL_MatchInfo matchInfo;
std::array<DSCommJoystickPacket, HAL_kMaxJoysticks> m_joystick_packets;
std::array<DSCommJoystickPacket, HAL_MAX_JOYSTICKS> m_joystick_packets;
double m_match_time = -1;
};

View File

@@ -34,7 +34,7 @@ class DSCommPacketTest : public ::testing::Test {
};
TEST_F(DSCommPacketTest, EmptyJoystickTag) {
for (int i = 0; i < HAL_kMaxJoysticks; i++) {
for (int i = 0; i < HAL_MAX_JOYSTICKS; i++) {
uint8_t arr[2];
auto& data = ReadJoystickTag(arr, 0);
ASSERT_EQ(data.axes.available, 0);
@@ -44,7 +44,7 @@ TEST_F(DSCommPacketTest, EmptyJoystickTag) {
}
TEST_F(DSCommPacketTest, BlankJoystickTag) {
for (int i = 0; i < HAL_kMaxJoysticks; i++) {
for (int i = 0; i < HAL_MAX_JOYSTICKS; i++) {
uint8_t arr[5];
arr[0] = 4;
arr[1] = 2;
@@ -59,7 +59,7 @@ TEST_F(DSCommPacketTest, BlankJoystickTag) {
}
TEST_F(DSCommPacketTest, MainJoystickTag) {
for (int i = 0; i < HAL_kMaxJoysticks; i++) {
for (int i = 0; i < HAL_MAX_JOYSTICKS; i++) {
// Just random data
std::array<uint8_t, 12> _buttons{{0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1}};
@@ -94,7 +94,7 @@ TEST_F(DSCommPacketTest, MainJoystickTag) {
}
TEST_F(DSCommPacketTest, DescriptorTag) {
for (int i = 0; i < HAL_kMaxJoysticks; i++) {
for (int i = 0; i < HAL_MAX_JOYSTICKS; i++) {
uint8_t arr[] = {// Size (2), tag
0, 0, 7,
// Joystick index, Is Xbox, Type
@@ -123,7 +123,7 @@ TEST_F(DSCommPacketTest, MatchInfoTag) {
arr[1] = sizeof(arr) - 2;
auto& matchInfo = ReadNewMatchInfoTag(arr);
ASSERT_STREQ(matchInfo.eventName, "WCBC");
ASSERT_EQ(matchInfo.matchType, HAL_MatchType::HAL_kMatchType_qualification);
ASSERT_EQ(matchInfo.matchType, HAL_MatchType::HAL_MATCH_TYPE_QUALIFICATION);
ASSERT_EQ(matchInfo.matchNumber, 18);
ASSERT_EQ(matchInfo.replayNumber, 1);
}

View File

@@ -200,11 +200,11 @@ class JoystickModel {
int axisCount;
int buttonCount;
int povCount;
std::unique_ptr<wpi::glass::DoubleSource> axes[HAL_kMaxJoystickAxes];
std::unique_ptr<wpi::glass::DoubleSource> axes[HAL_MAX_JOYSTICK_AXES];
// use pointer instead of unique_ptr to allow it to be passed directly
// to DrawLEDSources()
wpi::glass::BooleanSource* buttons[32];
std::unique_ptr<wpi::glass::IntegerSource> povs[HAL_kMaxJoystickPOVs];
std::unique_ptr<wpi::glass::IntegerSource> povs[HAL_MAX_JOYSTICK_POVS];
private:
static void CallbackFunc(const char*, void* param, const HAL_Value*);
@@ -276,7 +276,7 @@ static std::vector<std::unique_ptr<GlfwKeyboardJoystick>> gKeyboardJoysticks;
// robot joysticks
static std::vector<RobotJoystick> gRobotJoysticks;
static std::unique_ptr<JoystickModel> gJoystickSources[HAL_kMaxJoysticks];
static std::unique_ptr<JoystickModel> gJoystickSources[HAL_MAX_JOYSTICKS];
// FMS
static std::unique_ptr<FMSSimModel> gFMSModel;
@@ -323,13 +323,13 @@ static void UpdateOpModes(const char* name, void* param,
for (auto&& o : std::span{opmodes, opmodes + count}) {
OpModes* vec;
switch (HAL_OpMode_GetRobotMode(o.id)) {
case HAL_ROBOTMODE_AUTONOMOUS:
case HAL_ROBOT_MODE_AUTONOMOUS:
vec = &gAutoOpModes;
break;
case HAL_ROBOTMODE_TELEOPERATED:
case HAL_ROBOT_MODE_TELEOPERATED:
vec = &gTeleopOpModes;
break;
case HAL_ROBOTMODE_TEST:
case HAL_ROBOT_MODE_TEST:
vec = &gTestOpModes;
break;
default:
@@ -488,9 +488,9 @@ void GlfwSystemJoystick::GetData(HALJoystickData* data, bool mapGamepad) const {
data->desc.gamepadType = 1; // Standard
std::strncpy(data->desc.name, m_name, sizeof(data->desc.name) - 1);
data->desc.name[sizeof(data->desc.name) - 1] = '\0';
int axesCount = (std::min)(m_axisCount, HAL_kMaxJoystickAxes);
int axesCount = (std::min)(m_axisCount, HAL_MAX_JOYSTICK_AXES);
int buttonCount = (std::min)(m_buttonCount, 64);
int povsCount = (std::min)(m_hatCount, HAL_kMaxJoystickPOVs);
int povsCount = (std::min)(m_hatCount, HAL_MAX_JOYSTICK_POVS);
if (buttonCount < 64) {
data->buttons.available = (1ULL << buttonCount) - 1;
@@ -669,8 +669,8 @@ void KeyboardJoystick::SettingsDisplay() {
if (ImGui::InputInt("Count", &m_axisCount)) {
if (m_axisCount < 0) {
m_axisCount = 0;
} else if (m_axisCount > HAL_kMaxJoystickAxes) {
m_axisCount = HAL_kMaxJoystickAxes;
} else if (m_axisCount > HAL_MAX_JOYSTICK_AXES) {
m_axisCount = HAL_MAX_JOYSTICK_AXES;
}
}
while (m_axisCount > static_cast<int>(m_axisConfig.size())) {
@@ -726,8 +726,8 @@ void KeyboardJoystick::SettingsDisplay() {
if (m_povCount < 0) {
m_povCount = 0;
}
if (m_povCount > HAL_kMaxJoystickPOVs) {
m_povCount = HAL_kMaxJoystickPOVs;
if (m_povCount > HAL_MAX_JOYSTICK_POVS) {
m_povCount = HAL_MAX_JOYSTICK_POVS;
}
}
while (m_povCount > static_cast<int>(m_povConfig.size())) {
@@ -837,23 +837,23 @@ void KeyboardJoystick::Update() {
for (int i = 0; i < povsCount; ++i) {
auto& config = m_povConfig[i];
auto& povValue = m_data.povs.povs[i];
povValue = HAL_JoystickPOV_kCentered;
povValue = HAL_JOYSTICK_POV_CENTERED;
if (IsKeyDown(io, config.keyUp)) {
povValue = HAL_JoystickPOV_kUp;
povValue = HAL_JOYSTICK_POV_UP;
} else if (IsKeyDown(io, config.keyUpRight)) {
povValue = HAL_JoystickPOV_kRightUp;
povValue = HAL_JOYSTICK_POV_RIGHT_UP;
} else if (IsKeyDown(io, config.keyRight)) {
povValue = HAL_JoystickPOV_kRight;
povValue = HAL_JOYSTICK_POV_RIGHT;
} else if (IsKeyDown(io, config.keyDownRight)) {
povValue = HAL_JoystickPOV_kRightDown;
povValue = HAL_JOYSTICK_POV_RIGHT_DOWN;
} else if (IsKeyDown(io, config.keyDown)) {
povValue = HAL_JoystickPOV_kDown;
povValue = HAL_JOYSTICK_POV_DOWN;
} else if (IsKeyDown(io, config.keyDownLeft)) {
povValue = HAL_JoystickPOV_kLeftDown;
povValue = HAL_JOYSTICK_POV_LEFT_DOWN;
} else if (IsKeyDown(io, config.keyLeft)) {
povValue = HAL_JoystickPOV_kLeft;
povValue = HAL_JOYSTICK_POV_LEFT;
} else if (IsKeyDown(io, config.keyUpLeft)) {
povValue = HAL_JoystickPOV_kLeftUp;
povValue = HAL_JOYSTICK_POV_LEFT_UP;
}
}
@@ -1082,7 +1082,7 @@ static void DriverStationSetEnabled(bool enabled) {
static void DriverStationExecute() {
// update sources
for (int i = 0; i < HAL_kMaxJoysticks; ++i) {
for (int i = 0; i < HAL_MAX_JOYSTICKS; ++i) {
auto& source = gJoystickSources[i];
uint16_t axesAvailable;
uint8_t povsAvailable;
@@ -1196,17 +1196,17 @@ static void DriverStationExecute() {
}
if (ImGui::Selectable(
"Autonomous",
isAttached && robotMode == HAL_ROBOTMODE_AUTONOMOUS)) {
DriverStationSetRobotMode(HAL_ROBOTMODE_AUTONOMOUS);
isAttached && robotMode == HAL_ROBOT_MODE_AUTONOMOUS)) {
DriverStationSetRobotMode(HAL_ROBOT_MODE_AUTONOMOUS);
}
if (ImGui::Selectable(
"Teleoperated",
isAttached && robotMode == HAL_ROBOTMODE_TELEOPERATED)) {
DriverStationSetRobotMode(HAL_ROBOTMODE_TELEOPERATED);
isAttached && robotMode == HAL_ROBOT_MODE_TELEOPERATED)) {
DriverStationSetRobotMode(HAL_ROBOT_MODE_TELEOPERATED);
}
if (ImGui::Selectable("Test",
isAttached && robotMode == HAL_ROBOTMODE_TEST)) {
DriverStationSetRobotMode(HAL_ROBOTMODE_TEST);
isAttached && robotMode == HAL_ROBOT_MODE_TEST)) {
DriverStationSetRobotMode(HAL_ROBOT_MODE_TEST);
}
// OpMode
bool canEnable = isAttached && started;
@@ -1217,13 +1217,13 @@ static void DriverStationExecute() {
} else {
OpModes* modes;
switch (robotMode) {
case HAL_ROBOTMODE_AUTONOMOUS:
case HAL_ROBOT_MODE_AUTONOMOUS:
modes = &gAutoOpModes;
break;
case HAL_ROBOTMODE_TELEOPERATED:
case HAL_ROBOT_MODE_TELEOPERATED:
modes = &gTeleopOpModes;
break;
case HAL_ROBOTMODE_TEST:
case HAL_ROBOT_MODE_TEST:
modes = &gTestOpModes;
break;
default:
@@ -1286,9 +1286,9 @@ static void DriverStationExecute() {
}
// Update HAL
if (isAttached && robotMode != HAL_ROBOTMODE_AUTONOMOUS) {
if (isAttached && robotMode != HAL_ROBOT_MODE_AUTONOMOUS) {
for (int i = 0, end = gRobotJoysticks.size();
i < end && i < HAL_kMaxJoysticks; ++i) {
i < end && i < HAL_MAX_JOYSTICKS; ++i) {
gRobotJoysticks[i].SetHAL(i);
}
}
@@ -1305,7 +1305,7 @@ static void DriverStationExecute() {
FMSSimModel::FMSSimModel() {
m_matchTime.SetValue(-1.0);
m_allianceStationId.SetValue(HAL_AllianceStationID_kRed1);
m_allianceStationId.SetValue(HAL_ALLIANCE_STATION_RED_1);
}
void FMSSimModel::UpdateHAL() {
@@ -1415,10 +1415,10 @@ static void DisplaySystemJoysticks() {
static void DisplayJoysticks() {
bool disableDS = IsDSDisabled();
// imgui doesn't size columns properly with autoresize, so force it
ImGui::Dummy(ImVec2(ImGui::GetFontSize() * 10 * HAL_kMaxJoysticks, 0));
ImGui::Dummy(ImVec2(ImGui::GetFontSize() * 10 * HAL_MAX_JOYSTICKS, 0));
ImGui::Columns(HAL_kMaxJoysticks, "Joysticks", false);
for (int i = 0; i < HAL_kMaxJoysticks; ++i) {
ImGui::Columns(HAL_MAX_JOYSTICKS, "Joysticks", false);
for (int i = 0; i < HAL_MAX_JOYSTICKS; ++i) {
auto& joy = gRobotJoysticks[i];
char label[128];
joy.name.GetLabel(label, sizeof(label), "Joystick", i);
@@ -1459,7 +1459,7 @@ static void DisplayJoysticks() {
}
ImGui::Separator();
for (int i = 0; i < HAL_kMaxJoysticks; ++i) {
for (int i = 0; i < HAL_MAX_JOYSTICKS; ++i) {
auto& joy = gRobotJoysticks[i];
auto source = gJoystickSources[i].get();
@@ -1603,8 +1603,8 @@ void DriverStationGui::GlobalInit() {
}
auto& robotJoystickStorage = storageRoot.GetChildArray("robotJoysticks");
robotJoystickStorage.resize(HAL_kMaxJoysticks);
for (int i = 0; i < HAL_kMaxJoysticks; ++i) {
robotJoystickStorage.resize(HAL_MAX_JOYSTICKS);
for (int i = 0; i < HAL_MAX_JOYSTICKS; ++i) {
if (!robotJoystickStorage[i]) {
robotJoystickStorage[i] = std::make_unique<wpi::glass::Storage>();
}

View File

@@ -63,25 +63,25 @@ void HALSimWSProviderDriverStation::RegisterCallbacks() {
[](const char* name, void* param, const struct HAL_Value* value) {
std::string station;
switch (static_cast<HAL_AllianceStationID>(value->data.v_enum)) {
case HAL_AllianceStationID_kRed1:
case HAL_ALLIANCE_STATION_RED_1:
station = "red1";
break;
case HAL_AllianceStationID_kBlue1:
case HAL_ALLIANCE_STATION_BLUE_1:
station = "blue1";
break;
case HAL_AllianceStationID_kRed2:
case HAL_ALLIANCE_STATION_RED_2:
station = "red2";
break;
case HAL_AllianceStationID_kBlue2:
case HAL_ALLIANCE_STATION_BLUE_2:
station = "blue2";
break;
case HAL_AllianceStationID_kRed3:
case HAL_ALLIANCE_STATION_RED_3:
station = "red3";
break;
case HAL_AllianceStationID_kBlue3:
case HAL_ALLIANCE_STATION_BLUE_3:
station = "blue3";
break;
case HAL_AllianceStationID_kUnknown:
case HAL_ALLIANCE_STATION_UNKNOWN:
station = "unknown";
break;
}
@@ -144,17 +144,17 @@ void HALSimWSProviderDriverStation::OnNetValueChanged(
if ((it = json.find(">station")) != json.end()) {
auto& station = it.value().get_ref<const std::string&>();
if (station == "red1") {
HALSIM_SetDriverStationAllianceStationId(HAL_AllianceStationID_kRed1);
HALSIM_SetDriverStationAllianceStationId(HAL_ALLIANCE_STATION_RED_1);
} else if (station == "red2") {
HALSIM_SetDriverStationAllianceStationId(HAL_AllianceStationID_kRed2);
HALSIM_SetDriverStationAllianceStationId(HAL_ALLIANCE_STATION_RED_2);
} else if (station == "red3") {
HALSIM_SetDriverStationAllianceStationId(HAL_AllianceStationID_kRed3);
HALSIM_SetDriverStationAllianceStationId(HAL_ALLIANCE_STATION_RED_3);
} else if (station == "blue1") {
HALSIM_SetDriverStationAllianceStationId(HAL_AllianceStationID_kBlue1);
HALSIM_SetDriverStationAllianceStationId(HAL_ALLIANCE_STATION_BLUE_1);
} else if (station == "blue2") {
HALSIM_SetDriverStationAllianceStationId(HAL_AllianceStationID_kBlue2);
HALSIM_SetDriverStationAllianceStationId(HAL_ALLIANCE_STATION_BLUE_2);
} else if (station == "blue3") {
HALSIM_SetDriverStationAllianceStationId(HAL_AllianceStationID_kBlue3);
HALSIM_SetDriverStationAllianceStationId(HAL_ALLIANCE_STATION_BLUE_3);
}
}

View File

@@ -16,7 +16,7 @@ namespace wpilibws {
extern std::atomic<bool>* gDSSocketConnected;
void HALSimWSProviderJoystick::Initialize(WSRegisterFunc webregisterFunc) {
CreateProviders<HALSimWSProviderJoystick>("Joystick", HAL_kMaxJoysticks,
CreateProviders<HALSimWSProviderJoystick>("Joystick", HAL_MAX_JOYSTICKS,
webregisterFunc);
}
@@ -106,9 +106,9 @@ void HALSimWSProviderJoystick::OnNetValueChanged(const wpi::util::json& json) {
wpi::util::json::const_iterator it;
if ((it = json.find(">axes")) != json.end()) {
HAL_JoystickAxes axes{};
wpi::util::json::size_type axesCount =
std::min(it.value().size(),
static_cast<wpi::util::json::size_type>(HAL_kMaxJoystickAxes));
wpi::util::json::size_type axesCount = std::min(
it.value().size(),
static_cast<wpi::util::json::size_type>(HAL_MAX_JOYSTICK_AXES));
axes.available = (1 << axesCount) - 1;
for (wpi::util::json::size_type i = 0; i < axesCount; i++) {
axes.axes[i] = it.value()[i];
@@ -137,9 +137,9 @@ void HALSimWSProviderJoystick::OnNetValueChanged(const wpi::util::json& json) {
if ((it = json.find(">povs")) != json.end()) {
HAL_JoystickPOVs povs{};
wpi::util::json::size_type povsCount =
std::min(it.value().size(),
static_cast<wpi::util::json::size_type>(HAL_kMaxJoystickPOVs));
wpi::util::json::size_type povsCount = std::min(
it.value().size(),
static_cast<wpi::util::json::size_type>(HAL_MAX_JOYSTICK_POVS));
povs.available = (1 << povsCount) - 1;
for (wpi::util::json::size_type i = 0; i < povsCount; i++) {
povs.povs[i] = it.value()[i];

View File

@@ -138,7 +138,7 @@ class DataLogSender {
wpi::log::StringLogEntry m_logOpMode;
bool m_logJoysticks;
std::array<JoystickLogSender, DriverStation::kJoystickPorts> m_joysticks;
std::array<JoystickLogSender, DriverStation::JOYSTICK_PORTS> m_joysticks;
};
struct Instance {
@@ -151,10 +151,10 @@ struct Instance {
// Joystick button rising/falling edge flags
wpi::util::mutex buttonEdgeMutex;
std::array<HAL_JoystickButtons, DriverStation::kJoystickPorts>
std::array<HAL_JoystickButtons, DriverStation::JOYSTICK_PORTS>
previousButtonStates;
std::array<uint32_t, DriverStation::kJoystickPorts> joystickButtonsPressed;
std::array<uint32_t, DriverStation::kJoystickPorts> joystickButtonsReleased;
std::array<uint32_t, DriverStation::JOYSTICK_PORTS> joystickButtonsPressed;
std::array<uint32_t, DriverStation::JOYSTICK_PORTS> joystickButtonsReleased;
bool silenceJoystickWarning = false;
@@ -212,7 +212,7 @@ Instance::Instance() {
// All joysticks should default to having zero axes, povs and buttons, so
// uninitialized memory doesn't get sent to motor controllers.
for (unsigned int i = 0; i < DriverStation::kJoystickPorts; i++) {
for (unsigned int i = 0; i < DriverStation::JOYSTICK_PORTS; i++) {
joystickButtonsPressed[i] = 0;
joystickButtonsReleased[i] = 0;
previousButtonStates[i].available = 0;
@@ -227,7 +227,7 @@ Instance::~Instance() {
}
bool DriverStation::GetStickButton(int stick, int button) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return false;
}
@@ -253,7 +253,7 @@ bool DriverStation::GetStickButton(int stick, int button) {
std::optional<bool> DriverStation::GetStickButtonIfAvailable(int stick,
int button) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return false;
}
@@ -276,7 +276,7 @@ std::optional<bool> DriverStation::GetStickButtonIfAvailable(int stick,
}
bool DriverStation::GetStickButtonPressed(int stick, int button) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return false;
}
@@ -307,7 +307,7 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) {
}
bool DriverStation::GetStickButtonReleased(int stick, int button) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return false;
}
@@ -338,11 +338,11 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
}
double DriverStation::GetStickAxis(int stick, int axis) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return 0.0;
}
if (axis < 0 || axis >= HAL_kMaxJoystickAxes) {
if (axis < 0 || axis >= HAL_MAX_JOYSTICK_AXES) {
WPILIB_ReportError(warn::BadJoystickAxis, "axis {} out of range", axis);
return 0.0;
}
@@ -363,16 +363,16 @@ double DriverStation::GetStickAxis(int stick, int axis) {
DriverStation::TouchpadFinger DriverStation::GetStickTouchpadFinger(
int stick, int touchpad, int finger) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return TouchpadFinger{false, 0.0f, 0.0f};
}
if (touchpad < 0 || touchpad >= HAL_kMaxJoystickTouchpads) {
if (touchpad < 0 || touchpad >= HAL_MAX_JOYSTICK_TOUCHPADS) {
WPILIB_ReportError(warn::BadJoystickAxis, "touchpad {} out of range",
touchpad);
return TouchpadFinger{false, 0.0f, 0.0f};
}
if (finger < 0 || finger >= HAL_kMaxJoystickTouchpadFingers) {
if (finger < 0 || finger >= HAL_MAX_JOYSTICK_TOUCHPAD_FINGERS) {
WPILIB_ReportError(warn::BadJoystickAxis, "finger {} out of range", finger);
return TouchpadFinger{false, 0.0f, 0.0f};
}
@@ -399,16 +399,16 @@ DriverStation::TouchpadFinger DriverStation::GetStickTouchpadFinger(
bool DriverStation::GetStickTouchpadFingerAvailable(int stick, int touchpad,
int finger) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return false;
}
if (touchpad < 0 || touchpad >= HAL_kMaxJoystickTouchpads) {
if (touchpad < 0 || touchpad >= HAL_MAX_JOYSTICK_TOUCHPADS) {
WPILIB_ReportError(warn::BadJoystickAxis, "touchpad {} out of range",
touchpad);
return false;
}
if (finger < 0 || finger >= HAL_kMaxJoystickTouchpadFingers) {
if (finger < 0 || finger >= HAL_MAX_JOYSTICK_TOUCHPAD_FINGERS) {
WPILIB_ReportError(warn::BadJoystickAxis, "finger {} out of range", finger);
return false;
}
@@ -428,11 +428,11 @@ bool DriverStation::GetStickTouchpadFingerAvailable(int stick, int touchpad,
std::optional<double> DriverStation::GetStickAxisIfAvailable(int stick,
int axis) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return 0.0;
}
if (axis < 0 || axis >= HAL_kMaxJoystickAxes) {
if (axis < 0 || axis >= HAL_MAX_JOYSTICK_AXES) {
WPILIB_ReportError(warn::BadJoystickAxis, "axis {} out of range", axis);
return 0.0;
}
@@ -450,13 +450,13 @@ std::optional<double> DriverStation::GetStickAxisIfAvailable(int stick,
}
DriverStation::POVDirection DriverStation::GetStickPOV(int stick, int pov) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return kCenter;
return POVDirection::CENTER;
}
if (pov < 0 || pov >= HAL_kMaxJoystickPOVs) {
if (pov < 0 || pov >= HAL_MAX_JOYSTICK_POVS) {
WPILIB_ReportError(warn::BadJoystickAxis, "POV {} out of range", pov);
return kCenter;
return POVDirection::CENTER;
}
uint16_t mask = 1 << pov;
@@ -467,14 +467,14 @@ DriverStation::POVDirection DriverStation::GetStickPOV(int stick, int pov) {
if ((povs.available & mask) == 0) {
ReportJoystickWarning(stick, "Joystick POV {} on port {} not available",
pov, stick);
return kCenter;
return POVDirection::CENTER;
}
return static_cast<POVDirection>(povs.povs[pov]);
}
uint64_t DriverStation::GetStickButtons(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return 0;
}
@@ -490,7 +490,7 @@ int DriverStation::GetStickAxesMaximumIndex(int stick) {
}
int DriverStation::GetStickAxesAvailable(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return 0;
}
@@ -506,7 +506,7 @@ int DriverStation::GetStickPOVsMaximumIndex(int stick) {
}
int DriverStation::GetStickPOVsAvailable(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return 0;
}
@@ -522,7 +522,7 @@ int DriverStation::GetStickButtonsMaximumIndex(int stick) {
}
uint64_t DriverStation::GetStickButtonsAvailable(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return 0;
}
@@ -534,7 +534,7 @@ uint64_t DriverStation::GetStickButtonsAvailable(int stick) {
}
bool DriverStation::GetJoystickIsGamepad(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return false;
}
@@ -546,7 +546,7 @@ bool DriverStation::GetJoystickIsGamepad(int stick) {
}
int DriverStation::GetJoystickGamepadType(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return -1;
}
@@ -558,7 +558,7 @@ int DriverStation::GetJoystickGamepadType(int stick) {
}
int DriverStation::GetJoystickSupportedOutputs(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
return 0;
}
@@ -570,7 +570,7 @@ int DriverStation::GetJoystickSupportedOutputs(int stick) {
}
std::string DriverStation::GetJoystickName(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
if (stick < 0 || stick >= JOYSTICK_PORTS) {
WPILIB_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
}
@@ -723,14 +723,14 @@ std::optional<DriverStation::Alliance> DriverStation::GetAlliance() {
int32_t status = 0;
auto allianceStationID = HAL_GetAllianceStation(&status);
switch (allianceStationID) {
case HAL_AllianceStationID_kRed1:
case HAL_AllianceStationID_kRed2:
case HAL_AllianceStationID_kRed3:
return kRed;
case HAL_AllianceStationID_kBlue1:
case HAL_AllianceStationID_kBlue2:
case HAL_AllianceStationID_kBlue3:
return kBlue;
case HAL_ALLIANCE_STATION_RED_1:
case HAL_ALLIANCE_STATION_RED_2:
case HAL_ALLIANCE_STATION_RED_3:
return Alliance::RED;
case HAL_ALLIANCE_STATION_BLUE_1:
case HAL_ALLIANCE_STATION_BLUE_2:
case HAL_ALLIANCE_STATION_BLUE_3:
return Alliance::BLUE;
default:
return {};
}
@@ -740,14 +740,14 @@ std::optional<int> DriverStation::GetLocation() {
int32_t status = 0;
auto allianceStationID = HAL_GetAllianceStation(&status);
switch (allianceStationID) {
case HAL_AllianceStationID_kRed1:
case HAL_AllianceStationID_kBlue1:
case HAL_ALLIANCE_STATION_RED_1:
case HAL_ALLIANCE_STATION_BLUE_1:
return 1;
case HAL_AllianceStationID_kRed2:
case HAL_AllianceStationID_kBlue2:
case HAL_ALLIANCE_STATION_RED_2:
case HAL_ALLIANCE_STATION_BLUE_2:
return 2;
case HAL_AllianceStationID_kRed3:
case HAL_AllianceStationID_kBlue3:
case HAL_ALLIANCE_STATION_RED_3:
case HAL_ALLIANCE_STATION_BLUE_3:
return 3;
default:
return {};
@@ -781,7 +781,7 @@ void DriverStation::RefreshData() {
HAL_JoystickButtons currentButtons;
std::unique_lock lock(inst.buttonEdgeMutex);
for (int32_t i = 0; i < DriverStation::kJoystickPorts; i++) {
for (int32_t i = 0; i < DriverStation::JOYSTICK_PORTS; i++) {
HAL_GetJoystickButtons(i, &currentButtons);
// If buttons weren't pressed and are now, set flags in m_buttonsPressed
@@ -866,23 +866,23 @@ void SendMatchData() {
bool isRedAlliance = false;
int stationNumber = 1;
switch (alliance) {
case HAL_AllianceStationID::HAL_AllianceStationID_kBlue1:
case HAL_ALLIANCE_STATION_BLUE_1:
isRedAlliance = false;
stationNumber = 1;
break;
case HAL_AllianceStationID::HAL_AllianceStationID_kBlue2:
case HAL_ALLIANCE_STATION_BLUE_2:
isRedAlliance = false;
stationNumber = 2;
break;
case HAL_AllianceStationID::HAL_AllianceStationID_kBlue3:
case HAL_ALLIANCE_STATION_BLUE_3:
isRedAlliance = false;
stationNumber = 3;
break;
case HAL_AllianceStationID::HAL_AllianceStationID_kRed1:
case HAL_ALLIANCE_STATION_RED_1:
isRedAlliance = true;
stationNumber = 1;
break;
case HAL_AllianceStationID::HAL_AllianceStationID_kRed2:
case HAL_ALLIANCE_STATION_RED_2:
isRedAlliance = true;
stationNumber = 2;
break;
@@ -989,7 +989,7 @@ void JoystickLogSender::AppendButtons(HAL_JoystickButtons buttons,
void JoystickLogSender::AppendPOVs(const HAL_JoystickPOVs& povs,
uint64_t timestamp) {
int count = availableToCount(povs.available);
int64_t povsArr[HAL_kMaxJoystickPOVs];
int64_t povsArr[HAL_MAX_JOYSTICK_POVS];
for (int i = 0; i < count; ++i) {
povsArr[i] = povs.povs[i];
}

View File

@@ -14,7 +14,7 @@
using namespace wpi;
GenericHID::GenericHID(int port) {
if (port < 0 || port >= DriverStation::kJoystickPorts) {
if (port < 0 || port >= DriverStation::JOYSTICK_PORTS) {
throw WPILIB_MakeError(warn::BadJoystickIndex, "port {} out of range",
port);
}
@@ -58,39 +58,39 @@ BooleanEvent GenericHID::POV(int pov, DriverStation::POVDirection angle,
}
BooleanEvent GenericHID::POVUp(EventLoop* loop) const {
return POV(DriverStation::kUp, loop);
return POV(DriverStation::POVDirection::UP, loop);
}
BooleanEvent GenericHID::POVUpRight(EventLoop* loop) const {
return POV(DriverStation::kUpRight, loop);
return POV(DriverStation::POVDirection::UP_RIGHT, loop);
}
BooleanEvent GenericHID::POVRight(EventLoop* loop) const {
return POV(DriverStation::kRight, loop);
return POV(DriverStation::POVDirection::RIGHT, loop);
}
BooleanEvent GenericHID::POVDownRight(EventLoop* loop) const {
return POV(DriverStation::kDownRight, loop);
return POV(DriverStation::POVDirection::DOWN_RIGHT, loop);
}
BooleanEvent GenericHID::POVDown(EventLoop* loop) const {
return POV(DriverStation::kDown, loop);
return POV(DriverStation::POVDirection::DOWN, loop);
}
BooleanEvent GenericHID::POVDownLeft(EventLoop* loop) const {
return POV(DriverStation::kDownLeft, loop);
return POV(DriverStation::POVDirection::DOWN_LEFT, loop);
}
BooleanEvent GenericHID::POVLeft(EventLoop* loop) const {
return POV(DriverStation::kLeft, loop);
return POV(DriverStation::POVDirection::LEFT, loop);
}
BooleanEvent GenericHID::POVUpLeft(EventLoop* loop) const {
return POV(DriverStation::kUpLeft, loop);
return POV(DriverStation::POVDirection::UP_LEFT, loop);
}
BooleanEvent GenericHID::POVCenter(EventLoop* loop) const {
return POV(DriverStation::kCenter, loop);
return POV(DriverStation::POVDirection::CENTER, loop);
}
BooleanEvent GenericHID::AxisLessThan(int axis, double threshold,

View File

@@ -246,17 +246,17 @@ void Thread::Main() {
// match info comes through TCP, so we need to double-check we've
// actually received it
auto matchType = DriverStation::GetMatchType();
if (matchType != DriverStation::kNone) {
if (matchType != DriverStation::MatchType::NONE) {
// rename per match info
char matchTypeChar;
switch (matchType) {
case DriverStation::kPractice:
case DriverStation::MatchType::PRACTICE:
matchTypeChar = 'P';
break;
case DriverStation::kQualification:
case DriverStation::MatchType::QUALIFICATION:
matchTypeChar = 'Q';
break;
case DriverStation::kElimination:
case DriverStation::MatchType::ELIMINATION:
matchTypeChar = 'E';
break;
default:

View File

@@ -35,49 +35,49 @@ class DriverStation final {
/**
* The robot alliance that the robot is a part of.
*/
enum Alliance {
enum class Alliance {
/// Red alliance.
kRed,
RED,
/// Blue alliance.
kBlue
BLUE
};
/**
* The type of robot match that the robot is part of.
*/
enum MatchType {
enum class MatchType {
/// None.
kNone,
NONE,
/// Practice.
kPractice,
PRACTICE,
/// Qualification.
kQualification,
QUALIFICATION,
/// Elimination.
kElimination
ELIMINATION
};
/**
* A controller POV direction.
*/
enum POVDirection : uint8_t {
enum class POVDirection : uint8_t {
/// POV center.
kCenter = HAL_JoystickPOV_kCentered,
CENTER = HAL_JOYSTICK_POV_CENTERED,
/// POV up.
kUp = HAL_JoystickPOV_kUp,
UP = HAL_JOYSTICK_POV_UP,
/// POV up right.
kUpRight = HAL_JoystickPOV_kRightUp,
UP_RIGHT = HAL_JOYSTICK_POV_RIGHT_UP,
/// POV right.
kRight = HAL_JoystickPOV_kRight,
RIGHT = HAL_JOYSTICK_POV_RIGHT,
/// POV down right.
kDownRight = HAL_JoystickPOV_kRightDown,
DOWN_RIGHT = HAL_JOYSTICK_POV_RIGHT_DOWN,
/// POV down.
kDown = HAL_JoystickPOV_kDown,
DOWN = HAL_JOYSTICK_POV_DOWN,
/// POV down left.
kDownLeft = HAL_JoystickPOV_kLeftDown,
DOWN_LEFT = HAL_JOYSTICK_POV_LEFT_DOWN,
/// POV left.
kLeft = HAL_JoystickPOV_kLeft,
LEFT = HAL_JOYSTICK_POV_LEFT,
/// POV up left.
kUpLeft = HAL_JoystickPOV_kLeftUp,
UP_LEFT = HAL_JOYSTICK_POV_LEFT_UP,
};
struct TouchpadFinger final {
@@ -91,28 +91,28 @@ class DriverStation final {
*
* @param angle The POVDirection to convert.
* @return The angle clockwise from straight up, or std::nullopt if the
* POVDirection is kCenter.
* POVDirection is CENTER.
*/
static constexpr std::optional<wpi::math::Rotation2d> GetAngle(
POVDirection angle) {
switch (angle) {
case kCenter:
case POVDirection::CENTER:
return std::nullopt;
case kUp:
case POVDirection::UP:
return wpi::math::Rotation2d{0_deg};
case kUpRight:
case POVDirection::UP_RIGHT:
return wpi::math::Rotation2d{45_deg};
case kRight:
case POVDirection::RIGHT:
return wpi::math::Rotation2d{90_deg};
case kDownRight:
case POVDirection::DOWN_RIGHT:
return wpi::math::Rotation2d{135_deg};
case kDown:
case POVDirection::DOWN:
return wpi::math::Rotation2d{180_deg};
case kDownLeft:
case POVDirection::DOWN_LEFT:
return wpi::math::Rotation2d{225_deg};
case kLeft:
case POVDirection::LEFT:
return wpi::math::Rotation2d{270_deg};
case kUpLeft:
case POVDirection::UP_LEFT:
return wpi::math::Rotation2d{315_deg};
default:
return std::nullopt;
@@ -120,7 +120,7 @@ class DriverStation final {
}
/// Number of Joystick ports.
static constexpr int kJoystickPorts = 6;
static constexpr int JOYSTICK_PORTS = 6;
/**
* The state of one joystick button. Button indexes begin at 0.

View File

@@ -5,7 +5,7 @@ extra_includes:
classes:
wpi::DriverStation:
attributes:
kJoystickPorts:
JOYSTICK_PORTS:
enums:
Alliance:
MatchType:

View File

@@ -162,7 +162,7 @@ TEST_F(TimedRobotTest, AutonomousMode) {
wpi::sim::WaitForProgramStart();
wpi::sim::DriverStationSim::SetEnabled(true);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOTMODE_AUTONOMOUS);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_AUTONOMOUS);
wpi::sim::DriverStationSim::NotifyNewData();
EXPECT_EQ(1u, robot.m_simulationInitCount);
@@ -234,7 +234,7 @@ TEST_F(TimedRobotTest, TeleopMode) {
wpi::sim::WaitForProgramStart();
wpi::sim::DriverStationSim::SetEnabled(true);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOTMODE_TELEOPERATED);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TELEOPERATED);
wpi::sim::DriverStationSim::NotifyNewData();
EXPECT_EQ(1u, robot.m_simulationInitCount);
@@ -305,7 +305,7 @@ TEST_F(TimedRobotTest, TestMode) {
wpi::sim::WaitForProgramStart();
wpi::sim::DriverStationSim::SetEnabled(true);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOTMODE_TEST);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TEST);
wpi::sim::DriverStationSim::NotifyNewData();
EXPECT_EQ(1u, robot.m_simulationInitCount);
@@ -426,7 +426,7 @@ TEST_F(TimedRobotTest, ModeChange) {
// Transition to autonomous
wpi::sim::DriverStationSim::SetEnabled(true);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOTMODE_AUTONOMOUS);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_AUTONOMOUS);
wpi::sim::DriverStationSim::NotifyNewData();
wpi::sim::StepTiming(kPeriod);
@@ -443,7 +443,7 @@ TEST_F(TimedRobotTest, ModeChange) {
// Transition to teleop
wpi::sim::DriverStationSim::SetEnabled(true);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOTMODE_TELEOPERATED);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TELEOPERATED);
wpi::sim::DriverStationSim::NotifyNewData();
wpi::sim::StepTiming(kPeriod);
@@ -460,7 +460,7 @@ TEST_F(TimedRobotTest, ModeChange) {
// Transition to test
wpi::sim::DriverStationSim::SetEnabled(true);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOTMODE_TEST);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TEST);
wpi::sim::DriverStationSim::NotifyNewData();
wpi::sim::StepTiming(kPeriod);

View File

@@ -22,7 +22,7 @@ TEST(DriverStationTest, Enabled) {
BooleanCallback callback;
auto cb =
DriverStationSim::RegisterEnabledCallback(callback.GetCallback(), false);
DriverStationSim::SetRobotMode(HAL_ROBOTMODE_TELEOPERATED);
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TELEOPERATED);
DriverStationSim::SetEnabled(true);
DriverStationSim::NotifyNewData();
EXPECT_TRUE(DriverStationSim::GetEnabled());
@@ -39,13 +39,13 @@ TEST(DriverStationTest, AutonomousMode) {
EnumCallback callback;
auto cb = DriverStationSim::RegisterRobotModeCallback(callback.GetCallback(),
false);
DriverStationSim::SetRobotMode(HAL_ROBOTMODE_AUTONOMOUS);
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_AUTONOMOUS);
DriverStationSim::NotifyNewData();
EXPECT_EQ(DriverStationSim::GetRobotMode(), HAL_ROBOTMODE_AUTONOMOUS);
EXPECT_EQ(DriverStationSim::GetRobotMode(), HAL_ROBOT_MODE_AUTONOMOUS);
EXPECT_TRUE(DriverStation::IsAutonomous());
EXPECT_EQ(DriverStation::GetRobotMode(), RobotMode::AUTONOMOUS);
EXPECT_TRUE(callback.WasTriggered());
EXPECT_EQ(callback.GetLastValue(), HAL_ROBOTMODE_AUTONOMOUS);
EXPECT_EQ(callback.GetLastValue(), HAL_ROBOT_MODE_AUTONOMOUS);
}
TEST(DriverStationTest, Mode) {
@@ -56,13 +56,13 @@ TEST(DriverStationTest, Mode) {
EnumCallback callback;
auto cb = DriverStationSim::RegisterRobotModeCallback(callback.GetCallback(),
false);
DriverStationSim::SetRobotMode(HAL_ROBOTMODE_TEST);
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TEST);
DriverStationSim::NotifyNewData();
EXPECT_EQ(DriverStationSim::GetRobotMode(), HAL_ROBOTMODE_TEST);
EXPECT_EQ(DriverStationSim::GetRobotMode(), HAL_ROBOT_MODE_TEST);
EXPECT_TRUE(DriverStation::IsTest());
EXPECT_EQ(DriverStation::GetRobotMode(), RobotMode::TEST);
EXPECT_TRUE(callback.WasTriggered());
EXPECT_EQ(callback.GetLastValue(), HAL_ROBOTMODE_TEST);
EXPECT_EQ(callback.GetLastValue(), HAL_ROBOT_MODE_TEST);
}
TEST(DriverStationTest, Estop) {
@@ -125,14 +125,14 @@ TEST(DriverStationTest, AllianceStationId) {
EnumCallback callback;
HAL_AllianceStationID allianceStation = HAL_AllianceStationID_kBlue2;
HAL_AllianceStationID allianceStation = HAL_ALLIANCE_STATION_BLUE_2;
DriverStationSim::SetAllianceStationId(allianceStation);
auto cb = DriverStationSim::RegisterAllianceStationIdCallback(
callback.GetCallback(), false);
// Unknown
allianceStation = HAL_AllianceStationID_kUnknown;
allianceStation = HAL_ALLIANCE_STATION_UNKNOWN;
DriverStationSim::SetAllianceStationId(allianceStation);
wpi::sim::DriverStationSim::NotifyNewData();
EXPECT_EQ(allianceStation, DriverStationSim::GetAllianceStationId());
@@ -142,61 +142,61 @@ TEST(DriverStationTest, AllianceStationId) {
EXPECT_EQ(allianceStation, callback.GetLastValue());
// B1
allianceStation = HAL_AllianceStationID_kBlue1;
allianceStation = HAL_ALLIANCE_STATION_BLUE_1;
DriverStationSim::SetAllianceStationId(allianceStation);
wpi::sim::DriverStationSim::NotifyNewData();
EXPECT_EQ(allianceStation, DriverStationSim::GetAllianceStationId());
EXPECT_EQ(DriverStation::kBlue, DriverStation::GetAlliance());
EXPECT_EQ(DriverStation::Alliance::BLUE, DriverStation::GetAlliance());
EXPECT_EQ(1, DriverStation::GetLocation());
EXPECT_TRUE(callback.WasTriggered());
EXPECT_EQ(allianceStation, callback.GetLastValue());
// B2
allianceStation = HAL_AllianceStationID_kBlue2;
allianceStation = HAL_ALLIANCE_STATION_BLUE_2;
DriverStationSim::SetAllianceStationId(allianceStation);
wpi::sim::DriverStationSim::NotifyNewData();
EXPECT_EQ(allianceStation, DriverStationSim::GetAllianceStationId());
EXPECT_EQ(DriverStation::kBlue, DriverStation::GetAlliance());
EXPECT_EQ(DriverStation::Alliance::BLUE, DriverStation::GetAlliance());
EXPECT_EQ(2, DriverStation::GetLocation());
EXPECT_TRUE(callback.WasTriggered());
EXPECT_EQ(allianceStation, callback.GetLastValue());
// B3
allianceStation = HAL_AllianceStationID_kBlue3;
allianceStation = HAL_ALLIANCE_STATION_BLUE_3;
DriverStationSim::SetAllianceStationId(allianceStation);
wpi::sim::DriverStationSim::NotifyNewData();
EXPECT_EQ(allianceStation, DriverStationSim::GetAllianceStationId());
EXPECT_EQ(DriverStation::kBlue, DriverStation::GetAlliance());
EXPECT_EQ(DriverStation::Alliance::BLUE, DriverStation::GetAlliance());
EXPECT_EQ(3, DriverStation::GetLocation());
EXPECT_TRUE(callback.WasTriggered());
EXPECT_EQ(allianceStation, callback.GetLastValue());
// R1
allianceStation = HAL_AllianceStationID_kRed1;
allianceStation = HAL_ALLIANCE_STATION_RED_1;
DriverStationSim::SetAllianceStationId(allianceStation);
wpi::sim::DriverStationSim::NotifyNewData();
EXPECT_EQ(allianceStation, DriverStationSim::GetAllianceStationId());
EXPECT_EQ(DriverStation::kRed, DriverStation::GetAlliance());
EXPECT_EQ(DriverStation::Alliance::RED, DriverStation::GetAlliance());
EXPECT_EQ(1, DriverStation::GetLocation());
EXPECT_TRUE(callback.WasTriggered());
EXPECT_EQ(allianceStation, callback.GetLastValue());
// R2
allianceStation = HAL_AllianceStationID_kRed2;
allianceStation = HAL_ALLIANCE_STATION_RED_2;
DriverStationSim::SetAllianceStationId(allianceStation);
wpi::sim::DriverStationSim::NotifyNewData();
EXPECT_EQ(allianceStation, DriverStationSim::GetAllianceStationId());
EXPECT_EQ(DriverStation::kRed, DriverStation::GetAlliance());
EXPECT_EQ(DriverStation::Alliance::RED, DriverStation::GetAlliance());
EXPECT_EQ(2, DriverStation::GetLocation());
EXPECT_TRUE(callback.WasTriggered());
EXPECT_EQ(allianceStation, callback.GetLastValue());
// R3
allianceStation = HAL_AllianceStationID_kRed3;
allianceStation = HAL_ALLIANCE_STATION_RED_3;
DriverStationSim::SetAllianceStationId(allianceStation);
wpi::sim::DriverStationSim::NotifyNewData();
EXPECT_EQ(allianceStation, DriverStationSim::GetAllianceStationId());
EXPECT_EQ(DriverStation::kRed, DriverStation::GetAlliance());
EXPECT_EQ(DriverStation::Alliance::RED, DriverStation::GetAlliance());
EXPECT_EQ(3, DriverStation::GetLocation());
EXPECT_TRUE(callback.WasTriggered());
EXPECT_EQ(allianceStation, callback.GetLastValue());

View File

@@ -29,7 +29,7 @@ HAL_RobotMode getDSMode(void) {
// We send the observes, otherwise the DS disables
HAL_ObserveUserProgram(word);
return HAL_ControlWord_IsEnabled(word) ? HAL_ControlWord_GetRobotMode(word)
: HAL_ROBOTMODE_UNKNOWN;
: HAL_ROBOT_MODE_UNKNOWN;
}
int main(void) {
@@ -44,19 +44,19 @@ int main(void) {
// Create an opmode per robot mode
static struct HAL_OpModeOption opmodes[] = {
{HAL_MAKE_OPMODEID(HAL_ROBOTMODE_AUTONOMOUS, 0),
{HAL_MAKE_OPMODEID(HAL_ROBOT_MODE_AUTONOMOUS, 0),
{"Auto", 4},
{"", 0},
{"", 0},
-1,
-1},
{HAL_MAKE_OPMODEID(HAL_ROBOTMODE_TELEOPERATED, 0),
{HAL_MAKE_OPMODEID(HAL_ROBOT_MODE_TELEOPERATED, 0),
{"Teleop", 6},
{"", 0},
{"", 0},
-1,
-1},
{HAL_MAKE_OPMODEID(HAL_ROBOTMODE_TEST, 0),
{HAL_MAKE_OPMODEID(HAL_ROBOT_MODE_TEST, 0),
{"Test", 4},
{"", 0},
{"", 0},
@@ -104,9 +104,9 @@ int main(void) {
HAL_RobotMode dsMode = getDSMode();
switch (dsMode) {
case HAL_ROBOTMODE_UNKNOWN:
case HAL_ROBOT_MODE_UNKNOWN:
break;
case HAL_ROBOTMODE_TELEOPERATED:
case HAL_ROBOT_MODE_TELEOPERATED:
status = 0;
if (HAL_GetDIO(dio, &status)) {
HAL_SetPWMPulseTimeMicroseconds(pwmPort, 2000, &status);
@@ -114,9 +114,9 @@ int main(void) {
HAL_SetPWMPulseTimeMicroseconds(pwmPort, 1500, &status);
}
break;
case HAL_ROBOTMODE_AUTONOMOUS:
case HAL_ROBOT_MODE_AUTONOMOUS:
break;
case HAL_ROBOTMODE_TEST:
case HAL_ROBOT_MODE_TEST:
break;
default:
break;

View File

@@ -9,7 +9,7 @@
void Robot::RobotPeriodic() {
// pull alliance port high if on red alliance, pull low if on blue alliance
m_allianceOutput.Set(wpi::DriverStation::GetAlliance() ==
wpi::DriverStation::kRed);
wpi::DriverStation::Alliance::RED);
// pull enabled port high if enabled, low if disabled
m_enabledOutput.Set(wpi::DriverStation::IsEnabled());

View File

@@ -25,7 +25,7 @@ void Robot::RobotPeriodic() {
std::string allianceString = "U";
auto alliance = wpi::DriverStation::GetAlliance();
if (alliance.has_value()) {
if (alliance == wpi::DriverStation::Alliance::kRed) {
if (alliance == wpi::DriverStation::Alliance::RED) {
allianceString = "R";
} else {
allianceString = "B";

View File

@@ -56,7 +56,7 @@ TEST_P(ArmSimulationTest, Teleop) {
// teleop init
{
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOTMODE_TELEOPERATED);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TELEOPERATED);
wpi::sim::DriverStationSim::SetEnabled(true);
wpi::sim::DriverStationSim::NotifyNewData();

View File

@@ -52,7 +52,7 @@ class ElevatorSimulationTest : public testing::Test {
TEST_F(ElevatorSimulationTest, Teleop) {
// teleop init
{
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOTMODE_TELEOPERATED);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TELEOPERATED);
wpi::sim::DriverStationSim::SetEnabled(true);
wpi::sim::DriverStationSim::NotifyNewData();

View File

@@ -57,15 +57,15 @@ TEST_P(AllianceTest, Alliance) {
bool isRed = false;
switch (alliance) {
case HAL_AllianceStationID_kBlue1:
case HAL_AllianceStationID_kBlue2:
case HAL_AllianceStationID_kBlue3:
case HAL_AllianceStationID_kUnknown:
case HAL_ALLIANCE_STATION_BLUE_1:
case HAL_ALLIANCE_STATION_BLUE_2:
case HAL_ALLIANCE_STATION_BLUE_3:
case HAL_ALLIANCE_STATION_UNKNOWN:
isRed = false;
break;
case HAL_AllianceStationID_kRed1:
case HAL_AllianceStationID_kRed2:
case HAL_AllianceStationID_kRed3:
case HAL_ALLIANCE_STATION_RED_1:
case HAL_ALLIANCE_STATION_RED_2:
case HAL_ALLIANCE_STATION_RED_3:
isRed = true;
break;
}
@@ -75,25 +75,25 @@ TEST_P(AllianceTest, Alliance) {
INSTANTIATE_TEST_SUITE_P(
DigitalCommunicationTests, AllianceTest,
testing::Values<HAL_AllianceStationID>(
HAL_AllianceStationID_kRed1, HAL_AllianceStationID_kRed2,
HAL_AllianceStationID_kRed3, HAL_AllianceStationID_kBlue1,
HAL_AllianceStationID_kBlue2, HAL_AllianceStationID_kBlue3,
HAL_AllianceStationID_kUnknown),
HAL_ALLIANCE_STATION_RED_1, HAL_ALLIANCE_STATION_RED_2,
HAL_ALLIANCE_STATION_RED_3, HAL_ALLIANCE_STATION_BLUE_1,
HAL_ALLIANCE_STATION_BLUE_2, HAL_ALLIANCE_STATION_BLUE_3,
HAL_ALLIANCE_STATION_UNKNOWN),
[](const testing::TestParamInfo<AllianceTest::ParamType>& info) {
switch (info.param) {
case HAL_AllianceStationID_kBlue1:
case HAL_ALLIANCE_STATION_BLUE_1:
return std::string{"Blue1"};
case HAL_AllianceStationID_kBlue2:
case HAL_ALLIANCE_STATION_BLUE_2:
return std::string{"Blue2"};
case HAL_AllianceStationID_kBlue3:
case HAL_ALLIANCE_STATION_BLUE_3:
return std::string{"Blue3"};
case HAL_AllianceStationID_kRed1:
case HAL_ALLIANCE_STATION_RED_1:
return std::string{"Red1"};
case HAL_AllianceStationID_kRed2:
case HAL_ALLIANCE_STATION_RED_2:
return std::string{"Red2"};
case HAL_AllianceStationID_kRed3:
case HAL_ALLIANCE_STATION_RED_3:
return std::string{"Red3"};
case HAL_AllianceStationID_kUnknown:
case HAL_ALLIANCE_STATION_UNKNOWN:
return std::string{"Unknown"};
}
return std::string{"Error"};
@@ -122,7 +122,7 @@ class AutonomousTest : public DigitalCommunicationTest<bool> {};
TEST_P(AutonomousTest, Autonomous) {
auto autonomous = GetParam();
wpi::sim::DriverStationSim::SetRobotMode(
autonomous ? HAL_ROBOTMODE_AUTONOMOUS : HAL_ROBOTMODE_TELEOPERATED);
autonomous ? HAL_ROBOT_MODE_AUTONOMOUS : HAL_ROBOT_MODE_TELEOPERATED);
wpi::sim::DriverStationSim::NotifyNewData();
EXPECT_TRUE(m_autonomousOutput.GetInitialized());

View File

@@ -65,17 +65,17 @@ TEST_P(AllianceTest, Alliance) {
char expected = 'U';
switch (alliance) {
case HAL_AllianceStationID_kBlue1:
case HAL_AllianceStationID_kBlue2:
case HAL_AllianceStationID_kBlue3:
case HAL_ALLIANCE_STATION_BLUE_1:
case HAL_ALLIANCE_STATION_BLUE_2:
case HAL_ALLIANCE_STATION_BLUE_3:
expected = 'B';
break;
case HAL_AllianceStationID_kRed1:
case HAL_AllianceStationID_kRed2:
case HAL_AllianceStationID_kRed3:
case HAL_ALLIANCE_STATION_RED_1:
case HAL_ALLIANCE_STATION_RED_2:
case HAL_ALLIANCE_STATION_RED_3:
expected = 'R';
break;
case HAL_AllianceStationID_kUnknown:
case HAL_ALLIANCE_STATION_UNKNOWN:
expected = 'U';
break;
}
@@ -85,25 +85,25 @@ TEST_P(AllianceTest, Alliance) {
INSTANTIATE_TEST_SUITE_P(
I2CCommunicationTests, AllianceTest,
testing::Values<HAL_AllianceStationID>(
HAL_AllianceStationID_kRed1, HAL_AllianceStationID_kRed2,
HAL_AllianceStationID_kRed3, HAL_AllianceStationID_kBlue1,
HAL_AllianceStationID_kBlue2, HAL_AllianceStationID_kBlue3,
HAL_AllianceStationID_kUnknown),
HAL_ALLIANCE_STATION_RED_1, HAL_ALLIANCE_STATION_RED_2,
HAL_ALLIANCE_STATION_RED_3, HAL_ALLIANCE_STATION_BLUE_1,
HAL_ALLIANCE_STATION_BLUE_2, HAL_ALLIANCE_STATION_BLUE_3,
HAL_ALLIANCE_STATION_UNKNOWN),
[](const testing::TestParamInfo<AllianceTest::ParamType>& info) {
switch (info.param) {
case HAL_AllianceStationID_kBlue1:
case HAL_ALLIANCE_STATION_BLUE_1:
return std::string{"Blue1"};
case HAL_AllianceStationID_kBlue2:
case HAL_ALLIANCE_STATION_BLUE_2:
return std::string{"Blue2"};
case HAL_AllianceStationID_kBlue3:
case HAL_ALLIANCE_STATION_BLUE_3:
return std::string{"Blue3"};
case HAL_AllianceStationID_kRed1:
case HAL_ALLIANCE_STATION_RED_1:
return std::string{"Red1"};
case HAL_AllianceStationID_kRed2:
case HAL_ALLIANCE_STATION_RED_2:
return std::string{"Red2"};
case HAL_AllianceStationID_kRed3:
case HAL_ALLIANCE_STATION_RED_3:
return std::string{"Red3"};
case HAL_AllianceStationID_kUnknown:
case HAL_ALLIANCE_STATION_UNKNOWN:
return std::string{"Unknown"};
}
return std::string{"Error"};
@@ -132,7 +132,7 @@ class AutonomousTest : public I2CCommunicationTest<bool> {};
TEST_P(AutonomousTest, Autonomous) {
auto autonomous = GetParam();
wpi::sim::DriverStationSim::SetRobotMode(
autonomous ? HAL_ROBOTMODE_AUTONOMOUS : HAL_ROBOTMODE_TELEOPERATED);
autonomous ? HAL_ROBOT_MODE_AUTONOMOUS : HAL_ROBOT_MODE_TELEOPERATED);
wpi::sim::DriverStationSim::NotifyNewData();
EXPECT_TRUE(HALSIM_GetI2CInitialized(m_port));

View File

@@ -67,7 +67,7 @@ public final class DriverStation {
private static class HALJoystickTouchpad {
public final HALJoystickTouchpadFinger[] m_fingers =
new HALJoystickTouchpadFinger[DriverStationJNI.kMaxJoystickTouchpadFingers];
new HALJoystickTouchpadFinger[DriverStationJNI.MAX_JOYSTICK_TOUCHPAD_FINGERS];
public int m_count;
HALJoystickTouchpad() {
@@ -79,7 +79,7 @@ public final class DriverStation {
private static class HALJoystickTouchpads {
public final HALJoystickTouchpad[] m_touchpads =
new HALJoystickTouchpad[DriverStationJNI.kMaxJoystickTouchpads];
new HALJoystickTouchpad[DriverStationJNI.MAX_JOYSTICK_TOUCHPADS];
public int m_count;
HALJoystickTouchpads() {
@@ -129,21 +129,21 @@ public final class DriverStation {
/** The robot alliance that the robot is a part of. */
public enum Alliance {
/** Red alliance. */
Red,
RED,
/** Blue alliance. */
Blue
BLUE
}
/** The type of robot match that the robot is part of. */
public enum MatchType {
/** None. */
None,
NONE,
/** Practice. */
Practice,
PRACTICE,
/** Qualification. */
Qualification,
QUALIFICATION,
/** Elimination. */
Elimination
ELIMINATION
}
/** Represents a finger on a touchpad. */
@@ -175,23 +175,23 @@ public final class DriverStation {
/** A controller POV direction. */
public enum POVDirection {
/** POV center. */
Center(0x00),
CENTER(0x00),
/** POV up. */
Up(0x01),
UP(0x01),
/** POV up right. */
UpRight(0x01 | 0x02),
UP_RIGHT(0x01 | 0x02),
/** POV right. */
Right(0x02),
RIGHT(0x02),
/** POV down right. */
DownRight(0x02 | 0x04),
DOWN_RIGHT(0x02 | 0x04),
/** POV down. */
Down(0x04),
DOWN(0x04),
/** POV down left. */
DownLeft(0x04 | 0x08),
DOWN_LEFT(0x04 | 0x08),
/** POV left. */
Left(0x08),
LEFT(0x08),
/** POV up left. */
UpLeft(0x01 | 0x08);
UP_LEFT(0x01 | 0x08);
private static final double INVALID_POV_VALUE_INTERVAL = 1.0;
private static double s_nextMessageTime;
@@ -214,7 +214,7 @@ public final class DriverStation {
reportError("Invalid POV value " + value + "!", false);
s_nextMessageTime = currentTime + INVALID_POV_VALUE_INTERVAL;
}
return Center;
return CENTER;
}
/** The corresponding HAL value. */
@@ -232,15 +232,15 @@ public final class DriverStation {
*/
public Optional<Rotation2d> getAngle() {
return switch (this) {
case Center -> Optional.empty();
case Up -> Optional.of(Rotation2d.fromDegrees(0));
case UpRight -> Optional.of(Rotation2d.fromDegrees(45));
case Right -> Optional.of(Rotation2d.fromDegrees(90));
case DownRight -> Optional.of(Rotation2d.fromDegrees(135));
case Down -> Optional.of(Rotation2d.fromDegrees(180));
case DownLeft -> Optional.of(Rotation2d.fromDegrees(225));
case Left -> Optional.of(Rotation2d.fromDegrees(270));
case UpLeft -> Optional.of(Rotation2d.fromDegrees(315));
case CENTER -> Optional.empty();
case UP -> Optional.of(Rotation2d.fromDegrees(0));
case UP_RIGHT -> Optional.of(Rotation2d.fromDegrees(45));
case RIGHT -> Optional.of(Rotation2d.fromDegrees(90));
case DOWN_RIGHT -> Optional.of(Rotation2d.fromDegrees(135));
case DOWN -> Optional.of(Rotation2d.fromDegrees(180));
case DOWN_LEFT -> Optional.of(Rotation2d.fromDegrees(225));
case LEFT -> Optional.of(Rotation2d.fromDegrees(270));
case UP_LEFT -> Optional.of(Rotation2d.fromDegrees(315));
};
}
}
@@ -319,14 +319,14 @@ public final class DriverStation {
AllianceStationID allianceID = DriverStationJNI.getAllianceStation();
final int stationNumber =
switch (allianceID) {
case Blue1, Red1 -> 1;
case Blue2, Red2 -> 2;
case Blue3, Red3, Unknown -> 3;
case BLUE_1, RED_1 -> 1;
case BLUE_2, RED_2 -> 2;
case BLUE_3, RED_3, UNKNOWN -> 3;
};
final boolean isRedAlliance =
switch (allianceID) {
case Blue1, Blue2, Blue3 -> false;
case Red1, Red2, Red3, Unknown -> true;
case BLUE_1, BLUE_2, BLUE_3 -> false;
case RED_1, RED_2, RED_3, UNKNOWN -> true;
};
String currentEventName;
@@ -483,8 +483,8 @@ public final class DriverStation {
float[] m_sizedAxes;
long[] m_sizedPOVs;
final HALJoystickButtons m_prevButtons = new HALJoystickButtons();
final HALJoystickAxes m_prevAxes = new HALJoystickAxes(DriverStationJNI.kMaxJoystickAxes);
final HALJoystickPOVs m_prevPOVs = new HALJoystickPOVs(DriverStationJNI.kMaxJoystickPOVs);
final HALJoystickAxes m_prevAxes = new HALJoystickAxes(DriverStationJNI.MAX_JOYSTICK_AXES);
final HALJoystickPOVs m_prevPOVs = new HALJoystickPOVs(DriverStationJNI.MAX_JOYSTICK_POVS);
final BooleanArrayLogEntry m_logButtons;
final FloatArrayLogEntry m_logAxes;
final IntegerArrayLogEntry m_logPOVs;
@@ -594,15 +594,15 @@ public final class DriverStation {
for (int i = 0; i < kJoystickPorts; i++) {
m_joystickButtons[i] = new HALJoystickButtons();
m_joystickAxes[i] = new HALJoystickAxes(DriverStationJNI.kMaxJoystickAxes);
m_joystickAxesRaw[i] = new HALJoystickAxesRaw(DriverStationJNI.kMaxJoystickAxes);
m_joystickPOVs[i] = new HALJoystickPOVs(DriverStationJNI.kMaxJoystickPOVs);
m_joystickAxes[i] = new HALJoystickAxes(DriverStationJNI.MAX_JOYSTICK_AXES);
m_joystickAxesRaw[i] = new HALJoystickAxesRaw(DriverStationJNI.MAX_JOYSTICK_AXES);
m_joystickPOVs[i] = new HALJoystickPOVs(DriverStationJNI.MAX_JOYSTICK_POVS);
m_joystickTouchpads[i] = new HALJoystickTouchpads();
m_joystickButtonsCache[i] = new HALJoystickButtons();
m_joystickAxesCache[i] = new HALJoystickAxes(DriverStationJNI.kMaxJoystickAxes);
m_joystickAxesRawCache[i] = new HALJoystickAxesRaw(DriverStationJNI.kMaxJoystickAxes);
m_joystickPOVsCache[i] = new HALJoystickPOVs(DriverStationJNI.kMaxJoystickPOVs);
m_joystickAxesCache[i] = new HALJoystickAxes(DriverStationJNI.MAX_JOYSTICK_AXES);
m_joystickAxesRawCache[i] = new HALJoystickAxesRaw(DriverStationJNI.MAX_JOYSTICK_AXES);
m_joystickPOVsCache[i] = new HALJoystickPOVs(DriverStationJNI.MAX_JOYSTICK_POVS);
m_joystickTouchpadsCache[i] = new HALJoystickTouchpads();
}
@@ -699,7 +699,7 @@ public final class DriverStation {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
if (button < 0 || button >= DriverStationJNI.kMaxJoystickButtons) {
if (button < 0 || button >= DriverStationJNI.MAX_JOYSTICK_BUTTONS) {
throw new IllegalArgumentException("Joystick Button is out of range");
}
@@ -730,7 +730,7 @@ public final class DriverStation {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
if (button < 0 || button >= DriverStationJNI.kMaxJoystickButtons) {
if (button < 0 || button >= DriverStationJNI.MAX_JOYSTICK_BUTTONS) {
throw new IllegalArgumentException("Joystick Button is out of range");
}
@@ -758,7 +758,7 @@ public final class DriverStation {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
if (button < 0 || button >= DriverStationJNI.kMaxJoystickButtons) {
if (button < 0 || button >= DriverStationJNI.MAX_JOYSTICK_BUTTONS) {
throw new IllegalArgumentException("Joystick Button is out of range");
}
@@ -795,7 +795,7 @@ public final class DriverStation {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
if (button < 0 || button >= DriverStationJNI.kMaxJoystickButtons) {
if (button < 0 || button >= DriverStationJNI.MAX_JOYSTICK_BUTTONS) {
throw new IllegalArgumentException("Joystick Button is out of range");
}
@@ -833,7 +833,7 @@ public final class DriverStation {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
if (axis < 0 || axis >= DriverStationJNI.kMaxJoystickAxes) {
if (axis < 0 || axis >= DriverStationJNI.MAX_JOYSTICK_AXES) {
throw new IllegalArgumentException("Joystick axis is out of range");
}
@@ -864,10 +864,10 @@ public final class DriverStation {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
if (touchpad < 0 || touchpad >= DriverStationJNI.kMaxJoystickTouchpads) {
if (touchpad < 0 || touchpad >= DriverStationJNI.MAX_JOYSTICK_TOUCHPADS) {
throw new IllegalArgumentException("Joystick touchpad is out of range");
}
if (finger < 0 || finger >= DriverStationJNI.kMaxJoystickTouchpadFingers) {
if (finger < 0 || finger >= DriverStationJNI.MAX_JOYSTICK_TOUCHPAD_FINGERS) {
throw new IllegalArgumentException("Joystick touchpad finger is out of range");
}
@@ -910,10 +910,10 @@ public final class DriverStation {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
if (touchpad < 0 || touchpad >= DriverStationJNI.kMaxJoystickTouchpads) {
if (touchpad < 0 || touchpad >= DriverStationJNI.MAX_JOYSTICK_TOUCHPADS) {
throw new IllegalArgumentException("Joystick touchpad is out of range");
}
if (finger < 0 || finger >= DriverStationJNI.kMaxJoystickTouchpadFingers) {
if (finger < 0 || finger >= DriverStationJNI.MAX_JOYSTICK_TOUCHPAD_FINGERS) {
throw new IllegalArgumentException("Joystick touchpad finger is out of range");
}
@@ -946,7 +946,7 @@ public final class DriverStation {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
if (axis < 0 || axis >= DriverStationJNI.kMaxJoystickAxes) {
if (axis < 0 || axis >= DriverStationJNI.MAX_JOYSTICK_AXES) {
throw new IllegalArgumentException("Joystick axis is out of range");
}
@@ -975,7 +975,7 @@ public final class DriverStation {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
if (pov < 0 || pov >= DriverStationJNI.kMaxJoystickPOVs) {
if (pov < 0 || pov >= DriverStationJNI.MAX_JOYSTICK_POVS) {
throw new IllegalArgumentException("Joystick POV is out of range");
}
@@ -991,7 +991,7 @@ public final class DriverStation {
}
reportJoystickWarning(stick, "Joystick POV " + pov + " on port " + stick + " not available");
return POVDirection.Center;
return POVDirection.CENTER;
}
/**
@@ -1602,10 +1602,10 @@ public final class DriverStation {
m_cacheDataMutex.unlock();
}
return switch (matchType) {
case 1 -> MatchType.Practice;
case 2 -> MatchType.Qualification;
case 3 -> MatchType.Elimination;
default -> MatchType.None;
case 1 -> MatchType.PRACTICE;
case 2 -> MatchType.QUALIFICATION;
case 3 -> MatchType.ELIMINATION;
default -> MatchType.NONE;
};
}
@@ -1639,23 +1639,23 @@ public final class DriverStation {
private static Map<AllianceStationID, Optional<Alliance>> m_allianceMap =
Map.of(
AllianceStationID.Unknown, Optional.empty(),
AllianceStationID.Red1, Optional.of(Alliance.Red),
AllianceStationID.Red2, Optional.of(Alliance.Red),
AllianceStationID.Red3, Optional.of(Alliance.Red),
AllianceStationID.Blue1, Optional.of(Alliance.Blue),
AllianceStationID.Blue2, Optional.of(Alliance.Blue),
AllianceStationID.Blue3, Optional.of(Alliance.Blue));
AllianceStationID.UNKNOWN, Optional.empty(),
AllianceStationID.RED_1, Optional.of(Alliance.RED),
AllianceStationID.RED_2, Optional.of(Alliance.RED),
AllianceStationID.RED_3, Optional.of(Alliance.RED),
AllianceStationID.BLUE_1, Optional.of(Alliance.BLUE),
AllianceStationID.BLUE_2, Optional.of(Alliance.BLUE),
AllianceStationID.BLUE_3, Optional.of(Alliance.BLUE));
private static Map<AllianceStationID, OptionalInt> m_stationMap =
Map.of(
AllianceStationID.Unknown, OptionalInt.empty(),
AllianceStationID.Red1, OptionalInt.of(1),
AllianceStationID.Red2, OptionalInt.of(2),
AllianceStationID.Red3, OptionalInt.of(3),
AllianceStationID.Blue1, OptionalInt.of(1),
AllianceStationID.Blue2, OptionalInt.of(2),
AllianceStationID.Blue3, OptionalInt.of(3));
AllianceStationID.UNKNOWN, OptionalInt.empty(),
AllianceStationID.RED_1, OptionalInt.of(1),
AllianceStationID.RED_2, OptionalInt.of(2),
AllianceStationID.RED_3, OptionalInt.of(3),
AllianceStationID.BLUE_1, OptionalInt.of(1),
AllianceStationID.BLUE_2, OptionalInt.of(2),
AllianceStationID.BLUE_3, OptionalInt.of(3));
/**
* Get the current alliance from the FMS.
@@ -1667,7 +1667,7 @@ public final class DriverStation {
public static Optional<Alliance> getAlliance() {
AllianceStationID allianceStationID = DriverStationJNI.getAllianceStation();
if (allianceStationID == null) {
allianceStationID = AllianceStationID.Unknown;
allianceStationID = AllianceStationID.UNKNOWN;
}
return m_allianceMap.get(allianceStationID);
@@ -1683,7 +1683,7 @@ public final class DriverStation {
public static OptionalInt getLocation() {
AllianceStationID allianceStationID = DriverStationJNI.getAllianceStation();
if (allianceStationID == null) {
allianceStationID = AllianceStationID.Unknown;
allianceStationID = AllianceStationID.UNKNOWN;
}
return m_stationMap.get(allianceStationID);

View File

@@ -228,7 +228,7 @@ public class GenericHID {
* @return a BooleanEvent instance based around the up direction a POV on the HID.
*/
public BooleanEvent povUp(EventLoop loop) {
return pov(POVDirection.Up, loop);
return pov(POVDirection.UP, loop);
}
/**
@@ -239,7 +239,7 @@ public class GenericHID {
* @return a BooleanEvent instance based around the up right direction of a POV on the HID.
*/
public BooleanEvent povUpRight(EventLoop loop) {
return pov(POVDirection.UpRight, loop);
return pov(POVDirection.UP_RIGHT, loop);
}
/**
@@ -250,7 +250,7 @@ public class GenericHID {
* @return a BooleanEvent instance based around the right direction of a POV on the HID.
*/
public BooleanEvent povRight(EventLoop loop) {
return pov(POVDirection.Right, loop);
return pov(POVDirection.RIGHT, loop);
}
/**
@@ -261,7 +261,7 @@ public class GenericHID {
* @return a BooleanEvent instance based around the down right direction of a POV on the HID.
*/
public BooleanEvent povDownRight(EventLoop loop) {
return pov(POVDirection.DownRight, loop);
return pov(POVDirection.DOWN_RIGHT, loop);
}
/**
@@ -272,7 +272,7 @@ public class GenericHID {
* @return a BooleanEvent instance based around the down direction of a POV on the HID.
*/
public BooleanEvent povDown(EventLoop loop) {
return pov(POVDirection.Down, loop);
return pov(POVDirection.DOWN, loop);
}
/**
@@ -283,7 +283,7 @@ public class GenericHID {
* @return a BooleanEvent instance based around the down left direction of a POV on the HID.
*/
public BooleanEvent povDownLeft(EventLoop loop) {
return pov(POVDirection.DownLeft, loop);
return pov(POVDirection.DOWN_LEFT, loop);
}
/**
@@ -294,7 +294,7 @@ public class GenericHID {
* @return a BooleanEvent instance based around the left direction of a POV on the HID.
*/
public BooleanEvent povLeft(EventLoop loop) {
return pov(POVDirection.Left, loop);
return pov(POVDirection.LEFT, loop);
}
/**
@@ -305,7 +305,7 @@ public class GenericHID {
* @return a BooleanEvent instance based around the up left direction of a POV on the HID.
*/
public BooleanEvent povUpLeft(EventLoop loop) {
return pov(POVDirection.UpLeft, loop);
return pov(POVDirection.UP_LEFT, loop);
}
/**
@@ -316,7 +316,7 @@ public class GenericHID {
* @return a BooleanEvent instance based around the center of a POV on the HID.
*/
public BooleanEvent povCenter(EventLoop loop) {
return pov(POVDirection.Center, loop);
return pov(POVDirection.CENTER, loop);
}
/**

View File

@@ -195,14 +195,14 @@ public final class DriverStationSim {
*/
public static AllianceStationID getAllianceStationId() {
return switch (DriverStationDataJNI.getAllianceStationId()) {
case DriverStationJNI.kUnknownAllianceStation -> AllianceStationID.Unknown;
case DriverStationJNI.kRed1AllianceStation -> AllianceStationID.Red1;
case DriverStationJNI.kRed2AllianceStation -> AllianceStationID.Red2;
case DriverStationJNI.kRed3AllianceStation -> AllianceStationID.Red3;
case DriverStationJNI.kBlue1AllianceStation -> AllianceStationID.Blue1;
case DriverStationJNI.kBlue2AllianceStation -> AllianceStationID.Blue2;
case DriverStationJNI.kBlue3AllianceStation -> AllianceStationID.Blue3;
default -> AllianceStationID.Unknown;
case DriverStationJNI.ALLIANCE_STATION_UNKNOWN -> AllianceStationID.UNKNOWN;
case DriverStationJNI.ALLIANCE_STATION_RED_1 -> AllianceStationID.RED_1;
case DriverStationJNI.ALLIANCE_STATION_RED_2 -> AllianceStationID.RED_2;
case DriverStationJNI.ALLIANCE_STATION_RED_3 -> AllianceStationID.RED_3;
case DriverStationJNI.ALLIANCE_STATION_BLUE_1 -> AllianceStationID.BLUE_1;
case DriverStationJNI.ALLIANCE_STATION_BLUE_2 -> AllianceStationID.BLUE_2;
case DriverStationJNI.ALLIANCE_STATION_BLUE_3 -> AllianceStationID.BLUE_3;
default -> AllianceStationID.UNKNOWN;
};
}
@@ -214,13 +214,13 @@ public final class DriverStationSim {
public static void setAllianceStationId(AllianceStationID allianceStationId) {
int allianceStation =
switch (allianceStationId) {
case Unknown -> DriverStationJNI.kUnknownAllianceStation;
case Red1 -> DriverStationJNI.kRed1AllianceStation;
case Red2 -> DriverStationJNI.kRed2AllianceStation;
case Red3 -> DriverStationJNI.kRed3AllianceStation;
case Blue1 -> DriverStationJNI.kBlue1AllianceStation;
case Blue2 -> DriverStationJNI.kBlue2AllianceStation;
case Blue3 -> DriverStationJNI.kBlue3AllianceStation;
case UNKNOWN -> DriverStationJNI.ALLIANCE_STATION_UNKNOWN;
case RED_1 -> DriverStationJNI.ALLIANCE_STATION_RED_1;
case RED_2 -> DriverStationJNI.ALLIANCE_STATION_RED_2;
case RED_3 -> DriverStationJNI.ALLIANCE_STATION_RED_3;
case BLUE_1 -> DriverStationJNI.ALLIANCE_STATION_BLUE_1;
case BLUE_2 -> DriverStationJNI.ALLIANCE_STATION_BLUE_2;
case BLUE_3 -> DriverStationJNI.ALLIANCE_STATION_BLUE_3;
};
DriverStationDataJNI.setAllianceStationId(allianceStation);
}
@@ -526,10 +526,10 @@ public final class DriverStationSim {
public static void setMatchType(DriverStation.MatchType type) {
int matchType =
switch (type) {
case Practice -> 1;
case Qualification -> 2;
case Elimination -> 3;
case None -> 0;
case PRACTICE -> 1;
case QUALIFICATION -> 2;
case ELIMINATION -> 3;
case NONE -> 0;
};
DriverStationDataJNI.setMatchType(matchType);
}

View File

@@ -417,13 +417,13 @@ public final class DataLogManager {
// match info comes through TCP, so we need to double-check we've
// actually received it
DriverStation.MatchType matchType = DriverStation.getMatchType();
if (matchType != DriverStation.MatchType.None) {
if (matchType != DriverStation.MatchType.NONE) {
// rename per match info
char matchTypeChar =
switch (matchType) {
case Practice -> 'P';
case Qualification -> 'Q';
case Elimination -> 'E';
case PRACTICE -> 'P';
case QUALIFICATION -> 'Q';
case ELIMINATION -> 'E';
default -> '_';
};
m_log.setFilename(

View File

@@ -17,7 +17,7 @@ import org.wpilib.simulation.DriverStationSim;
class MatchInfoDataTest {
@Test
void testSetMatchInfo() {
MatchType matchType = MatchType.Qualification;
MatchType matchType = MatchType.QUALIFICATION;
DriverStationDataJNI.setMatchInfo("Event Name", 174, 191, matchType.ordinal());
DriverStationSim.notifyNewData();

View File

@@ -137,12 +137,12 @@ class DriverStationSimTest {
EnumCallback callback = new EnumCallback();
AllianceStationID allianceStation = AllianceStationID.Blue2;
AllianceStationID allianceStation = AllianceStationID.BLUE_2;
DriverStationSim.setAllianceStationId(allianceStation);
try (CallbackStore cb = DriverStationSim.registerAllianceStationIdCallback(callback, false)) {
// Unknown
allianceStation = AllianceStationID.Unknown;
allianceStation = AllianceStationID.UNKNOWN;
DriverStationSim.setAllianceStationId(allianceStation);
DriverStationSim.notifyNewData();
assertEquals(allianceStation, DriverStationSim.getAllianceStationId());
@@ -152,61 +152,61 @@ class DriverStationSimTest {
assertEquals(allianceStation.ordinal(), callback.getSetValue());
// B1
allianceStation = AllianceStationID.Blue1;
allianceStation = AllianceStationID.BLUE_1;
DriverStationSim.setAllianceStationId(allianceStation);
DriverStationSim.notifyNewData();
assertEquals(allianceStation, DriverStationSim.getAllianceStationId());
assertEquals(DriverStation.Alliance.Blue, DriverStation.getAlliance().get());
assertEquals(DriverStation.Alliance.BLUE, DriverStation.getAlliance().get());
assertEquals(1, DriverStation.getLocation().getAsInt());
assertTrue(callback.wasTriggered());
assertEquals(allianceStation.ordinal(), callback.getSetValue());
// B2
allianceStation = AllianceStationID.Blue2;
allianceStation = AllianceStationID.BLUE_2;
DriverStationSim.setAllianceStationId(allianceStation);
DriverStationSim.notifyNewData();
assertEquals(allianceStation, DriverStationSim.getAllianceStationId());
assertEquals(DriverStation.Alliance.Blue, DriverStation.getAlliance().get());
assertEquals(DriverStation.Alliance.BLUE, DriverStation.getAlliance().get());
assertEquals(2, DriverStation.getLocation().getAsInt());
assertTrue(callback.wasTriggered());
assertEquals(allianceStation.ordinal(), callback.getSetValue());
// B3
allianceStation = AllianceStationID.Blue3;
allianceStation = AllianceStationID.BLUE_3;
DriverStationSim.setAllianceStationId(allianceStation);
DriverStationSim.notifyNewData();
assertEquals(allianceStation, DriverStationSim.getAllianceStationId());
assertEquals(DriverStation.Alliance.Blue, DriverStation.getAlliance().get());
assertEquals(DriverStation.Alliance.BLUE, DriverStation.getAlliance().get());
assertEquals(3, DriverStation.getLocation().getAsInt());
assertTrue(callback.wasTriggered());
assertEquals(allianceStation.ordinal(), callback.getSetValue());
// R1
allianceStation = AllianceStationID.Red1;
allianceStation = AllianceStationID.RED_1;
DriverStationSim.setAllianceStationId(allianceStation);
DriverStationSim.notifyNewData();
assertEquals(allianceStation, DriverStationSim.getAllianceStationId());
assertEquals(DriverStation.Alliance.Red, DriverStation.getAlliance().get());
assertEquals(DriverStation.Alliance.RED, DriverStation.getAlliance().get());
assertEquals(1, DriverStation.getLocation().getAsInt());
assertTrue(callback.wasTriggered());
assertEquals(allianceStation.ordinal(), callback.getSetValue());
// R2
allianceStation = AllianceStationID.Red2;
allianceStation = AllianceStationID.RED_2;
DriverStationSim.setAllianceStationId(allianceStation);
DriverStationSim.notifyNewData();
assertEquals(allianceStation, DriverStationSim.getAllianceStationId());
assertEquals(DriverStation.Alliance.Red, DriverStation.getAlliance().get());
assertEquals(DriverStation.Alliance.RED, DriverStation.getAlliance().get());
assertEquals(2, DriverStation.getLocation().getAsInt());
assertTrue(callback.wasTriggered());
assertEquals(allianceStation.ordinal(), callback.getSetValue());
// R3
allianceStation = AllianceStationID.Red3;
allianceStation = AllianceStationID.RED_3;
DriverStationSim.setAllianceStationId(allianceStation);
DriverStationSim.notifyNewData();
assertEquals(allianceStation, DriverStationSim.getAllianceStationId());
assertEquals(DriverStation.Alliance.Red, DriverStation.getAlliance().get());
assertEquals(DriverStation.Alliance.RED, DriverStation.getAlliance().get());
assertEquals(3, DriverStation.getLocation().getAsInt());
assertTrue(callback.wasTriggered());
assertEquals(allianceStation.ordinal(), callback.getSetValue());

View File

@@ -30,7 +30,7 @@ public class Robot extends TimedRobot {
boolean setAlliance = false;
Optional<DriverStation.Alliance> alliance = DriverStation.getAlliance();
if (alliance.isPresent()) {
setAlliance = alliance.get() == DriverStation.Alliance.Red;
setAlliance = alliance.get() == DriverStation.Alliance.RED;
}
// pull alliance port high if on red alliance, pull low if on blue alliance

View File

@@ -53,7 +53,7 @@ public class Robot extends TimedRobot {
String allianceString = "U";
Optional<DriverStation.Alliance> alliance = DriverStation.getAlliance();
if (alliance.isPresent()) {
allianceString = alliance.get() == DriverStation.Alliance.Red ? "R" : "B";
allianceString = alliance.get() == DriverStation.Alliance.RED ? "R" : "B";
}
stateMessage

View File

@@ -69,7 +69,7 @@ class DigitalCommunicationTest {
SimHooks.stepTiming(0.02);
assertEquals(alliance.name().startsWith("Red"), m_allianceOutput.getValue());
assertEquals(alliance.name().startsWith("RED"), m_allianceOutput.getValue());
}
@ValueSource(booleans = {true, false})

View File

@@ -76,8 +76,8 @@ class I2CCommunicationTest {
SimHooks.stepTiming(0.02);
String str = assertTimeoutPreemptively(Duration.ofMillis(20L), () -> m_future.get());
char expected = alliance.name().startsWith("Red") ? 'R' : 'B';
if (alliance.name().startsWith("Unknown")) {
char expected = alliance.name().startsWith("RED") ? 'R' : 'B';
if (alliance.name().startsWith("UNKNOWN")) {
expected = 'U';
}