mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +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);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc/geometry/Rotation2d.h>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include <hal/DriverStationTypes.h>
|
||||
#include <units/time.h>
|
||||
#include <wpi/Synchronization.h>
|
||||
|
||||
@@ -46,6 +49,62 @@ class DriverStation final {
|
||||
kElimination
|
||||
};
|
||||
|
||||
/**
|
||||
* A controller POV direction.
|
||||
*/
|
||||
enum POVDirection : uint8_t {
|
||||
/// POV center.
|
||||
kCenter = HAL_JoystickPOV_kCentered,
|
||||
/// POV up.
|
||||
kUp = HAL_JoystickPOV_kUp,
|
||||
/// POV up right.
|
||||
kUpRight = HAL_JoystickPOV_kRightUp,
|
||||
/// POV right.
|
||||
kRight = HAL_JoystickPOV_kRight,
|
||||
/// POV down right.
|
||||
kDownRight = HAL_JoystickPOV_kRightDown,
|
||||
/// POV down.
|
||||
kDown = HAL_JoystickPOV_kDown,
|
||||
/// POV down left.
|
||||
kDownLeft = HAL_JoystickPOV_kLeftDown,
|
||||
/// POV left.
|
||||
kLeft = HAL_JoystickPOV_kLeft,
|
||||
/// POV up left.
|
||||
kUpLeft = HAL_JoystickPOV_kLeftUp,
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the angle of a POVDirection.
|
||||
*
|
||||
* @param angle The POVDirection to convert.
|
||||
* @return The angle clockwise from straight up, or std::nullopt if the
|
||||
* POVDirection is kCenter.
|
||||
*/
|
||||
static constexpr std::optional<Rotation2d> GetAngle(POVDirection angle) {
|
||||
switch (angle) {
|
||||
case kCenter:
|
||||
return std::nullopt;
|
||||
case kUp:
|
||||
return Rotation2d{0_deg};
|
||||
case kUpRight:
|
||||
return Rotation2d{45_deg};
|
||||
case kRight:
|
||||
return Rotation2d{90_deg};
|
||||
case kDownRight:
|
||||
return Rotation2d{135_deg};
|
||||
case kDown:
|
||||
return Rotation2d{180_deg};
|
||||
case kDownLeft:
|
||||
return Rotation2d{225_deg};
|
||||
case kLeft:
|
||||
return Rotation2d{270_deg};
|
||||
case kUpLeft:
|
||||
return Rotation2d{315_deg};
|
||||
default:
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
/// Number of Joystick ports.
|
||||
static constexpr int kJoystickPorts = 6;
|
||||
|
||||
@@ -93,9 +152,9 @@ class DriverStation final {
|
||||
/**
|
||||
* Get the state of a POV on the joystick.
|
||||
*
|
||||
* @return the angle of the POV in degrees, or -1 if the POV is not pressed.
|
||||
* @return the angle of the POV.
|
||||
*/
|
||||
static int GetStickPOV(int stick, int pov);
|
||||
static POVDirection GetStickPOV(int stick, int pov);
|
||||
|
||||
/**
|
||||
* The state of the buttons on the joystick.
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class BooleanEvent;
|
||||
@@ -141,113 +143,105 @@ class GenericHID {
|
||||
double GetRawAxis(int axis) const;
|
||||
|
||||
/**
|
||||
* Get the angle in degrees of a POV on the HID.
|
||||
*
|
||||
* The POV angles start at 0 in the up direction, and increase clockwise
|
||||
* (e.g. right is 90, upper-left is 315).
|
||||
* Get the angle of a POV on the HID.
|
||||
*
|
||||
* @param pov The index of the POV to read (starting at 0)
|
||||
* @return the angle of the POV in degrees, or -1 if the POV is not pressed.
|
||||
* @return the angle of the POV.
|
||||
*/
|
||||
int GetPOV(int pov = 0) const;
|
||||
DriverStation::POVDirection GetPOV(int pov = 0) const;
|
||||
|
||||
/**
|
||||
* Constructs a BooleanEvent instance based around this angle of a POV on the
|
||||
* HID.
|
||||
*
|
||||
* <p>The POV angles start at 0 in the up direction, and increase clockwise
|
||||
* (eg right is 90, upper-left is 315).
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @param angle POV angle in degrees, or -1 for the center / not pressed.
|
||||
* @param angle POV angle.
|
||||
* @return a BooleanEvent instance based around this angle of a POV on the
|
||||
* HID.
|
||||
*/
|
||||
BooleanEvent POV(int angle, EventLoop* loop) const;
|
||||
BooleanEvent POV(DriverStation::POVDirection angle, EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs a BooleanEvent instance based around this angle of a POV on the
|
||||
* HID.
|
||||
*
|
||||
* <p>The POV angles start at 0 in the up direction, and increase clockwise
|
||||
* (eg right is 90, upper-left is 315).
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @param pov index of the POV to read (starting at 0). Defaults to 0.
|
||||
* @param angle POV angle in degrees, or -1 for the center / not pressed.
|
||||
* @param angle POV angle.
|
||||
* @return a BooleanEvent instance based around this angle of a POV on the
|
||||
* HID.
|
||||
*/
|
||||
BooleanEvent POV(int pov, int angle, EventLoop* loop) const;
|
||||
BooleanEvent POV(int pov, DriverStation::POVDirection angle,
|
||||
EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs a BooleanEvent instance based around the 0 degree angle (up) of
|
||||
* Constructs a BooleanEvent instance based around the up direction of
|
||||
* the default (index 0) POV on the HID.
|
||||
*
|
||||
* @return a BooleanEvent instance based around the 0 degree angle of a POV on
|
||||
* @return a BooleanEvent instance based around the up direction of a POV on
|
||||
* the HID.
|
||||
*/
|
||||
BooleanEvent POVUp(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs a BooleanEvent instance based around the 45 degree angle (right
|
||||
* up) of the default (index 0) POV on the HID.
|
||||
* Constructs a BooleanEvent instance based around the up right direction
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @return a BooleanEvent instance based around the 45 degree angle of a POV
|
||||
* on the HID.
|
||||
* @return a BooleanEvent instance based around the up right direction of a
|
||||
* POV on the HID.
|
||||
*/
|
||||
BooleanEvent POVUpRight(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs a BooleanEvent instance based around the 90 degree angle (right)
|
||||
* Constructs a BooleanEvent instance based around the right direction
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @return a BooleanEvent instance based around the 90 degree angle of a POV
|
||||
* @return a BooleanEvent instance based around the right direction of a POV
|
||||
* on the HID.
|
||||
*/
|
||||
BooleanEvent POVRight(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs a BooleanEvent instance based around the 135 degree angle (right
|
||||
* down) of the default (index 0) POV on the HID.
|
||||
* Constructs a BooleanEvent instance based around the down right direction
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @return a BooleanEvent instance based around the 135 degree angle of a POV
|
||||
* on the HID.
|
||||
* @return a BooleanEvent instance based around the down right direction of a
|
||||
* POV on the HID.
|
||||
*/
|
||||
BooleanEvent POVDownRight(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs a BooleanEvent instance based around the 180 degree angle (down)
|
||||
* Constructs a BooleanEvent instance based around the down direction
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @return a BooleanEvent instance based around the 180 degree angle of a POV
|
||||
* @return a BooleanEvent instance based around the down direction of a POV
|
||||
* on the HID.
|
||||
*/
|
||||
BooleanEvent POVDown(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs a BooleanEvent instance based around the 225 degree angle (down
|
||||
* left) of the default (index 0) POV on the HID.
|
||||
* Constructs a BooleanEvent instance based around the down left direction
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @return a BooleanEvent instance based around the 225 degree angle of a POV
|
||||
* on the HID.
|
||||
* @return a BooleanEvent instance based around the down left direction of a
|
||||
* POV on the HID.
|
||||
*/
|
||||
BooleanEvent POVDownLeft(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs a BooleanEvent instance based around the 270 degree angle (left)
|
||||
* Constructs a BooleanEvent instance based around the left direction
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @return a BooleanEvent instance based around the 270 degree angle of a POV
|
||||
* @return a BooleanEvent instance based around the left direction of a POV
|
||||
* on the HID.
|
||||
*/
|
||||
BooleanEvent POVLeft(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs a BooleanEvent instance based around the 315 degree angle (left
|
||||
* up) of the default (index 0) POV on the HID.
|
||||
* Constructs a BooleanEvent instance based around the up left direction
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @return a BooleanEvent instance based around the 315 degree angle of a POV
|
||||
* @return a BooleanEvent instance based around the up left direction of a POV
|
||||
* on the HID.
|
||||
*/
|
||||
BooleanEvent POVUpLeft(EventLoop* loop) const;
|
||||
|
||||
@@ -286,9 +286,10 @@ class DriverStationSim {
|
||||
*
|
||||
* @param stick The joystick number
|
||||
* @param pov The POV number
|
||||
* @param value the angle of the POV in degrees, or -1 for not pressed
|
||||
* @param value the angle of the POV
|
||||
*/
|
||||
static void SetJoystickPOV(int stick, int pov, int value);
|
||||
static void SetJoystickPOV(int stick, int pov,
|
||||
DriverStation::POVDirection value);
|
||||
|
||||
/**
|
||||
* Sets the state of all the buttons on a joystick.
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/GenericHID.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -60,14 +61,14 @@ class GenericHIDSim {
|
||||
* @param pov the POV to set
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetPOV(int pov, int value);
|
||||
void SetPOV(int pov, DriverStation::POVDirection value);
|
||||
|
||||
/**
|
||||
* Set the value of the default POV (port 0).
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetPOV(int value);
|
||||
void SetPOV(DriverStation::POVDirection value);
|
||||
|
||||
/**
|
||||
* Set the axis count of this device.
|
||||
|
||||
Reference in New Issue
Block a user