mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[hal,wpilib] Use new DS available API from mrccomm (#8302)
Instead of just having a max count for joystick values, there's an available mask of values. This is because in the future we're expecting there to be holes in the list of available buttons and axes. This updates everything to support that scenario. Also, Joystick buttons, axes, and POVs all now start at 0 instead of 1.
This commit is contained in:
@@ -35,6 +35,10 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static constexpr int availableToCount(uint64_t available) {
|
||||
return 64 - std::countl_zero(available);
|
||||
}
|
||||
|
||||
namespace {
|
||||
// A simple class which caches the previous value written to an NT entry
|
||||
// Used to prevent redundant, repeated writes of the same value
|
||||
@@ -157,14 +161,6 @@ static Instance& GetInstance() {
|
||||
|
||||
static void SendMatchData();
|
||||
|
||||
/**
|
||||
* Reports errors related to unplugged joysticks.
|
||||
*
|
||||
* Throttles the errors so that they don't overwhelm the DS.
|
||||
*/
|
||||
static void ReportJoystickUnpluggedErrorV(fmt::string_view format,
|
||||
fmt::format_args args);
|
||||
|
||||
template <typename S, typename... Args>
|
||||
static inline void ReportJoystickUnpluggedError(const S& format,
|
||||
Args&&... args) {
|
||||
@@ -193,7 +189,7 @@ Instance::Instance() {
|
||||
for (unsigned int i = 0; i < DriverStation::kJoystickPorts; i++) {
|
||||
joystickButtonsPressed[i] = 0;
|
||||
joystickButtonsReleased[i] = 0;
|
||||
previousButtonStates[i].count = 0;
|
||||
previousButtonStates[i].available = 0;
|
||||
previousButtonStates[i].buttons = 0;
|
||||
}
|
||||
}
|
||||
@@ -209,24 +205,49 @@ bool DriverStation::GetStickButton(int stick, int button) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return false;
|
||||
}
|
||||
if (button <= 0) {
|
||||
ReportJoystickUnpluggedError(
|
||||
"Joystick Button {} index out of range; indexes begin at 1", button);
|
||||
if (button < 0 || button >= 64) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "button {} out of range", button);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t mask = 1LLU << button;
|
||||
|
||||
HAL_JoystickButtons buttons;
|
||||
HAL_GetJoystickButtons(stick, &buttons);
|
||||
|
||||
if (button > buttons.count) {
|
||||
if ((buttons.available & mask) == 0) {
|
||||
ReportJoystickUnpluggedWarning(
|
||||
"Joystick Button {} missing (max {}), check if all controllers are "
|
||||
"Joystick Button {} missing (available {}), check if all controllers "
|
||||
"are "
|
||||
"plugged in",
|
||||
button, buttons.count);
|
||||
button, buttons.available);
|
||||
return false;
|
||||
}
|
||||
|
||||
return buttons.buttons & 1 << (button - 1);
|
||||
return (buttons.buttons & mask) != 0;
|
||||
}
|
||||
|
||||
std::optional<bool> DriverStation::GetStickButtonIfAvailable(int stick,
|
||||
int button) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return false;
|
||||
}
|
||||
if (button < 0 || button >= 64) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "button {} out of range", button);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t mask = 1LLU << button;
|
||||
|
||||
HAL_JoystickButtons buttons;
|
||||
HAL_GetJoystickButtons(stick, &buttons);
|
||||
|
||||
if ((buttons.available & mask) == 0) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return (buttons.buttons & mask) != 0;
|
||||
}
|
||||
|
||||
bool DriverStation::GetStickButtonPressed(int stick, int button) {
|
||||
@@ -234,27 +255,29 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return false;
|
||||
}
|
||||
if (button <= 0) {
|
||||
ReportJoystickUnpluggedError(
|
||||
"Joystick Button {} index out of range; indexes begin at 1", button);
|
||||
if (button < 0 || button >= 64) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "button {} out of range", button);
|
||||
return false;
|
||||
}
|
||||
|
||||
HAL_JoystickButtons buttons;
|
||||
HAL_GetJoystickButtons(stick, &buttons);
|
||||
|
||||
if (button > buttons.count) {
|
||||
uint64_t mask = 1LLU << button;
|
||||
|
||||
if ((buttons.available & mask) == 0) {
|
||||
ReportJoystickUnpluggedWarning(
|
||||
"Joystick Button {} missing (max {}), check if all controllers are "
|
||||
"Joystick Button {} missing (available {}), check if all controllers "
|
||||
"are "
|
||||
"plugged in",
|
||||
button, buttons.count);
|
||||
button, buttons.available);
|
||||
return false;
|
||||
}
|
||||
auto& inst = ::GetInstance();
|
||||
std::unique_lock lock(inst.buttonEdgeMutex);
|
||||
// If button was pressed, clear flag and return true
|
||||
if (inst.joystickButtonsPressed[stick] & 1 << (button - 1)) {
|
||||
inst.joystickButtonsPressed[stick] &= ~(1 << (button - 1));
|
||||
if (inst.joystickButtonsPressed[stick] & mask) {
|
||||
inst.joystickButtonsPressed[stick] &= ~mask;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -265,27 +288,29 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return false;
|
||||
}
|
||||
if (button <= 0) {
|
||||
ReportJoystickUnpluggedError(
|
||||
"Joystick Button {} index out of range; indexes begin at 1", button);
|
||||
if (button < 0 || button >= 64) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "button {} out of range", button);
|
||||
return false;
|
||||
}
|
||||
|
||||
HAL_JoystickButtons buttons;
|
||||
HAL_GetJoystickButtons(stick, &buttons);
|
||||
|
||||
if (button > buttons.count) {
|
||||
uint64_t mask = 1LLU << button;
|
||||
|
||||
if ((buttons.available & mask) == 0) {
|
||||
ReportJoystickUnpluggedWarning(
|
||||
"Joystick Button {} missing (max {}), check if all controllers are "
|
||||
"Joystick Button {} missing (available {}), check if all controllers "
|
||||
"are "
|
||||
"plugged in",
|
||||
button, buttons.count);
|
||||
button, buttons.available);
|
||||
return false;
|
||||
}
|
||||
auto& inst = ::GetInstance();
|
||||
std::unique_lock lock(inst.buttonEdgeMutex);
|
||||
// If button was released, clear flag and return true
|
||||
if (inst.joystickButtonsReleased[stick] & 1 << (button - 1)) {
|
||||
inst.joystickButtonsReleased[stick] &= ~(1 << (button - 1));
|
||||
if (inst.joystickButtonsReleased[stick] & mask) {
|
||||
inst.joystickButtonsReleased[stick] &= ~mask;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -301,20 +326,45 @@ double DriverStation::GetStickAxis(int stick, int axis) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
uint16_t mask = 1 << axis;
|
||||
|
||||
HAL_JoystickAxes axes;
|
||||
HAL_GetJoystickAxes(stick, &axes);
|
||||
|
||||
if (axis >= axes.count) {
|
||||
if ((axes.available & mask) == 0) {
|
||||
ReportJoystickUnpluggedWarning(
|
||||
"Joystick Axis {} missing (max {}), check if all controllers are "
|
||||
"Joystick Axis {} missing (available {}), check if all controllers are "
|
||||
"plugged in",
|
||||
axis, axes.count);
|
||||
axis, axes.available);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return axes.axes[axis];
|
||||
}
|
||||
|
||||
std::optional<double> DriverStation::GetStickAxisIfAvailable(int stick,
|
||||
int axis) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0.0;
|
||||
}
|
||||
if (axis < 0 || axis >= HAL_kMaxJoystickAxes) {
|
||||
FRC_ReportError(warn::BadJoystickAxis, "axis {} out of range", axis);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
uint16_t mask = 1 << axis;
|
||||
|
||||
HAL_JoystickAxes axes;
|
||||
HAL_GetJoystickAxes(stick, &axes);
|
||||
|
||||
if ((axes.available & mask) == 0) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return axes.axes[axis];
|
||||
}
|
||||
|
||||
DriverStation::POVDirection DriverStation::GetStickPOV(int stick, int pov) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
@@ -325,21 +375,23 @@ DriverStation::POVDirection DriverStation::GetStickPOV(int stick, int pov) {
|
||||
return kCenter;
|
||||
}
|
||||
|
||||
uint16_t mask = 1 << pov;
|
||||
|
||||
HAL_JoystickPOVs povs;
|
||||
HAL_GetJoystickPOVs(stick, &povs);
|
||||
|
||||
if (pov >= povs.count) {
|
||||
if ((povs.available & mask) == 0) {
|
||||
ReportJoystickUnpluggedWarning(
|
||||
"Joystick POV {} missing (max {}), check if all controllers are "
|
||||
"Joystick POV {} missing (available {}), check if all controllers are "
|
||||
"plugged in",
|
||||
pov, povs.count);
|
||||
pov, povs.available);
|
||||
return kCenter;
|
||||
}
|
||||
|
||||
return static_cast<POVDirection>(povs.povs[pov]);
|
||||
}
|
||||
|
||||
int DriverStation::GetStickButtons(int stick) {
|
||||
uint64_t DriverStation::GetStickButtons(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0;
|
||||
@@ -351,7 +403,11 @@ int DriverStation::GetStickButtons(int stick) {
|
||||
return buttons.buttons;
|
||||
}
|
||||
|
||||
int DriverStation::GetStickAxisCount(int stick) {
|
||||
int DriverStation::GetStickAxesMaximumIndex(int stick) {
|
||||
return availableToCount(GetStickAxesAvailable(stick));
|
||||
}
|
||||
|
||||
int DriverStation::GetStickAxesAvailable(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0;
|
||||
@@ -360,10 +416,14 @@ int DriverStation::GetStickAxisCount(int stick) {
|
||||
HAL_JoystickAxes axes;
|
||||
HAL_GetJoystickAxes(stick, &axes);
|
||||
|
||||
return axes.count;
|
||||
return axes.available;
|
||||
}
|
||||
|
||||
int DriverStation::GetStickPOVCount(int stick) {
|
||||
int DriverStation::GetStickPOVsMaximumIndex(int stick) {
|
||||
return availableToCount(GetStickPOVsAvailable(stick));
|
||||
}
|
||||
|
||||
int DriverStation::GetStickPOVsAvailable(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0;
|
||||
@@ -372,10 +432,14 @@ int DriverStation::GetStickPOVCount(int stick) {
|
||||
HAL_JoystickPOVs povs;
|
||||
HAL_GetJoystickPOVs(stick, &povs);
|
||||
|
||||
return povs.count;
|
||||
return povs.available;
|
||||
}
|
||||
|
||||
int DriverStation::GetStickButtonCount(int stick) {
|
||||
int DriverStation::GetStickButtonsMaximumIndex(int stick) {
|
||||
return availableToCount(GetStickButtonsAvailable(stick));
|
||||
}
|
||||
|
||||
uint64_t DriverStation::GetStickButtonsAvailable(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0;
|
||||
@@ -384,7 +448,7 @@ int DriverStation::GetStickButtonCount(int stick) {
|
||||
HAL_JoystickButtons buttons;
|
||||
HAL_GetJoystickButtons(stick, &buttons);
|
||||
|
||||
return buttons.count;
|
||||
return buttons.available;
|
||||
}
|
||||
|
||||
bool DriverStation::GetJoystickIsGamepad(int stick) {
|
||||
@@ -422,25 +486,10 @@ std::string DriverStation::GetJoystickName(int stick) {
|
||||
return descriptor.name;
|
||||
}
|
||||
|
||||
int DriverStation::GetJoystickAxisType(int stick, int axis) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return -1;
|
||||
}
|
||||
if (axis < 0 || axis >= HAL_kMaxJoystickAxes) {
|
||||
FRC_ReportError(warn::BadJoystickAxis, "axis {} out of range", axis);
|
||||
return -1;
|
||||
}
|
||||
|
||||
HAL_JoystickDescriptor descriptor;
|
||||
HAL_GetJoystickDescriptor(stick, &descriptor);
|
||||
|
||||
return descriptor.axisTypes[axis];
|
||||
}
|
||||
|
||||
bool DriverStation::IsJoystickConnected(int stick) {
|
||||
return GetStickAxisCount(stick) > 0 || GetStickButtonCount(stick) > 0 ||
|
||||
GetStickPOVCount(stick) > 0;
|
||||
return GetStickAxesAvailable(stick) != 0 ||
|
||||
GetStickButtonsAvailable(stick) != 0 ||
|
||||
GetStickPOVsAvailable(stick) != 0;
|
||||
}
|
||||
|
||||
bool DriverStation::IsEnabled() {
|
||||
@@ -661,16 +710,6 @@ void DriverStation::StartDataLog(wpi::log::DataLog& log, bool logJoysticks) {
|
||||
}
|
||||
}
|
||||
|
||||
void ReportJoystickUnpluggedErrorV(fmt::string_view format,
|
||||
fmt::format_args args) {
|
||||
auto& inst = GetInstance();
|
||||
auto currentTime = Timer::GetTimestamp();
|
||||
if (currentTime > inst.nextMessageTime) {
|
||||
ReportErrorV(err::Error, "", 0, "", format, args);
|
||||
inst.nextMessageTime = currentTime + kJoystickUnpluggedMessageInterval;
|
||||
}
|
||||
}
|
||||
|
||||
void ReportJoystickUnpluggedWarningV(fmt::string_view format,
|
||||
fmt::format_args args) {
|
||||
auto& inst = GetInstance();
|
||||
@@ -751,9 +790,9 @@ void JoystickLogSender::Init(wpi::log::DataLog& log, unsigned int stick,
|
||||
HAL_GetJoystickAxes(m_stick, &m_prevAxes);
|
||||
HAL_GetJoystickPOVs(m_stick, &m_prevPOVs);
|
||||
AppendButtons(m_prevButtons, timestamp);
|
||||
int axesCount = availableToCount(m_prevAxes.available);
|
||||
m_logAxes.Append(
|
||||
std::span<const float>{m_prevAxes.axes,
|
||||
static_cast<size_t>(m_prevAxes.count)},
|
||||
std::span<const float>{m_prevAxes.axes, static_cast<size_t>(axesCount)},
|
||||
timestamp);
|
||||
AppendPOVs(m_prevPOVs, timestamp);
|
||||
}
|
||||
@@ -761,7 +800,7 @@ void JoystickLogSender::Init(wpi::log::DataLog& log, unsigned int stick,
|
||||
void JoystickLogSender::Send(uint64_t timestamp) {
|
||||
HAL_JoystickButtons buttons;
|
||||
HAL_GetJoystickButtons(m_stick, &buttons);
|
||||
if (buttons.count != m_prevButtons.count ||
|
||||
if (buttons.available != m_prevButtons.available ||
|
||||
buttons.buttons != m_prevButtons.buttons) {
|
||||
AppendButtons(buttons, timestamp);
|
||||
}
|
||||
@@ -769,20 +808,22 @@ void JoystickLogSender::Send(uint64_t timestamp) {
|
||||
|
||||
HAL_JoystickAxes axes;
|
||||
HAL_GetJoystickAxes(m_stick, &axes);
|
||||
if (axes.count != m_prevAxes.count ||
|
||||
int axesCount = availableToCount(axes.available);
|
||||
if (axes.available != m_prevAxes.available ||
|
||||
std::memcmp(axes.axes, m_prevAxes.axes,
|
||||
sizeof(axes.axes[0]) * axes.count) != 0) {
|
||||
sizeof(axes.axes[0]) * axesCount) != 0) {
|
||||
m_logAxes.Append(
|
||||
std::span<const float>{axes.axes, static_cast<size_t>(axes.count)},
|
||||
std::span<const float>{axes.axes, static_cast<size_t>(axesCount)},
|
||||
timestamp);
|
||||
}
|
||||
m_prevAxes = axes;
|
||||
|
||||
HAL_JoystickPOVs povs;
|
||||
HAL_GetJoystickPOVs(m_stick, &povs);
|
||||
if (povs.count != m_prevPOVs.count ||
|
||||
int povsCount = availableToCount(povs.available);
|
||||
if (povs.available != m_prevPOVs.available ||
|
||||
std::memcmp(povs.povs, m_prevPOVs.povs,
|
||||
sizeof(povs.povs[0]) * povs.count) != 0) {
|
||||
sizeof(povs.povs[0]) * povsCount) != 0) {
|
||||
AppendPOVs(povs, timestamp);
|
||||
}
|
||||
m_prevPOVs = povs;
|
||||
@@ -790,23 +831,25 @@ void JoystickLogSender::Send(uint64_t timestamp) {
|
||||
|
||||
void JoystickLogSender::AppendButtons(HAL_JoystickButtons buttons,
|
||||
uint64_t timestamp) {
|
||||
uint8_t buttonsArr[32];
|
||||
for (unsigned int i = 0; i < buttons.count; ++i) {
|
||||
buttonsArr[i] = (buttons.buttons & (1u << i)) != 0;
|
||||
int count = availableToCount(buttons.available);
|
||||
uint8_t buttonsArr[64];
|
||||
for (int i = 0; i < count; ++i) {
|
||||
buttonsArr[i] = (buttons.buttons & (1llu << i)) != 0;
|
||||
}
|
||||
m_logButtons.Append(std::span<const uint8_t>{buttonsArr, buttons.count},
|
||||
timestamp);
|
||||
m_logButtons.Append(
|
||||
std::span<const uint8_t>{buttonsArr, static_cast<size_t>(count)},
|
||||
timestamp);
|
||||
}
|
||||
|
||||
void JoystickLogSender::AppendPOVs(const HAL_JoystickPOVs& povs,
|
||||
uint64_t timestamp) {
|
||||
int count = availableToCount(povs.available);
|
||||
int64_t povsArr[HAL_kMaxJoystickPOVs];
|
||||
for (int i = 0; i < povs.count; ++i) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
povsArr[i] = povs.povs[i];
|
||||
}
|
||||
m_logPOVs.Append(
|
||||
std::span<const int64_t>{povsArr, static_cast<size_t>(povs.count)},
|
||||
timestamp);
|
||||
std::span<const int64_t>{povsArr, static_cast<size_t>(count)}, timestamp);
|
||||
}
|
||||
|
||||
void DataLogSender::Init(wpi::log::DataLog& log, bool logJoysticks,
|
||||
|
||||
582
wpilibc/src/main/native/cpp/Gamepad.cpp
Normal file
582
wpilibc/src/main/native/cpp/Gamepad.cpp
Normal file
@@ -0,0 +1,582 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/Gamepad.h"
|
||||
|
||||
#include <hal/UsageReporting.h>
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
#include "frc/event/BooleanEvent.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
Gamepad::Gamepad(int port) : GenericHID(port) {
|
||||
HAL_ReportUsage("HID", port, "Gamepad");
|
||||
}
|
||||
|
||||
double Gamepad::GetLeftX() const {
|
||||
return GetRawAxis(Axis::kLeftX);
|
||||
}
|
||||
|
||||
double Gamepad::GetLeftY() const {
|
||||
return GetRawAxis(Axis::kLeftY);
|
||||
}
|
||||
|
||||
double Gamepad::GetRightX() const {
|
||||
return GetRawAxis(Axis::kRightX);
|
||||
}
|
||||
|
||||
double Gamepad::GetRightY() const {
|
||||
return GetRawAxis(Axis::kRightY);
|
||||
}
|
||||
|
||||
double Gamepad::GetLeftTriggerAxis() const {
|
||||
return GetRawAxis(Axis::kLeftTrigger);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::LeftTrigger(double threshold, EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this, threshold] {
|
||||
return this->GetLeftTriggerAxis() > threshold;
|
||||
});
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::LeftTrigger(EventLoop* loop) const {
|
||||
return this->LeftTrigger(0.5, loop);
|
||||
}
|
||||
|
||||
double Gamepad::GetRightTriggerAxis() const {
|
||||
return GetRawAxis(Axis::kRightTrigger);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::RightTrigger(double threshold, EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this, threshold] {
|
||||
return this->GetRightTriggerAxis() > threshold;
|
||||
});
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::RightTrigger(EventLoop* loop) const {
|
||||
return this->RightTrigger(0.5, loop);
|
||||
}
|
||||
|
||||
bool Gamepad::GetSouthFaceButton() const {
|
||||
return GetRawButton(Button::kSouthFace);
|
||||
}
|
||||
|
||||
bool Gamepad::GetSouthFaceButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kSouthFace);
|
||||
}
|
||||
|
||||
bool Gamepad::GetSouthFaceButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kSouthFace);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::SouthFace(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetSouthFaceButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetEastFaceButton() const {
|
||||
return GetRawButton(Button::kEastFace);
|
||||
}
|
||||
|
||||
bool Gamepad::GetEastFaceButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kEastFace);
|
||||
}
|
||||
|
||||
bool Gamepad::GetEastFaceButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kEastFace);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::EastFace(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetEastFaceButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetWestFaceButton() const {
|
||||
return GetRawButton(Button::kWestFace);
|
||||
}
|
||||
|
||||
bool Gamepad::GetWestFaceButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kWestFace);
|
||||
}
|
||||
|
||||
bool Gamepad::GetWestFaceButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kWestFace);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::WestFace(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetWestFaceButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetNorthFacenButton() const {
|
||||
return GetRawButton(Button::kNorthFacen);
|
||||
}
|
||||
|
||||
bool Gamepad::GetNorthFacenButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kNorthFacen);
|
||||
}
|
||||
|
||||
bool Gamepad::GetNorthFacenButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kNorthFacen);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::NorthFacen(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetNorthFacenButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetBackButton() const {
|
||||
return GetRawButton(Button::kBack);
|
||||
}
|
||||
|
||||
bool Gamepad::GetBackButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kBack);
|
||||
}
|
||||
|
||||
bool Gamepad::GetBackButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kBack);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::Back(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetBackButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetGuideButton() const {
|
||||
return GetRawButton(Button::kGuide);
|
||||
}
|
||||
|
||||
bool Gamepad::GetGuideButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kGuide);
|
||||
}
|
||||
|
||||
bool Gamepad::GetGuideButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kGuide);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::Guide(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetGuideButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetStartButton() const {
|
||||
return GetRawButton(Button::kStart);
|
||||
}
|
||||
|
||||
bool Gamepad::GetStartButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kStart);
|
||||
}
|
||||
|
||||
bool Gamepad::GetStartButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kStart);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::Start(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetStartButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetLeftStickButton() const {
|
||||
return GetRawButton(Button::kLeftStick);
|
||||
}
|
||||
|
||||
bool Gamepad::GetLeftStickButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kLeftStick);
|
||||
}
|
||||
|
||||
bool Gamepad::GetLeftStickButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kLeftStick);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::LeftStick(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetLeftStickButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetRightStickButton() const {
|
||||
return GetRawButton(Button::kRightStick);
|
||||
}
|
||||
|
||||
bool Gamepad::GetRightStickButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kRightStick);
|
||||
}
|
||||
|
||||
bool Gamepad::GetRightStickButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kRightStick);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::RightStick(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetRightStickButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetLeftShoulderButton() const {
|
||||
return GetRawButton(Button::kLeftShoulder);
|
||||
}
|
||||
|
||||
bool Gamepad::GetLeftShoulderButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kLeftShoulder);
|
||||
}
|
||||
|
||||
bool Gamepad::GetLeftShoulderButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kLeftShoulder);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::LeftShoulder(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetLeftShoulderButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetRightShoulderButton() const {
|
||||
return GetRawButton(Button::kRightShoulder);
|
||||
}
|
||||
|
||||
bool Gamepad::GetRightShoulderButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kRightShoulder);
|
||||
}
|
||||
|
||||
bool Gamepad::GetRightShoulderButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kRightShoulder);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::RightShoulder(EventLoop* loop) const {
|
||||
return BooleanEvent(loop,
|
||||
[this]() { return this->GetRightShoulderButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetDpadUpButton() const {
|
||||
return GetRawButton(Button::kDpadUp);
|
||||
}
|
||||
|
||||
bool Gamepad::GetDpadUpButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kDpadUp);
|
||||
}
|
||||
|
||||
bool Gamepad::GetDpadUpButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kDpadUp);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::DpadUp(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetDpadUpButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetDpadDownButton() const {
|
||||
return GetRawButton(Button::kDpadDown);
|
||||
}
|
||||
|
||||
bool Gamepad::GetDpadDownButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kDpadDown);
|
||||
}
|
||||
|
||||
bool Gamepad::GetDpadDownButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kDpadDown);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::DpadDown(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetDpadDownButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetDpadLeftButton() const {
|
||||
return GetRawButton(Button::kDpadLeft);
|
||||
}
|
||||
|
||||
bool Gamepad::GetDpadLeftButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kDpadLeft);
|
||||
}
|
||||
|
||||
bool Gamepad::GetDpadLeftButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kDpadLeft);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::DpadLeft(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetDpadLeftButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetDpadRightButton() const {
|
||||
return GetRawButton(Button::kDpadRight);
|
||||
}
|
||||
|
||||
bool Gamepad::GetDpadRightButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kDpadRight);
|
||||
}
|
||||
|
||||
bool Gamepad::GetDpadRightButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kDpadRight);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::DpadRight(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetDpadRightButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc1Button() const {
|
||||
return GetRawButton(Button::kMisc1);
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc1ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kMisc1);
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc1ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kMisc1);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::Misc1(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetMisc1Button(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetRightPaddle1Button() const {
|
||||
return GetRawButton(Button::kRightPaddle1);
|
||||
}
|
||||
|
||||
bool Gamepad::GetRightPaddle1ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kRightPaddle1);
|
||||
}
|
||||
|
||||
bool Gamepad::GetRightPaddle1ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kRightPaddle1);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::RightPaddle1(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetRightPaddle1Button(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetLeftPaddle1Button() const {
|
||||
return GetRawButton(Button::kLeftPaddle1);
|
||||
}
|
||||
|
||||
bool Gamepad::GetLeftPaddle1ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kLeftPaddle1);
|
||||
}
|
||||
|
||||
bool Gamepad::GetLeftPaddle1ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kLeftPaddle1);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::LeftPaddle1(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetLeftPaddle1Button(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetRightPaddle2Button() const {
|
||||
return GetRawButton(Button::kRightPaddle2);
|
||||
}
|
||||
|
||||
bool Gamepad::GetRightPaddle2ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kRightPaddle2);
|
||||
}
|
||||
|
||||
bool Gamepad::GetRightPaddle2ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kRightPaddle2);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::RightPaddle2(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetRightPaddle2Button(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetLeftPaddle2Button() const {
|
||||
return GetRawButton(Button::kLeftPaddle2);
|
||||
}
|
||||
|
||||
bool Gamepad::GetLeftPaddle2ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kLeftPaddle2);
|
||||
}
|
||||
|
||||
bool Gamepad::GetLeftPaddle2ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kLeftPaddle2);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::LeftPaddle2(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetLeftPaddle2Button(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetTouchpadButton() const {
|
||||
return GetRawButton(Button::kTouchpad);
|
||||
}
|
||||
|
||||
bool Gamepad::GetTouchpadButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kTouchpad);
|
||||
}
|
||||
|
||||
bool Gamepad::GetTouchpadButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kTouchpad);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::Touchpad(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetTouchpadButton(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc2Button() const {
|
||||
return GetRawButton(Button::kMisc2);
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc2ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kMisc2);
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc2ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kMisc2);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::Misc2(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetMisc2Button(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc3Button() const {
|
||||
return GetRawButton(Button::kMisc3);
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc3ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kMisc3);
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc3ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kMisc3);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::Misc3(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetMisc3Button(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc4Button() const {
|
||||
return GetRawButton(Button::kMisc4);
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc4ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kMisc4);
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc4ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kMisc4);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::Misc4(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetMisc4Button(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc5Button() const {
|
||||
return GetRawButton(Button::kMisc5);
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc5ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kMisc5);
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc5ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kMisc5);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::Misc5(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetMisc5Button(); });
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc6Button() const {
|
||||
return GetRawButton(Button::kMisc6);
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc6ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kMisc6);
|
||||
}
|
||||
|
||||
bool Gamepad::GetMisc6ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kMisc6);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::Misc6(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetMisc6Button(); });
|
||||
}
|
||||
|
||||
double Gamepad::GetAxisForSendable(int axis) const {
|
||||
return DriverStation::GetStickAxisIfAvailable(GetPort(), axis).value_or(0.0);
|
||||
}
|
||||
|
||||
bool Gamepad::GetButtonForSendable(int button) const {
|
||||
return DriverStation::GetStickButtonIfAvailable(GetPort(), button)
|
||||
.value_or(false);
|
||||
}
|
||||
|
||||
void Gamepad::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("HID");
|
||||
builder.PublishConstString("ControllerType", "Gamepad");
|
||||
builder.AddDoubleProperty(
|
||||
"LeftTrigger Axis",
|
||||
[this] { return GetAxisForSendable(Axis::kLeftTrigger); }, nullptr);
|
||||
builder.AddDoubleProperty(
|
||||
"RightTrigger Axis",
|
||||
[this] { return GetAxisForSendable(Axis::kRightTrigger); }, nullptr);
|
||||
builder.AddDoubleProperty(
|
||||
"LeftX", [this] { return GetAxisForSendable(Axis::kLeftX); }, nullptr);
|
||||
builder.AddDoubleProperty(
|
||||
"LeftY", [this] { return GetAxisForSendable(Axis::kLeftY); }, nullptr);
|
||||
builder.AddDoubleProperty(
|
||||
"RightX", [this] { return GetAxisForSendable(Axis::kRightX); }, nullptr);
|
||||
builder.AddDoubleProperty(
|
||||
"RightY", [this] { return GetAxisForSendable(Axis::kRightY); }, nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"SouthFace", [this] { return GetButtonForSendable(Button::kSouthFace); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"EastFace", [this] { return GetButtonForSendable(Button::kEastFace); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"WestFace", [this] { return GetButtonForSendable(Button::kWestFace); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"NorthFacen",
|
||||
[this] { return GetButtonForSendable(Button::kNorthFacen); }, nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"Back", [this] { return GetButtonForSendable(Button::kBack); }, nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"Guide", [this] { return GetButtonForSendable(Button::kGuide); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"Start", [this] { return GetButtonForSendable(Button::kStart); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"LeftStick", [this] { return GetButtonForSendable(Button::kLeftStick); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"RightStick",
|
||||
[this] { return GetButtonForSendable(Button::kRightStick); }, nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"LeftShoulder",
|
||||
[this] { return GetButtonForSendable(Button::kLeftShoulder); }, nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"RightShoulder",
|
||||
[this] { return GetButtonForSendable(Button::kRightShoulder); }, nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"DpadUp", [this] { return GetButtonForSendable(Button::kDpadUp); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"DpadDown", [this] { return GetButtonForSendable(Button::kDpadDown); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"DpadLeft", [this] { return GetButtonForSendable(Button::kDpadLeft); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"DpadRight", [this] { return GetButtonForSendable(Button::kDpadRight); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"Misc1", [this] { return GetButtonForSendable(Button::kMisc1); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"RightPaddle1",
|
||||
[this] { return GetButtonForSendable(Button::kRightPaddle1); }, nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"LeftPaddle1",
|
||||
[this] { return GetButtonForSendable(Button::kLeftPaddle1); }, nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"RightPaddle2",
|
||||
[this] { return GetButtonForSendable(Button::kRightPaddle2); }, nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"LeftPaddle2",
|
||||
[this] { return GetButtonForSendable(Button::kLeftPaddle2); }, nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"Touchpad", [this] { return GetButtonForSendable(Button::kTouchpad); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"Misc2", [this] { return GetButtonForSendable(Button::kMisc2); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"Misc3", [this] { return GetButtonForSendable(Button::kMisc3); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"Misc4", [this] { return GetButtonForSendable(Button::kMisc4); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"Misc5", [this] { return GetButtonForSendable(Button::kMisc5); },
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"Misc6", [this] { return GetButtonForSendable(Button::kMisc6); },
|
||||
nullptr);
|
||||
}
|
||||
@@ -107,16 +107,28 @@ BooleanEvent GenericHID::AxisGreaterThan(int axis, double threshold,
|
||||
});
|
||||
}
|
||||
|
||||
int GenericHID::GetAxisCount() const {
|
||||
return DriverStation::GetStickAxisCount(m_port);
|
||||
int GenericHID::GetAxesMaximumIndex() const {
|
||||
return DriverStation::GetStickAxesMaximumIndex(m_port);
|
||||
}
|
||||
|
||||
int GenericHID::GetPOVCount() const {
|
||||
return DriverStation::GetStickPOVCount(m_port);
|
||||
int GenericHID::GetAxesAvailable() const {
|
||||
return DriverStation::GetStickAxesAvailable(m_port);
|
||||
}
|
||||
|
||||
int GenericHID::GetButtonCount() const {
|
||||
return DriverStation::GetStickButtonCount(m_port);
|
||||
int GenericHID::GetPOVsMaximumIndex() const {
|
||||
return DriverStation::GetStickPOVsMaximumIndex(m_port);
|
||||
}
|
||||
|
||||
int GenericHID::GetPOVsAvailable() const {
|
||||
return DriverStation::GetStickPOVsAvailable(m_port);
|
||||
}
|
||||
|
||||
int GenericHID::GetButtonsMaximumIndex() const {
|
||||
return DriverStation::GetStickButtonsMaximumIndex(m_port);
|
||||
}
|
||||
|
||||
uint64_t GenericHID::GetButtonsAvailable() const {
|
||||
return DriverStation::GetStickButtonsAvailable(m_port);
|
||||
}
|
||||
|
||||
bool GenericHID::IsConnected() const {
|
||||
@@ -131,10 +143,6 @@ std::string GenericHID::GetName() const {
|
||||
return DriverStation::GetJoystickName(m_port);
|
||||
}
|
||||
|
||||
int GenericHID::GetAxisType(int axis) const {
|
||||
return DriverStation::GetJoystickAxisType(m_port, axis);
|
||||
}
|
||||
|
||||
int GenericHID::GetPort() const {
|
||||
return m_port;
|
||||
}
|
||||
|
||||
@@ -210,22 +210,54 @@ void DriverStationSim::SetJoystickPOV(int stick, int pov,
|
||||
HALSIM_SetJoystickPOV(stick, pov, static_cast<HAL_JoystickPOV>(value));
|
||||
}
|
||||
|
||||
void DriverStationSim::SetJoystickButtons(int stick, uint32_t buttons) {
|
||||
HALSIM_SetJoystickButtonsValue(stick, buttons);
|
||||
void DriverStationSim::SetJoystickAxesMaximumIndex(int stick,
|
||||
int maximumIndex) {
|
||||
SetJoystickAxesAvailable(stick, (1 << maximumIndex) - 1);
|
||||
}
|
||||
|
||||
void DriverStationSim::SetJoystickAxisCount(int stick, int count) {
|
||||
HALSIM_SetJoystickAxisCount(stick, count);
|
||||
void DriverStationSim::SetJoystickAxesAvailable(int stick, int count) {
|
||||
HALSIM_SetJoystickAxesAvailable(stick, count);
|
||||
}
|
||||
|
||||
void DriverStationSim::SetJoystickPOVCount(int stick, int count) {
|
||||
HALSIM_SetJoystickPOVCount(stick, count);
|
||||
void DriverStationSim::SetJoystickPOVsMaximumIndex(int stick,
|
||||
int maximumIndex) {
|
||||
SetJoystickPOVsAvailable(stick, (1 << maximumIndex) - 1);
|
||||
}
|
||||
|
||||
void DriverStationSim::SetJoystickButtonCount(int stick, int count) {
|
||||
HALSIM_SetJoystickButtonCount(stick, count);
|
||||
void DriverStationSim::SetJoystickPOVsAvailable(int stick, int count) {
|
||||
HALSIM_SetJoystickPOVsAvailable(stick, count);
|
||||
}
|
||||
|
||||
void DriverStationSim::SetJoystickButtonsMaximumIndex(int stick,
|
||||
int maximumIndex) {
|
||||
if (maximumIndex >= 64) {
|
||||
SetJoystickButtonsAvailable(stick, 0xFFFFFFFFFFFFFFFFL);
|
||||
} else {
|
||||
SetJoystickButtonsAvailable(stick, (1L << maximumIndex) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void DriverStationSim::SetJoystickButtonsAvailable(int stick,
|
||||
uint64_t available) {
|
||||
HALSIM_SetJoystickButtonsAvailable(stick, available);
|
||||
}
|
||||
|
||||
// void DriverStationSim::SetJoystickButtons(int stick, uint32_t buttons) {
|
||||
// HALSIM_SetJoystickButtonsValue(stick, buttons);
|
||||
// }
|
||||
|
||||
// void DriverStationSim::SetJoystickAxisCount(int stick, int count) {
|
||||
// HALSIM_SetJoystickAxisCount(stick, count);
|
||||
// }
|
||||
|
||||
// void DriverStationSim::SetJoystickPOVCount(int stick, int count) {
|
||||
// HALSIM_SetJoystickPOVCount(stick, count);
|
||||
// }
|
||||
|
||||
// void DriverStationSim::SetJoystickButtonCount(int stick, int count) {
|
||||
// HALSIM_SetJoystickButtonCount(stick, count);
|
||||
// }
|
||||
|
||||
void DriverStationSim::SetJoystickIsGamepad(int stick, bool isGamepad) {
|
||||
HALSIM_SetJoystickIsGamepad(stick, isGamepad);
|
||||
}
|
||||
@@ -239,10 +271,6 @@ void DriverStationSim::SetJoystickName(int stick, std::string_view name) {
|
||||
HALSIM_SetJoystickName(stick, &str);
|
||||
}
|
||||
|
||||
void DriverStationSim::SetJoystickAxisType(int stick, int axis, int type) {
|
||||
HALSIM_SetJoystickAxisType(stick, axis, type);
|
||||
}
|
||||
|
||||
void DriverStationSim::SetGameSpecificMessage(std::string_view message) {
|
||||
auto str = wpi::make_string(message);
|
||||
HALSIM_SetGameSpecificMessage(&str);
|
||||
|
||||
150
wpilibc/src/main/native/cpp/simulation/GamepadSim.cpp
Normal file
150
wpilibc/src/main/native/cpp/simulation/GamepadSim.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/simulation/GamepadSim.h"
|
||||
|
||||
#include "frc/Gamepad.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
GamepadSim::GamepadSim(const Gamepad& joystick) : GenericHIDSim{joystick} {
|
||||
SetAxesMaximumIndex(6);
|
||||
SetButtonsMaximumIndex(26);
|
||||
SetPOVsMaximumIndex(1);
|
||||
}
|
||||
|
||||
GamepadSim::GamepadSim(int port) : GenericHIDSim{port} {
|
||||
SetAxesMaximumIndex(6);
|
||||
SetButtonsMaximumIndex(26);
|
||||
SetPOVsMaximumIndex(1);
|
||||
}
|
||||
|
||||
void GamepadSim::SetLeftX(double value) {
|
||||
SetRawAxis(Gamepad::Axis::kLeftX, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetLeftY(double value) {
|
||||
SetRawAxis(Gamepad::Axis::kLeftY, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetRightX(double value) {
|
||||
SetRawAxis(Gamepad::Axis::kRightX, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetRightY(double value) {
|
||||
SetRawAxis(Gamepad::Axis::kRightY, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetLeftTriggerAxis(double value) {
|
||||
SetRawAxis(Gamepad::Axis::kLeftTrigger, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetRightTriggerAxis(double value) {
|
||||
SetRawAxis(Gamepad::Axis::kRightTrigger, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetSouthFaceButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kSouthFace, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetEastFaceButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kEastFace, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetWestFaceButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kWestFace, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetNorthFacenButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kNorthFacen, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetBackButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kBack, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetGuideButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kGuide, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetStartButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kStart, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetLeftStickButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kLeftStick, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetRightStickButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kRightStick, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetLeftShoulderButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kLeftShoulder, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetRightShoulderButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kRightShoulder, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetDpadUpButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kDpadUp, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetDpadDownButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kDpadDown, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetDpadLeftButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kDpadLeft, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetDpadRightButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kDpadRight, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetMisc1Button(bool value) {
|
||||
SetRawButton(Gamepad::Button::kMisc1, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetRightPaddle1Button(bool value) {
|
||||
SetRawButton(Gamepad::Button::kRightPaddle1, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetLeftPaddle1Button(bool value) {
|
||||
SetRawButton(Gamepad::Button::kLeftPaddle1, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetRightPaddle2Button(bool value) {
|
||||
SetRawButton(Gamepad::Button::kRightPaddle2, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetLeftPaddle2Button(bool value) {
|
||||
SetRawButton(Gamepad::Button::kLeftPaddle2, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetTouchpadButton(bool value) {
|
||||
SetRawButton(Gamepad::Button::kTouchpad, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetMisc2Button(bool value) {
|
||||
SetRawButton(Gamepad::Button::kMisc2, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetMisc3Button(bool value) {
|
||||
SetRawButton(Gamepad::Button::kMisc3, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetMisc4Button(bool value) {
|
||||
SetRawButton(Gamepad::Button::kMisc4, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetMisc5Button(bool value) {
|
||||
SetRawButton(Gamepad::Button::kMisc5, value);
|
||||
}
|
||||
|
||||
void GamepadSim::SetMisc6Button(bool value) {
|
||||
SetRawButton(Gamepad::Button::kMisc6, value);
|
||||
}
|
||||
@@ -36,16 +36,28 @@ void GenericHIDSim::SetPOV(DriverStation::POVDirection value) {
|
||||
SetPOV(0, value);
|
||||
}
|
||||
|
||||
void GenericHIDSim::SetAxisCount(int count) {
|
||||
DriverStationSim::SetJoystickAxisCount(m_port, count);
|
||||
void GenericHIDSim::SetAxesMaximumIndex(int maximumIndex) {
|
||||
DriverStationSim::SetJoystickAxesMaximumIndex(m_port, maximumIndex);
|
||||
}
|
||||
|
||||
void GenericHIDSim::SetPOVCount(int count) {
|
||||
DriverStationSim::SetJoystickPOVCount(m_port, count);
|
||||
void GenericHIDSim::SetAxesAvailable(int count) {
|
||||
DriverStationSim::SetJoystickAxesAvailable(m_port, count);
|
||||
}
|
||||
|
||||
void GenericHIDSim::SetButtonCount(int count) {
|
||||
DriverStationSim::SetJoystickButtonCount(m_port, count);
|
||||
void GenericHIDSim::SetPOVsMaximumIndex(int maximumIndex) {
|
||||
DriverStationSim::SetJoystickPOVsMaximumIndex(m_port, maximumIndex);
|
||||
}
|
||||
|
||||
void GenericHIDSim::SetPOVsAvailable(int count) {
|
||||
DriverStationSim::SetJoystickPOVsAvailable(m_port, count);
|
||||
}
|
||||
|
||||
void GenericHIDSim::SetButtonsMaximumIndex(int maximumIndex) {
|
||||
DriverStationSim::SetJoystickButtonsMaximumIndex(m_port, maximumIndex);
|
||||
}
|
||||
|
||||
void GenericHIDSim::SetButtonsAvailable(uint64_t count) {
|
||||
DriverStationSim::SetJoystickButtonsAvailable(m_port, count);
|
||||
}
|
||||
|
||||
void GenericHIDSim::SetType(GenericHID::HIDType type) {
|
||||
@@ -56,10 +68,6 @@ void GenericHIDSim::SetName(const char* name) {
|
||||
DriverStationSim::SetJoystickName(m_port, name);
|
||||
}
|
||||
|
||||
void GenericHIDSim::SetAxisType(int axis, int type) {
|
||||
DriverStationSim::SetJoystickAxisType(m_port, axis, type);
|
||||
}
|
||||
|
||||
bool GenericHIDSim::GetOutput(int outputNumber) {
|
||||
int64_t outputs = GetOutputs();
|
||||
return (outputs & (static_cast<int64_t>(1) << (outputNumber - 1))) != 0;
|
||||
|
||||
@@ -13,16 +13,16 @@ using namespace frc::sim;
|
||||
JoystickSim::JoystickSim(const Joystick& joystick)
|
||||
: GenericHIDSim{joystick}, m_joystick{&joystick} {
|
||||
// default to a reasonable joystick configuration
|
||||
SetAxisCount(5);
|
||||
SetButtonCount(12);
|
||||
SetPOVCount(1);
|
||||
SetAxesMaximumIndex(5);
|
||||
SetButtonsMaximumIndex(12);
|
||||
SetPOVsMaximumIndex(1);
|
||||
}
|
||||
|
||||
JoystickSim::JoystickSim(int port) : GenericHIDSim{port} {
|
||||
// default to a reasonable joystick configuration
|
||||
SetAxisCount(5);
|
||||
SetButtonCount(12);
|
||||
SetPOVCount(1);
|
||||
SetAxesMaximumIndex(5);
|
||||
SetButtonsMaximumIndex(12);
|
||||
SetPOVsMaximumIndex(1);
|
||||
}
|
||||
|
||||
void JoystickSim::SetX(double value) {
|
||||
|
||||
Reference in New Issue
Block a user