mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
[hal,wpilib,cmd] Update POVs to use enums (#7978)
This commit is contained in:
@@ -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