[hal,wpilib,cmd] Update POVs to use enums (#7978)

This commit is contained in:
Joseph Eng
2025-06-29 18:32:26 -07:00
committed by GitHub
parent e13d237390
commit f55564729b
30 changed files with 538 additions and 378 deletions

View File

@@ -16,49 +16,51 @@ Trigger CommandGenericHID::Button(int button, frc::EventLoop* loop) const {
return Trigger(loop, [this, button] { return m_hid.GetRawButton(button); });
}
Trigger CommandGenericHID::POV(int angle, frc::EventLoop* loop) const {
Trigger CommandGenericHID::POV(frc::DriverStation::POVDirection angle,
frc::EventLoop* loop) const {
return POV(0, angle, loop);
}
Trigger CommandGenericHID::POV(int pov, int angle, frc::EventLoop* loop) const {
Trigger CommandGenericHID::POV(int pov, frc::DriverStation::POVDirection angle,
frc::EventLoop* loop) const {
return Trigger(loop,
[this, pov, angle] { return m_hid.GetPOV(pov) == angle; });
}
Trigger CommandGenericHID::POVUp(frc::EventLoop* loop) const {
return POV(0, loop);
return POV(frc::DriverStation::POVDirection::kUp, loop);
}
Trigger CommandGenericHID::POVUpRight(frc::EventLoop* loop) const {
return POV(45, loop);
return POV(frc::DriverStation::POVDirection::kUpRight, loop);
}
Trigger CommandGenericHID::POVRight(frc::EventLoop* loop) const {
return POV(90, loop);
return POV(frc::DriverStation::POVDirection::kRight, loop);
}
Trigger CommandGenericHID::POVDownRight(frc::EventLoop* loop) const {
return POV(135, loop);
return POV(frc::DriverStation::POVDirection::kDownRight, loop);
}
Trigger CommandGenericHID::POVDown(frc::EventLoop* loop) const {
return POV(180, loop);
return POV(frc::DriverStation::POVDirection::kDown, loop);
}
Trigger CommandGenericHID::POVDownLeft(frc::EventLoop* loop) const {
return POV(225, loop);
return POV(frc::DriverStation::POVDirection::kDownLeft, loop);
}
Trigger CommandGenericHID::POVLeft(frc::EventLoop* loop) const {
return POV(270, loop);
return POV(frc::DriverStation::POVDirection::kLeft, loop);
}
Trigger CommandGenericHID::POVUpLeft(frc::EventLoop* loop) const {
return POV(315, loop);
return POV(frc::DriverStation::POVDirection::kUpLeft, loop);
}
Trigger CommandGenericHID::POVCenter(frc::EventLoop* loop) const {
return POV(360, loop);
return POV(frc::DriverStation::POVDirection::kCenter, loop);
}
Trigger CommandGenericHID::AxisLessThan(int axis, double threshold,

View File

@@ -3,6 +3,8 @@
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/DriverStation.h>
#include <frc/GenericHID.h>
#include "Trigger.h"
@@ -49,133 +51,127 @@ class CommandGenericHID {
/**
* Constructs a Trigger 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. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @param angle POV angle in degrees, or -1 for the center / not pressed.
* @param angle POV angle.
* @return a Trigger instance based around this angle of a POV on the HID.
*/
Trigger POV(int angle,
Trigger POV(frc::DriverStation::POVDirection angle,
frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger 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. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @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 Trigger instance based around this angle of a POV on the HID.
*/
Trigger POV(int pov, int angle,
Trigger POV(int pov, frc::DriverStation::POVDirection angle,
frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance based around the 0 degree angle (up) of the
* Constructs a Trigger instance based around the up direction of the
* default (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance based around the 0 degree angle of a POV on the
* @return a Trigger instance based around the up direction of a POV on the
* HID.
*/
Trigger POVUp(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance based around the 45 degree angle (right up)
* Constructs a Trigger instance based around the up right direction
* of the default (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance based around the 45 degree angle of a POV on the
* HID.
* @return a Trigger instance based around the up right direction of a POV on
* the HID.
*/
Trigger POVUpRight(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance based around the 90 degree angle (right) of
* Constructs a Trigger instance based around the right direction of
* the default (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance based around the 90 degree angle of a POV on the
* @return a Trigger instance based around the right direction of a POV on the
* HID.
*/
Trigger POVRight(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance based around the 135 degree angle (right
* down) of the default (index 0) POV on the HID.
* Constructs a Trigger instance based around the down right direction
* of the default (index 0) POV on the HID.
*
* @return a Trigger instance based around the 135 degree angle of a POV on
* the HID.
* @return a Trigger instance based around the down right direction of a POV
* on the HID.
*/
Trigger POVDownRight(
frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance based around the 180 degree angle (down) of
* Constructs a Trigger instance based around the down direction of
* the default (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance based around the 180 degree angle of a POV on
* @return a Trigger instance based around the down direction of a POV on
* the HID.
*/
Trigger POVDown(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance based around the 225 degree angle (down left)
* Constructs a Trigger instance based around the down left direction
* of the default (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance based around the 225 degree angle of a POV on
* @return a Trigger instance based around the down left direction of a POV on
* the HID.
*/
Trigger POVDownLeft(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance based around the 270 degree angle (left) of
* Constructs a Trigger instance based around the left direction of
* the default (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance based around the 270 degree angle of a POV on
* @return a Trigger instance based around the left direction of a POV on
* the HID.
*/
Trigger POVLeft(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance based around the 315 degree angle (left up)
* Constructs a Trigger instance based around the up left direction
* of the default (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance based around the 315 degree angle of a POV on
* @return a Trigger instance based around the up left direction of a POV on
* the HID.
*/
Trigger POVUpLeft(frc::EventLoop* loop = CommandScheduler::GetInstance()

View File

@@ -4,6 +4,7 @@
#pragma once
#include <frc/DriverStation.h>
#include <frc/GenericHID.h>
#include "Trigger.h"
@@ -26,7 +27,8 @@ class POVButton : public Trigger {
* @param angle The angle of the POV corresponding to a button press.
* @param povNumber The number of the POV on the joystick.
*/
POVButton(frc::GenericHID* joystick, int angle, int povNumber = 0)
POVButton(frc::GenericHID* joystick, frc::DriverStation::POVDirection angle,
int povNumber = 0)
: Trigger([joystick, angle, povNumber] {
return joystick->GetPOV(povNumber) == angle;
}) {}