mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +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:
@@ -109,20 +109,30 @@ class DriverStation final {
|
||||
static constexpr int kJoystickPorts = 6;
|
||||
|
||||
/**
|
||||
* The state of one joystick button. %Button indexes begin at 1.
|
||||
* The state of one joystick button. Button indexes begin at 0.
|
||||
*
|
||||
* @param stick The joystick to read.
|
||||
* @param button The button index, beginning at 1.
|
||||
* @param button The button index, beginning at 0.
|
||||
* @return The state of the joystick button.
|
||||
*/
|
||||
static bool GetStickButton(int stick, int button);
|
||||
|
||||
/**
|
||||
* The state of one joystick button, only if available. Button indexes begin
|
||||
* at 0.
|
||||
*
|
||||
* @param stick The joystick to read.
|
||||
* @param button The button index, beginning at 0.
|
||||
* @return The state of the joystick button, or empty if unavailable.
|
||||
*/
|
||||
static std::optional<bool> GetStickButtonIfAvailable(int stick, int button);
|
||||
|
||||
/**
|
||||
* Whether one joystick button was pressed since the last check. %Button
|
||||
* indexes begin at 1.
|
||||
*
|
||||
* @param stick The joystick to read.
|
||||
* @param button The button index, beginning at 1.
|
||||
* @param button The button index, beginning at 0.
|
||||
* @return Whether the joystick button was pressed since the last check.
|
||||
*/
|
||||
static bool GetStickButtonPressed(int stick, int button);
|
||||
@@ -132,7 +142,7 @@ class DriverStation final {
|
||||
* indexes begin at 1.
|
||||
*
|
||||
* @param stick The joystick to read.
|
||||
* @param button The button index, beginning at 1.
|
||||
* @param button The button index, beginning at 0.
|
||||
* @return Whether the joystick button was released since the last check.
|
||||
*/
|
||||
static bool GetStickButtonReleased(int stick, int button);
|
||||
@@ -149,6 +159,18 @@ class DriverStation final {
|
||||
*/
|
||||
static double GetStickAxis(int stick, int axis);
|
||||
|
||||
/**
|
||||
* Get the value of the axis on a joystick, if available.
|
||||
*
|
||||
* This depends on the mapping of the joystick connected to the specified
|
||||
* port.
|
||||
*
|
||||
* @param stick The joystick to read.
|
||||
* @param axis The analog axis value to read from the joystick.
|
||||
* @return The value of the axis on the joystick, or empty if not available.
|
||||
*/
|
||||
static std::optional<double> GetStickAxisIfAvailable(int stick, int axis);
|
||||
|
||||
/**
|
||||
* Get the state of a POV on the joystick.
|
||||
*
|
||||
@@ -162,31 +184,55 @@ class DriverStation final {
|
||||
* @param stick The joystick to read.
|
||||
* @return The state of the buttons on the joystick.
|
||||
*/
|
||||
static int GetStickButtons(int stick);
|
||||
static uint64_t GetStickButtons(int stick);
|
||||
|
||||
/**
|
||||
* Returns the number of axes on a given joystick port.
|
||||
* Returns the maximum axis index on a given joystick port.
|
||||
*
|
||||
* @param stick The joystick port number
|
||||
* @return The number of axes on the indicated joystick
|
||||
* @return The maximum axis index on the indicated joystick
|
||||
*/
|
||||
static int GetStickAxisCount(int stick);
|
||||
static int GetStickAxesMaximumIndex(int stick);
|
||||
|
||||
/**
|
||||
* Returns the number of POVs on a given joystick port.
|
||||
* Returns the mask of available axes on a given joystick port.
|
||||
*
|
||||
* @param stick The joystick port number
|
||||
* @return The number of POVs on the indicated joystick
|
||||
* @return The mask of available axes on the indicated joystick
|
||||
*/
|
||||
static int GetStickPOVCount(int stick);
|
||||
static int GetStickAxesAvailable(int stick);
|
||||
|
||||
/**
|
||||
* Returns the number of buttons on a given joystick port.
|
||||
* Returns the maximum POV index on a given joystick port.
|
||||
*
|
||||
* @param stick The joystick port number
|
||||
* @return The number of buttons on the indicated joystick
|
||||
* @return The maximum POV index on the indicated joystick
|
||||
*/
|
||||
static int GetStickButtonCount(int stick);
|
||||
static int GetStickPOVsMaximumIndex(int stick);
|
||||
|
||||
/**
|
||||
* Returns the mask of available POVs on a given joystick port.
|
||||
*
|
||||
* @param stick The joystick port number
|
||||
* @return The mask of available POVs on the indicated joystick
|
||||
*/
|
||||
static int GetStickPOVsAvailable(int stick);
|
||||
|
||||
/**
|
||||
* Returns the maximum button index on a given joystick port.
|
||||
*
|
||||
* @param stick The joystick port number
|
||||
* @return The maximum button index on the indicated joystick
|
||||
*/
|
||||
static int GetStickButtonsMaximumIndex(int stick);
|
||||
|
||||
/**
|
||||
* Returns the mask of available buttons on a given joystick port.
|
||||
*
|
||||
* @param stick The joystick port number
|
||||
* @return The mask of available buttons on the indicated joystick
|
||||
*/
|
||||
static uint64_t GetStickButtonsAvailable(int stick);
|
||||
|
||||
/**
|
||||
* Returns a boolean indicating if the controller is an xbox controller.
|
||||
@@ -212,15 +258,6 @@ class DriverStation final {
|
||||
*/
|
||||
static std::string GetJoystickName(int stick);
|
||||
|
||||
/**
|
||||
* Returns the types of Axes on a given joystick port.
|
||||
*
|
||||
* @param stick The joystick port number and the target axis
|
||||
* @param axis The analog axis value to read from the joystick.
|
||||
* @return What type of axis the axis is reporting to be
|
||||
*/
|
||||
static int GetJoystickAxisType(int stick, int axis);
|
||||
|
||||
/**
|
||||
* Returns if a joystick is connected to the Driver Station.
|
||||
*
|
||||
|
||||
1018
wpilibc/src/main/native/include/frc/Gamepad.h
Normal file
1018
wpilibc/src/main/native/include/frc/Gamepad.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -106,7 +106,7 @@ class GenericHID {
|
||||
* since the last time this method was called. This is useful if you only
|
||||
* want to call a function once when you press the button.
|
||||
*
|
||||
* @param button The button index, beginning at 1.
|
||||
* @param button The button index, beginning at 0.
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
bool GetRawButtonPressed(int button);
|
||||
@@ -119,7 +119,7 @@ class GenericHID {
|
||||
* since the last time this method was called. This is useful if you only
|
||||
* want to call a function once when you release the button.
|
||||
*
|
||||
* @param button The button index, beginning at 1.
|
||||
* @param button The button index, beginning at 0.
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
bool GetRawButtonReleased(int button);
|
||||
@@ -280,26 +280,32 @@ class GenericHID {
|
||||
BooleanEvent AxisGreaterThan(int axis, double threshold,
|
||||
EventLoop* loop) const;
|
||||
|
||||
int GetAxesMaximumIndex() const;
|
||||
|
||||
/**
|
||||
* Get the number of axes for the HID.
|
||||
*
|
||||
* @return the number of axis for the current HID
|
||||
*/
|
||||
int GetAxisCount() const;
|
||||
int GetAxesAvailable() const;
|
||||
|
||||
int GetPOVsMaximumIndex() const;
|
||||
|
||||
/**
|
||||
* Get the number of POVs for the HID.
|
||||
*
|
||||
* @return the number of POVs for the current HID
|
||||
*/
|
||||
int GetPOVCount() const;
|
||||
int GetPOVsAvailable() const;
|
||||
|
||||
int GetButtonsMaximumIndex() const;
|
||||
|
||||
/**
|
||||
* Get the number of buttons for the HID.
|
||||
*
|
||||
* @return the number of buttons on the current HID
|
||||
*/
|
||||
int GetButtonCount() const;
|
||||
uint64_t GetButtonsAvailable() const;
|
||||
|
||||
/**
|
||||
* Get if the HID is connected.
|
||||
@@ -322,13 +328,6 @@ class GenericHID {
|
||||
*/
|
||||
std::string GetName() const;
|
||||
|
||||
/**
|
||||
* Get the axis type of a joystick axis.
|
||||
*
|
||||
* @return the axis type of a joystick axis.
|
||||
*/
|
||||
int GetAxisType(int axis) const;
|
||||
|
||||
/**
|
||||
* Get the port number of the HID.
|
||||
*
|
||||
|
||||
@@ -264,10 +264,10 @@ class DriverStationSim {
|
||||
static int GetJoystickRumble(int stick, int rumbleNum);
|
||||
|
||||
/**
|
||||
* Sets the state of one joystick button. %Button indexes begin at 1.
|
||||
* Sets the state of one joystick button. %Button indexes begin at 0.
|
||||
*
|
||||
* @param stick The joystick number
|
||||
* @param button The button index, beginning at 1
|
||||
* @param button The button index, beginning at 0
|
||||
* @param state The state of the joystick button
|
||||
*/
|
||||
static void SetJoystickButton(int stick, int button, bool state);
|
||||
@@ -292,28 +292,36 @@ class DriverStationSim {
|
||||
DriverStation::POVDirection value);
|
||||
|
||||
/**
|
||||
* Sets the state of all the buttons on a joystick.
|
||||
* Sets the number of axes for a joystick.
|
||||
*
|
||||
* @param stick The joystick number
|
||||
* @param buttons The bitmap state of the buttons on the joystick
|
||||
* @param maximumIndex The number of axes on the indicated joystick
|
||||
*/
|
||||
static void SetJoystickButtons(int stick, uint32_t buttons);
|
||||
static void SetJoystickAxesMaximumIndex(int stick, int maximumIndex);
|
||||
|
||||
/**
|
||||
* Sets the number of axes for a joystick.
|
||||
*
|
||||
* @param stick The joystick number
|
||||
* @param count The number of axes on the indicated joystick
|
||||
* @param available The number of axes on the indicated joystick
|
||||
*/
|
||||
static void SetJoystickAxisCount(int stick, int count);
|
||||
static void SetJoystickAxesAvailable(int stick, int available);
|
||||
|
||||
/**
|
||||
* Sets the number of POVs for a joystick.
|
||||
*
|
||||
* @param stick The joystick number
|
||||
* @param count The number of POVs on the indicated joystick
|
||||
* @param maximumIndex The number of POVs on the indicated joystick
|
||||
*/
|
||||
static void SetJoystickPOVCount(int stick, int count);
|
||||
static void SetJoystickPOVsMaximumIndex(int stick, int maximumIndex);
|
||||
|
||||
/**
|
||||
* Sets the number of POVs for a joystick.
|
||||
*
|
||||
* @param stick The joystick number
|
||||
* @param available The number of POVs on the indicated joystick
|
||||
*/
|
||||
static void SetJoystickPOVsAvailable(int stick, int available);
|
||||
|
||||
/**
|
||||
* Sets the number of buttons for a joystick.
|
||||
@@ -321,7 +329,9 @@ class DriverStationSim {
|
||||
* @param stick The joystick number
|
||||
* @param count The number of buttons on the indicated joystick
|
||||
*/
|
||||
static void SetJoystickButtonCount(int stick, int count);
|
||||
static void SetJoystickButtonsMaximumIndex(int stick, int count);
|
||||
|
||||
static void SetJoystickButtonsAvailable(int stick, uint64_t available);
|
||||
|
||||
/**
|
||||
* Sets the value of isGamepad for a joystick.
|
||||
@@ -347,15 +357,6 @@ class DriverStationSim {
|
||||
*/
|
||||
static void SetJoystickName(int stick, std::string_view name);
|
||||
|
||||
/**
|
||||
* Sets the types of Axes for a joystick.
|
||||
*
|
||||
* @param stick The joystick number
|
||||
* @param axis The target axis
|
||||
* @param type The type of axis
|
||||
*/
|
||||
static void SetJoystickAxisType(int stick, int axis, int type);
|
||||
|
||||
/**
|
||||
* Sets the game specific message.
|
||||
*
|
||||
|
||||
260
wpilibc/src/main/native/include/frc/simulation/GamepadSim.h
Normal file
260
wpilibc/src/main/native/include/frc/simulation/GamepadSim.h
Normal file
@@ -0,0 +1,260 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "frc/simulation/GenericHIDSim.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class Gamepad;
|
||||
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated Gamepad controller.
|
||||
*/
|
||||
class GamepadSim : public GenericHIDSim {
|
||||
public:
|
||||
/**
|
||||
* Constructs from a Gamepad object.
|
||||
*
|
||||
* @param joystick controller to simulate
|
||||
*/
|
||||
explicit GamepadSim(const Gamepad& joystick);
|
||||
|
||||
/**
|
||||
* Constructs from a joystick port number.
|
||||
*
|
||||
* @param port port number
|
||||
*/
|
||||
explicit GamepadSim(int port);
|
||||
|
||||
/**
|
||||
* Change the left X value of the controller's joystick.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetLeftX(double value);
|
||||
|
||||
/**
|
||||
* Change the left Y value of the controller's joystick.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetLeftY(double value);
|
||||
|
||||
/**
|
||||
* Change the right X value of the controller's joystick.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetRightX(double value);
|
||||
|
||||
/**
|
||||
* Change the right Y value of the controller's joystick.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetRightY(double value);
|
||||
|
||||
/**
|
||||
* Change the value of the left trigger axis on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetLeftTriggerAxis(double value);
|
||||
|
||||
/**
|
||||
* Change the value of the right trigger axis on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetRightTriggerAxis(double value);
|
||||
|
||||
/**
|
||||
* Change the value of the South Face button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetSouthFaceButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the East Face button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetEastFaceButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the West Face button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetWestFaceButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the North Face button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetNorthFacenButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Back button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetBackButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Guide button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetGuideButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Start button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetStartButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the left stick button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetLeftStickButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the right stick button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetRightStickButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the right shoulder button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetLeftShoulderButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the right shoulder button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetRightShoulderButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the D-pad up button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetDpadUpButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the D-pad down button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetDpadDownButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the D-pad left button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetDpadLeftButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the D-pad right button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetDpadRightButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Miscellaneous 1 button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetMisc1Button(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Right Paddle 1 button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetRightPaddle1Button(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Left Paddle 1 button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetLeftPaddle1Button(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Right Paddle 2 button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetRightPaddle2Button(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Left Paddle 2 button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetLeftPaddle2Button(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Touchpad button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetTouchpadButton(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Miscellaneous 2 button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetMisc2Button(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Miscellaneous 3 button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetMisc3Button(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Miscellaneous 4 button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetMisc4Button(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Miscellaneous 5 button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetMisc5Button(bool value);
|
||||
|
||||
/**
|
||||
* Change the value of the Miscellaneous 6 button on the controller.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void SetMisc6Button(bool value);
|
||||
};
|
||||
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -70,26 +70,32 @@ class GenericHIDSim {
|
||||
*/
|
||||
void SetPOV(DriverStation::POVDirection value);
|
||||
|
||||
void SetAxesMaximumIndex(int maximumIndex);
|
||||
|
||||
/**
|
||||
* Set the axis count of this device.
|
||||
*
|
||||
* @param count the new axis count
|
||||
*/
|
||||
void SetAxisCount(int count);
|
||||
void SetAxesAvailable(int count);
|
||||
|
||||
void SetPOVsMaximumIndex(int maximumIndex);
|
||||
|
||||
/**
|
||||
* Set the POV count of this device.
|
||||
*
|
||||
* @param count the new POV count
|
||||
*/
|
||||
void SetPOVCount(int count);
|
||||
void SetPOVsAvailable(int count);
|
||||
|
||||
void SetButtonsMaximumIndex(int maximumIndex);
|
||||
|
||||
/**
|
||||
* Set the button count of this device.
|
||||
*
|
||||
* @param count the new button count
|
||||
*/
|
||||
void SetButtonCount(int count);
|
||||
void SetButtonsAvailable(uint64_t count);
|
||||
|
||||
/**
|
||||
* Set the type of this device.
|
||||
|
||||
Reference in New Issue
Block a user