mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[hal,wpilib,cmd] Update POVs to use enums (#7978)
This commit is contained in:
@@ -315,14 +315,14 @@ double DriverStation::GetStickAxis(int stick, int axis) {
|
||||
return axes.axes[axis];
|
||||
}
|
||||
|
||||
int DriverStation::GetStickPOV(int stick, int pov) {
|
||||
DriverStation::POVDirection DriverStation::GetStickPOV(int stick, int pov) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return -1;
|
||||
return kCenter;
|
||||
}
|
||||
if (pov < 0 || pov >= HAL_kMaxJoystickPOVs) {
|
||||
FRC_ReportError(warn::BadJoystickAxis, "POV {} out of range", pov);
|
||||
return -1;
|
||||
return kCenter;
|
||||
}
|
||||
|
||||
HAL_JoystickPOVs povs;
|
||||
@@ -333,10 +333,10 @@ int DriverStation::GetStickPOV(int stick, int pov) {
|
||||
"Joystick POV {} missing (max {}), check if all controllers are "
|
||||
"plugged in",
|
||||
pov, povs.count);
|
||||
return -1;
|
||||
return kCenter;
|
||||
}
|
||||
|
||||
return povs.povs[pov];
|
||||
return static_cast<POVDirection>(povs.povs[pov]);
|
||||
}
|
||||
|
||||
int DriverStation::GetStickButtons(int stick) {
|
||||
|
||||
@@ -42,53 +42,55 @@ double GenericHID::GetRawAxis(int axis) const {
|
||||
return DriverStation::GetStickAxis(m_port, axis);
|
||||
}
|
||||
|
||||
int GenericHID::GetPOV(int pov) const {
|
||||
DriverStation::POVDirection GenericHID::GetPOV(int pov) const {
|
||||
return DriverStation::GetStickPOV(m_port, pov);
|
||||
}
|
||||
|
||||
BooleanEvent GenericHID::POV(int angle, EventLoop* loop) const {
|
||||
BooleanEvent GenericHID::POV(DriverStation::POVDirection angle,
|
||||
EventLoop* loop) const {
|
||||
return POV(0, angle, loop);
|
||||
}
|
||||
|
||||
BooleanEvent GenericHID::POV(int pov, int angle, EventLoop* loop) const {
|
||||
BooleanEvent GenericHID::POV(int pov, DriverStation::POVDirection angle,
|
||||
EventLoop* loop) const {
|
||||
return BooleanEvent(
|
||||
loop, [this, pov, angle] { return this->GetPOV(pov) == angle; });
|
||||
}
|
||||
|
||||
BooleanEvent GenericHID::POVUp(EventLoop* loop) const {
|
||||
return POV(0, loop);
|
||||
return POV(DriverStation::kUp, loop);
|
||||
}
|
||||
|
||||
BooleanEvent GenericHID::POVUpRight(EventLoop* loop) const {
|
||||
return POV(45, loop);
|
||||
return POV(DriverStation::kUpRight, loop);
|
||||
}
|
||||
|
||||
BooleanEvent GenericHID::POVRight(EventLoop* loop) const {
|
||||
return POV(90, loop);
|
||||
return POV(DriverStation::kRight, loop);
|
||||
}
|
||||
|
||||
BooleanEvent GenericHID::POVDownRight(EventLoop* loop) const {
|
||||
return POV(135, loop);
|
||||
return POV(DriverStation::kDownRight, loop);
|
||||
}
|
||||
|
||||
BooleanEvent GenericHID::POVDown(EventLoop* loop) const {
|
||||
return POV(180, loop);
|
||||
return POV(DriverStation::kDown, loop);
|
||||
}
|
||||
|
||||
BooleanEvent GenericHID::POVDownLeft(EventLoop* loop) const {
|
||||
return POV(225, loop);
|
||||
return POV(DriverStation::kDownLeft, loop);
|
||||
}
|
||||
|
||||
BooleanEvent GenericHID::POVLeft(EventLoop* loop) const {
|
||||
return POV(270, loop);
|
||||
return POV(DriverStation::kLeft, loop);
|
||||
}
|
||||
|
||||
BooleanEvent GenericHID::POVUpLeft(EventLoop* loop) const {
|
||||
return POV(315, loop);
|
||||
return POV(DriverStation::kUpLeft, loop);
|
||||
}
|
||||
|
||||
BooleanEvent GenericHID::POVCenter(EventLoop* loop) const {
|
||||
return POV(360, loop);
|
||||
return POV(DriverStation::kCenter, loop);
|
||||
}
|
||||
|
||||
BooleanEvent GenericHID::AxisLessThan(int axis, double threshold,
|
||||
|
||||
@@ -205,8 +205,9 @@ void DriverStationSim::SetJoystickAxis(int stick, int axis, double value) {
|
||||
HALSIM_SetJoystickAxis(stick, axis, value);
|
||||
}
|
||||
|
||||
void DriverStationSim::SetJoystickPOV(int stick, int pov, int value) {
|
||||
HALSIM_SetJoystickPOV(stick, pov, value);
|
||||
void DriverStationSim::SetJoystickPOV(int stick, int pov,
|
||||
DriverStation::POVDirection value) {
|
||||
HALSIM_SetJoystickPOV(stick, pov, static_cast<HAL_JoystickPOV>(value));
|
||||
}
|
||||
|
||||
void DriverStationSim::SetJoystickButtons(int stick, uint32_t buttons) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "frc/simulation/GenericHIDSim.h"
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/GenericHID.h"
|
||||
#include "frc/simulation/DriverStationSim.h"
|
||||
|
||||
@@ -27,11 +28,11 @@ void GenericHIDSim::SetRawAxis(int axis, double value) {
|
||||
DriverStationSim::SetJoystickAxis(m_port, axis, value);
|
||||
}
|
||||
|
||||
void GenericHIDSim::SetPOV(int pov, int value) {
|
||||
void GenericHIDSim::SetPOV(int pov, DriverStation::POVDirection value) {
|
||||
DriverStationSim::SetJoystickPOV(m_port, pov, value);
|
||||
}
|
||||
|
||||
void GenericHIDSim::SetPOV(int value) {
|
||||
void GenericHIDSim::SetPOV(DriverStation::POVDirection value) {
|
||||
SetPOV(0, value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user