mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib,cmd] Cache HID wrappers (#8970)
Store DriverStation-owned GenericHID and Gamepad instances in Java and C++, and expose the cached objects to Python bindings. Move hand-written command gamepad and joystick wrappers to compose cached CommandGenericHID instances plus typed HID wrappers, including a Python CommandGamepad. This will let us remove UserControls, while helping ensure that we don't have state smashing between GenericHID objects. Another bonus is without inheritance, intellisense will no longer show a bunch of annoying methods, and instead just what actually exists. --------- Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
This commit is contained in:
@@ -18,8 +18,9 @@ import org.wpilib.event.EventLoop;
|
||||
* @see {{ ConsoleName }}Controller
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
private final {{ ConsoleName }}Controller m_hid;
|
||||
public class Command{{ ConsoleName }}Controller {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final {{ ConsoleName }}Controller m_controller;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -27,19 +28,27 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public Command{{ ConsoleName }}Controller(int port) {
|
||||
super(port);
|
||||
m_hid = new {{ ConsoleName }}Controller(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(port);
|
||||
m_controller = new {{ ConsoleName }}Controller(m_hid.getHID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public {{ ConsoleName }}Controller getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying {{ ConsoleName }}Controller object.
|
||||
*
|
||||
* @return the wrapped {{ ConsoleName }}Controller object
|
||||
*/
|
||||
public {{ ConsoleName }}Controller get{{ ConsoleName }}Controller() {
|
||||
return m_controller;
|
||||
}
|
||||
{% for button in buttons %}
|
||||
/**
|
||||
* Constructs a Trigger instance around the {{ button.DocName|default(button.name) }} button's digital signal.
|
||||
@@ -60,7 +69,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger {{ button.name }}(EventLoop loop) {
|
||||
return button({{ ConsoleName }}Controller.Button.k{{ capitalize_first(button.name) }}.value, loop);
|
||||
return m_hid.button({{ ConsoleName }}Controller.Button.k{{ capitalize_first(button.name) }}.value, loop);
|
||||
}
|
||||
{% endfor -%}
|
||||
{% for trigger in triggers -%}
|
||||
@@ -76,7 +85,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
* threshold, attached to the given event loop
|
||||
*/
|
||||
public Trigger {{ trigger.name }}(double threshold, EventLoop loop) {
|
||||
return axisGreaterThan({{ ConsoleName }}Controller.Axis.k{{ capitalize_first(trigger.name) }}.value, threshold, loop);
|
||||
return m_hid.axisGreaterThan({{ ConsoleName }}Controller.Axis.k{{ capitalize_first(trigger.name) }}.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +121,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double get{{ stick.NameParts|map("capitalize")|join }}() {
|
||||
return m_hid.get{{ stick.NameParts|map("capitalize")|join }}();
|
||||
return m_controller.get{{ stick.NameParts|map("capitalize")|join }}();
|
||||
}
|
||||
{% endfor -%}
|
||||
{% for trigger in triggers %}
|
||||
@@ -123,7 +132,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double get{{ capitalize_first(trigger.name) }}Axis() {
|
||||
return m_hid.get{{ capitalize_first(trigger.name) }}Axis();
|
||||
return m_controller.get{{ capitalize_first(trigger.name) }}Axis();
|
||||
}
|
||||
{% endfor -%}
|
||||
}
|
||||
|
||||
@@ -11,33 +11,39 @@
|
||||
using namespace wpi::cmd;
|
||||
|
||||
Command{{ ConsoleName }}Controller::Command{{ ConsoleName }}Controller(int port)
|
||||
: CommandGenericHID(port), m_hid{wpi::{{ ConsoleName }}Controller(port)} {}
|
||||
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)},
|
||||
m_controller{m_hid->GetHID()} {}
|
||||
|
||||
wpi::{{ ConsoleName }}Controller& Command{{ ConsoleName }}Controller::GetHID() {
|
||||
return m_hid;
|
||||
CommandGenericHID& Command{{ ConsoleName }}Controller::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
wpi::{{ ConsoleName }}Controller&
|
||||
Command{{ ConsoleName }}Controller::Get{{ ConsoleName }}Controller() {
|
||||
return m_controller;
|
||||
}
|
||||
{% for button in buttons %}
|
||||
Trigger Command{{ ConsoleName }}Controller::{{ capitalize_first(button.name) }}(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::{{ ConsoleName }}Controller::Button::k{{ capitalize_first(button.name) }}, loop);
|
||||
return m_hid->Button(
|
||||
wpi::{{ ConsoleName }}Controller::Button::k{{ capitalize_first(button.name) }}, loop);
|
||||
}
|
||||
{% endfor -%}
|
||||
{% for trigger in triggers -%}
|
||||
{% if trigger.UseThresholdMethods %}
|
||||
Trigger Command{{ ConsoleName }}Controller::{{ capitalize_first(trigger.name) }}(double threshold,
|
||||
wpi::EventLoop* loop) const {
|
||||
return Trigger(loop, [this, threshold] {
|
||||
return m_hid.Get{{ capitalize_first(trigger.name) }}Axis() > threshold;
|
||||
});
|
||||
return m_hid->AxisGreaterThan(
|
||||
wpi::{{ ConsoleName }}Controller::Axis::k{{ capitalize_first(trigger.name) }}, threshold, loop);
|
||||
}
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
{% for stick in sticks %}
|
||||
double Command{{ ConsoleName }}Controller::Get{{ stick.NameParts|map("capitalize")|join }}() const {
|
||||
return m_hid.Get{{ stick.NameParts|map("capitalize")|join }}();
|
||||
return m_controller.Get{{ stick.NameParts|map("capitalize")|join }}();
|
||||
}
|
||||
{% endfor -%}
|
||||
{% for trigger in triggers %}
|
||||
double Command{{ ConsoleName }}Controller::Get{{ capitalize_first(trigger.name) }}Axis() const {
|
||||
return m_hid.Get{{ capitalize_first(trigger.name) }}Axis();
|
||||
return m_controller.Get{{ capitalize_first(trigger.name) }}Axis();
|
||||
}
|
||||
{% endfor -%}
|
||||
|
||||
@@ -8,11 +8,10 @@
|
||||
{%- endmacro %}
|
||||
#pragma once
|
||||
|
||||
#include "wpi/driverstation/{{ ConsoleName }}Controller.hpp"
|
||||
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/commands2/CommandScheduler.hpp"
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/commands2/button/CommandGenericHID.hpp"
|
||||
#include "wpi/driverstation/{{ ConsoleName }}Controller.hpp"
|
||||
|
||||
namespace wpi::cmd {
|
||||
/**
|
||||
@@ -21,7 +20,7 @@ namespace wpi::cmd {
|
||||
*
|
||||
* @see wpi::{{ ConsoleName }}Controller
|
||||
*/
|
||||
class Command{{ ConsoleName }}Controller : public CommandGenericHID {
|
||||
class Command{{ ConsoleName }}Controller {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -32,11 +31,18 @@ class Command{{ ConsoleName }}Controller : public CommandGenericHID {
|
||||
explicit Command{{ ConsoleName }}Controller(int port);
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
wpi::{{ ConsoleName }}Controller& GetHID();
|
||||
CommandGenericHID& GetHID();
|
||||
|
||||
/**
|
||||
* Get the underlying {{ ConsoleName }}Controller object.
|
||||
*
|
||||
* @return the wrapped {{ ConsoleName }}Controller object
|
||||
*/
|
||||
wpi::{{ ConsoleName }}Controller& Get{{ ConsoleName }}Controller();
|
||||
{% for button in buttons %}
|
||||
/**
|
||||
* Constructs a Trigger instance around the {{ button.DocName|default(button.name) }} button's
|
||||
@@ -88,6 +94,7 @@ class Command{{ ConsoleName }}Controller : public CommandGenericHID {
|
||||
double Get{{ capitalize_first(trigger.name) }}Axis() const;
|
||||
{% endfor %}
|
||||
private:
|
||||
wpi::{{ ConsoleName }}Controller m_hid;
|
||||
CommandGenericHID* m_hid;
|
||||
wpi::{{ ConsoleName }}Controller m_controller;
|
||||
};
|
||||
} // namespace wpi::cmd
|
||||
|
||||
@@ -16,8 +16,9 @@ import org.wpilib.event.EventLoop;
|
||||
* @see NiDsPS4Controller
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
private final NiDsPS4Controller m_hid;
|
||||
public class CommandNiDsPS4Controller {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final NiDsPS4Controller m_controller;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -25,20 +26,28 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandNiDsPS4Controller(int port) {
|
||||
super(port);
|
||||
m_hid = new NiDsPS4Controller(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(port);
|
||||
m_controller = new NiDsPS4Controller(m_hid.getHID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public NiDsPS4Controller getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying NiDsPS4Controller object.
|
||||
*
|
||||
* @return the wrapped NiDsPS4Controller object
|
||||
*/
|
||||
public NiDsPS4Controller getNiDsPS4Controller() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the square button's digital signal.
|
||||
*
|
||||
@@ -58,7 +67,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger square(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kSquare.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kSquare.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +89,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger cross(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kCross.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kCross.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +111,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger circle(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kCircle.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kCircle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +133,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger triangle(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kTriangle.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kTriangle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +155,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger L1(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kL1.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kL1.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,7 +177,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger R1(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kR1.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kR1.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,7 +199,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger L2(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kL2.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kL2.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,7 +221,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger R2(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kR2.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kR2.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,7 +243,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger share(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kShare.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kShare.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +265,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger options(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kOptions.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kOptions.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,7 +287,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger L3(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kL3.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kL3.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,7 +309,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger R3(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kR3.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kR3.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,7 +331,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger PS(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kPS.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kPS.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,7 +353,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger touchpad(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kTouchpad.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kTouchpad.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,7 +362,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return m_hid.getLeftX();
|
||||
return m_controller.getLeftX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -362,7 +371,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return m_hid.getLeftY();
|
||||
return m_controller.getLeftY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -371,7 +380,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return m_hid.getRightX();
|
||||
return m_controller.getRightX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -380,7 +389,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return m_hid.getRightY();
|
||||
return m_controller.getRightY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -390,7 +399,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getL2Axis() {
|
||||
return m_hid.getL2Axis();
|
||||
return m_controller.getL2Axis();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -400,6 +409,6 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getR2Axis() {
|
||||
return m_hid.getR2Axis();
|
||||
return m_controller.getR2Axis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,9 @@ import org.wpilib.event.EventLoop;
|
||||
* @see NiDsPS5Controller
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
private final NiDsPS5Controller m_hid;
|
||||
public class CommandNiDsPS5Controller {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final NiDsPS5Controller m_controller;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -25,20 +26,28 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandNiDsPS5Controller(int port) {
|
||||
super(port);
|
||||
m_hid = new NiDsPS5Controller(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(port);
|
||||
m_controller = new NiDsPS5Controller(m_hid.getHID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public NiDsPS5Controller getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying NiDsPS5Controller object.
|
||||
*
|
||||
* @return the wrapped NiDsPS5Controller object
|
||||
*/
|
||||
public NiDsPS5Controller getNiDsPS5Controller() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the square button's digital signal.
|
||||
*
|
||||
@@ -58,7 +67,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger square(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kSquare.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kSquare.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +89,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger cross(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kCross.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kCross.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +111,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger circle(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kCircle.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kCircle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +133,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger triangle(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kTriangle.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kTriangle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +155,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger L1(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kL1.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kL1.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,7 +177,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger R1(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kR1.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kR1.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,7 +199,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger L2(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kL2.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kL2.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,7 +221,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger R2(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kR2.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kR2.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,7 +243,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger create(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kCreate.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kCreate.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +265,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger options(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kOptions.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kOptions.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,7 +287,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger L3(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kL3.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kL3.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,7 +309,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger R3(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kR3.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kR3.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,7 +331,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger PS(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kPS.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kPS.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,7 +353,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger touchpad(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kTouchpad.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kTouchpad.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,7 +362,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return m_hid.getLeftX();
|
||||
return m_controller.getLeftX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -362,7 +371,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return m_hid.getLeftY();
|
||||
return m_controller.getLeftY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -371,7 +380,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return m_hid.getRightX();
|
||||
return m_controller.getRightX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -380,7 +389,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return m_hid.getRightY();
|
||||
return m_controller.getRightY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -390,7 +399,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getL2Axis() {
|
||||
return m_hid.getL2Axis();
|
||||
return m_controller.getL2Axis();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -400,6 +409,6 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getR2Axis() {
|
||||
return m_hid.getR2Axis();
|
||||
return m_controller.getR2Axis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,9 @@ import org.wpilib.event.EventLoop;
|
||||
* @see NiDsStadiaController
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
private final NiDsStadiaController m_hid;
|
||||
public class CommandNiDsStadiaController {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final NiDsStadiaController m_controller;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -25,20 +26,28 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandNiDsStadiaController(int port) {
|
||||
super(port);
|
||||
m_hid = new NiDsStadiaController(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(port);
|
||||
m_controller = new NiDsStadiaController(m_hid.getHID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public NiDsStadiaController getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying NiDsStadiaController object.
|
||||
*
|
||||
* @return the wrapped NiDsStadiaController object
|
||||
*/
|
||||
public NiDsStadiaController getNiDsStadiaController() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the A button's digital signal.
|
||||
*
|
||||
@@ -58,7 +67,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger a(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kA.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kA.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +89,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger b(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kB.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kB.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +111,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger x(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kX.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kX.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +133,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger y(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kY.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kY.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +155,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger leftBumper(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kLeftBumper.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kLeftBumper.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,7 +177,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger rightBumper(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kRightBumper.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kRightBumper.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,7 +199,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger leftStick(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kLeftStick.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kLeftStick.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,7 +221,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger rightStick(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kRightStick.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kRightStick.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,7 +243,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger ellipses(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kEllipses.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kEllipses.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +265,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger hamburger(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kHamburger.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kHamburger.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,7 +287,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger stadia(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kStadia.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kStadia.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,7 +309,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger rightTrigger(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kRightTrigger.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kRightTrigger.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,7 +331,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger leftTrigger(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kLeftTrigger.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kLeftTrigger.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,7 +353,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger google(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kGoogle.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kGoogle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -366,7 +375,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger frame(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kFrame.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kFrame.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,7 +384,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return m_hid.getLeftX();
|
||||
return m_controller.getLeftX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -384,7 +393,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return m_hid.getRightX();
|
||||
return m_controller.getRightX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -393,7 +402,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return m_hid.getLeftY();
|
||||
return m_controller.getLeftY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -402,6 +411,6 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return m_hid.getRightY();
|
||||
return m_controller.getRightY();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,9 @@ import org.wpilib.event.EventLoop;
|
||||
* @see NiDsXboxController
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
private final NiDsXboxController m_hid;
|
||||
public class CommandNiDsXboxController {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final NiDsXboxController m_controller;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -25,20 +26,28 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandNiDsXboxController(int port) {
|
||||
super(port);
|
||||
m_hid = new NiDsXboxController(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(port);
|
||||
m_controller = new NiDsXboxController(m_hid.getHID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public NiDsXboxController getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying NiDsXboxController object.
|
||||
*
|
||||
* @return the wrapped NiDsXboxController object
|
||||
*/
|
||||
public NiDsXboxController getNiDsXboxController() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the A button's digital signal.
|
||||
*
|
||||
@@ -58,7 +67,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger a(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kA.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kA.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +89,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger b(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kB.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kB.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +111,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger x(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kX.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kX.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +133,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger y(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kY.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kY.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +155,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger leftBumper(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kLeftBumper.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kLeftBumper.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,7 +177,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger rightBumper(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kRightBumper.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kRightBumper.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,7 +199,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger back(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kBack.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kBack.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,7 +221,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger start(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kStart.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kStart.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,7 +243,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger leftStick(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kLeftStick.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kLeftStick.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +265,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger rightStick(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kRightStick.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kRightStick.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,7 +279,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* threshold, attached to the given event loop
|
||||
*/
|
||||
public Trigger leftTrigger(double threshold, EventLoop loop) {
|
||||
return axisGreaterThan(NiDsXboxController.Axis.kLeftTrigger.value, threshold, loop);
|
||||
return m_hid.axisGreaterThan(NiDsXboxController.Axis.kLeftTrigger.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -309,7 +318,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* threshold, attached to the given event loop
|
||||
*/
|
||||
public Trigger rightTrigger(double threshold, EventLoop loop) {
|
||||
return axisGreaterThan(NiDsXboxController.Axis.kRightTrigger.value, threshold, loop);
|
||||
return m_hid.axisGreaterThan(NiDsXboxController.Axis.kRightTrigger.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -343,7 +352,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return m_hid.getLeftX();
|
||||
return m_controller.getLeftX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -352,7 +361,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return m_hid.getRightX();
|
||||
return m_controller.getRightX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -361,7 +370,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return m_hid.getLeftY();
|
||||
return m_controller.getLeftY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -370,7 +379,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return m_hid.getRightY();
|
||||
return m_controller.getRightY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -380,7 +389,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftTriggerAxis() {
|
||||
return m_hid.getLeftTriggerAxis();
|
||||
return m_controller.getLeftTriggerAxis();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -390,6 +399,6 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightTriggerAxis() {
|
||||
return m_hid.getRightTriggerAxis();
|
||||
return m_controller.getRightTriggerAxis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,88 +9,108 @@
|
||||
using namespace wpi::cmd;
|
||||
|
||||
CommandNiDsPS4Controller::CommandNiDsPS4Controller(int port)
|
||||
: CommandGenericHID(port), m_hid{wpi::NiDsPS4Controller(port)} {}
|
||||
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)},
|
||||
m_controller{m_hid->GetHID()} {}
|
||||
|
||||
wpi::NiDsPS4Controller& CommandNiDsPS4Controller::GetHID() {
|
||||
return m_hid;
|
||||
CommandGenericHID& CommandNiDsPS4Controller::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
wpi::NiDsPS4Controller&
|
||||
CommandNiDsPS4Controller::GetNiDsPS4Controller() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::Square(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kSquare, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kSquare, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::Cross(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kCross, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kCross, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::Circle(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kCircle, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kCircle, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::Triangle(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kTriangle, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kTriangle, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::L1(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kL1, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kL1, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::R1(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kR1, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kR1, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::L2(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kL2, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kL2, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::R2(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kR2, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kR2, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::Share(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kShare, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kShare, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::Options(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kOptions, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kOptions, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::L3(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kL3, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kL3, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::R3(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kR3, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kR3, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::PS(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kPS, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kPS, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS4Controller::Touchpad(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS4Controller::Button::kTouchpad, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS4Controller::Button::kTouchpad, loop);
|
||||
}
|
||||
|
||||
double CommandNiDsPS4Controller::GetLeftX() const {
|
||||
return m_hid.GetLeftX();
|
||||
return m_controller.GetLeftX();
|
||||
}
|
||||
|
||||
double CommandNiDsPS4Controller::GetLeftY() const {
|
||||
return m_hid.GetLeftY();
|
||||
return m_controller.GetLeftY();
|
||||
}
|
||||
|
||||
double CommandNiDsPS4Controller::GetRightX() const {
|
||||
return m_hid.GetRightX();
|
||||
return m_controller.GetRightX();
|
||||
}
|
||||
|
||||
double CommandNiDsPS4Controller::GetRightY() const {
|
||||
return m_hid.GetRightY();
|
||||
return m_controller.GetRightY();
|
||||
}
|
||||
|
||||
double CommandNiDsPS4Controller::GetL2Axis() const {
|
||||
return m_hid.GetL2Axis();
|
||||
return m_controller.GetL2Axis();
|
||||
}
|
||||
|
||||
double CommandNiDsPS4Controller::GetR2Axis() const {
|
||||
return m_hid.GetR2Axis();
|
||||
return m_controller.GetR2Axis();
|
||||
}
|
||||
|
||||
@@ -9,88 +9,108 @@
|
||||
using namespace wpi::cmd;
|
||||
|
||||
CommandNiDsPS5Controller::CommandNiDsPS5Controller(int port)
|
||||
: CommandGenericHID(port), m_hid{wpi::NiDsPS5Controller(port)} {}
|
||||
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)},
|
||||
m_controller{m_hid->GetHID()} {}
|
||||
|
||||
wpi::NiDsPS5Controller& CommandNiDsPS5Controller::GetHID() {
|
||||
return m_hid;
|
||||
CommandGenericHID& CommandNiDsPS5Controller::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
wpi::NiDsPS5Controller&
|
||||
CommandNiDsPS5Controller::GetNiDsPS5Controller() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::Square(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kSquare, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kSquare, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::Cross(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kCross, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kCross, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::Circle(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kCircle, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kCircle, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::Triangle(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kTriangle, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kTriangle, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::L1(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kL1, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kL1, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::R1(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kR1, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kR1, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::L2(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kL2, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kL2, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::R2(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kR2, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kR2, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::Create(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kCreate, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kCreate, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::Options(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kOptions, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kOptions, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::L3(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kL3, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kL3, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::R3(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kR3, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kR3, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::PS(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kPS, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kPS, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsPS5Controller::Touchpad(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsPS5Controller::Button::kTouchpad, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsPS5Controller::Button::kTouchpad, loop);
|
||||
}
|
||||
|
||||
double CommandNiDsPS5Controller::GetLeftX() const {
|
||||
return m_hid.GetLeftX();
|
||||
return m_controller.GetLeftX();
|
||||
}
|
||||
|
||||
double CommandNiDsPS5Controller::GetLeftY() const {
|
||||
return m_hid.GetLeftY();
|
||||
return m_controller.GetLeftY();
|
||||
}
|
||||
|
||||
double CommandNiDsPS5Controller::GetRightX() const {
|
||||
return m_hid.GetRightX();
|
||||
return m_controller.GetRightX();
|
||||
}
|
||||
|
||||
double CommandNiDsPS5Controller::GetRightY() const {
|
||||
return m_hid.GetRightY();
|
||||
return m_controller.GetRightY();
|
||||
}
|
||||
|
||||
double CommandNiDsPS5Controller::GetL2Axis() const {
|
||||
return m_hid.GetL2Axis();
|
||||
return m_controller.GetL2Axis();
|
||||
}
|
||||
|
||||
double CommandNiDsPS5Controller::GetR2Axis() const {
|
||||
return m_hid.GetR2Axis();
|
||||
return m_controller.GetR2Axis();
|
||||
}
|
||||
|
||||
@@ -9,84 +9,105 @@
|
||||
using namespace wpi::cmd;
|
||||
|
||||
CommandNiDsStadiaController::CommandNiDsStadiaController(int port)
|
||||
: CommandGenericHID(port), m_hid{wpi::NiDsStadiaController(port)} {}
|
||||
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)},
|
||||
m_controller{m_hid->GetHID()} {}
|
||||
|
||||
wpi::NiDsStadiaController& CommandNiDsStadiaController::GetHID() {
|
||||
return m_hid;
|
||||
CommandGenericHID& CommandNiDsStadiaController::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
wpi::NiDsStadiaController&
|
||||
CommandNiDsStadiaController::GetNiDsStadiaController() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::A(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kA, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kA, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::B(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kB, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kB, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::X(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kX, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kX, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::Y(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kY, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kY, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::LeftBumper(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kLeftBumper, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kLeftBumper, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::RightBumper(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kRightBumper, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kRightBumper, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::LeftStick(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kLeftStick, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kLeftStick, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::RightStick(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kRightStick, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kRightStick, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::Ellipses(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kEllipses, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kEllipses, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::Hamburger(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kHamburger, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kHamburger, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::Stadia(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kStadia, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kStadia, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::RightTrigger(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kRightTrigger, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kRightTrigger, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::LeftTrigger(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kLeftTrigger, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kLeftTrigger, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::Google(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kGoogle, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kGoogle, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsStadiaController::Frame(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsStadiaController::Button::kFrame, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsStadiaController::Button::kFrame, loop);
|
||||
}
|
||||
|
||||
double CommandNiDsStadiaController::GetLeftX() const {
|
||||
return m_hid.GetLeftX();
|
||||
return m_controller.GetLeftX();
|
||||
}
|
||||
|
||||
double CommandNiDsStadiaController::GetRightX() const {
|
||||
return m_hid.GetRightX();
|
||||
return m_controller.GetRightX();
|
||||
}
|
||||
|
||||
double CommandNiDsStadiaController::GetLeftY() const {
|
||||
return m_hid.GetLeftY();
|
||||
return m_controller.GetLeftY();
|
||||
}
|
||||
|
||||
double CommandNiDsStadiaController::GetRightY() const {
|
||||
return m_hid.GetRightY();
|
||||
return m_controller.GetRightY();
|
||||
}
|
||||
|
||||
@@ -9,86 +9,100 @@
|
||||
using namespace wpi::cmd;
|
||||
|
||||
CommandNiDsXboxController::CommandNiDsXboxController(int port)
|
||||
: CommandGenericHID(port), m_hid{wpi::NiDsXboxController(port)} {}
|
||||
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)},
|
||||
m_controller{m_hid->GetHID()} {}
|
||||
|
||||
wpi::NiDsXboxController& CommandNiDsXboxController::GetHID() {
|
||||
return m_hid;
|
||||
CommandGenericHID& CommandNiDsXboxController::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
wpi::NiDsXboxController&
|
||||
CommandNiDsXboxController::GetNiDsXboxController() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
Trigger CommandNiDsXboxController::A(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsXboxController::Button::kA, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsXboxController::Button::kA, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsXboxController::B(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsXboxController::Button::kB, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsXboxController::Button::kB, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsXboxController::X(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsXboxController::Button::kX, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsXboxController::Button::kX, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsXboxController::Y(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsXboxController::Button::kY, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsXboxController::Button::kY, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsXboxController::LeftBumper(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsXboxController::Button::kLeftBumper, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsXboxController::Button::kLeftBumper, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsXboxController::RightBumper(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsXboxController::Button::kRightBumper, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsXboxController::Button::kRightBumper, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsXboxController::Back(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsXboxController::Button::kBack, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsXboxController::Button::kBack, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsXboxController::Start(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsXboxController::Button::kStart, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsXboxController::Button::kStart, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsXboxController::LeftStick(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsXboxController::Button::kLeftStick, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsXboxController::Button::kLeftStick, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsXboxController::RightStick(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::NiDsXboxController::Button::kRightStick, loop);
|
||||
return m_hid->Button(
|
||||
wpi::NiDsXboxController::Button::kRightStick, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsXboxController::LeftTrigger(double threshold,
|
||||
wpi::EventLoop* loop) const {
|
||||
return Trigger(loop, [this, threshold] {
|
||||
return m_hid.GetLeftTriggerAxis() > threshold;
|
||||
});
|
||||
return m_hid->AxisGreaterThan(
|
||||
wpi::NiDsXboxController::Axis::kLeftTrigger, threshold, loop);
|
||||
}
|
||||
|
||||
Trigger CommandNiDsXboxController::RightTrigger(double threshold,
|
||||
wpi::EventLoop* loop) const {
|
||||
return Trigger(loop, [this, threshold] {
|
||||
return m_hid.GetRightTriggerAxis() > threshold;
|
||||
});
|
||||
return m_hid->AxisGreaterThan(
|
||||
wpi::NiDsXboxController::Axis::kRightTrigger, threshold, loop);
|
||||
}
|
||||
|
||||
double CommandNiDsXboxController::GetLeftX() const {
|
||||
return m_hid.GetLeftX();
|
||||
return m_controller.GetLeftX();
|
||||
}
|
||||
|
||||
double CommandNiDsXboxController::GetRightX() const {
|
||||
return m_hid.GetRightX();
|
||||
return m_controller.GetRightX();
|
||||
}
|
||||
|
||||
double CommandNiDsXboxController::GetLeftY() const {
|
||||
return m_hid.GetLeftY();
|
||||
return m_controller.GetLeftY();
|
||||
}
|
||||
|
||||
double CommandNiDsXboxController::GetRightY() const {
|
||||
return m_hid.GetRightY();
|
||||
return m_controller.GetRightY();
|
||||
}
|
||||
|
||||
double CommandNiDsXboxController::GetLeftTriggerAxis() const {
|
||||
return m_hid.GetLeftTriggerAxis();
|
||||
return m_controller.GetLeftTriggerAxis();
|
||||
}
|
||||
|
||||
double CommandNiDsXboxController::GetRightTriggerAxis() const {
|
||||
return m_hid.GetRightTriggerAxis();
|
||||
return m_controller.GetRightTriggerAxis();
|
||||
}
|
||||
|
||||
@@ -6,11 +6,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "wpi/driverstation/NiDsPS4Controller.hpp"
|
||||
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/commands2/CommandScheduler.hpp"
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/commands2/button/CommandGenericHID.hpp"
|
||||
#include "wpi/driverstation/NiDsPS4Controller.hpp"
|
||||
|
||||
namespace wpi::cmd {
|
||||
/**
|
||||
@@ -19,7 +18,7 @@ namespace wpi::cmd {
|
||||
*
|
||||
* @see wpi::NiDsPS4Controller
|
||||
*/
|
||||
class CommandNiDsPS4Controller : public CommandGenericHID {
|
||||
class CommandNiDsPS4Controller {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -30,11 +29,18 @@ class CommandNiDsPS4Controller : public CommandGenericHID {
|
||||
explicit CommandNiDsPS4Controller(int port);
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
wpi::NiDsPS4Controller& GetHID();
|
||||
CommandGenericHID& GetHID();
|
||||
|
||||
/**
|
||||
* Get the underlying NiDsPS4Controller object.
|
||||
*
|
||||
* @return the wrapped NiDsPS4Controller object
|
||||
*/
|
||||
wpi::NiDsPS4Controller& GetNiDsPS4Controller();
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the square button's
|
||||
@@ -249,6 +255,7 @@ class CommandNiDsPS4Controller : public CommandGenericHID {
|
||||
double GetR2Axis() const;
|
||||
|
||||
private:
|
||||
wpi::NiDsPS4Controller m_hid;
|
||||
CommandGenericHID* m_hid;
|
||||
wpi::NiDsPS4Controller m_controller;
|
||||
};
|
||||
} // namespace wpi::cmd
|
||||
|
||||
@@ -6,11 +6,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "wpi/driverstation/NiDsPS5Controller.hpp"
|
||||
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/commands2/CommandScheduler.hpp"
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/commands2/button/CommandGenericHID.hpp"
|
||||
#include "wpi/driverstation/NiDsPS5Controller.hpp"
|
||||
|
||||
namespace wpi::cmd {
|
||||
/**
|
||||
@@ -19,7 +18,7 @@ namespace wpi::cmd {
|
||||
*
|
||||
* @see wpi::NiDsPS5Controller
|
||||
*/
|
||||
class CommandNiDsPS5Controller : public CommandGenericHID {
|
||||
class CommandNiDsPS5Controller {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -30,11 +29,18 @@ class CommandNiDsPS5Controller : public CommandGenericHID {
|
||||
explicit CommandNiDsPS5Controller(int port);
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
wpi::NiDsPS5Controller& GetHID();
|
||||
CommandGenericHID& GetHID();
|
||||
|
||||
/**
|
||||
* Get the underlying NiDsPS5Controller object.
|
||||
*
|
||||
* @return the wrapped NiDsPS5Controller object
|
||||
*/
|
||||
wpi::NiDsPS5Controller& GetNiDsPS5Controller();
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the square button's
|
||||
@@ -249,6 +255,7 @@ class CommandNiDsPS5Controller : public CommandGenericHID {
|
||||
double GetR2Axis() const;
|
||||
|
||||
private:
|
||||
wpi::NiDsPS5Controller m_hid;
|
||||
CommandGenericHID* m_hid;
|
||||
wpi::NiDsPS5Controller m_controller;
|
||||
};
|
||||
} // namespace wpi::cmd
|
||||
|
||||
@@ -6,11 +6,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "wpi/driverstation/NiDsStadiaController.hpp"
|
||||
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/commands2/CommandScheduler.hpp"
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/commands2/button/CommandGenericHID.hpp"
|
||||
#include "wpi/driverstation/NiDsStadiaController.hpp"
|
||||
|
||||
namespace wpi::cmd {
|
||||
/**
|
||||
@@ -19,7 +18,7 @@ namespace wpi::cmd {
|
||||
*
|
||||
* @see wpi::NiDsStadiaController
|
||||
*/
|
||||
class CommandNiDsStadiaController : public CommandGenericHID {
|
||||
class CommandNiDsStadiaController {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -30,11 +29,18 @@ class CommandNiDsStadiaController : public CommandGenericHID {
|
||||
explicit CommandNiDsStadiaController(int port);
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
wpi::NiDsStadiaController& GetHID();
|
||||
CommandGenericHID& GetHID();
|
||||
|
||||
/**
|
||||
* Get the underlying NiDsStadiaController object.
|
||||
*
|
||||
* @return the wrapped NiDsStadiaController object
|
||||
*/
|
||||
wpi::NiDsStadiaController& GetNiDsStadiaController();
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the A button's
|
||||
@@ -245,6 +251,7 @@ class CommandNiDsStadiaController : public CommandGenericHID {
|
||||
double GetRightY() const;
|
||||
|
||||
private:
|
||||
wpi::NiDsStadiaController m_hid;
|
||||
CommandGenericHID* m_hid;
|
||||
wpi::NiDsStadiaController m_controller;
|
||||
};
|
||||
} // namespace wpi::cmd
|
||||
|
||||
@@ -6,11 +6,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "wpi/driverstation/NiDsXboxController.hpp"
|
||||
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/commands2/CommandScheduler.hpp"
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/commands2/button/CommandGenericHID.hpp"
|
||||
#include "wpi/driverstation/NiDsXboxController.hpp"
|
||||
|
||||
namespace wpi::cmd {
|
||||
/**
|
||||
@@ -19,7 +18,7 @@ namespace wpi::cmd {
|
||||
*
|
||||
* @see wpi::NiDsXboxController
|
||||
*/
|
||||
class CommandNiDsXboxController : public CommandGenericHID {
|
||||
class CommandNiDsXboxController {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -30,11 +29,18 @@ class CommandNiDsXboxController : public CommandGenericHID {
|
||||
explicit CommandNiDsXboxController(int port);
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
wpi::NiDsXboxController& GetHID();
|
||||
CommandGenericHID& GetHID();
|
||||
|
||||
/**
|
||||
* Get the underlying NiDsXboxController object.
|
||||
*
|
||||
* @return the wrapped NiDsXboxController object
|
||||
*/
|
||||
wpi::NiDsXboxController& GetNiDsXboxController();
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the A button's
|
||||
@@ -235,6 +241,7 @@ class CommandNiDsXboxController : public CommandGenericHID {
|
||||
double GetRightTriggerAxis() const;
|
||||
|
||||
private:
|
||||
wpi::NiDsXboxController m_hid;
|
||||
CommandGenericHID* m_hid;
|
||||
wpi::NiDsXboxController m_controller;
|
||||
};
|
||||
} // namespace wpi::cmd
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package org.wpilib.command2.button;
|
||||
|
||||
import org.wpilib.command2.CommandScheduler;
|
||||
import org.wpilib.driverstation.DriverStation;
|
||||
import org.wpilib.driverstation.Gamepad;
|
||||
import org.wpilib.event.EventLoop;
|
||||
|
||||
@@ -14,8 +15,9 @@ import org.wpilib.event.EventLoop;
|
||||
* @see Gamepad
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class CommandGamepad extends CommandGenericHID {
|
||||
private final Gamepad m_hid;
|
||||
public class CommandGamepad {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final Gamepad m_gamepad;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -23,20 +25,51 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandGamepad(int port) {
|
||||
super(port);
|
||||
m_hid = new Gamepad(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(port);
|
||||
m_gamepad = DriverStation.getGamepad(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public Gamepad getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying Gamepad object.
|
||||
*
|
||||
* @return the wrapped Gamepad object
|
||||
*/
|
||||
public Gamepad getGamepad() {
|
||||
return m_gamepad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
*
|
||||
* @param button the button index
|
||||
* @return an event instance representing the button's digital signal attached to the {@link
|
||||
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
|
||||
* @see #button(int, EventLoop)
|
||||
*/
|
||||
public Trigger button(int button) {
|
||||
return m_hid.button(button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
*
|
||||
* @param button the button index
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @return an event instance representing the button's digital signal attached to the given loop.
|
||||
*/
|
||||
public Trigger button(int button, EventLoop loop) {
|
||||
return m_hid.button(button, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
*
|
||||
@@ -46,7 +79,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #button(Gamepad.Button, EventLoop)
|
||||
*/
|
||||
public Trigger button(Gamepad.Button button) {
|
||||
return super.button(button.value);
|
||||
return button(button.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -721,7 +754,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* threshold.
|
||||
*/
|
||||
public Trigger axisLessThan(Gamepad.Axis axis, double threshold) {
|
||||
return super.axisLessThan(axis.value, threshold);
|
||||
return m_hid.axisLessThan(axis.value, threshold);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -735,7 +768,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* threshold.
|
||||
*/
|
||||
public Trigger axisLessThan(Gamepad.Axis axis, double threshold, EventLoop loop) {
|
||||
return super.axisLessThan(axis.value, threshold, loop);
|
||||
return m_hid.axisLessThan(axis.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -749,7 +782,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* threshold.
|
||||
*/
|
||||
public Trigger axisGreaterThan(Gamepad.Axis axis, double threshold) {
|
||||
return super.axisGreaterThan(axis.value, threshold);
|
||||
return m_hid.axisGreaterThan(axis.value, threshold);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -763,7 +796,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* threshold.
|
||||
*/
|
||||
public Trigger axisGreaterThan(Gamepad.Axis axis, double threshold, EventLoop loop) {
|
||||
return super.axisGreaterThan(axis.value, threshold, loop);
|
||||
return m_hid.axisGreaterThan(axis.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -777,7 +810,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* provided threshold.
|
||||
*/
|
||||
public Trigger axisMagnitudeGreaterThan(Gamepad.Axis axis, double threshold, EventLoop loop) {
|
||||
return super.axisMagnitudeGreaterThan(axis.value, threshold, loop);
|
||||
return m_hid.axisMagnitudeGreaterThan(axis.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -790,7 +823,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return a Trigger instance that is true when the deadbanded axis value is active (non-zero).
|
||||
*/
|
||||
public Trigger axisMagnitudeGreaterThan(Gamepad.Axis axis, double threshold) {
|
||||
return super.axisMagnitudeGreaterThan(axis.value, threshold);
|
||||
return m_hid.axisMagnitudeGreaterThan(axis.value, threshold);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -800,7 +833,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return The value of the axis.
|
||||
*/
|
||||
public double getAxis(Gamepad.Axis axis) {
|
||||
return getRawAxis(axis.value);
|
||||
return m_hid.getRawAxis(axis.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -809,7 +842,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return m_hid.getLeftX();
|
||||
return m_gamepad.getLeftX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -818,7 +851,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return m_hid.getLeftY();
|
||||
return m_gamepad.getLeftY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -827,7 +860,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return m_hid.getRightX();
|
||||
return m_gamepad.getRightX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -836,7 +869,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return m_hid.getRightY();
|
||||
return m_gamepad.getRightY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -846,7 +879,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftTriggerAxis() {
|
||||
return m_hid.getLeftTriggerAxis();
|
||||
return m_gamepad.getLeftTriggerAxis();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -856,6 +889,6 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightTriggerAxis() {
|
||||
return m_hid.getRightTriggerAxis();
|
||||
return m_gamepad.getRightTriggerAxis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,13 @@ package org.wpilib.command2.button;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.wpilib.command2.CommandScheduler;
|
||||
import org.wpilib.driverstation.DriverStation;
|
||||
import org.wpilib.driverstation.GenericHID;
|
||||
import org.wpilib.driverstation.POVDirection;
|
||||
import org.wpilib.driverstation.internal.DriverStationBackend;
|
||||
import org.wpilib.event.EventLoop;
|
||||
import org.wpilib.math.util.Pair;
|
||||
|
||||
@@ -17,7 +21,11 @@ import org.wpilib.math.util.Pair;
|
||||
*
|
||||
* @see GenericHID
|
||||
*/
|
||||
public class CommandGenericHID {
|
||||
public final class CommandGenericHID {
|
||||
private static final Lock m_hidsLock = new ReentrantLock();
|
||||
private static final CommandGenericHID[] m_hids =
|
||||
new CommandGenericHID[DriverStationBackend.JOYSTICK_PORTS];
|
||||
|
||||
private final GenericHID m_hid;
|
||||
private final Map<EventLoop, Map<Integer, Trigger>> m_buttonCache = new HashMap<>();
|
||||
private final Map<EventLoop, Map<Pair<Integer, Double>, Trigger>> m_axisLessThanCache =
|
||||
@@ -34,7 +42,38 @@ public class CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the device is plugged into.
|
||||
*/
|
||||
public CommandGenericHID(int port) {
|
||||
m_hid = new GenericHID(port);
|
||||
m_hid = DriverStation.getGenericHID(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a device with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this command HID.
|
||||
*/
|
||||
public CommandGenericHID(GenericHID hid) {
|
||||
m_hid = hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the CommandGenericHID object for the given port. CommandGenericHID objects are cached, so
|
||||
* this will always return the same object for the same port.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the device is plugged into.
|
||||
* @return The CommandGenericHID object for the given port.
|
||||
*/
|
||||
public static CommandGenericHID getCommandGenericHID(int port) {
|
||||
DriverStation.getGenericHID(port);
|
||||
m_hidsLock.lock();
|
||||
try {
|
||||
CommandGenericHID toRet = m_hids[port];
|
||||
if (toRet == null) {
|
||||
toRet = new CommandGenericHID(port);
|
||||
m_hids[port] = toRet;
|
||||
}
|
||||
return toRet;
|
||||
} finally {
|
||||
m_hidsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package org.wpilib.command2.button;
|
||||
|
||||
import org.wpilib.command2.CommandScheduler;
|
||||
import org.wpilib.driverstation.DriverStation;
|
||||
import org.wpilib.driverstation.Joystick;
|
||||
import org.wpilib.event.EventLoop;
|
||||
|
||||
@@ -13,8 +14,9 @@ import org.wpilib.event.EventLoop;
|
||||
*
|
||||
* @see Joystick
|
||||
*/
|
||||
public class CommandJoystick extends CommandGenericHID {
|
||||
private final Joystick m_hid;
|
||||
public class CommandJoystick {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final Joystick m_joystick;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -22,20 +24,28 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandJoystick(int port) {
|
||||
super(port);
|
||||
m_hid = new Joystick(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(port);
|
||||
m_joystick = new Joystick(DriverStation.getGenericHID(port));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public Joystick getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying Joystick object.
|
||||
*
|
||||
* @return the wrapped Joystick object
|
||||
*/
|
||||
public Joystick getJoystick() {
|
||||
return m_joystick;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the trigger button's digital signal.
|
||||
*
|
||||
@@ -55,7 +65,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* given loop.
|
||||
*/
|
||||
public Trigger trigger(EventLoop loop) {
|
||||
return button(Joystick.ButtonType.kTrigger.value, loop);
|
||||
return m_hid.button(Joystick.ButtonType.kTrigger.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +87,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* loop.
|
||||
*/
|
||||
public Trigger top(EventLoop loop) {
|
||||
return button(Joystick.ButtonType.kTop.value, loop);
|
||||
return m_hid.button(Joystick.ButtonType.kTop.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,7 +96,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @param channel The channel to set the axis to.
|
||||
*/
|
||||
public void setXChannel(int channel) {
|
||||
m_hid.setXChannel(channel);
|
||||
m_joystick.setXChannel(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +105,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @param channel The channel to set the axis to.
|
||||
*/
|
||||
public void setYChannel(int channel) {
|
||||
m_hid.setYChannel(channel);
|
||||
m_joystick.setYChannel(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +114,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @param channel The channel to set the axis to.
|
||||
*/
|
||||
public void setZChannel(int channel) {
|
||||
m_hid.setZChannel(channel);
|
||||
m_joystick.setZChannel(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +123,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @param channel The channel to set the axis to.
|
||||
*/
|
||||
public void setThrottleChannel(int channel) {
|
||||
m_hid.setThrottleChannel(channel);
|
||||
m_joystick.setThrottleChannel(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +132,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @param channel The channel to set the axis to.
|
||||
*/
|
||||
public void setTwistChannel(int channel) {
|
||||
m_hid.setTwistChannel(channel);
|
||||
m_joystick.setTwistChannel(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +141,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The channel for the axis.
|
||||
*/
|
||||
public int getXChannel() {
|
||||
return m_hid.getXChannel();
|
||||
return m_joystick.getXChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,7 +150,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The channel for the axis.
|
||||
*/
|
||||
public int getYChannel() {
|
||||
return m_hid.getYChannel();
|
||||
return m_joystick.getYChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +159,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The channel for the axis.
|
||||
*/
|
||||
public int getZChannel() {
|
||||
return m_hid.getZChannel();
|
||||
return m_joystick.getZChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +168,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The channel for the axis.
|
||||
*/
|
||||
public int getTwistChannel() {
|
||||
return m_hid.getTwistChannel();
|
||||
return m_joystick.getTwistChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +177,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The channel for the axis.
|
||||
*/
|
||||
public int getThrottleChannel() {
|
||||
return m_hid.getThrottleChannel();
|
||||
return m_joystick.getThrottleChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,7 +189,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return the x position
|
||||
*/
|
||||
public double getX() {
|
||||
return m_hid.getX();
|
||||
return m_joystick.getX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +201,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return the y position
|
||||
*/
|
||||
public double getY() {
|
||||
return m_hid.getY();
|
||||
return m_joystick.getY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,7 +210,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return the z position
|
||||
*/
|
||||
public double getZ() {
|
||||
return m_hid.getZ();
|
||||
return m_joystick.getZ();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,7 +220,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The Twist value of the joystick.
|
||||
*/
|
||||
public double getTwist() {
|
||||
return m_hid.getTwist();
|
||||
return m_joystick.getTwist();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,7 +230,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The Throttle value of the joystick.
|
||||
*/
|
||||
public double getThrottle() {
|
||||
return m_hid.getThrottle();
|
||||
return m_joystick.getThrottle();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,7 +240,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The magnitude of the direction vector
|
||||
*/
|
||||
public double getMagnitude() {
|
||||
return m_hid.getMagnitude();
|
||||
return m_joystick.getMagnitude();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,7 +258,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
//
|
||||
// It's rotated 90 degrees CCW (y is negated and the arguments are reversed)
|
||||
// so that 0 radians is forward.
|
||||
return m_hid.getDirectionRadians();
|
||||
return m_joystick.getDirectionRadians();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,6 +268,6 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The direction of the vector in degrees
|
||||
*/
|
||||
public double getDirectionDegrees() {
|
||||
return m_hid.getDirectionDegrees();
|
||||
return m_joystick.getDirectionDegrees();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.wpilib.command2.button;
|
||||
import static org.wpilib.util.ErrorMessages.requireNonNullParam;
|
||||
|
||||
import org.wpilib.driverstation.GenericHID;
|
||||
import org.wpilib.driverstation.HIDDevice;
|
||||
|
||||
/**
|
||||
* A {@link Trigger} that gets its state from a {@link GenericHID}.
|
||||
@@ -24,4 +25,14 @@ public class JoystickButton extends Trigger {
|
||||
super(() -> joystick.getRawButton(buttonNumber));
|
||||
requireNonNullParam(joystick, "joystick", "JoystickButton");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a joystick button for triggering commands.
|
||||
*
|
||||
* @param joystick The HIDDevice object that has the button
|
||||
* @param buttonNumber The button number (see {@link GenericHID#getRawButton(int) }
|
||||
*/
|
||||
public JoystickButton(HIDDevice joystick, int buttonNumber) {
|
||||
this(requireNonNullParam(joystick, "joystick", "JoystickButton").getHID(), buttonNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.wpilib.command2.button;
|
||||
import static org.wpilib.util.ErrorMessages.requireNonNullParam;
|
||||
|
||||
import org.wpilib.driverstation.GenericHID;
|
||||
import org.wpilib.driverstation.HIDDevice;
|
||||
import org.wpilib.driverstation.POVDirection;
|
||||
|
||||
/**
|
||||
@@ -36,4 +37,25 @@ public class POVButton extends Trigger {
|
||||
public POVButton(GenericHID joystick, POVDirection angle) {
|
||||
this(joystick, angle, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a POV button for triggering commands.
|
||||
*
|
||||
* @param joystick The HIDDevice object that has the POV
|
||||
* @param angle The desired angle
|
||||
* @param povNumber The POV number (see {@link GenericHID#getPOV(int)})
|
||||
*/
|
||||
public POVButton(HIDDevice joystick, POVDirection angle, int povNumber) {
|
||||
this(requireNonNullParam(joystick, "joystick", "POVButton").getHID(), angle, povNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a POV button for triggering commands. By default, acts on POV 0
|
||||
*
|
||||
* @param joystick The HIDDevice object that has the POV
|
||||
* @param angle The desired angle
|
||||
*/
|
||||
public POVButton(HIDDevice joystick, POVDirection angle) {
|
||||
this(joystick, angle, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,15 +9,24 @@
|
||||
using namespace wpi::cmd;
|
||||
|
||||
CommandGamepad::CommandGamepad(int port)
|
||||
: CommandGenericHID(port), m_hid{wpi::Gamepad(port)} {}
|
||||
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)},
|
||||
m_gamepad{&wpi::DriverStation::GetGamepad(port)} {}
|
||||
|
||||
wpi::Gamepad& CommandGamepad::GetHID() {
|
||||
return m_hid;
|
||||
CommandGenericHID& CommandGamepad::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
wpi::Gamepad& CommandGamepad::GetGamepad() {
|
||||
return *m_gamepad;
|
||||
}
|
||||
|
||||
Trigger CommandGamepad::Button(int button, wpi::EventLoop* loop) const {
|
||||
return m_hid->Button(button, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGamepad::Button(enum wpi::Gamepad::Button button,
|
||||
wpi::EventLoop* loop) const {
|
||||
return CommandGenericHID::Button(static_cast<int>(button), loop);
|
||||
return Button(static_cast<int>(button), loop);
|
||||
}
|
||||
|
||||
Trigger CommandGamepad::FaceDown(wpi::EventLoop* loop) const {
|
||||
@@ -127,57 +136,55 @@ Trigger CommandGamepad::Misc6(wpi::EventLoop* loop) const {
|
||||
Trigger CommandGamepad::LeftTrigger(double threshold,
|
||||
wpi::EventLoop* loop) const {
|
||||
return Trigger(loop, [this, threshold] {
|
||||
return m_hid.GetAxis(wpi::Gamepad::Axis::LEFT_TRIGGER) > threshold;
|
||||
return m_gamepad->GetAxis(wpi::Gamepad::Axis::LEFT_TRIGGER) > threshold;
|
||||
});
|
||||
}
|
||||
|
||||
Trigger CommandGamepad::RightTrigger(double threshold,
|
||||
wpi::EventLoop* loop) const {
|
||||
return Trigger(loop, [this, threshold] {
|
||||
return m_hid.GetAxis(wpi::Gamepad::Axis::RIGHT_TRIGGER) > threshold;
|
||||
return m_gamepad->GetAxis(wpi::Gamepad::Axis::RIGHT_TRIGGER) > threshold;
|
||||
});
|
||||
}
|
||||
|
||||
Trigger CommandGamepad::AxisLessThan(wpi::Gamepad::Axis axis, double threshold,
|
||||
wpi::EventLoop* loop) const {
|
||||
return CommandGenericHID::AxisLessThan(static_cast<int>(axis), threshold,
|
||||
loop);
|
||||
return m_hid->AxisLessThan(static_cast<int>(axis), threshold, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGamepad::AxisGreaterThan(wpi::Gamepad::Axis axis,
|
||||
double threshold,
|
||||
wpi::EventLoop* loop) const {
|
||||
return CommandGenericHID::AxisGreaterThan(static_cast<int>(axis), threshold,
|
||||
loop);
|
||||
return m_hid->AxisGreaterThan(static_cast<int>(axis), threshold, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGamepad::AxisMagnitudeGreaterThan(wpi::Gamepad::Axis axis,
|
||||
double threshold,
|
||||
wpi::EventLoop* loop) const {
|
||||
return CommandGenericHID::AxisMagnitudeGreaterThan(static_cast<int>(axis),
|
||||
threshold, loop);
|
||||
return m_hid->AxisMagnitudeGreaterThan(static_cast<int>(axis), threshold,
|
||||
loop);
|
||||
}
|
||||
|
||||
double CommandGamepad::GetLeftX() const {
|
||||
return m_hid.GetLeftX();
|
||||
return m_gamepad->GetLeftX();
|
||||
}
|
||||
|
||||
double CommandGamepad::GetLeftY() const {
|
||||
return m_hid.GetLeftY();
|
||||
return m_gamepad->GetLeftY();
|
||||
}
|
||||
|
||||
double CommandGamepad::GetRightX() const {
|
||||
return m_hid.GetRightX();
|
||||
return m_gamepad->GetRightX();
|
||||
}
|
||||
|
||||
double CommandGamepad::GetRightY() const {
|
||||
return m_hid.GetRightY();
|
||||
return m_gamepad->GetRightY();
|
||||
}
|
||||
|
||||
double CommandGamepad::GetLeftTriggerAxis() const {
|
||||
return m_hid.GetLeftTriggerAxis();
|
||||
return m_gamepad->GetLeftTriggerAxis();
|
||||
}
|
||||
|
||||
double CommandGamepad::GetRightTriggerAxis() const {
|
||||
return m_hid.GetRightTriggerAxis();
|
||||
return m_gamepad->GetRightTriggerAxis();
|
||||
}
|
||||
|
||||
@@ -4,16 +4,41 @@
|
||||
|
||||
#include "wpi/commands2/button/CommandGenericHID.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
using namespace wpi::cmd;
|
||||
|
||||
CommandGenericHID::CommandGenericHID(int port) : m_hid{port} {}
|
||||
namespace {
|
||||
std::mutex hidsMutex;
|
||||
std::array<std::unique_ptr<CommandGenericHID>,
|
||||
wpi::internal::DriverStationBackend::JOYSTICK_PORTS>
|
||||
hids;
|
||||
} // namespace
|
||||
|
||||
CommandGenericHID::CommandGenericHID(int port)
|
||||
: CommandGenericHID{wpi::DriverStation::GetGenericHID(port)} {}
|
||||
|
||||
CommandGenericHID::CommandGenericHID(wpi::GenericHID& hid) : m_hid{&hid} {}
|
||||
|
||||
CommandGenericHID& CommandGenericHID::GetCommandGenericHID(int port) {
|
||||
auto& hid = wpi::DriverStation::GetGenericHID(port);
|
||||
std::scoped_lock lock{hidsMutex};
|
||||
|
||||
if (!hids[port]) {
|
||||
hids[port] = std::make_unique<CommandGenericHID>(hid);
|
||||
}
|
||||
|
||||
return *hids[port];
|
||||
}
|
||||
|
||||
wpi::GenericHID& CommandGenericHID::GetHID() {
|
||||
return m_hid;
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::Button(int button, wpi::EventLoop* loop) const {
|
||||
return Trigger(loop, [this, button] { return m_hid.GetRawButton(button); });
|
||||
return Trigger(loop, [this, button] { return m_hid->GetRawButton(button); });
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POV(wpi::POVDirection angle,
|
||||
@@ -24,7 +49,7 @@ Trigger CommandGenericHID::POV(wpi::POVDirection angle,
|
||||
Trigger CommandGenericHID::POV(int pov, wpi::POVDirection angle,
|
||||
wpi::EventLoop* loop) const {
|
||||
return Trigger(loop,
|
||||
[this, pov, angle] { return m_hid.GetPOV(pov) == angle; });
|
||||
[this, pov, angle] { return m_hid->GetPOV(pov) == angle; });
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVUp(wpi::EventLoop* loop) const {
|
||||
@@ -66,29 +91,29 @@ Trigger CommandGenericHID::POVCenter(wpi::EventLoop* loop) const {
|
||||
Trigger CommandGenericHID::AxisLessThan(int axis, double threshold,
|
||||
wpi::EventLoop* loop) const {
|
||||
return Trigger(loop, [this, axis, threshold]() {
|
||||
return m_hid.GetRawAxis(axis) < threshold;
|
||||
return m_hid->GetRawAxis(axis) < threshold;
|
||||
});
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::AxisGreaterThan(int axis, double threshold,
|
||||
wpi::EventLoop* loop) const {
|
||||
return Trigger(loop, [this, axis, threshold]() {
|
||||
return m_hid.GetRawAxis(axis) > threshold;
|
||||
return m_hid->GetRawAxis(axis) > threshold;
|
||||
});
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::AxisMagnitudeGreaterThan(
|
||||
int axis, double threshold, wpi::EventLoop* loop) const {
|
||||
return Trigger(loop, [this, axis, threshold]() {
|
||||
return std::abs(m_hid.GetRawAxis(axis)) > threshold;
|
||||
return std::abs(m_hid->GetRawAxis(axis)) > threshold;
|
||||
});
|
||||
}
|
||||
|
||||
void CommandGenericHID::SetRumble(wpi::GenericHID::RumbleType type,
|
||||
double value) {
|
||||
m_hid.SetRumble(type, value);
|
||||
m_hid->SetRumble(type, value);
|
||||
}
|
||||
|
||||
bool CommandGenericHID::IsConnected() const {
|
||||
return m_hid.IsConnected();
|
||||
return m_hid->IsConnected();
|
||||
}
|
||||
|
||||
@@ -7,22 +7,27 @@
|
||||
using namespace wpi::cmd;
|
||||
|
||||
CommandJoystick::CommandJoystick(int port)
|
||||
: CommandGenericHID(port), m_hid{wpi::Joystick(port)} {}
|
||||
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)},
|
||||
m_joystick{wpi::DriverStation::GetGenericHID(port)} {}
|
||||
|
||||
wpi::Joystick& CommandJoystick::GetHID() {
|
||||
return m_hid;
|
||||
CommandGenericHID& CommandJoystick::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
wpi::Joystick& CommandJoystick::GetJoystick() {
|
||||
return m_joystick;
|
||||
}
|
||||
|
||||
Trigger CommandJoystick::Trigger(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::Joystick::ButtonType::kTriggerButton, loop);
|
||||
return m_hid->Button(wpi::Joystick::ButtonType::kTriggerButton, loop);
|
||||
}
|
||||
|
||||
Trigger CommandJoystick::Top(wpi::EventLoop* loop) const {
|
||||
return Button(wpi::Joystick::ButtonType::kTopButton, loop);
|
||||
return m_hid->Button(wpi::Joystick::ButtonType::kTopButton, loop);
|
||||
}
|
||||
|
||||
double CommandJoystick::GetMagnitude() const {
|
||||
return m_hid.GetMagnitude();
|
||||
return m_joystick.GetMagnitude();
|
||||
}
|
||||
|
||||
wpi::units::radian_t CommandJoystick::GetDirection() const {
|
||||
@@ -34,5 +39,5 @@ wpi::units::radian_t CommandJoystick::GetDirection() const {
|
||||
//
|
||||
// It's rotated 90 degrees CCW (y is negated and the arguments are reversed)
|
||||
// so that 0 radians is forward.
|
||||
return m_hid.GetDirection();
|
||||
return m_joystick.GetDirection();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace wpi::cmd {
|
||||
*
|
||||
* @see wpi::Gamepad
|
||||
*/
|
||||
class CommandGamepad : public CommandGenericHID {
|
||||
class CommandGamepad {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -26,11 +26,31 @@ class CommandGamepad : public CommandGenericHID {
|
||||
explicit CommandGamepad(int port);
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
wpi::Gamepad& GetHID();
|
||||
CommandGenericHID& GetHID();
|
||||
|
||||
/**
|
||||
* Get the underlying Gamepad object.
|
||||
*
|
||||
* @return the wrapped Gamepad object
|
||||
*/
|
||||
wpi::Gamepad& GetGamepad();
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
*
|
||||
* @param button the button index
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the button's digital signal attached
|
||||
* to the given loop.
|
||||
*/
|
||||
Trigger Button(int button,
|
||||
wpi::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
@@ -490,6 +510,7 @@ class CommandGamepad : public CommandGenericHID {
|
||||
double GetRightTriggerAxis() const;
|
||||
|
||||
private:
|
||||
wpi::Gamepad m_hid;
|
||||
CommandGenericHID* m_hid;
|
||||
wpi::Gamepad* m_gamepad;
|
||||
};
|
||||
} // namespace wpi::cmd
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "wpi/commands2/CommandScheduler.hpp"
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/driverstation/POVDirection.hpp"
|
||||
#include "wpi/driverstation/internal/DriverStationBackend.hpp"
|
||||
@@ -18,7 +19,7 @@ namespace wpi::cmd {
|
||||
*
|
||||
* @see GenericHID
|
||||
*/
|
||||
class CommandGenericHID {
|
||||
class CommandGenericHID final {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a device.
|
||||
@@ -28,6 +29,24 @@ class CommandGenericHID {
|
||||
*/
|
||||
explicit CommandGenericHID(int port);
|
||||
|
||||
/**
|
||||
* Construct an instance of a device with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this command HID.
|
||||
*/
|
||||
explicit CommandGenericHID(wpi::GenericHID& hid);
|
||||
|
||||
/**
|
||||
* Gets the CommandGenericHID object for the given port. CommandGenericHID
|
||||
* objects are cached, so this will always return the same object for the same
|
||||
* port.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the device is
|
||||
* plugged into.
|
||||
* @return The CommandGenericHID object for the given port.
|
||||
*/
|
||||
static CommandGenericHID& GetCommandGenericHID(int port);
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
@@ -259,6 +278,6 @@ class CommandGenericHID {
|
||||
bool IsConnected() const;
|
||||
|
||||
private:
|
||||
wpi::GenericHID m_hid;
|
||||
wpi::GenericHID* m_hid;
|
||||
};
|
||||
} // namespace wpi::cmd
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace wpi::cmd {
|
||||
*
|
||||
* @see wpi::Joystick
|
||||
*/
|
||||
class CommandJoystick : public CommandGenericHID {
|
||||
class CommandJoystick {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -26,11 +26,18 @@ class CommandJoystick : public CommandGenericHID {
|
||||
explicit CommandJoystick(int port);
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
wpi::Joystick& GetHID();
|
||||
CommandGenericHID& GetHID();
|
||||
|
||||
/**
|
||||
* Get the underlying Joystick object.
|
||||
*
|
||||
* @return the wrapped Joystick object
|
||||
*/
|
||||
wpi::Joystick& GetJoystick();
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the trigger button's digital signal.
|
||||
@@ -72,6 +79,7 @@ class CommandJoystick : public CommandGenericHID {
|
||||
wpi::units::radian_t GetDirection() const;
|
||||
|
||||
private:
|
||||
wpi::Joystick m_hid;
|
||||
CommandGenericHID* m_hid;
|
||||
wpi::Joystick m_joystick;
|
||||
};
|
||||
} // namespace wpi::cmd
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/driverstation/HIDDevice.hpp"
|
||||
|
||||
namespace wpi::cmd {
|
||||
/**
|
||||
@@ -27,5 +28,14 @@ class JoystickButton : public Trigger {
|
||||
: Trigger([joystick, buttonNumber] {
|
||||
return joystick->GetRawButton(buttonNumber);
|
||||
}) {}
|
||||
|
||||
/**
|
||||
* Creates a JoystickButton that commands can be bound to.
|
||||
*
|
||||
* @param joystick The HID device on which the button is located.
|
||||
* @param buttonNumber The number of the button on the HID device.
|
||||
*/
|
||||
explicit JoystickButton(wpi::HIDDevice* joystick, int buttonNumber)
|
||||
: JoystickButton(&joystick->GetHID(), buttonNumber) {}
|
||||
};
|
||||
} // namespace wpi::cmd
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/driverstation/HIDDevice.hpp"
|
||||
#include "wpi/driverstation/POVDirection.hpp"
|
||||
|
||||
namespace wpi::cmd {
|
||||
@@ -31,5 +32,16 @@ class POVButton : public Trigger {
|
||||
: Trigger([joystick, angle, povNumber] {
|
||||
return joystick->GetPOV(povNumber) == angle;
|
||||
}) {}
|
||||
|
||||
/**
|
||||
* Creates a POVButton that commands can be bound to.
|
||||
*
|
||||
* @param joystick The HID device on which the POV is located.
|
||||
* @param angle The angle of the POV corresponding to a button press.
|
||||
* @param povNumber The number of the POV on the HID device.
|
||||
*/
|
||||
POVButton(wpi::HIDDevice* joystick, wpi::POVDirection angle,
|
||||
int povNumber = 0)
|
||||
: POVButton(&joystick->GetHID(), angle, povNumber) {}
|
||||
};
|
||||
} // namespace wpi::cmd
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from .commandgenerichid import CommandGenericHID
|
||||
from .commandgamepad import CommandGamepad
|
||||
from .commandjoystick import CommandJoystick
|
||||
from .commandnidsps4controller import CommandNiDsPS4Controller
|
||||
from .commandnidsxboxcontroller import CommandNiDsXboxController
|
||||
@@ -10,6 +11,7 @@ from .trigger import Trigger
|
||||
__all__ = [
|
||||
"Trigger",
|
||||
"CommandGenericHID",
|
||||
"CommandGamepad",
|
||||
"CommandJoystick",
|
||||
"CommandNiDsPS4Controller",
|
||||
"CommandNiDsXboxController",
|
||||
|
||||
190
commandsv2/src/main/python/commands2/button/commandgamepad.py
Normal file
190
commandsv2/src/main/python/commands2/button/commandgamepad.py
Normal file
@@ -0,0 +1,190 @@
|
||||
# validated: 2024-01-20 DS 92149efa11fa button/CommandGamepad.java
|
||||
from typing import Optional
|
||||
|
||||
from wpilib import DriverStation, EventLoop, Gamepad
|
||||
|
||||
from .commandgenerichid import CommandGenericHID
|
||||
from .trigger import Trigger
|
||||
|
||||
|
||||
def _enum_value(value) -> int:
|
||||
try:
|
||||
return int(value)
|
||||
except TypeError:
|
||||
return value.value
|
||||
|
||||
|
||||
class CommandGamepad:
|
||||
"""
|
||||
A version of :class:`wpilib.Gamepad` with :class:`.Trigger` factories for command-based.
|
||||
"""
|
||||
|
||||
_hid: CommandGenericHID
|
||||
_gamepad: Gamepad
|
||||
|
||||
def __init__(self, port: int):
|
||||
"""
|
||||
Construct an instance of a controller.
|
||||
|
||||
:param port: The port index on the Driver Station that the controller is plugged into.
|
||||
"""
|
||||
|
||||
self._hid = CommandGenericHID.getCommandGenericHID(port)
|
||||
self._gamepad = DriverStation.getGamepad(port)
|
||||
|
||||
def __getattr__(self, name: str):
|
||||
return getattr(self._hid, name)
|
||||
|
||||
def getHID(self) -> CommandGenericHID:
|
||||
"""
|
||||
Get the underlying CommandGenericHID object.
|
||||
|
||||
:returns: the wrapped CommandGenericHID object
|
||||
"""
|
||||
return self._hid
|
||||
|
||||
def getGamepad(self) -> Gamepad:
|
||||
"""
|
||||
Get the underlying Gamepad object.
|
||||
|
||||
:returns: the wrapped Gamepad object
|
||||
"""
|
||||
return self._gamepad
|
||||
|
||||
def button(self, button, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
"""
|
||||
Constructs an event instance around this button's digital signal.
|
||||
|
||||
:param button: the button index or :class:`wpilib.Gamepad.Button`
|
||||
:param loop: the event loop instance to attach the event to
|
||||
"""
|
||||
return self._hid.button(_enum_value(button), loop)
|
||||
|
||||
def faceDown(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.FACE_DOWN, loop)
|
||||
|
||||
def faceRight(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.FACE_RIGHT, loop)
|
||||
|
||||
def faceLeft(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.FACE_LEFT, loop)
|
||||
|
||||
def faceUp(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.FACE_UP, loop)
|
||||
|
||||
def back(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.BACK, loop)
|
||||
|
||||
def guide(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.GUIDE, loop)
|
||||
|
||||
def start(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.START, loop)
|
||||
|
||||
def leftStick(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.LEFT_STICK, loop)
|
||||
|
||||
def rightStick(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.RIGHT_STICK, loop)
|
||||
|
||||
def leftBumper(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.LEFT_BUMPER, loop)
|
||||
|
||||
def rightBumper(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.RIGHT_BUMPER, loop)
|
||||
|
||||
def dpadUp(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.DPAD_UP, loop)
|
||||
|
||||
def dpadDown(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.DPAD_DOWN, loop)
|
||||
|
||||
def dpadLeft(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.DPAD_LEFT, loop)
|
||||
|
||||
def dpadRight(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.DPAD_RIGHT, loop)
|
||||
|
||||
def misc1(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.MISC_1, loop)
|
||||
|
||||
def rightPaddle1(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.RIGHT_PADDLE_1, loop)
|
||||
|
||||
def leftPaddle1(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.LEFT_PADDLE_1, loop)
|
||||
|
||||
def rightPaddle2(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.RIGHT_PADDLE_2, loop)
|
||||
|
||||
def leftPaddle2(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.LEFT_PADDLE_2, loop)
|
||||
|
||||
def touchpad(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.TOUCHPAD, loop)
|
||||
|
||||
def misc2(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.MISC_2, loop)
|
||||
|
||||
def misc3(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.MISC_3, loop)
|
||||
|
||||
def misc4(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.MISC_4, loop)
|
||||
|
||||
def misc5(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.MISC_5, loop)
|
||||
|
||||
def misc6(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
return self.button(Gamepad.Button.MISC_6, loop)
|
||||
|
||||
def leftTrigger(
|
||||
self, threshold: float = 0.5, loop: Optional[EventLoop] = None
|
||||
) -> Trigger:
|
||||
return self.axisGreaterThan(Gamepad.Axis.LEFT_TRIGGER, threshold, loop)
|
||||
|
||||
def rightTrigger(
|
||||
self, threshold: float = 0.5, loop: Optional[EventLoop] = None
|
||||
) -> Trigger:
|
||||
return self.axisGreaterThan(Gamepad.Axis.RIGHT_TRIGGER, threshold, loop)
|
||||
|
||||
def axisLessThan(
|
||||
self, axis, threshold: float, loop: Optional[EventLoop] = None
|
||||
) -> Trigger:
|
||||
return self._hid.axisLessThan(_enum_value(axis), threshold, loop)
|
||||
|
||||
def axisGreaterThan(
|
||||
self, axis, threshold: float, loop: Optional[EventLoop] = None
|
||||
) -> Trigger:
|
||||
return self._hid.axisGreaterThan(_enum_value(axis), threshold, loop)
|
||||
|
||||
def axisMagnitudeGreaterThan(
|
||||
self, axis, threshold: float, loop: Optional[EventLoop] = None
|
||||
) -> Trigger:
|
||||
return self._hid.axisMagnitudeGreaterThan(_enum_value(axis), threshold, loop)
|
||||
|
||||
def getAxis(self, axis) -> float:
|
||||
"""
|
||||
Get the value of the axis.
|
||||
|
||||
:param axis: the axis index or :class:`wpilib.Gamepad.Axis`
|
||||
"""
|
||||
return self._hid.getRawAxis(_enum_value(axis))
|
||||
|
||||
def getLeftX(self) -> float:
|
||||
return self._gamepad.getLeftX()
|
||||
|
||||
def getLeftY(self) -> float:
|
||||
return self._gamepad.getLeftY()
|
||||
|
||||
def getRightX(self) -> float:
|
||||
return self._gamepad.getRightX()
|
||||
|
||||
def getRightY(self) -> float:
|
||||
return self._gamepad.getRightY()
|
||||
|
||||
def getLeftTriggerAxis(self) -> float:
|
||||
return self._gamepad.getLeftTriggerAxis()
|
||||
|
||||
def getRightTriggerAxis(self) -> float:
|
||||
return self._gamepad.getRightTriggerAxis()
|
||||
@@ -1,24 +1,41 @@
|
||||
# validated: 2024-01-20 DS 92149efa11fa button/CommandGenericHID.java
|
||||
from typing import Optional
|
||||
import threading
|
||||
from typing import ClassVar, Optional, final
|
||||
|
||||
from wpilib import EventLoop, GenericHID
|
||||
from wpilib import DriverStation, EventLoop, GenericHID
|
||||
|
||||
from ..commandscheduler import CommandScheduler
|
||||
from .trigger import Trigger
|
||||
|
||||
|
||||
@final
|
||||
class CommandGenericHID:
|
||||
"""
|
||||
A version of :class:`wpilib.GenericHID` with :class:`.Trigger` factories for command-based.
|
||||
"""
|
||||
|
||||
_hids: ClassVar[dict[int, "CommandGenericHID"]] = {}
|
||||
_hids_lock = threading.Lock()
|
||||
|
||||
def __init__(self, port: int):
|
||||
"""
|
||||
Construct an instance of a device.
|
||||
|
||||
:param port: The port on the Driver Station that the device is plugged into.
|
||||
"""
|
||||
self._hid = GenericHID(port)
|
||||
self._hid = DriverStation.getGenericHID(port)
|
||||
|
||||
@classmethod
|
||||
def getCommandGenericHID(cls, port: int) -> "CommandGenericHID":
|
||||
"""
|
||||
Gets the CommandGenericHID object for the given port.
|
||||
"""
|
||||
with cls._hids_lock:
|
||||
hid = cls._hids.get(port)
|
||||
if hid is None:
|
||||
hid = cls(port)
|
||||
cls._hids[port] = hid
|
||||
return hid
|
||||
|
||||
def getHID(self) -> GenericHID:
|
||||
"""
|
||||
@@ -221,3 +238,8 @@ class CommandGenericHID:
|
||||
:returns: True if the HID is connected.
|
||||
"""
|
||||
return self._hid.isConnected()
|
||||
|
||||
|
||||
def _resetCommandGenericHIDData() -> None:
|
||||
with CommandGenericHID._hids_lock:
|
||||
CommandGenericHID._hids.clear()
|
||||
|
||||
@@ -8,12 +8,13 @@ from .commandgenerichid import CommandGenericHID
|
||||
from .trigger import Trigger
|
||||
|
||||
|
||||
class CommandJoystick(CommandGenericHID):
|
||||
class CommandJoystick:
|
||||
"""
|
||||
A version of :class:`wpilib.Joystick` with :class:`.Trigger` factories for command-based.
|
||||
"""
|
||||
|
||||
_hid: Joystick
|
||||
_hid: CommandGenericHID
|
||||
_joystick: Joystick
|
||||
|
||||
def __init__(self, port: int):
|
||||
"""
|
||||
@@ -22,17 +23,28 @@ class CommandJoystick(CommandGenericHID):
|
||||
:param port: The port index on the Driver Station that the controller is plugged into.
|
||||
"""
|
||||
|
||||
super().__init__(port)
|
||||
self._hid = Joystick(port)
|
||||
self._hid = CommandGenericHID.getCommandGenericHID(port)
|
||||
self._joystick = Joystick(self._hid.getHID())
|
||||
|
||||
def getHID(self) -> Joystick:
|
||||
def __getattr__(self, name: str):
|
||||
return getattr(self._hid, name)
|
||||
|
||||
def getHID(self) -> CommandGenericHID:
|
||||
"""
|
||||
Get the underlying GenericHID object.
|
||||
Get the underlying CommandGenericHID object.
|
||||
|
||||
:returns: the wrapped GenericHID object
|
||||
:returns: the wrapped CommandGenericHID object
|
||||
"""
|
||||
return self._hid
|
||||
|
||||
def getJoystick(self) -> Joystick:
|
||||
"""
|
||||
Get the underlying Joystick object.
|
||||
|
||||
:returns: the wrapped Joystick object
|
||||
"""
|
||||
return self._joystick
|
||||
|
||||
def trigger(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
"""
|
||||
Constructs an event instance around the trigger button's digital signal.
|
||||
@@ -45,7 +57,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
"""
|
||||
if loop is None:
|
||||
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
|
||||
return Trigger(loop, lambda: self._hid.getTrigger())
|
||||
return Trigger(loop, lambda: self._joystick.getTrigger())
|
||||
|
||||
def top(self, loop: Optional[EventLoop] = None) -> Trigger:
|
||||
"""
|
||||
@@ -59,7 +71,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
"""
|
||||
if loop is None:
|
||||
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
|
||||
return Trigger(loop, lambda: self._hid.getTop())
|
||||
return Trigger(loop, lambda: self._joystick.getTop())
|
||||
|
||||
def setXChannel(self, channel: int):
|
||||
"""
|
||||
@@ -67,7 +79,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:param channel: The channel to set the axis to.
|
||||
"""
|
||||
self._hid.setXChannel(channel)
|
||||
self._joystick.setXChannel(channel)
|
||||
|
||||
def setYChannel(self, channel: int):
|
||||
"""
|
||||
@@ -75,7 +87,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:param channel: The channel to set the axis to.
|
||||
"""
|
||||
self._hid.setYChannel(channel)
|
||||
self._joystick.setYChannel(channel)
|
||||
|
||||
def setZChannel(self, channel: int):
|
||||
"""
|
||||
@@ -83,7 +95,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:param channel: The channel to set the axis to.
|
||||
"""
|
||||
self._hid.setZChannel(channel)
|
||||
self._joystick.setZChannel(channel)
|
||||
|
||||
def setThrottleChannel(self, channel: int):
|
||||
"""
|
||||
@@ -91,7 +103,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:param channel: The channel to set the axis to.
|
||||
"""
|
||||
self._hid.setThrottleChannel(channel)
|
||||
self._joystick.setThrottleChannel(channel)
|
||||
|
||||
def setTwistChannel(self, channel: int):
|
||||
"""
|
||||
@@ -99,7 +111,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:param channel: The channel to set the axis to.
|
||||
"""
|
||||
self._hid.setTwistChannel(channel)
|
||||
self._joystick.setTwistChannel(channel)
|
||||
|
||||
def getXChannel(self) -> int:
|
||||
"""
|
||||
@@ -107,7 +119,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:returns: The channel for the axis.
|
||||
"""
|
||||
return self._hid.getXChannel()
|
||||
return self._joystick.getXChannel()
|
||||
|
||||
def getYChannel(self) -> int:
|
||||
"""
|
||||
@@ -115,7 +127,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:returns: The channel for the axis.
|
||||
"""
|
||||
return self._hid.getYChannel()
|
||||
return self._joystick.getYChannel()
|
||||
|
||||
def getZChannel(self) -> int:
|
||||
"""
|
||||
@@ -123,7 +135,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:returns: The channel for the axis.
|
||||
"""
|
||||
return self._hid.getZChannel()
|
||||
return self._joystick.getZChannel()
|
||||
|
||||
def getTwistChannel(self) -> int:
|
||||
"""
|
||||
@@ -131,7 +143,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:returns: The channel for the axis.
|
||||
"""
|
||||
return self._hid.getTwistChannel()
|
||||
return self._joystick.getTwistChannel()
|
||||
|
||||
def getThrottleChannel(self) -> int:
|
||||
"""
|
||||
@@ -139,7 +151,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:returns: The channel for the axis.
|
||||
"""
|
||||
return self._hid.getThrottleChannel()
|
||||
return self._joystick.getThrottleChannel()
|
||||
|
||||
def getX(self) -> float:
|
||||
"""
|
||||
@@ -150,7 +162,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:returns: the x position
|
||||
"""
|
||||
return self._hid.getX()
|
||||
return self._joystick.getX()
|
||||
|
||||
def getY(self) -> float:
|
||||
"""
|
||||
@@ -161,7 +173,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:returns: the y position
|
||||
"""
|
||||
return self._hid.getY()
|
||||
return self._joystick.getY()
|
||||
|
||||
def getZ(self) -> float:
|
||||
"""
|
||||
@@ -169,7 +181,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:returns: the z position
|
||||
"""
|
||||
return self._hid.getZ()
|
||||
return self._joystick.getZ()
|
||||
|
||||
def getTwist(self) -> float:
|
||||
"""
|
||||
@@ -178,7 +190,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:returns: The Twist value of the joystick.
|
||||
"""
|
||||
return self._hid.getTwist()
|
||||
return self._joystick.getTwist()
|
||||
|
||||
def getThrottle(self) -> float:
|
||||
"""
|
||||
@@ -187,7 +199,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:returns: The Throttle value of the joystick.
|
||||
"""
|
||||
return self._hid.getThrottle()
|
||||
return self._joystick.getThrottle()
|
||||
|
||||
def getMagnitude(self) -> float:
|
||||
"""
|
||||
@@ -196,7 +208,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:returns: The magnitude of the direction vector
|
||||
"""
|
||||
return self._hid.getMagnitude()
|
||||
return self._joystick.getMagnitude()
|
||||
|
||||
def getDirectionRadians(self) -> float:
|
||||
"""
|
||||
@@ -213,7 +225,7 @@ class CommandJoystick(CommandGenericHID):
|
||||
#
|
||||
# It's rotated 90 degrees CCW (y is negated and the arguments are reversed)
|
||||
# so that 0 radians is forward.
|
||||
return self._hid.getDirectionRadians()
|
||||
return self._joystick.getDirectionRadians()
|
||||
|
||||
def getDirectionDegrees(self) -> float:
|
||||
"""
|
||||
@@ -222,4 +234,4 @@ class CommandJoystick(CommandGenericHID):
|
||||
|
||||
:returns: The direction of the vector in degrees
|
||||
"""
|
||||
return self._hid.getDirectionDegrees()
|
||||
return self._joystick.getDirectionDegrees()
|
||||
|
||||
@@ -8,11 +8,12 @@ from .commandgenerichid import CommandGenericHID
|
||||
from .trigger import Trigger
|
||||
|
||||
|
||||
class CommandNiDsPS4Controller(CommandGenericHID):
|
||||
class CommandNiDsPS4Controller:
|
||||
"""
|
||||
A version of NI DS PS4Controller with Trigger factories for command-based.
|
||||
"""
|
||||
|
||||
_command_hid: CommandGenericHID
|
||||
_hid: NiDsPS4Controller
|
||||
|
||||
def __init__(self, port: int):
|
||||
@@ -21,14 +22,25 @@ class CommandNiDsPS4Controller(CommandGenericHID):
|
||||
|
||||
:param port: The port index on the Driver Station that the device is plugged into.
|
||||
"""
|
||||
super().__init__(port)
|
||||
self._hid = NiDsPS4Controller(port)
|
||||
self._command_hid = CommandGenericHID.getCommandGenericHID(port)
|
||||
self._hid = NiDsPS4Controller(self._command_hid.getHID())
|
||||
|
||||
def getHID(self) -> NiDsPS4Controller:
|
||||
def __getattr__(self, name: str):
|
||||
return getattr(self._command_hid, name)
|
||||
|
||||
def getHID(self) -> CommandGenericHID:
|
||||
"""
|
||||
Get the underlying GenericHID object.
|
||||
Get the underlying CommandGenericHID object.
|
||||
|
||||
:returns: the wrapped GenericHID object
|
||||
:returns: the wrapped CommandGenericHID object
|
||||
"""
|
||||
return self._command_hid
|
||||
|
||||
def getNiDsPS4Controller(self) -> NiDsPS4Controller:
|
||||
"""
|
||||
Get the underlying NiDsPS4Controller object.
|
||||
|
||||
:returns: the wrapped NiDsPS4Controller object
|
||||
"""
|
||||
return self._hid
|
||||
|
||||
|
||||
@@ -8,11 +8,12 @@ from .commandgenerichid import CommandGenericHID
|
||||
from .trigger import Trigger
|
||||
|
||||
|
||||
class CommandNiDsXboxController(CommandGenericHID):
|
||||
class CommandNiDsXboxController:
|
||||
"""
|
||||
A version of NI DS XboxController with Trigger factories for command-based.
|
||||
"""
|
||||
|
||||
_command_hid: CommandGenericHID
|
||||
_hid: NiDsXboxController
|
||||
|
||||
def __init__(self, port: int):
|
||||
@@ -21,14 +22,25 @@ class CommandNiDsXboxController(CommandGenericHID):
|
||||
|
||||
:param port: The port index on the Driver Station that the controller is plugged into.
|
||||
"""
|
||||
super().__init__(port)
|
||||
self._hid = NiDsXboxController(port)
|
||||
self._command_hid = CommandGenericHID.getCommandGenericHID(port)
|
||||
self._hid = NiDsXboxController(self._command_hid.getHID())
|
||||
|
||||
def getHID(self) -> NiDsXboxController:
|
||||
def __getattr__(self, name: str):
|
||||
return getattr(self._command_hid, name)
|
||||
|
||||
def getHID(self) -> CommandGenericHID:
|
||||
"""
|
||||
Get the underlying GenericHID object.
|
||||
Get the underlying CommandGenericHID object.
|
||||
|
||||
:returns: the wrapped GenericHID object
|
||||
:returns: the wrapped CommandGenericHID object
|
||||
"""
|
||||
return self._command_hid
|
||||
|
||||
def getNiDsXboxController(self) -> NiDsXboxController:
|
||||
"""
|
||||
Get the underlying NiDsXboxController object.
|
||||
|
||||
:returns: the wrapped NiDsXboxController object
|
||||
"""
|
||||
return self._hid
|
||||
|
||||
|
||||
54
commandsv2/src/test/python/test_commandgenerichid.py
Normal file
54
commandsv2/src/test/python/test_commandgenerichid.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import threading
|
||||
import time
|
||||
|
||||
from commands2.button.commandgenerichid import (
|
||||
CommandGenericHID,
|
||||
_resetCommandGenericHIDData,
|
||||
)
|
||||
|
||||
|
||||
def test_get_command_generic_hid_is_thread_safe(monkeypatch):
|
||||
monkeypatch.setattr(CommandGenericHID, "_hids", {})
|
||||
|
||||
init_count = 0
|
||||
init_count_lock = threading.Lock()
|
||||
|
||||
def fake_init(self, port):
|
||||
nonlocal init_count
|
||||
with init_count_lock:
|
||||
init_count += 1
|
||||
time.sleep(0.02)
|
||||
self._hid = object()
|
||||
|
||||
monkeypatch.setattr(CommandGenericHID, "__init__", fake_init)
|
||||
|
||||
thread_count = 16
|
||||
start = threading.Barrier(thread_count)
|
||||
results = [None] * thread_count
|
||||
exceptions = []
|
||||
|
||||
def worker(index):
|
||||
try:
|
||||
start.wait()
|
||||
results[index] = CommandGenericHID.getCommandGenericHID(0)
|
||||
except Exception as exc:
|
||||
exceptions.append(exc)
|
||||
|
||||
threads = [threading.Thread(target=worker, args=(i,)) for i in range(thread_count)]
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
|
||||
assert not exceptions
|
||||
assert init_count == 1
|
||||
assert len({id(result) for result in results}) == 1
|
||||
|
||||
|
||||
def test_reset_command_generic_hid_data(monkeypatch):
|
||||
first = object()
|
||||
monkeypatch.setattr(CommandGenericHID, "_hids", {0: first})
|
||||
|
||||
_resetCommandGenericHIDData()
|
||||
|
||||
assert CommandGenericHID._hids == {}
|
||||
@@ -19,8 +19,9 @@ import org.wpilib.event.EventLoop;
|
||||
* @see {{ ConsoleName }}Controller
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
private final {{ ConsoleName }}Controller m_hid;
|
||||
public class Command{{ ConsoleName }}Controller {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final {{ ConsoleName }}Controller m_controller;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller. Commands bound to buttons on the controller will be
|
||||
@@ -29,8 +30,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public Command{{ ConsoleName }}Controller(int port) {
|
||||
super(port);
|
||||
m_hid = new {{ ConsoleName }}Controller(port);
|
||||
this(Scheduler.getDefault(), port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,19 +41,27 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public Command{{ ConsoleName }}Controller(Scheduler scheduler, int port) {
|
||||
super(scheduler, port);
|
||||
m_hid = new {{ ConsoleName }}Controller(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(scheduler, port);
|
||||
m_controller = new {{ ConsoleName }}Controller(m_hid.getHID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public {{ ConsoleName }}Controller getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying {{ ConsoleName }}Controller object.
|
||||
*
|
||||
* @return the wrapped {{ ConsoleName }}Controller object
|
||||
*/
|
||||
public {{ ConsoleName }}Controller get{{ ConsoleName }}Controller() {
|
||||
return m_controller;
|
||||
}
|
||||
{% for button in buttons %}
|
||||
/**
|
||||
* Constructs a Trigger instance around the {{ button.DocName|default(button.name) }} button's digital signal.
|
||||
@@ -65,7 +73,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
* @see #{{ button.name }}(EventLoop)
|
||||
*/
|
||||
public Trigger {{ button.name }}() {
|
||||
return {{ button.name }}(getScheduler().getDefaultEventLoop());
|
||||
return {{ button.name }}(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +84,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger {{ button.name }}(EventLoop loop) {
|
||||
return button({{ ConsoleName }}Controller.Button.k{{ capitalize_first(button.name) }}.value, loop);
|
||||
return m_hid.button({{ ConsoleName }}Controller.Button.k{{ capitalize_first(button.name) }}.value, loop);
|
||||
}
|
||||
{% endfor -%}
|
||||
{% for trigger in triggers -%}
|
||||
@@ -92,7 +100,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
* threshold, attached to the given event loop
|
||||
*/
|
||||
public Trigger {{ trigger.name }}(double threshold, EventLoop loop) {
|
||||
return axisGreaterThan({{ ConsoleName }}Controller.Axis.k{{ capitalize_first(trigger.name) }}.value, threshold, loop);
|
||||
return m_hid.axisGreaterThan({{ ConsoleName }}Controller.Axis.k{{ capitalize_first(trigger.name) }}.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +115,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
* Scheduler#getDefault default scheduler} if a scheduler was not explicitly provided.
|
||||
*/
|
||||
public Trigger {{ trigger.name }}(double threshold) {
|
||||
return {{ trigger.name }}(threshold, getScheduler().getDefaultEventLoop());
|
||||
return {{ trigger.name }}(threshold, m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +139,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double get{{ stick.NameParts|map("capitalize")|join }}() {
|
||||
return m_hid.get{{ stick.NameParts|map("capitalize")|join }}();
|
||||
return m_controller.get{{ stick.NameParts|map("capitalize")|join }}();
|
||||
}
|
||||
{% endfor -%}
|
||||
{% for trigger in triggers %}
|
||||
@@ -142,7 +150,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double get{{ capitalize_first(trigger.name) }}Axis() {
|
||||
return m_hid.get{{ capitalize_first(trigger.name) }}Axis();
|
||||
return m_controller.get{{ capitalize_first(trigger.name) }}Axis();
|
||||
}
|
||||
{% endfor -%}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ import org.wpilib.event.EventLoop;
|
||||
* @see NiDsPS4Controller
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
private final NiDsPS4Controller m_hid;
|
||||
public class CommandNiDsPS4Controller {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final NiDsPS4Controller m_controller;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller. Commands bound to buttons on the controller will be
|
||||
@@ -27,8 +28,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandNiDsPS4Controller(int port) {
|
||||
super(port);
|
||||
m_hid = new NiDsPS4Controller(port);
|
||||
this(Scheduler.getDefault(), port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,20 +39,28 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandNiDsPS4Controller(Scheduler scheduler, int port) {
|
||||
super(scheduler, port);
|
||||
m_hid = new NiDsPS4Controller(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(scheduler, port);
|
||||
m_controller = new NiDsPS4Controller(m_hid.getHID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public NiDsPS4Controller getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying NiDsPS4Controller object.
|
||||
*
|
||||
* @return the wrapped NiDsPS4Controller object
|
||||
*/
|
||||
public NiDsPS4Controller getNiDsPS4Controller() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the square button's digital signal.
|
||||
*
|
||||
@@ -63,7 +71,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #square(EventLoop)
|
||||
*/
|
||||
public Trigger square() {
|
||||
return square(getScheduler().getDefaultEventLoop());
|
||||
return square(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +82,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger square(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kSquare.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kSquare.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +95,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #cross(EventLoop)
|
||||
*/
|
||||
public Trigger cross() {
|
||||
return cross(getScheduler().getDefaultEventLoop());
|
||||
return cross(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +106,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger cross(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kCross.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kCross.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +119,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #circle(EventLoop)
|
||||
*/
|
||||
public Trigger circle() {
|
||||
return circle(getScheduler().getDefaultEventLoop());
|
||||
return circle(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +130,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger circle(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kCircle.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kCircle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +143,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #triangle(EventLoop)
|
||||
*/
|
||||
public Trigger triangle() {
|
||||
return triangle(getScheduler().getDefaultEventLoop());
|
||||
return triangle(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +154,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger triangle(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kTriangle.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kTriangle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +167,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #L1(EventLoop)
|
||||
*/
|
||||
public Trigger L1() {
|
||||
return L1(getScheduler().getDefaultEventLoop());
|
||||
return L1(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +178,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger L1(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kL1.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kL1.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,7 +191,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #R1(EventLoop)
|
||||
*/
|
||||
public Trigger R1() {
|
||||
return R1(getScheduler().getDefaultEventLoop());
|
||||
return R1(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +202,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger R1(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kR1.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kR1.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +215,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #L2(EventLoop)
|
||||
*/
|
||||
public Trigger L2() {
|
||||
return L2(getScheduler().getDefaultEventLoop());
|
||||
return L2(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +226,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger L2(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kL2.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kL2.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,7 +239,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #R2(EventLoop)
|
||||
*/
|
||||
public Trigger R2() {
|
||||
return R2(getScheduler().getDefaultEventLoop());
|
||||
return R2(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,7 +250,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger R2(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kR2.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kR2.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,7 +263,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #share(EventLoop)
|
||||
*/
|
||||
public Trigger share() {
|
||||
return share(getScheduler().getDefaultEventLoop());
|
||||
return share(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,7 +274,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger share(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kShare.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kShare.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,7 +287,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #options(EventLoop)
|
||||
*/
|
||||
public Trigger options() {
|
||||
return options(getScheduler().getDefaultEventLoop());
|
||||
return options(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,7 +298,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger options(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kOptions.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kOptions.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,7 +311,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #L3(EventLoop)
|
||||
*/
|
||||
public Trigger L3() {
|
||||
return L3(getScheduler().getDefaultEventLoop());
|
||||
return L3(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -314,7 +322,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger L3(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kL3.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kL3.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,7 +335,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #R3(EventLoop)
|
||||
*/
|
||||
public Trigger R3() {
|
||||
return R3(getScheduler().getDefaultEventLoop());
|
||||
return R3(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,7 +346,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger R3(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kR3.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kR3.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -351,7 +359,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #PS(EventLoop)
|
||||
*/
|
||||
public Trigger PS() {
|
||||
return PS(getScheduler().getDefaultEventLoop());
|
||||
return PS(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -362,7 +370,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger PS(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kPS.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kPS.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,7 +383,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @see #touchpad(EventLoop)
|
||||
*/
|
||||
public Trigger touchpad() {
|
||||
return touchpad(getScheduler().getDefaultEventLoop());
|
||||
return touchpad(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -386,7 +394,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger touchpad(EventLoop loop) {
|
||||
return button(NiDsPS4Controller.Button.kTouchpad.value, loop);
|
||||
return m_hid.button(NiDsPS4Controller.Button.kTouchpad.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -395,7 +403,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return m_hid.getLeftX();
|
||||
return m_controller.getLeftX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -404,7 +412,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return m_hid.getLeftY();
|
||||
return m_controller.getLeftY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -413,7 +421,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return m_hid.getRightX();
|
||||
return m_controller.getRightX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -422,7 +430,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return m_hid.getRightY();
|
||||
return m_controller.getRightY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -432,7 +440,7 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getL2Axis() {
|
||||
return m_hid.getL2Axis();
|
||||
return m_controller.getL2Axis();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -442,6 +450,6 @@ public class CommandNiDsPS4Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getR2Axis() {
|
||||
return m_hid.getR2Axis();
|
||||
return m_controller.getR2Axis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ import org.wpilib.event.EventLoop;
|
||||
* @see NiDsPS5Controller
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
private final NiDsPS5Controller m_hid;
|
||||
public class CommandNiDsPS5Controller {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final NiDsPS5Controller m_controller;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller. Commands bound to buttons on the controller will be
|
||||
@@ -27,8 +28,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandNiDsPS5Controller(int port) {
|
||||
super(port);
|
||||
m_hid = new NiDsPS5Controller(port);
|
||||
this(Scheduler.getDefault(), port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,20 +39,28 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandNiDsPS5Controller(Scheduler scheduler, int port) {
|
||||
super(scheduler, port);
|
||||
m_hid = new NiDsPS5Controller(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(scheduler, port);
|
||||
m_controller = new NiDsPS5Controller(m_hid.getHID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public NiDsPS5Controller getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying NiDsPS5Controller object.
|
||||
*
|
||||
* @return the wrapped NiDsPS5Controller object
|
||||
*/
|
||||
public NiDsPS5Controller getNiDsPS5Controller() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the square button's digital signal.
|
||||
*
|
||||
@@ -63,7 +71,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #square(EventLoop)
|
||||
*/
|
||||
public Trigger square() {
|
||||
return square(getScheduler().getDefaultEventLoop());
|
||||
return square(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +82,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger square(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kSquare.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kSquare.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +95,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #cross(EventLoop)
|
||||
*/
|
||||
public Trigger cross() {
|
||||
return cross(getScheduler().getDefaultEventLoop());
|
||||
return cross(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +106,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger cross(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kCross.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kCross.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +119,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #circle(EventLoop)
|
||||
*/
|
||||
public Trigger circle() {
|
||||
return circle(getScheduler().getDefaultEventLoop());
|
||||
return circle(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +130,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger circle(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kCircle.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kCircle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +143,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #triangle(EventLoop)
|
||||
*/
|
||||
public Trigger triangle() {
|
||||
return triangle(getScheduler().getDefaultEventLoop());
|
||||
return triangle(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +154,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger triangle(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kTriangle.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kTriangle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +167,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #L1(EventLoop)
|
||||
*/
|
||||
public Trigger L1() {
|
||||
return L1(getScheduler().getDefaultEventLoop());
|
||||
return L1(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +178,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger L1(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kL1.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kL1.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,7 +191,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #R1(EventLoop)
|
||||
*/
|
||||
public Trigger R1() {
|
||||
return R1(getScheduler().getDefaultEventLoop());
|
||||
return R1(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +202,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger R1(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kR1.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kR1.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +215,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #L2(EventLoop)
|
||||
*/
|
||||
public Trigger L2() {
|
||||
return L2(getScheduler().getDefaultEventLoop());
|
||||
return L2(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +226,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger L2(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kL2.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kL2.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,7 +239,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #R2(EventLoop)
|
||||
*/
|
||||
public Trigger R2() {
|
||||
return R2(getScheduler().getDefaultEventLoop());
|
||||
return R2(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,7 +250,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger R2(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kR2.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kR2.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,7 +263,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #create(EventLoop)
|
||||
*/
|
||||
public Trigger create() {
|
||||
return create(getScheduler().getDefaultEventLoop());
|
||||
return create(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,7 +274,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger create(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kCreate.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kCreate.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,7 +287,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #options(EventLoop)
|
||||
*/
|
||||
public Trigger options() {
|
||||
return options(getScheduler().getDefaultEventLoop());
|
||||
return options(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,7 +298,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger options(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kOptions.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kOptions.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,7 +311,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #L3(EventLoop)
|
||||
*/
|
||||
public Trigger L3() {
|
||||
return L3(getScheduler().getDefaultEventLoop());
|
||||
return L3(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -314,7 +322,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger L3(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kL3.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kL3.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,7 +335,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #R3(EventLoop)
|
||||
*/
|
||||
public Trigger R3() {
|
||||
return R3(getScheduler().getDefaultEventLoop());
|
||||
return R3(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,7 +346,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger R3(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kR3.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kR3.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -351,7 +359,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #PS(EventLoop)
|
||||
*/
|
||||
public Trigger PS() {
|
||||
return PS(getScheduler().getDefaultEventLoop());
|
||||
return PS(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -362,7 +370,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger PS(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kPS.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kPS.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,7 +383,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @see #touchpad(EventLoop)
|
||||
*/
|
||||
public Trigger touchpad() {
|
||||
return touchpad(getScheduler().getDefaultEventLoop());
|
||||
return touchpad(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -386,7 +394,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger touchpad(EventLoop loop) {
|
||||
return button(NiDsPS5Controller.Button.kTouchpad.value, loop);
|
||||
return m_hid.button(NiDsPS5Controller.Button.kTouchpad.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -395,7 +403,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return m_hid.getLeftX();
|
||||
return m_controller.getLeftX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -404,7 +412,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return m_hid.getLeftY();
|
||||
return m_controller.getLeftY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -413,7 +421,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return m_hid.getRightX();
|
||||
return m_controller.getRightX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -422,7 +430,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return m_hid.getRightY();
|
||||
return m_controller.getRightY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -432,7 +440,7 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getL2Axis() {
|
||||
return m_hid.getL2Axis();
|
||||
return m_controller.getL2Axis();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -442,6 +450,6 @@ public class CommandNiDsPS5Controller extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getR2Axis() {
|
||||
return m_hid.getR2Axis();
|
||||
return m_controller.getR2Axis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ import org.wpilib.event.EventLoop;
|
||||
* @see NiDsStadiaController
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
private final NiDsStadiaController m_hid;
|
||||
public class CommandNiDsStadiaController {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final NiDsStadiaController m_controller;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller. Commands bound to buttons on the controller will be
|
||||
@@ -27,8 +28,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandNiDsStadiaController(int port) {
|
||||
super(port);
|
||||
m_hid = new NiDsStadiaController(port);
|
||||
this(Scheduler.getDefault(), port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,20 +39,28 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandNiDsStadiaController(Scheduler scheduler, int port) {
|
||||
super(scheduler, port);
|
||||
m_hid = new NiDsStadiaController(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(scheduler, port);
|
||||
m_controller = new NiDsStadiaController(m_hid.getHID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public NiDsStadiaController getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying NiDsStadiaController object.
|
||||
*
|
||||
* @return the wrapped NiDsStadiaController object
|
||||
*/
|
||||
public NiDsStadiaController getNiDsStadiaController() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the A button's digital signal.
|
||||
*
|
||||
@@ -63,7 +71,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #a(EventLoop)
|
||||
*/
|
||||
public Trigger a() {
|
||||
return a(getScheduler().getDefaultEventLoop());
|
||||
return a(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +82,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger a(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kA.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kA.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +95,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #b(EventLoop)
|
||||
*/
|
||||
public Trigger b() {
|
||||
return b(getScheduler().getDefaultEventLoop());
|
||||
return b(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +106,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger b(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kB.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kB.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +119,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #x(EventLoop)
|
||||
*/
|
||||
public Trigger x() {
|
||||
return x(getScheduler().getDefaultEventLoop());
|
||||
return x(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +130,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger x(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kX.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kX.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +143,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #y(EventLoop)
|
||||
*/
|
||||
public Trigger y() {
|
||||
return y(getScheduler().getDefaultEventLoop());
|
||||
return y(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +154,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger y(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kY.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kY.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +167,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #leftBumper(EventLoop)
|
||||
*/
|
||||
public Trigger leftBumper() {
|
||||
return leftBumper(getScheduler().getDefaultEventLoop());
|
||||
return leftBumper(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +178,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger leftBumper(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kLeftBumper.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kLeftBumper.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,7 +191,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #rightBumper(EventLoop)
|
||||
*/
|
||||
public Trigger rightBumper() {
|
||||
return rightBumper(getScheduler().getDefaultEventLoop());
|
||||
return rightBumper(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +202,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger rightBumper(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kRightBumper.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kRightBumper.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +215,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #leftStick(EventLoop)
|
||||
*/
|
||||
public Trigger leftStick() {
|
||||
return leftStick(getScheduler().getDefaultEventLoop());
|
||||
return leftStick(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +226,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger leftStick(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kLeftStick.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kLeftStick.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,7 +239,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #rightStick(EventLoop)
|
||||
*/
|
||||
public Trigger rightStick() {
|
||||
return rightStick(getScheduler().getDefaultEventLoop());
|
||||
return rightStick(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,7 +250,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger rightStick(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kRightStick.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kRightStick.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,7 +263,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #ellipses(EventLoop)
|
||||
*/
|
||||
public Trigger ellipses() {
|
||||
return ellipses(getScheduler().getDefaultEventLoop());
|
||||
return ellipses(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,7 +274,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger ellipses(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kEllipses.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kEllipses.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,7 +287,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #hamburger(EventLoop)
|
||||
*/
|
||||
public Trigger hamburger() {
|
||||
return hamburger(getScheduler().getDefaultEventLoop());
|
||||
return hamburger(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,7 +298,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger hamburger(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kHamburger.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kHamburger.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,7 +311,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #stadia(EventLoop)
|
||||
*/
|
||||
public Trigger stadia() {
|
||||
return stadia(getScheduler().getDefaultEventLoop());
|
||||
return stadia(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -314,7 +322,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger stadia(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kStadia.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kStadia.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,7 +335,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #rightTrigger(EventLoop)
|
||||
*/
|
||||
public Trigger rightTrigger() {
|
||||
return rightTrigger(getScheduler().getDefaultEventLoop());
|
||||
return rightTrigger(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,7 +346,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger rightTrigger(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kRightTrigger.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kRightTrigger.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -351,7 +359,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #leftTrigger(EventLoop)
|
||||
*/
|
||||
public Trigger leftTrigger() {
|
||||
return leftTrigger(getScheduler().getDefaultEventLoop());
|
||||
return leftTrigger(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -362,7 +370,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger leftTrigger(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kLeftTrigger.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kLeftTrigger.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,7 +383,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #google(EventLoop)
|
||||
*/
|
||||
public Trigger google() {
|
||||
return google(getScheduler().getDefaultEventLoop());
|
||||
return google(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -386,7 +394,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger google(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kGoogle.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kGoogle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,7 +407,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @see #frame(EventLoop)
|
||||
*/
|
||||
public Trigger frame() {
|
||||
return frame(getScheduler().getDefaultEventLoop());
|
||||
return frame(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -410,7 +418,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger frame(EventLoop loop) {
|
||||
return button(NiDsStadiaController.Button.kFrame.value, loop);
|
||||
return m_hid.button(NiDsStadiaController.Button.kFrame.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -419,7 +427,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return m_hid.getLeftX();
|
||||
return m_controller.getLeftX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -428,7 +436,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return m_hid.getRightX();
|
||||
return m_controller.getRightX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -437,7 +445,7 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return m_hid.getLeftY();
|
||||
return m_controller.getLeftY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -446,6 +454,6 @@ public class CommandNiDsStadiaController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return m_hid.getRightY();
|
||||
return m_controller.getRightY();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ import org.wpilib.event.EventLoop;
|
||||
* @see NiDsXboxController
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
private final NiDsXboxController m_hid;
|
||||
public class CommandNiDsXboxController {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final NiDsXboxController m_controller;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller. Commands bound to buttons on the controller will be
|
||||
@@ -27,8 +28,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandNiDsXboxController(int port) {
|
||||
super(port);
|
||||
m_hid = new NiDsXboxController(port);
|
||||
this(Scheduler.getDefault(), port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,20 +39,28 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandNiDsXboxController(Scheduler scheduler, int port) {
|
||||
super(scheduler, port);
|
||||
m_hid = new NiDsXboxController(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(scheduler, port);
|
||||
m_controller = new NiDsXboxController(m_hid.getHID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public NiDsXboxController getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying NiDsXboxController object.
|
||||
*
|
||||
* @return the wrapped NiDsXboxController object
|
||||
*/
|
||||
public NiDsXboxController getNiDsXboxController() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the A button's digital signal.
|
||||
*
|
||||
@@ -63,7 +71,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @see #a(EventLoop)
|
||||
*/
|
||||
public Trigger a() {
|
||||
return a(getScheduler().getDefaultEventLoop());
|
||||
return a(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +82,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger a(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kA.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kA.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +95,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @see #b(EventLoop)
|
||||
*/
|
||||
public Trigger b() {
|
||||
return b(getScheduler().getDefaultEventLoop());
|
||||
return b(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +106,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger b(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kB.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kB.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +119,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @see #x(EventLoop)
|
||||
*/
|
||||
public Trigger x() {
|
||||
return x(getScheduler().getDefaultEventLoop());
|
||||
return x(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +130,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger x(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kX.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kX.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +143,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @see #y(EventLoop)
|
||||
*/
|
||||
public Trigger y() {
|
||||
return y(getScheduler().getDefaultEventLoop());
|
||||
return y(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +154,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger y(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kY.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kY.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +167,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @see #leftBumper(EventLoop)
|
||||
*/
|
||||
public Trigger leftBumper() {
|
||||
return leftBumper(getScheduler().getDefaultEventLoop());
|
||||
return leftBumper(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +178,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger leftBumper(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kLeftBumper.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kLeftBumper.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,7 +191,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @see #rightBumper(EventLoop)
|
||||
*/
|
||||
public Trigger rightBumper() {
|
||||
return rightBumper(getScheduler().getDefaultEventLoop());
|
||||
return rightBumper(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +202,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger rightBumper(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kRightBumper.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kRightBumper.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +215,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @see #back(EventLoop)
|
||||
*/
|
||||
public Trigger back() {
|
||||
return back(getScheduler().getDefaultEventLoop());
|
||||
return back(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +226,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger back(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kBack.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kBack.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,7 +239,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @see #start(EventLoop)
|
||||
*/
|
||||
public Trigger start() {
|
||||
return start(getScheduler().getDefaultEventLoop());
|
||||
return start(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,7 +250,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger start(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kStart.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kStart.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,7 +263,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @see #leftStick(EventLoop)
|
||||
*/
|
||||
public Trigger leftStick() {
|
||||
return leftStick(getScheduler().getDefaultEventLoop());
|
||||
return leftStick(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,7 +274,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger leftStick(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kLeftStick.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kLeftStick.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,7 +287,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @see #rightStick(EventLoop)
|
||||
*/
|
||||
public Trigger rightStick() {
|
||||
return rightStick(getScheduler().getDefaultEventLoop());
|
||||
return rightStick(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,7 +298,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger rightStick(EventLoop loop) {
|
||||
return button(NiDsXboxController.Button.kRightStick.value, loop);
|
||||
return m_hid.button(NiDsXboxController.Button.kRightStick.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,7 +312,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* threshold, attached to the given event loop
|
||||
*/
|
||||
public Trigger leftTrigger(double threshold, EventLoop loop) {
|
||||
return axisGreaterThan(NiDsXboxController.Axis.kLeftTrigger.value, threshold, loop);
|
||||
return m_hid.axisGreaterThan(NiDsXboxController.Axis.kLeftTrigger.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,7 +327,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* Scheduler#getDefault default scheduler} if a scheduler was not explicitly provided.
|
||||
*/
|
||||
public Trigger leftTrigger(double threshold) {
|
||||
return leftTrigger(threshold, getScheduler().getDefaultEventLoop());
|
||||
return leftTrigger(threshold, m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -346,7 +354,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* threshold, attached to the given event loop
|
||||
*/
|
||||
public Trigger rightTrigger(double threshold, EventLoop loop) {
|
||||
return axisGreaterThan(NiDsXboxController.Axis.kRightTrigger.value, threshold, loop);
|
||||
return m_hid.axisGreaterThan(NiDsXboxController.Axis.kRightTrigger.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -361,7 +369,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* Scheduler#getDefault default scheduler} if a scheduler was not explicitly provided.
|
||||
*/
|
||||
public Trigger rightTrigger(double threshold) {
|
||||
return rightTrigger(threshold, getScheduler().getDefaultEventLoop());
|
||||
return rightTrigger(threshold, m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -383,7 +391,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return m_hid.getLeftX();
|
||||
return m_controller.getLeftX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,7 +400,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return m_hid.getRightX();
|
||||
return m_controller.getRightX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -401,7 +409,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return m_hid.getLeftY();
|
||||
return m_controller.getLeftY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -410,7 +418,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return m_hid.getRightY();
|
||||
return m_controller.getRightY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -420,7 +428,7 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftTriggerAxis() {
|
||||
return m_hid.getLeftTriggerAxis();
|
||||
return m_controller.getLeftTriggerAxis();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -430,6 +438,6 @@ public class CommandNiDsXboxController extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightTriggerAxis() {
|
||||
return m_hid.getRightTriggerAxis();
|
||||
return m_controller.getRightTriggerAxis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package org.wpilib.command3.button;
|
||||
|
||||
import org.wpilib.command3.Scheduler;
|
||||
import org.wpilib.command3.Trigger;
|
||||
import org.wpilib.driverstation.DriverStation;
|
||||
import org.wpilib.driverstation.Gamepad;
|
||||
import org.wpilib.event.EventLoop;
|
||||
|
||||
@@ -15,8 +16,9 @@ import org.wpilib.event.EventLoop;
|
||||
* @see Gamepad
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class CommandGamepad extends CommandGenericHID {
|
||||
private final Gamepad m_hid;
|
||||
public class CommandGamepad {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final Gamepad m_gamepad;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -24,8 +26,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandGamepad(int port) {
|
||||
super(port);
|
||||
m_hid = new Gamepad(port);
|
||||
this(Scheduler.getDefault(), port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,20 +36,51 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandGamepad(Scheduler scheduler, int port) {
|
||||
super(scheduler, port);
|
||||
m_hid = new Gamepad(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(scheduler, port);
|
||||
m_gamepad = DriverStation.getGamepad(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public Gamepad getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying Gamepad object.
|
||||
*
|
||||
* @return the wrapped Gamepad object
|
||||
*/
|
||||
public Gamepad getGamepad() {
|
||||
return m_gamepad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
*
|
||||
* @param button the button index
|
||||
* @return an event instance representing the button's digital signal attached to the {@link
|
||||
* Scheduler#getDefaultEventLoop() default scheduler button loop}.
|
||||
* @see #button(int, EventLoop)
|
||||
*/
|
||||
public Trigger button(int button) {
|
||||
return m_hid.button(button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
*
|
||||
* @param button the button index
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @return an event instance representing the button's digital signal attached to the given loop.
|
||||
*/
|
||||
public Trigger button(int button, EventLoop loop) {
|
||||
return m_hid.button(button, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Face Down button's digital signal.
|
||||
*
|
||||
@@ -59,7 +91,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #faceDown(EventLoop)
|
||||
*/
|
||||
public Trigger faceDown() {
|
||||
return faceDown(getScheduler().getDefaultEventLoop());
|
||||
return faceDown(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +115,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #faceRight(EventLoop)
|
||||
*/
|
||||
public Trigger faceRight() {
|
||||
return faceRight(getScheduler().getDefaultEventLoop());
|
||||
return faceRight(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +139,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #faceLeft(EventLoop)
|
||||
*/
|
||||
public Trigger faceLeft() {
|
||||
return faceLeft(getScheduler().getDefaultEventLoop());
|
||||
return faceLeft(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +163,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #faceUp(EventLoop)
|
||||
*/
|
||||
public Trigger faceUp() {
|
||||
return faceUp(getScheduler().getDefaultEventLoop());
|
||||
return faceUp(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,7 +187,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #back(EventLoop)
|
||||
*/
|
||||
public Trigger back() {
|
||||
return back(getScheduler().getDefaultEventLoop());
|
||||
return back(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,7 +211,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #guide(EventLoop)
|
||||
*/
|
||||
public Trigger guide() {
|
||||
return guide(getScheduler().getDefaultEventLoop());
|
||||
return guide(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,7 +235,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #start(EventLoop)
|
||||
*/
|
||||
public Trigger start() {
|
||||
return start(getScheduler().getDefaultEventLoop());
|
||||
return start(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,7 +259,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #leftStick(EventLoop)
|
||||
*/
|
||||
public Trigger leftStick() {
|
||||
return leftStick(getScheduler().getDefaultEventLoop());
|
||||
return leftStick(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,7 +283,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #rightStick(EventLoop)
|
||||
*/
|
||||
public Trigger rightStick() {
|
||||
return rightStick(getScheduler().getDefaultEventLoop());
|
||||
return rightStick(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,7 +307,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #leftBumper(EventLoop)
|
||||
*/
|
||||
public Trigger leftBumper() {
|
||||
return leftBumper(getScheduler().getDefaultEventLoop());
|
||||
return leftBumper(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,7 +331,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #rightBumper(EventLoop)
|
||||
*/
|
||||
public Trigger rightBumper() {
|
||||
return rightBumper(getScheduler().getDefaultEventLoop());
|
||||
return rightBumper(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -323,7 +355,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #dpadUp(EventLoop)
|
||||
*/
|
||||
public Trigger dpadUp() {
|
||||
return dpadUp(getScheduler().getDefaultEventLoop());
|
||||
return dpadUp(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,7 +379,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #dpadDown(EventLoop)
|
||||
*/
|
||||
public Trigger dpadDown() {
|
||||
return dpadDown(getScheduler().getDefaultEventLoop());
|
||||
return dpadDown(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -371,7 +403,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #dpadLeft(EventLoop)
|
||||
*/
|
||||
public Trigger dpadLeft() {
|
||||
return dpadLeft(getScheduler().getDefaultEventLoop());
|
||||
return dpadLeft(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -395,7 +427,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #dpadRight(EventLoop)
|
||||
*/
|
||||
public Trigger dpadRight() {
|
||||
return dpadRight(getScheduler().getDefaultEventLoop());
|
||||
return dpadRight(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -419,7 +451,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #misc1(EventLoop)
|
||||
*/
|
||||
public Trigger misc1() {
|
||||
return misc1(getScheduler().getDefaultEventLoop());
|
||||
return misc1(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -443,7 +475,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #rightPaddle1(EventLoop)
|
||||
*/
|
||||
public Trigger rightPaddle1() {
|
||||
return rightPaddle1(getScheduler().getDefaultEventLoop());
|
||||
return rightPaddle1(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -467,7 +499,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #leftPaddle1(EventLoop)
|
||||
*/
|
||||
public Trigger leftPaddle1() {
|
||||
return leftPaddle1(getScheduler().getDefaultEventLoop());
|
||||
return leftPaddle1(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -491,7 +523,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #rightPaddle2(EventLoop)
|
||||
*/
|
||||
public Trigger rightPaddle2() {
|
||||
return rightPaddle2(getScheduler().getDefaultEventLoop());
|
||||
return rightPaddle2(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -515,7 +547,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #leftPaddle2(EventLoop)
|
||||
*/
|
||||
public Trigger leftPaddle2() {
|
||||
return leftPaddle2(getScheduler().getDefaultEventLoop());
|
||||
return leftPaddle2(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -539,7 +571,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #touchpad(EventLoop)
|
||||
*/
|
||||
public Trigger touchpad() {
|
||||
return touchpad(getScheduler().getDefaultEventLoop());
|
||||
return touchpad(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -563,7 +595,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #misc2(EventLoop)
|
||||
*/
|
||||
public Trigger misc2() {
|
||||
return misc2(getScheduler().getDefaultEventLoop());
|
||||
return misc2(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -587,7 +619,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #misc3(EventLoop)
|
||||
*/
|
||||
public Trigger misc3() {
|
||||
return misc3(getScheduler().getDefaultEventLoop());
|
||||
return misc3(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -611,7 +643,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #misc4(EventLoop)
|
||||
*/
|
||||
public Trigger misc4() {
|
||||
return misc4(getScheduler().getDefaultEventLoop());
|
||||
return misc4(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -635,7 +667,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #misc5(EventLoop)
|
||||
*/
|
||||
public Trigger misc5() {
|
||||
return misc5(getScheduler().getDefaultEventLoop());
|
||||
return misc5(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -659,7 +691,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @see #misc6(EventLoop)
|
||||
*/
|
||||
public Trigger misc6() {
|
||||
return misc6(getScheduler().getDefaultEventLoop());
|
||||
return misc6(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -684,7 +716,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* threshold, attached to the given event loop
|
||||
*/
|
||||
public Trigger leftTrigger(double threshold, EventLoop loop) {
|
||||
return axisGreaterThan(Gamepad.Axis.LEFT_TRIGGER.value, threshold, loop);
|
||||
return m_hid.axisGreaterThan(Gamepad.Axis.LEFT_TRIGGER.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -698,7 +730,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* loop}.
|
||||
*/
|
||||
public Trigger leftTrigger(double threshold) {
|
||||
return leftTrigger(threshold, getScheduler().getDefaultEventLoop());
|
||||
return leftTrigger(threshold, m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -725,7 +757,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* threshold, attached to the given event loop
|
||||
*/
|
||||
public Trigger rightTrigger(double threshold, EventLoop loop) {
|
||||
return axisGreaterThan(Gamepad.Axis.RIGHT_TRIGGER.value, threshold, loop);
|
||||
return m_hid.axisGreaterThan(Gamepad.Axis.RIGHT_TRIGGER.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -739,7 +771,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* loop}.
|
||||
*/
|
||||
public Trigger rightTrigger(double threshold) {
|
||||
return rightTrigger(threshold, getScheduler().getDefaultEventLoop());
|
||||
return rightTrigger(threshold, m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -761,7 +793,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return m_hid.getLeftX();
|
||||
return m_gamepad.getLeftX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -770,7 +802,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return m_hid.getLeftY();
|
||||
return m_gamepad.getLeftY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -779,7 +811,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return m_hid.getRightX();
|
||||
return m_gamepad.getRightX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -788,7 +820,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return m_hid.getRightY();
|
||||
return m_gamepad.getRightY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -798,7 +830,7 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftTriggerAxis() {
|
||||
return m_hid.getLeftTriggerAxis();
|
||||
return m_gamepad.getLeftTriggerAxis();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -808,6 +840,6 @@ public class CommandGamepad extends CommandGenericHID {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightTriggerAxis() {
|
||||
return m_hid.getRightTriggerAxis();
|
||||
return m_gamepad.getRightTriggerAxis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,16 @@
|
||||
package org.wpilib.command3.button;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.wpilib.command3.Scheduler;
|
||||
import org.wpilib.command3.Trigger;
|
||||
import org.wpilib.driverstation.DriverStation;
|
||||
import org.wpilib.driverstation.GenericHID;
|
||||
import org.wpilib.driverstation.POVDirection;
|
||||
import org.wpilib.driverstation.internal.DriverStationBackend;
|
||||
import org.wpilib.event.EventLoop;
|
||||
import org.wpilib.math.util.Pair;
|
||||
|
||||
@@ -18,7 +23,10 @@ import org.wpilib.math.util.Pair;
|
||||
*
|
||||
* @see GenericHID
|
||||
*/
|
||||
public class CommandGenericHID {
|
||||
public final class CommandGenericHID {
|
||||
private static final Lock m_hidsLock = new ReentrantLock();
|
||||
private static final Map<Scheduler, CommandGenericHID[]> m_hids = new IdentityHashMap<>();
|
||||
|
||||
private final Scheduler m_scheduler;
|
||||
private final GenericHID m_hid;
|
||||
private final Map<EventLoop, Map<Integer, Trigger>> m_buttonCache = new HashMap<>();
|
||||
@@ -38,7 +46,65 @@ public class CommandGenericHID {
|
||||
*/
|
||||
public CommandGenericHID(Scheduler scheduler, int port) {
|
||||
m_scheduler = scheduler;
|
||||
m_hid = new GenericHID(port);
|
||||
m_hid = DriverStation.getGenericHID(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a device with a GenericHID object.
|
||||
*
|
||||
* @param scheduler The scheduler that should execute the triggered commands.
|
||||
* @param hid The GenericHID object to use for this command HID.
|
||||
*/
|
||||
public CommandGenericHID(Scheduler scheduler, GenericHID hid) {
|
||||
m_scheduler = scheduler;
|
||||
m_hid = hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a device with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this command HID.
|
||||
*/
|
||||
public CommandGenericHID(GenericHID hid) {
|
||||
this(Scheduler.getDefault(), hid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the CommandGenericHID object for the given scheduler and port. CommandGenericHID objects
|
||||
* are cached, so this will always return the same object for the same scheduler and port.
|
||||
*
|
||||
* @param scheduler The scheduler that should execute the triggered commands.
|
||||
* @param port The port index on the Driver Station that the device is plugged into.
|
||||
* @return The CommandGenericHID object for the given scheduler and port.
|
||||
*/
|
||||
public static CommandGenericHID getCommandGenericHID(Scheduler scheduler, int port) {
|
||||
DriverStation.getGenericHID(port);
|
||||
m_hidsLock.lock();
|
||||
try {
|
||||
CommandGenericHID[] hids =
|
||||
m_hids.computeIfAbsent(
|
||||
scheduler, k -> new CommandGenericHID[DriverStationBackend.JOYSTICK_PORTS]);
|
||||
CommandGenericHID toRet = hids[port];
|
||||
if (toRet == null) {
|
||||
toRet = new CommandGenericHID(scheduler, port);
|
||||
hids[port] = toRet;
|
||||
}
|
||||
return toRet;
|
||||
} finally {
|
||||
m_hidsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the CommandGenericHID object for the given port using the default scheduler.
|
||||
* CommandGenericHID objects are cached, so this will always return the same object for the same
|
||||
* port.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the device is plugged into.
|
||||
* @return The CommandGenericHID object for the given port.
|
||||
*/
|
||||
public static CommandGenericHID getCommandGenericHID(int port) {
|
||||
return getCommandGenericHID(Scheduler.getDefault(), port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -337,7 +403,7 @@ public class CommandGenericHID {
|
||||
*
|
||||
* @return the scheduler that should execute the triggered commands
|
||||
*/
|
||||
protected final Scheduler getScheduler() {
|
||||
Scheduler getScheduler() {
|
||||
return m_scheduler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package org.wpilib.command3.button;
|
||||
|
||||
import org.wpilib.command3.Scheduler;
|
||||
import org.wpilib.command3.Trigger;
|
||||
import org.wpilib.driverstation.DriverStation;
|
||||
import org.wpilib.driverstation.Joystick;
|
||||
import org.wpilib.event.EventLoop;
|
||||
|
||||
@@ -14,8 +15,9 @@ import org.wpilib.event.EventLoop;
|
||||
*
|
||||
* @see Joystick
|
||||
*/
|
||||
public class CommandJoystick extends CommandGenericHID {
|
||||
private final Joystick m_hid;
|
||||
public class CommandJoystick {
|
||||
private final CommandGenericHID m_hid;
|
||||
private final Joystick m_joystick;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -23,8 +25,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandJoystick(int port) {
|
||||
super(port);
|
||||
m_hid = new Joystick(port);
|
||||
this(Scheduler.getDefault(), port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,20 +35,28 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public CommandJoystick(Scheduler scheduler, int port) {
|
||||
super(scheduler, port);
|
||||
m_hid = new Joystick(port);
|
||||
m_hid = CommandGenericHID.getCommandGenericHID(scheduler, port);
|
||||
m_joystick = new Joystick(DriverStation.getGenericHID(port));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
* Get the underlying CommandGenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
* @return the wrapped CommandGenericHID object
|
||||
*/
|
||||
@Override
|
||||
public Joystick getHID() {
|
||||
public CommandGenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying Joystick object.
|
||||
*
|
||||
* @return the wrapped Joystick object
|
||||
*/
|
||||
public Joystick getJoystick() {
|
||||
return m_joystick;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the trigger button's digital signal.
|
||||
*
|
||||
@@ -56,7 +65,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @see #trigger(EventLoop)
|
||||
*/
|
||||
public Trigger trigger() {
|
||||
return trigger(getScheduler().getDefaultEventLoop());
|
||||
return trigger(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,7 +76,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* given loop.
|
||||
*/
|
||||
public Trigger trigger(EventLoop loop) {
|
||||
return button(Joystick.ButtonType.kTrigger.value, loop);
|
||||
return m_hid.button(Joystick.ButtonType.kTrigger.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +87,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @see #top(EventLoop)
|
||||
*/
|
||||
public Trigger top() {
|
||||
return top(getScheduler().getDefaultEventLoop());
|
||||
return top(m_hid.getScheduler().getDefaultEventLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +98,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* loop.
|
||||
*/
|
||||
public Trigger top(EventLoop loop) {
|
||||
return button(Joystick.ButtonType.kTop.value, loop);
|
||||
return m_hid.button(Joystick.ButtonType.kTop.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +107,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @param channel The channel to set the axis to.
|
||||
*/
|
||||
public void setXChannel(int channel) {
|
||||
m_hid.setXChannel(channel);
|
||||
m_joystick.setXChannel(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +116,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @param channel The channel to set the axis to.
|
||||
*/
|
||||
public void setYChannel(int channel) {
|
||||
m_hid.setYChannel(channel);
|
||||
m_joystick.setYChannel(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +125,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @param channel The channel to set the axis to.
|
||||
*/
|
||||
public void setZChannel(int channel) {
|
||||
m_hid.setZChannel(channel);
|
||||
m_joystick.setZChannel(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +134,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @param channel The channel to set the axis to.
|
||||
*/
|
||||
public void setThrottleChannel(int channel) {
|
||||
m_hid.setThrottleChannel(channel);
|
||||
m_joystick.setThrottleChannel(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,7 +143,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @param channel The channel to set the axis to.
|
||||
*/
|
||||
public void setTwistChannel(int channel) {
|
||||
m_hid.setTwistChannel(channel);
|
||||
m_joystick.setTwistChannel(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,7 +152,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The channel for the axis.
|
||||
*/
|
||||
public int getXChannel() {
|
||||
return m_hid.getXChannel();
|
||||
return m_joystick.getXChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +161,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The channel for the axis.
|
||||
*/
|
||||
public int getYChannel() {
|
||||
return m_hid.getYChannel();
|
||||
return m_joystick.getYChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,7 +170,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The channel for the axis.
|
||||
*/
|
||||
public int getZChannel() {
|
||||
return m_hid.getZChannel();
|
||||
return m_joystick.getZChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +179,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The channel for the axis.
|
||||
*/
|
||||
public int getTwistChannel() {
|
||||
return m_hid.getTwistChannel();
|
||||
return m_joystick.getTwistChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,7 +188,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The channel for the axis.
|
||||
*/
|
||||
public int getThrottleChannel() {
|
||||
return m_hid.getThrottleChannel();
|
||||
return m_joystick.getThrottleChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +200,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return the x position
|
||||
*/
|
||||
public double getX() {
|
||||
return m_hid.getX();
|
||||
return m_joystick.getX();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,7 +212,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return the y position
|
||||
*/
|
||||
public double getY() {
|
||||
return m_hid.getY();
|
||||
return m_joystick.getY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,7 +221,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return the z position
|
||||
*/
|
||||
public double getZ() {
|
||||
return m_hid.getZ();
|
||||
return m_joystick.getZ();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,7 +231,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The Twist value of the joystick.
|
||||
*/
|
||||
public double getTwist() {
|
||||
return m_hid.getTwist();
|
||||
return m_joystick.getTwist();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,7 +241,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The Throttle value of the joystick.
|
||||
*/
|
||||
public double getThrottle() {
|
||||
return m_hid.getThrottle();
|
||||
return m_joystick.getThrottle();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,7 +251,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The magnitude of the direction vector
|
||||
*/
|
||||
public double getMagnitude() {
|
||||
return m_hid.getMagnitude();
|
||||
return m_joystick.getMagnitude();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,7 +269,7 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
//
|
||||
// It's rotated 90 degrees CCW (y is negated and the arguments are reversed)
|
||||
// so that 0 radians is forward.
|
||||
return m_hid.getDirectionRadians();
|
||||
return m_joystick.getDirectionRadians();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,6 +279,6 @@ public class CommandJoystick extends CommandGenericHID {
|
||||
* @return The direction of the vector in degrees
|
||||
*/
|
||||
public double getDirectionDegrees() {
|
||||
return m_hid.getDirectionDegrees();
|
||||
return m_joystick.getDirectionDegrees();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import static org.wpilib.util.ErrorMessages.requireNonNullParam;
|
||||
|
||||
import org.wpilib.command3.Trigger;
|
||||
import org.wpilib.driverstation.GenericHID;
|
||||
import org.wpilib.driverstation.HIDDevice;
|
||||
|
||||
/** A {@link Trigger} that gets its state from a {@link GenericHID}. */
|
||||
public class JoystickButton extends Trigger {
|
||||
@@ -21,4 +22,14 @@ public class JoystickButton extends Trigger {
|
||||
super(() -> joystick.getRawButton(buttonNumber));
|
||||
requireNonNullParam(joystick, "joystick", "JoystickButton");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a joystick button for triggering commands.
|
||||
*
|
||||
* @param joystick The HIDDevice object that has the button
|
||||
* @param buttonNumber The button number (see {@link GenericHID#getRawButton(int) }
|
||||
*/
|
||||
public JoystickButton(HIDDevice joystick, int buttonNumber) {
|
||||
this(requireNonNullParam(joystick, "joystick", "JoystickButton").getHID(), buttonNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import static org.wpilib.util.ErrorMessages.requireNonNullParam;
|
||||
|
||||
import org.wpilib.command3.Trigger;
|
||||
import org.wpilib.driverstation.GenericHID;
|
||||
import org.wpilib.driverstation.HIDDevice;
|
||||
import org.wpilib.driverstation.POVDirection;
|
||||
|
||||
/** A {@link Trigger} that gets its state from a POV on a {@link GenericHID}. */
|
||||
@@ -33,4 +34,25 @@ public class POVButton extends Trigger {
|
||||
public POVButton(GenericHID joystick, POVDirection angle) {
|
||||
this(joystick, angle, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a POV button for triggering commands.
|
||||
*
|
||||
* @param joystick The HIDDevice object that has the POV
|
||||
* @param angle The desired angle
|
||||
* @param povNumber The POV number (see {@link GenericHID#getPOV(int)})
|
||||
*/
|
||||
public POVButton(HIDDevice joystick, POVDirection angle, int povNumber) {
|
||||
this(requireNonNullParam(joystick, "joystick", "POVButton").getHID(), angle, povNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a POV button for triggering commands. By default, acts on POV 0
|
||||
*
|
||||
* @param joystick The HIDDevice object that has the POV
|
||||
* @param angle The desired angle
|
||||
*/
|
||||
public POVButton(HIDDevice joystick, POVDirection angle) {
|
||||
this(joystick, angle, 0);
|
||||
}
|
||||
}
|
||||
|
||||
10
wpilibc/robotpy_pybind_build_info.bzl
generated
10
wpilibc/robotpy_pybind_build_info.bzl
generated
@@ -211,6 +211,16 @@ def wpilib_extension(srcs = [], header_to_dat_deps = [], extra_hdrs = [], includ
|
||||
("wpi::GenericHID", "wpi__GenericHID.hpp"),
|
||||
],
|
||||
),
|
||||
struct(
|
||||
class_name = "HIDDevice",
|
||||
yml_file = "semiwrap/HIDDevice.yml",
|
||||
header_root = "$(execpath :robotpy-native-wpilib.copy_headers)",
|
||||
header_file = "$(execpath :robotpy-native-wpilib.copy_headers)/wpi/driverstation/HIDDevice.hpp",
|
||||
tmpl_class_names = [],
|
||||
trampolines = [
|
||||
("wpi::HIDDevice", "wpi__HIDDevice.hpp"),
|
||||
],
|
||||
),
|
||||
struct(
|
||||
class_name = "Joystick",
|
||||
yml_file = "semiwrap/Joystick.yml",
|
||||
|
||||
@@ -8,28 +8,42 @@
|
||||
{%- endmacro %}
|
||||
#include "wpi/driverstation/{{ ConsoleName }}Controller.hpp"
|
||||
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/event/BooleanEvent.hpp"
|
||||
#include "wpi/hal/UsageReporting.hpp"
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
|
||||
#include "wpi/event/BooleanEvent.hpp"
|
||||
|
||||
using namespace wpi;
|
||||
|
||||
{{ ConsoleName }}Controller::{{ ConsoleName }}Controller(int port) : GenericHID(port) {
|
||||
HAL_ReportUsage("HID", port, "{{ ConsoleName }}Controller");
|
||||
{{ ConsoleName }}Controller::{{ ConsoleName }}Controller(int port)
|
||||
: {{ ConsoleName }}Controller{DriverStation::GetGenericHID(port)} {}
|
||||
|
||||
{{ ConsoleName }}Controller::{{ ConsoleName }}Controller(GenericHID& hid)
|
||||
: m_hid{&hid} {
|
||||
HAL_ReportUsage("HID", hid.GetPort(), "{{ ConsoleName }}Controller");
|
||||
}
|
||||
|
||||
GenericHID& {{ ConsoleName }}Controller::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
const GenericHID& {{ ConsoleName }}Controller::GetHID() const {
|
||||
return *m_hid;
|
||||
}
|
||||
{% for stick in sticks %}
|
||||
double {{ ConsoleName }}Controller::Get{{ stick.NameParts|map("capitalize")|join }}() const {
|
||||
return GetRawAxis(Axis::k{{ stick.NameParts|map("capitalize")|join }});
|
||||
return m_hid->GetRawAxis(Axis::k{{ stick.NameParts|map("capitalize")|join }});
|
||||
}
|
||||
{% endfor -%}
|
||||
{% for trigger in triggers %}
|
||||
double {{ ConsoleName }}Controller::Get{{ capitalize_first(trigger.name) }}Axis() const {
|
||||
return GetRawAxis(Axis::k{{ capitalize_first(trigger.name) }});
|
||||
return m_hid->GetRawAxis(Axis::k{{ capitalize_first(trigger.name) }});
|
||||
}
|
||||
{% if trigger.UseThresholdMethods %}
|
||||
BooleanEvent {{ ConsoleName }}Controller::{{ capitalize_first(trigger.name) }}(double threshold, EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this, threshold] { return this->Get{{ capitalize_first(trigger.name) }}Axis() > threshold; });
|
||||
BooleanEvent {{ ConsoleName }}Controller::{{ capitalize_first(trigger.name) }}(double threshold,
|
||||
EventLoop* loop) const {
|
||||
return BooleanEvent(
|
||||
loop, [this, threshold] { return this->Get{{ capitalize_first(trigger.name) }}Axis() > threshold; });
|
||||
}
|
||||
|
||||
BooleanEvent {{ ConsoleName }}Controller::{{ capitalize_first(trigger.name) }}(EventLoop* loop) const {
|
||||
@@ -39,31 +53,59 @@ BooleanEvent {{ ConsoleName }}Controller::{{ capitalize_first(trigger.name) }}(E
|
||||
{% endfor -%}
|
||||
{% for button in buttons %}
|
||||
bool {{ ConsoleName }}Controller::Get{{ capitalize_first(button.name) }}Button() const {
|
||||
return GetRawButton(Button::k{{ capitalize_first(button.name) }});
|
||||
return m_hid->GetRawButton(Button::k{{ capitalize_first(button.name) }});
|
||||
}
|
||||
|
||||
bool {{ ConsoleName }}Controller::Get{{ capitalize_first(button.name) }}ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::k{{ capitalize_first(button.name) }});
|
||||
return m_hid->GetRawButtonPressed(Button::k{{ capitalize_first(button.name) }});
|
||||
}
|
||||
|
||||
bool {{ ConsoleName }}Controller::Get{{ capitalize_first(button.name) }}ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::k{{ capitalize_first(button.name) }});
|
||||
return m_hid->GetRawButtonReleased(Button::k{{ capitalize_first(button.name) }});
|
||||
}
|
||||
|
||||
BooleanEvent {{ ConsoleName }}Controller::{{ capitalize_first(button.name) }}(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->Get{{ capitalize_first(button.name) }}Button(); });
|
||||
}
|
||||
{% endfor %}
|
||||
bool {{ ConsoleName }}Controller::IsConnected() const {
|
||||
return m_hid->IsConnected();
|
||||
}
|
||||
|
||||
GenericHID::HIDType {{ ConsoleName }}Controller::GetGamepadType() const {
|
||||
return m_hid->GetGamepadType();
|
||||
}
|
||||
|
||||
GenericHID::SupportedOutputs {{ ConsoleName }}Controller::GetSupportedOutputs() const {
|
||||
return m_hid->GetSupportedOutputs();
|
||||
}
|
||||
|
||||
std::string {{ ConsoleName }}Controller::GetName() const {
|
||||
return m_hid->GetName();
|
||||
}
|
||||
|
||||
int {{ ConsoleName }}Controller::GetPort() const {
|
||||
return m_hid->GetPort();
|
||||
}
|
||||
|
||||
void {{ ConsoleName }}Controller::SetRumble(GenericHID::RumbleType type,
|
||||
double value) {
|
||||
m_hid->SetRumble(type, value);
|
||||
}
|
||||
|
||||
void {{ ConsoleName }}Controller::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("HID");
|
||||
builder.PublishConstString("ControllerType", "{{ ConsoleName }}");
|
||||
{%- for trigger in triggers %}
|
||||
builder.AddDoubleProperty("{{ capitalize_first(trigger.name) }} Axis", [this] { return Get{{ capitalize_first(trigger.name) }}Axis(); }, nullptr);
|
||||
builder.AddDoubleProperty("{{ capitalize_first(trigger.name) }} Axis",
|
||||
[this] { return Get{{ capitalize_first(trigger.name) }}Axis(); }, nullptr);
|
||||
{%- endfor -%}
|
||||
{% for stick in sticks %}
|
||||
builder.AddDoubleProperty("{{ stick.NameParts|map("capitalize")|join }}", [this] { return Get{{ stick.NameParts|map("capitalize")|join }}(); }, nullptr);
|
||||
builder.AddDoubleProperty("{{ stick.NameParts|map("capitalize")|join }}",
|
||||
[this] { return Get{{ stick.NameParts|map("capitalize")|join }}(); }, nullptr);
|
||||
{%- endfor -%}
|
||||
{% for button in buttons %}
|
||||
builder.AddBooleanProperty("{{ capitalize_first(button.name) }}", [this] { return Get{{ capitalize_first(button.name) }}Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("{{ capitalize_first(button.name) }}",
|
||||
[this] { return Get{{ capitalize_first(button.name) }}Button(); }, nullptr);
|
||||
{%- endfor %}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ using namespace wpi;
|
||||
using namespace wpi::sim;
|
||||
|
||||
{{ ConsoleName }}ControllerSim::{{ ConsoleName }}ControllerSim(const {{ ConsoleName }}Controller& joystick)
|
||||
: GenericHIDSim{joystick} {
|
||||
: GenericHIDSim{joystick.GetHID()} {
|
||||
SetAxesMaximumIndex({{ sticks|length + triggers|length }});
|
||||
SetButtonsMaximumIndex({{ buttons|length }});
|
||||
SetPOVsMaximumIndex(1);
|
||||
|
||||
@@ -8,10 +8,12 @@
|
||||
{%- endmacro %}
|
||||
#pragma once
|
||||
|
||||
#include "wpi/util/sendable/Sendable.hpp"
|
||||
#include "wpi/util/sendable/SendableHelper.hpp"
|
||||
#include <string>
|
||||
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/driverstation/HIDDevice.hpp"
|
||||
#include "wpi/util/sendable/Sendable.hpp"
|
||||
#include "wpi/util/sendable/SendableHelper.hpp"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
@@ -27,9 +29,10 @@ namespace wpi {
|
||||
* correct mapping, and only through the official NI DS. Sim is not guaranteed
|
||||
* to have the same mapping, as well as any 3rd party controllers.
|
||||
*/
|
||||
class {{ ConsoleName }}Controller : public GenericHID,
|
||||
public wpi::util::Sendable,
|
||||
public wpi::util::SendableHelper<{{ ConsoleName }}Controller> {
|
||||
class {{ ConsoleName }}Controller
|
||||
: public HIDDevice,
|
||||
public wpi::util::Sendable,
|
||||
public wpi::util::SendableHelper<{{ ConsoleName }}Controller> {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -41,10 +44,31 @@ class {{ ConsoleName }}Controller : public GenericHID,
|
||||
*/
|
||||
explicit {{ ConsoleName }}Controller(int port);
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this controller.
|
||||
*/
|
||||
explicit {{ ConsoleName }}Controller(GenericHID& hid);
|
||||
|
||||
~{{ ConsoleName }}Controller() override = default;
|
||||
|
||||
{{ ConsoleName }}Controller({{ ConsoleName }}Controller&&) = default;
|
||||
{{ ConsoleName }}Controller& operator=({{ ConsoleName }}Controller&&) = default;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
GenericHID& GetHID() override;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
const GenericHID& GetHID() const override;
|
||||
{% for stick in sticks %}
|
||||
/**
|
||||
* Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. {{ stick.PositiveDirection }} is positive.
|
||||
@@ -137,7 +161,56 @@ class {{ ConsoleName }}Controller : public GenericHID,
|
||||
{%- endfor %}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get if the controller is connected.
|
||||
*
|
||||
* @return true if the controller is connected
|
||||
*/
|
||||
bool IsConnected() const;
|
||||
|
||||
/**
|
||||
* Get the type of the controller.
|
||||
*
|
||||
* @return the type of the controller.
|
||||
*/
|
||||
GenericHID::HIDType GetGamepadType() const;
|
||||
|
||||
/**
|
||||
* Get the supported outputs of the controller.
|
||||
*
|
||||
* @return the supported outputs of the controller.
|
||||
*/
|
||||
GenericHID::SupportedOutputs GetSupportedOutputs() const;
|
||||
|
||||
/**
|
||||
* Get the name of the controller.
|
||||
*
|
||||
* @return the name of the controller.
|
||||
*/
|
||||
std::string GetName() const;
|
||||
|
||||
/**
|
||||
* Get the port number of the controller.
|
||||
*
|
||||
* @return The port number of the controller.
|
||||
*/
|
||||
int GetPort() const;
|
||||
|
||||
/**
|
||||
* Set the rumble output for the HID.
|
||||
*
|
||||
* The DS currently supports 4 rumble values: left rumble, right rumble, left
|
||||
* trigger rumble, and right trigger rumble.
|
||||
*
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
void SetRumble(GenericHID::RumbleType type, double value);
|
||||
|
||||
void InitSendable(wpi::util::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
GenericHID* m_hid;
|
||||
};
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
@@ -6,51 +6,63 @@
|
||||
|
||||
#include "wpi/driverstation/NiDsPS4Controller.hpp"
|
||||
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/event/BooleanEvent.hpp"
|
||||
#include "wpi/hal/UsageReporting.hpp"
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
|
||||
#include "wpi/event/BooleanEvent.hpp"
|
||||
|
||||
using namespace wpi;
|
||||
|
||||
NiDsPS4Controller::NiDsPS4Controller(int port) : GenericHID(port) {
|
||||
HAL_ReportUsage("HID", port, "NiDsPS4Controller");
|
||||
NiDsPS4Controller::NiDsPS4Controller(int port)
|
||||
: NiDsPS4Controller{DriverStation::GetGenericHID(port)} {}
|
||||
|
||||
NiDsPS4Controller::NiDsPS4Controller(GenericHID& hid)
|
||||
: m_hid{&hid} {
|
||||
HAL_ReportUsage("HID", hid.GetPort(), "NiDsPS4Controller");
|
||||
}
|
||||
|
||||
GenericHID& NiDsPS4Controller::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
const GenericHID& NiDsPS4Controller::GetHID() const {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
double NiDsPS4Controller::GetLeftX() const {
|
||||
return GetRawAxis(Axis::kLeftX);
|
||||
return m_hid->GetRawAxis(Axis::kLeftX);
|
||||
}
|
||||
|
||||
double NiDsPS4Controller::GetLeftY() const {
|
||||
return GetRawAxis(Axis::kLeftY);
|
||||
return m_hid->GetRawAxis(Axis::kLeftY);
|
||||
}
|
||||
|
||||
double NiDsPS4Controller::GetRightX() const {
|
||||
return GetRawAxis(Axis::kRightX);
|
||||
return m_hid->GetRawAxis(Axis::kRightX);
|
||||
}
|
||||
|
||||
double NiDsPS4Controller::GetRightY() const {
|
||||
return GetRawAxis(Axis::kRightY);
|
||||
return m_hid->GetRawAxis(Axis::kRightY);
|
||||
}
|
||||
|
||||
double NiDsPS4Controller::GetL2Axis() const {
|
||||
return GetRawAxis(Axis::kL2);
|
||||
return m_hid->GetRawAxis(Axis::kL2);
|
||||
}
|
||||
|
||||
double NiDsPS4Controller::GetR2Axis() const {
|
||||
return GetRawAxis(Axis::kR2);
|
||||
return m_hid->GetRawAxis(Axis::kR2);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetSquareButton() const {
|
||||
return GetRawButton(Button::kSquare);
|
||||
return m_hid->GetRawButton(Button::kSquare);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetSquareButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kSquare);
|
||||
return m_hid->GetRawButtonPressed(Button::kSquare);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetSquareButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kSquare);
|
||||
return m_hid->GetRawButtonReleased(Button::kSquare);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::Square(EventLoop* loop) const {
|
||||
@@ -58,15 +70,15 @@ BooleanEvent NiDsPS4Controller::Square(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetCrossButton() const {
|
||||
return GetRawButton(Button::kCross);
|
||||
return m_hid->GetRawButton(Button::kCross);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetCrossButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kCross);
|
||||
return m_hid->GetRawButtonPressed(Button::kCross);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetCrossButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kCross);
|
||||
return m_hid->GetRawButtonReleased(Button::kCross);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::Cross(EventLoop* loop) const {
|
||||
@@ -74,15 +86,15 @@ BooleanEvent NiDsPS4Controller::Cross(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetCircleButton() const {
|
||||
return GetRawButton(Button::kCircle);
|
||||
return m_hid->GetRawButton(Button::kCircle);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetCircleButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kCircle);
|
||||
return m_hid->GetRawButtonPressed(Button::kCircle);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetCircleButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kCircle);
|
||||
return m_hid->GetRawButtonReleased(Button::kCircle);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::Circle(EventLoop* loop) const {
|
||||
@@ -90,15 +102,15 @@ BooleanEvent NiDsPS4Controller::Circle(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetTriangleButton() const {
|
||||
return GetRawButton(Button::kTriangle);
|
||||
return m_hid->GetRawButton(Button::kTriangle);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetTriangleButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kTriangle);
|
||||
return m_hid->GetRawButtonPressed(Button::kTriangle);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetTriangleButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kTriangle);
|
||||
return m_hid->GetRawButtonReleased(Button::kTriangle);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::Triangle(EventLoop* loop) const {
|
||||
@@ -106,15 +118,15 @@ BooleanEvent NiDsPS4Controller::Triangle(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetL1Button() const {
|
||||
return GetRawButton(Button::kL1);
|
||||
return m_hid->GetRawButton(Button::kL1);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetL1ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kL1);
|
||||
return m_hid->GetRawButtonPressed(Button::kL1);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetL1ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kL1);
|
||||
return m_hid->GetRawButtonReleased(Button::kL1);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::L1(EventLoop* loop) const {
|
||||
@@ -122,15 +134,15 @@ BooleanEvent NiDsPS4Controller::L1(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetR1Button() const {
|
||||
return GetRawButton(Button::kR1);
|
||||
return m_hid->GetRawButton(Button::kR1);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetR1ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kR1);
|
||||
return m_hid->GetRawButtonPressed(Button::kR1);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetR1ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kR1);
|
||||
return m_hid->GetRawButtonReleased(Button::kR1);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::R1(EventLoop* loop) const {
|
||||
@@ -138,15 +150,15 @@ BooleanEvent NiDsPS4Controller::R1(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetL2Button() const {
|
||||
return GetRawButton(Button::kL2);
|
||||
return m_hid->GetRawButton(Button::kL2);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetL2ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kL2);
|
||||
return m_hid->GetRawButtonPressed(Button::kL2);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetL2ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kL2);
|
||||
return m_hid->GetRawButtonReleased(Button::kL2);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::L2(EventLoop* loop) const {
|
||||
@@ -154,15 +166,15 @@ BooleanEvent NiDsPS4Controller::L2(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetR2Button() const {
|
||||
return GetRawButton(Button::kR2);
|
||||
return m_hid->GetRawButton(Button::kR2);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetR2ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kR2);
|
||||
return m_hid->GetRawButtonPressed(Button::kR2);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetR2ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kR2);
|
||||
return m_hid->GetRawButtonReleased(Button::kR2);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::R2(EventLoop* loop) const {
|
||||
@@ -170,15 +182,15 @@ BooleanEvent NiDsPS4Controller::R2(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetShareButton() const {
|
||||
return GetRawButton(Button::kShare);
|
||||
return m_hid->GetRawButton(Button::kShare);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetShareButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kShare);
|
||||
return m_hid->GetRawButtonPressed(Button::kShare);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetShareButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kShare);
|
||||
return m_hid->GetRawButtonReleased(Button::kShare);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::Share(EventLoop* loop) const {
|
||||
@@ -186,15 +198,15 @@ BooleanEvent NiDsPS4Controller::Share(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetOptionsButton() const {
|
||||
return GetRawButton(Button::kOptions);
|
||||
return m_hid->GetRawButton(Button::kOptions);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetOptionsButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kOptions);
|
||||
return m_hid->GetRawButtonPressed(Button::kOptions);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetOptionsButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kOptions);
|
||||
return m_hid->GetRawButtonReleased(Button::kOptions);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::Options(EventLoop* loop) const {
|
||||
@@ -202,15 +214,15 @@ BooleanEvent NiDsPS4Controller::Options(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetL3Button() const {
|
||||
return GetRawButton(Button::kL3);
|
||||
return m_hid->GetRawButton(Button::kL3);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetL3ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kL3);
|
||||
return m_hid->GetRawButtonPressed(Button::kL3);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetL3ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kL3);
|
||||
return m_hid->GetRawButtonReleased(Button::kL3);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::L3(EventLoop* loop) const {
|
||||
@@ -218,15 +230,15 @@ BooleanEvent NiDsPS4Controller::L3(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetR3Button() const {
|
||||
return GetRawButton(Button::kR3);
|
||||
return m_hid->GetRawButton(Button::kR3);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetR3ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kR3);
|
||||
return m_hid->GetRawButtonPressed(Button::kR3);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetR3ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kR3);
|
||||
return m_hid->GetRawButtonReleased(Button::kR3);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::R3(EventLoop* loop) const {
|
||||
@@ -234,15 +246,15 @@ BooleanEvent NiDsPS4Controller::R3(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetPSButton() const {
|
||||
return GetRawButton(Button::kPS);
|
||||
return m_hid->GetRawButton(Button::kPS);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetPSButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kPS);
|
||||
return m_hid->GetRawButtonPressed(Button::kPS);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetPSButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kPS);
|
||||
return m_hid->GetRawButtonReleased(Button::kPS);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::PS(EventLoop* loop) const {
|
||||
@@ -250,42 +262,87 @@ BooleanEvent NiDsPS4Controller::PS(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetTouchpadButton() const {
|
||||
return GetRawButton(Button::kTouchpad);
|
||||
return m_hid->GetRawButton(Button::kTouchpad);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetTouchpadButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kTouchpad);
|
||||
return m_hid->GetRawButtonPressed(Button::kTouchpad);
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::GetTouchpadButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kTouchpad);
|
||||
return m_hid->GetRawButtonReleased(Button::kTouchpad);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS4Controller::Touchpad(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetTouchpadButton(); });
|
||||
}
|
||||
|
||||
bool NiDsPS4Controller::IsConnected() const {
|
||||
return m_hid->IsConnected();
|
||||
}
|
||||
|
||||
GenericHID::HIDType NiDsPS4Controller::GetGamepadType() const {
|
||||
return m_hid->GetGamepadType();
|
||||
}
|
||||
|
||||
GenericHID::SupportedOutputs NiDsPS4Controller::GetSupportedOutputs() const {
|
||||
return m_hid->GetSupportedOutputs();
|
||||
}
|
||||
|
||||
std::string NiDsPS4Controller::GetName() const {
|
||||
return m_hid->GetName();
|
||||
}
|
||||
|
||||
int NiDsPS4Controller::GetPort() const {
|
||||
return m_hid->GetPort();
|
||||
}
|
||||
|
||||
void NiDsPS4Controller::SetRumble(GenericHID::RumbleType type,
|
||||
double value) {
|
||||
m_hid->SetRumble(type, value);
|
||||
}
|
||||
|
||||
void NiDsPS4Controller::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("HID");
|
||||
builder.PublishConstString("ControllerType", "NiDsPS4");
|
||||
builder.AddDoubleProperty("L2 Axis", [this] { return GetL2Axis(); }, nullptr);
|
||||
builder.AddDoubleProperty("R2 Axis", [this] { return GetR2Axis(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftX", [this] { return GetLeftX(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftY", [this] { return GetLeftY(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightX", [this] { return GetRightX(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightY", [this] { return GetRightY(); }, nullptr);
|
||||
builder.AddBooleanProperty("Square", [this] { return GetSquareButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Cross", [this] { return GetCrossButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Circle", [this] { return GetCircleButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Triangle", [this] { return GetTriangleButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("L1", [this] { return GetL1Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("R1", [this] { return GetR1Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("L2", [this] { return GetL2Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("R2", [this] { return GetR2Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("Share", [this] { return GetShareButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Options", [this] { return GetOptionsButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("L3", [this] { return GetL3Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("R3", [this] { return GetR3Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("PS", [this] { return GetPSButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Touchpad", [this] { return GetTouchpadButton(); }, nullptr);
|
||||
builder.AddDoubleProperty("L2 Axis",
|
||||
[this] { return GetL2Axis(); }, nullptr);
|
||||
builder.AddDoubleProperty("R2 Axis",
|
||||
[this] { return GetR2Axis(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftX",
|
||||
[this] { return GetLeftX(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftY",
|
||||
[this] { return GetLeftY(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightX",
|
||||
[this] { return GetRightX(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightY",
|
||||
[this] { return GetRightY(); }, nullptr);
|
||||
builder.AddBooleanProperty("Square",
|
||||
[this] { return GetSquareButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Cross",
|
||||
[this] { return GetCrossButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Circle",
|
||||
[this] { return GetCircleButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Triangle",
|
||||
[this] { return GetTriangleButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("L1",
|
||||
[this] { return GetL1Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("R1",
|
||||
[this] { return GetR1Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("L2",
|
||||
[this] { return GetL2Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("R2",
|
||||
[this] { return GetR2Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("Share",
|
||||
[this] { return GetShareButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Options",
|
||||
[this] { return GetOptionsButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("L3",
|
||||
[this] { return GetL3Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("R3",
|
||||
[this] { return GetR3Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("PS",
|
||||
[this] { return GetPSButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Touchpad",
|
||||
[this] { return GetTouchpadButton(); }, nullptr);
|
||||
}
|
||||
@@ -6,51 +6,63 @@
|
||||
|
||||
#include "wpi/driverstation/NiDsPS5Controller.hpp"
|
||||
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/event/BooleanEvent.hpp"
|
||||
#include "wpi/hal/UsageReporting.hpp"
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
|
||||
#include "wpi/event/BooleanEvent.hpp"
|
||||
|
||||
using namespace wpi;
|
||||
|
||||
NiDsPS5Controller::NiDsPS5Controller(int port) : GenericHID(port) {
|
||||
HAL_ReportUsage("HID", port, "NiDsPS5Controller");
|
||||
NiDsPS5Controller::NiDsPS5Controller(int port)
|
||||
: NiDsPS5Controller{DriverStation::GetGenericHID(port)} {}
|
||||
|
||||
NiDsPS5Controller::NiDsPS5Controller(GenericHID& hid)
|
||||
: m_hid{&hid} {
|
||||
HAL_ReportUsage("HID", hid.GetPort(), "NiDsPS5Controller");
|
||||
}
|
||||
|
||||
GenericHID& NiDsPS5Controller::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
const GenericHID& NiDsPS5Controller::GetHID() const {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
double NiDsPS5Controller::GetLeftX() const {
|
||||
return GetRawAxis(Axis::kLeftX);
|
||||
return m_hid->GetRawAxis(Axis::kLeftX);
|
||||
}
|
||||
|
||||
double NiDsPS5Controller::GetLeftY() const {
|
||||
return GetRawAxis(Axis::kLeftY);
|
||||
return m_hid->GetRawAxis(Axis::kLeftY);
|
||||
}
|
||||
|
||||
double NiDsPS5Controller::GetRightX() const {
|
||||
return GetRawAxis(Axis::kRightX);
|
||||
return m_hid->GetRawAxis(Axis::kRightX);
|
||||
}
|
||||
|
||||
double NiDsPS5Controller::GetRightY() const {
|
||||
return GetRawAxis(Axis::kRightY);
|
||||
return m_hid->GetRawAxis(Axis::kRightY);
|
||||
}
|
||||
|
||||
double NiDsPS5Controller::GetL2Axis() const {
|
||||
return GetRawAxis(Axis::kL2);
|
||||
return m_hid->GetRawAxis(Axis::kL2);
|
||||
}
|
||||
|
||||
double NiDsPS5Controller::GetR2Axis() const {
|
||||
return GetRawAxis(Axis::kR2);
|
||||
return m_hid->GetRawAxis(Axis::kR2);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetSquareButton() const {
|
||||
return GetRawButton(Button::kSquare);
|
||||
return m_hid->GetRawButton(Button::kSquare);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetSquareButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kSquare);
|
||||
return m_hid->GetRawButtonPressed(Button::kSquare);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetSquareButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kSquare);
|
||||
return m_hid->GetRawButtonReleased(Button::kSquare);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::Square(EventLoop* loop) const {
|
||||
@@ -58,15 +70,15 @@ BooleanEvent NiDsPS5Controller::Square(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetCrossButton() const {
|
||||
return GetRawButton(Button::kCross);
|
||||
return m_hid->GetRawButton(Button::kCross);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetCrossButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kCross);
|
||||
return m_hid->GetRawButtonPressed(Button::kCross);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetCrossButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kCross);
|
||||
return m_hid->GetRawButtonReleased(Button::kCross);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::Cross(EventLoop* loop) const {
|
||||
@@ -74,15 +86,15 @@ BooleanEvent NiDsPS5Controller::Cross(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetCircleButton() const {
|
||||
return GetRawButton(Button::kCircle);
|
||||
return m_hid->GetRawButton(Button::kCircle);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetCircleButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kCircle);
|
||||
return m_hid->GetRawButtonPressed(Button::kCircle);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetCircleButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kCircle);
|
||||
return m_hid->GetRawButtonReleased(Button::kCircle);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::Circle(EventLoop* loop) const {
|
||||
@@ -90,15 +102,15 @@ BooleanEvent NiDsPS5Controller::Circle(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetTriangleButton() const {
|
||||
return GetRawButton(Button::kTriangle);
|
||||
return m_hid->GetRawButton(Button::kTriangle);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetTriangleButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kTriangle);
|
||||
return m_hid->GetRawButtonPressed(Button::kTriangle);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetTriangleButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kTriangle);
|
||||
return m_hid->GetRawButtonReleased(Button::kTriangle);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::Triangle(EventLoop* loop) const {
|
||||
@@ -106,15 +118,15 @@ BooleanEvent NiDsPS5Controller::Triangle(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetL1Button() const {
|
||||
return GetRawButton(Button::kL1);
|
||||
return m_hid->GetRawButton(Button::kL1);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetL1ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kL1);
|
||||
return m_hid->GetRawButtonPressed(Button::kL1);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetL1ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kL1);
|
||||
return m_hid->GetRawButtonReleased(Button::kL1);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::L1(EventLoop* loop) const {
|
||||
@@ -122,15 +134,15 @@ BooleanEvent NiDsPS5Controller::L1(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetR1Button() const {
|
||||
return GetRawButton(Button::kR1);
|
||||
return m_hid->GetRawButton(Button::kR1);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetR1ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kR1);
|
||||
return m_hid->GetRawButtonPressed(Button::kR1);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetR1ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kR1);
|
||||
return m_hid->GetRawButtonReleased(Button::kR1);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::R1(EventLoop* loop) const {
|
||||
@@ -138,15 +150,15 @@ BooleanEvent NiDsPS5Controller::R1(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetL2Button() const {
|
||||
return GetRawButton(Button::kL2);
|
||||
return m_hid->GetRawButton(Button::kL2);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetL2ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kL2);
|
||||
return m_hid->GetRawButtonPressed(Button::kL2);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetL2ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kL2);
|
||||
return m_hid->GetRawButtonReleased(Button::kL2);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::L2(EventLoop* loop) const {
|
||||
@@ -154,15 +166,15 @@ BooleanEvent NiDsPS5Controller::L2(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetR2Button() const {
|
||||
return GetRawButton(Button::kR2);
|
||||
return m_hid->GetRawButton(Button::kR2);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetR2ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kR2);
|
||||
return m_hid->GetRawButtonPressed(Button::kR2);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetR2ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kR2);
|
||||
return m_hid->GetRawButtonReleased(Button::kR2);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::R2(EventLoop* loop) const {
|
||||
@@ -170,15 +182,15 @@ BooleanEvent NiDsPS5Controller::R2(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetCreateButton() const {
|
||||
return GetRawButton(Button::kCreate);
|
||||
return m_hid->GetRawButton(Button::kCreate);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetCreateButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kCreate);
|
||||
return m_hid->GetRawButtonPressed(Button::kCreate);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetCreateButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kCreate);
|
||||
return m_hid->GetRawButtonReleased(Button::kCreate);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::Create(EventLoop* loop) const {
|
||||
@@ -186,15 +198,15 @@ BooleanEvent NiDsPS5Controller::Create(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetOptionsButton() const {
|
||||
return GetRawButton(Button::kOptions);
|
||||
return m_hid->GetRawButton(Button::kOptions);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetOptionsButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kOptions);
|
||||
return m_hid->GetRawButtonPressed(Button::kOptions);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetOptionsButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kOptions);
|
||||
return m_hid->GetRawButtonReleased(Button::kOptions);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::Options(EventLoop* loop) const {
|
||||
@@ -202,15 +214,15 @@ BooleanEvent NiDsPS5Controller::Options(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetL3Button() const {
|
||||
return GetRawButton(Button::kL3);
|
||||
return m_hid->GetRawButton(Button::kL3);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetL3ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kL3);
|
||||
return m_hid->GetRawButtonPressed(Button::kL3);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetL3ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kL3);
|
||||
return m_hid->GetRawButtonReleased(Button::kL3);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::L3(EventLoop* loop) const {
|
||||
@@ -218,15 +230,15 @@ BooleanEvent NiDsPS5Controller::L3(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetR3Button() const {
|
||||
return GetRawButton(Button::kR3);
|
||||
return m_hid->GetRawButton(Button::kR3);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetR3ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kR3);
|
||||
return m_hid->GetRawButtonPressed(Button::kR3);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetR3ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kR3);
|
||||
return m_hid->GetRawButtonReleased(Button::kR3);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::R3(EventLoop* loop) const {
|
||||
@@ -234,15 +246,15 @@ BooleanEvent NiDsPS5Controller::R3(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetPSButton() const {
|
||||
return GetRawButton(Button::kPS);
|
||||
return m_hid->GetRawButton(Button::kPS);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetPSButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kPS);
|
||||
return m_hid->GetRawButtonPressed(Button::kPS);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetPSButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kPS);
|
||||
return m_hid->GetRawButtonReleased(Button::kPS);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::PS(EventLoop* loop) const {
|
||||
@@ -250,42 +262,87 @@ BooleanEvent NiDsPS5Controller::PS(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetTouchpadButton() const {
|
||||
return GetRawButton(Button::kTouchpad);
|
||||
return m_hid->GetRawButton(Button::kTouchpad);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetTouchpadButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kTouchpad);
|
||||
return m_hid->GetRawButtonPressed(Button::kTouchpad);
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::GetTouchpadButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kTouchpad);
|
||||
return m_hid->GetRawButtonReleased(Button::kTouchpad);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsPS5Controller::Touchpad(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetTouchpadButton(); });
|
||||
}
|
||||
|
||||
bool NiDsPS5Controller::IsConnected() const {
|
||||
return m_hid->IsConnected();
|
||||
}
|
||||
|
||||
GenericHID::HIDType NiDsPS5Controller::GetGamepadType() const {
|
||||
return m_hid->GetGamepadType();
|
||||
}
|
||||
|
||||
GenericHID::SupportedOutputs NiDsPS5Controller::GetSupportedOutputs() const {
|
||||
return m_hid->GetSupportedOutputs();
|
||||
}
|
||||
|
||||
std::string NiDsPS5Controller::GetName() const {
|
||||
return m_hid->GetName();
|
||||
}
|
||||
|
||||
int NiDsPS5Controller::GetPort() const {
|
||||
return m_hid->GetPort();
|
||||
}
|
||||
|
||||
void NiDsPS5Controller::SetRumble(GenericHID::RumbleType type,
|
||||
double value) {
|
||||
m_hid->SetRumble(type, value);
|
||||
}
|
||||
|
||||
void NiDsPS5Controller::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("HID");
|
||||
builder.PublishConstString("ControllerType", "NiDsPS5");
|
||||
builder.AddDoubleProperty("L2 Axis", [this] { return GetL2Axis(); }, nullptr);
|
||||
builder.AddDoubleProperty("R2 Axis", [this] { return GetR2Axis(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftX", [this] { return GetLeftX(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftY", [this] { return GetLeftY(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightX", [this] { return GetRightX(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightY", [this] { return GetRightY(); }, nullptr);
|
||||
builder.AddBooleanProperty("Square", [this] { return GetSquareButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Cross", [this] { return GetCrossButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Circle", [this] { return GetCircleButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Triangle", [this] { return GetTriangleButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("L1", [this] { return GetL1Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("R1", [this] { return GetR1Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("L2", [this] { return GetL2Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("R2", [this] { return GetR2Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("Create", [this] { return GetCreateButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Options", [this] { return GetOptionsButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("L3", [this] { return GetL3Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("R3", [this] { return GetR3Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("PS", [this] { return GetPSButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Touchpad", [this] { return GetTouchpadButton(); }, nullptr);
|
||||
builder.AddDoubleProperty("L2 Axis",
|
||||
[this] { return GetL2Axis(); }, nullptr);
|
||||
builder.AddDoubleProperty("R2 Axis",
|
||||
[this] { return GetR2Axis(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftX",
|
||||
[this] { return GetLeftX(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftY",
|
||||
[this] { return GetLeftY(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightX",
|
||||
[this] { return GetRightX(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightY",
|
||||
[this] { return GetRightY(); }, nullptr);
|
||||
builder.AddBooleanProperty("Square",
|
||||
[this] { return GetSquareButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Cross",
|
||||
[this] { return GetCrossButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Circle",
|
||||
[this] { return GetCircleButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Triangle",
|
||||
[this] { return GetTriangleButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("L1",
|
||||
[this] { return GetL1Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("R1",
|
||||
[this] { return GetR1Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("L2",
|
||||
[this] { return GetL2Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("R2",
|
||||
[this] { return GetR2Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("Create",
|
||||
[this] { return GetCreateButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Options",
|
||||
[this] { return GetOptionsButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("L3",
|
||||
[this] { return GetL3Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("R3",
|
||||
[this] { return GetR3Button(); }, nullptr);
|
||||
builder.AddBooleanProperty("PS",
|
||||
[this] { return GetPSButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Touchpad",
|
||||
[this] { return GetTouchpadButton(); }, nullptr);
|
||||
}
|
||||
@@ -6,43 +6,55 @@
|
||||
|
||||
#include "wpi/driverstation/NiDsStadiaController.hpp"
|
||||
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/event/BooleanEvent.hpp"
|
||||
#include "wpi/hal/UsageReporting.hpp"
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
|
||||
#include "wpi/event/BooleanEvent.hpp"
|
||||
|
||||
using namespace wpi;
|
||||
|
||||
NiDsStadiaController::NiDsStadiaController(int port) : GenericHID(port) {
|
||||
HAL_ReportUsage("HID", port, "NiDsStadiaController");
|
||||
NiDsStadiaController::NiDsStadiaController(int port)
|
||||
: NiDsStadiaController{DriverStation::GetGenericHID(port)} {}
|
||||
|
||||
NiDsStadiaController::NiDsStadiaController(GenericHID& hid)
|
||||
: m_hid{&hid} {
|
||||
HAL_ReportUsage("HID", hid.GetPort(), "NiDsStadiaController");
|
||||
}
|
||||
|
||||
GenericHID& NiDsStadiaController::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
const GenericHID& NiDsStadiaController::GetHID() const {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
double NiDsStadiaController::GetLeftX() const {
|
||||
return GetRawAxis(Axis::kLeftX);
|
||||
return m_hid->GetRawAxis(Axis::kLeftX);
|
||||
}
|
||||
|
||||
double NiDsStadiaController::GetRightX() const {
|
||||
return GetRawAxis(Axis::kRightX);
|
||||
return m_hid->GetRawAxis(Axis::kRightX);
|
||||
}
|
||||
|
||||
double NiDsStadiaController::GetLeftY() const {
|
||||
return GetRawAxis(Axis::kLeftY);
|
||||
return m_hid->GetRawAxis(Axis::kLeftY);
|
||||
}
|
||||
|
||||
double NiDsStadiaController::GetRightY() const {
|
||||
return GetRawAxis(Axis::kRightY);
|
||||
return m_hid->GetRawAxis(Axis::kRightY);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetAButton() const {
|
||||
return GetRawButton(Button::kA);
|
||||
return m_hid->GetRawButton(Button::kA);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetAButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kA);
|
||||
return m_hid->GetRawButtonPressed(Button::kA);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetAButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kA);
|
||||
return m_hid->GetRawButtonReleased(Button::kA);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::A(EventLoop* loop) const {
|
||||
@@ -50,15 +62,15 @@ BooleanEvent NiDsStadiaController::A(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetBButton() const {
|
||||
return GetRawButton(Button::kB);
|
||||
return m_hid->GetRawButton(Button::kB);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetBButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kB);
|
||||
return m_hid->GetRawButtonPressed(Button::kB);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetBButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kB);
|
||||
return m_hid->GetRawButtonReleased(Button::kB);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::B(EventLoop* loop) const {
|
||||
@@ -66,15 +78,15 @@ BooleanEvent NiDsStadiaController::B(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetXButton() const {
|
||||
return GetRawButton(Button::kX);
|
||||
return m_hid->GetRawButton(Button::kX);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetXButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kX);
|
||||
return m_hid->GetRawButtonPressed(Button::kX);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetXButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kX);
|
||||
return m_hid->GetRawButtonReleased(Button::kX);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::X(EventLoop* loop) const {
|
||||
@@ -82,15 +94,15 @@ BooleanEvent NiDsStadiaController::X(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetYButton() const {
|
||||
return GetRawButton(Button::kY);
|
||||
return m_hid->GetRawButton(Button::kY);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetYButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kY);
|
||||
return m_hid->GetRawButtonPressed(Button::kY);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetYButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kY);
|
||||
return m_hid->GetRawButtonReleased(Button::kY);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::Y(EventLoop* loop) const {
|
||||
@@ -98,15 +110,15 @@ BooleanEvent NiDsStadiaController::Y(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetLeftBumperButton() const {
|
||||
return GetRawButton(Button::kLeftBumper);
|
||||
return m_hid->GetRawButton(Button::kLeftBumper);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetLeftBumperButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kLeftBumper);
|
||||
return m_hid->GetRawButtonPressed(Button::kLeftBumper);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetLeftBumperButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kLeftBumper);
|
||||
return m_hid->GetRawButtonReleased(Button::kLeftBumper);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::LeftBumper(EventLoop* loop) const {
|
||||
@@ -114,15 +126,15 @@ BooleanEvent NiDsStadiaController::LeftBumper(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetRightBumperButton() const {
|
||||
return GetRawButton(Button::kRightBumper);
|
||||
return m_hid->GetRawButton(Button::kRightBumper);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetRightBumperButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kRightBumper);
|
||||
return m_hid->GetRawButtonPressed(Button::kRightBumper);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetRightBumperButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kRightBumper);
|
||||
return m_hid->GetRawButtonReleased(Button::kRightBumper);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::RightBumper(EventLoop* loop) const {
|
||||
@@ -130,15 +142,15 @@ BooleanEvent NiDsStadiaController::RightBumper(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetLeftStickButton() const {
|
||||
return GetRawButton(Button::kLeftStick);
|
||||
return m_hid->GetRawButton(Button::kLeftStick);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetLeftStickButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kLeftStick);
|
||||
return m_hid->GetRawButtonPressed(Button::kLeftStick);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetLeftStickButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kLeftStick);
|
||||
return m_hid->GetRawButtonReleased(Button::kLeftStick);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::LeftStick(EventLoop* loop) const {
|
||||
@@ -146,15 +158,15 @@ BooleanEvent NiDsStadiaController::LeftStick(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetRightStickButton() const {
|
||||
return GetRawButton(Button::kRightStick);
|
||||
return m_hid->GetRawButton(Button::kRightStick);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetRightStickButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kRightStick);
|
||||
return m_hid->GetRawButtonPressed(Button::kRightStick);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetRightStickButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kRightStick);
|
||||
return m_hid->GetRawButtonReleased(Button::kRightStick);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::RightStick(EventLoop* loop) const {
|
||||
@@ -162,15 +174,15 @@ BooleanEvent NiDsStadiaController::RightStick(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetEllipsesButton() const {
|
||||
return GetRawButton(Button::kEllipses);
|
||||
return m_hid->GetRawButton(Button::kEllipses);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetEllipsesButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kEllipses);
|
||||
return m_hid->GetRawButtonPressed(Button::kEllipses);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetEllipsesButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kEllipses);
|
||||
return m_hid->GetRawButtonReleased(Button::kEllipses);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::Ellipses(EventLoop* loop) const {
|
||||
@@ -178,15 +190,15 @@ BooleanEvent NiDsStadiaController::Ellipses(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetHamburgerButton() const {
|
||||
return GetRawButton(Button::kHamburger);
|
||||
return m_hid->GetRawButton(Button::kHamburger);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetHamburgerButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kHamburger);
|
||||
return m_hid->GetRawButtonPressed(Button::kHamburger);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetHamburgerButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kHamburger);
|
||||
return m_hid->GetRawButtonReleased(Button::kHamburger);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::Hamburger(EventLoop* loop) const {
|
||||
@@ -194,15 +206,15 @@ BooleanEvent NiDsStadiaController::Hamburger(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetStadiaButton() const {
|
||||
return GetRawButton(Button::kStadia);
|
||||
return m_hid->GetRawButton(Button::kStadia);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetStadiaButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kStadia);
|
||||
return m_hid->GetRawButtonPressed(Button::kStadia);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetStadiaButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kStadia);
|
||||
return m_hid->GetRawButtonReleased(Button::kStadia);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::Stadia(EventLoop* loop) const {
|
||||
@@ -210,15 +222,15 @@ BooleanEvent NiDsStadiaController::Stadia(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetRightTriggerButton() const {
|
||||
return GetRawButton(Button::kRightTrigger);
|
||||
return m_hid->GetRawButton(Button::kRightTrigger);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetRightTriggerButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kRightTrigger);
|
||||
return m_hid->GetRawButtonPressed(Button::kRightTrigger);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetRightTriggerButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kRightTrigger);
|
||||
return m_hid->GetRawButtonReleased(Button::kRightTrigger);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::RightTrigger(EventLoop* loop) const {
|
||||
@@ -226,15 +238,15 @@ BooleanEvent NiDsStadiaController::RightTrigger(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetLeftTriggerButton() const {
|
||||
return GetRawButton(Button::kLeftTrigger);
|
||||
return m_hid->GetRawButton(Button::kLeftTrigger);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetLeftTriggerButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kLeftTrigger);
|
||||
return m_hid->GetRawButtonPressed(Button::kLeftTrigger);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetLeftTriggerButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kLeftTrigger);
|
||||
return m_hid->GetRawButtonReleased(Button::kLeftTrigger);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::LeftTrigger(EventLoop* loop) const {
|
||||
@@ -242,15 +254,15 @@ BooleanEvent NiDsStadiaController::LeftTrigger(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetGoogleButton() const {
|
||||
return GetRawButton(Button::kGoogle);
|
||||
return m_hid->GetRawButton(Button::kGoogle);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetGoogleButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kGoogle);
|
||||
return m_hid->GetRawButtonPressed(Button::kGoogle);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetGoogleButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kGoogle);
|
||||
return m_hid->GetRawButtonReleased(Button::kGoogle);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::Google(EventLoop* loop) const {
|
||||
@@ -258,41 +270,85 @@ BooleanEvent NiDsStadiaController::Google(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetFrameButton() const {
|
||||
return GetRawButton(Button::kFrame);
|
||||
return m_hid->GetRawButton(Button::kFrame);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetFrameButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kFrame);
|
||||
return m_hid->GetRawButtonPressed(Button::kFrame);
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::GetFrameButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kFrame);
|
||||
return m_hid->GetRawButtonReleased(Button::kFrame);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsStadiaController::Frame(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetFrameButton(); });
|
||||
}
|
||||
|
||||
bool NiDsStadiaController::IsConnected() const {
|
||||
return m_hid->IsConnected();
|
||||
}
|
||||
|
||||
GenericHID::HIDType NiDsStadiaController::GetGamepadType() const {
|
||||
return m_hid->GetGamepadType();
|
||||
}
|
||||
|
||||
GenericHID::SupportedOutputs NiDsStadiaController::GetSupportedOutputs() const {
|
||||
return m_hid->GetSupportedOutputs();
|
||||
}
|
||||
|
||||
std::string NiDsStadiaController::GetName() const {
|
||||
return m_hid->GetName();
|
||||
}
|
||||
|
||||
int NiDsStadiaController::GetPort() const {
|
||||
return m_hid->GetPort();
|
||||
}
|
||||
|
||||
void NiDsStadiaController::SetRumble(GenericHID::RumbleType type,
|
||||
double value) {
|
||||
m_hid->SetRumble(type, value);
|
||||
}
|
||||
|
||||
void NiDsStadiaController::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("HID");
|
||||
builder.PublishConstString("ControllerType", "NiDsStadia");
|
||||
builder.AddDoubleProperty("LeftX", [this] { return GetLeftX(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightX", [this] { return GetRightX(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftY", [this] { return GetLeftY(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightY", [this] { return GetRightY(); }, nullptr);
|
||||
builder.AddBooleanProperty("A", [this] { return GetAButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("B", [this] { return GetBButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("X", [this] { return GetXButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Y", [this] { return GetYButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("LeftBumper", [this] { return GetLeftBumperButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("RightBumper", [this] { return GetRightBumperButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("LeftStick", [this] { return GetLeftStickButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("RightStick", [this] { return GetRightStickButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Ellipses", [this] { return GetEllipsesButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Hamburger", [this] { return GetHamburgerButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Stadia", [this] { return GetStadiaButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("RightTrigger", [this] { return GetRightTriggerButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("LeftTrigger", [this] { return GetLeftTriggerButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Google", [this] { return GetGoogleButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Frame", [this] { return GetFrameButton(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftX",
|
||||
[this] { return GetLeftX(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightX",
|
||||
[this] { return GetRightX(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftY",
|
||||
[this] { return GetLeftY(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightY",
|
||||
[this] { return GetRightY(); }, nullptr);
|
||||
builder.AddBooleanProperty("A",
|
||||
[this] { return GetAButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("B",
|
||||
[this] { return GetBButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("X",
|
||||
[this] { return GetXButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Y",
|
||||
[this] { return GetYButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("LeftBumper",
|
||||
[this] { return GetLeftBumperButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("RightBumper",
|
||||
[this] { return GetRightBumperButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("LeftStick",
|
||||
[this] { return GetLeftStickButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("RightStick",
|
||||
[this] { return GetRightStickButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Ellipses",
|
||||
[this] { return GetEllipsesButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Hamburger",
|
||||
[this] { return GetHamburgerButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Stadia",
|
||||
[this] { return GetStadiaButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("RightTrigger",
|
||||
[this] { return GetRightTriggerButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("LeftTrigger",
|
||||
[this] { return GetLeftTriggerButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Google",
|
||||
[this] { return GetGoogleButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Frame",
|
||||
[this] { return GetFrameButton(); }, nullptr);
|
||||
}
|
||||
@@ -6,39 +6,53 @@
|
||||
|
||||
#include "wpi/driverstation/NiDsXboxController.hpp"
|
||||
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/event/BooleanEvent.hpp"
|
||||
#include "wpi/hal/UsageReporting.hpp"
|
||||
#include "wpi/util/sendable/SendableBuilder.hpp"
|
||||
|
||||
#include "wpi/event/BooleanEvent.hpp"
|
||||
|
||||
using namespace wpi;
|
||||
|
||||
NiDsXboxController::NiDsXboxController(int port) : GenericHID(port) {
|
||||
HAL_ReportUsage("HID", port, "NiDsXboxController");
|
||||
NiDsXboxController::NiDsXboxController(int port)
|
||||
: NiDsXboxController{DriverStation::GetGenericHID(port)} {}
|
||||
|
||||
NiDsXboxController::NiDsXboxController(GenericHID& hid)
|
||||
: m_hid{&hid} {
|
||||
HAL_ReportUsage("HID", hid.GetPort(), "NiDsXboxController");
|
||||
}
|
||||
|
||||
GenericHID& NiDsXboxController::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
const GenericHID& NiDsXboxController::GetHID() const {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
double NiDsXboxController::GetLeftX() const {
|
||||
return GetRawAxis(Axis::kLeftX);
|
||||
return m_hid->GetRawAxis(Axis::kLeftX);
|
||||
}
|
||||
|
||||
double NiDsXboxController::GetRightX() const {
|
||||
return GetRawAxis(Axis::kRightX);
|
||||
return m_hid->GetRawAxis(Axis::kRightX);
|
||||
}
|
||||
|
||||
double NiDsXboxController::GetLeftY() const {
|
||||
return GetRawAxis(Axis::kLeftY);
|
||||
return m_hid->GetRawAxis(Axis::kLeftY);
|
||||
}
|
||||
|
||||
double NiDsXboxController::GetRightY() const {
|
||||
return GetRawAxis(Axis::kRightY);
|
||||
return m_hid->GetRawAxis(Axis::kRightY);
|
||||
}
|
||||
|
||||
double NiDsXboxController::GetLeftTriggerAxis() const {
|
||||
return GetRawAxis(Axis::kLeftTrigger);
|
||||
return m_hid->GetRawAxis(Axis::kLeftTrigger);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::LeftTrigger(double threshold, EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this, threshold] { return this->GetLeftTriggerAxis() > threshold; });
|
||||
BooleanEvent NiDsXboxController::LeftTrigger(double threshold,
|
||||
EventLoop* loop) const {
|
||||
return BooleanEvent(
|
||||
loop, [this, threshold] { return this->GetLeftTriggerAxis() > threshold; });
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::LeftTrigger(EventLoop* loop) const {
|
||||
@@ -46,11 +60,13 @@ BooleanEvent NiDsXboxController::LeftTrigger(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
double NiDsXboxController::GetRightTriggerAxis() const {
|
||||
return GetRawAxis(Axis::kRightTrigger);
|
||||
return m_hid->GetRawAxis(Axis::kRightTrigger);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::RightTrigger(double threshold, EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this, threshold] { return this->GetRightTriggerAxis() > threshold; });
|
||||
BooleanEvent NiDsXboxController::RightTrigger(double threshold,
|
||||
EventLoop* loop) const {
|
||||
return BooleanEvent(
|
||||
loop, [this, threshold] { return this->GetRightTriggerAxis() > threshold; });
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::RightTrigger(EventLoop* loop) const {
|
||||
@@ -58,15 +74,15 @@ BooleanEvent NiDsXboxController::RightTrigger(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetAButton() const {
|
||||
return GetRawButton(Button::kA);
|
||||
return m_hid->GetRawButton(Button::kA);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetAButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kA);
|
||||
return m_hid->GetRawButtonPressed(Button::kA);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetAButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kA);
|
||||
return m_hid->GetRawButtonReleased(Button::kA);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::A(EventLoop* loop) const {
|
||||
@@ -74,15 +90,15 @@ BooleanEvent NiDsXboxController::A(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetBButton() const {
|
||||
return GetRawButton(Button::kB);
|
||||
return m_hid->GetRawButton(Button::kB);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetBButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kB);
|
||||
return m_hid->GetRawButtonPressed(Button::kB);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetBButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kB);
|
||||
return m_hid->GetRawButtonReleased(Button::kB);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::B(EventLoop* loop) const {
|
||||
@@ -90,15 +106,15 @@ BooleanEvent NiDsXboxController::B(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetXButton() const {
|
||||
return GetRawButton(Button::kX);
|
||||
return m_hid->GetRawButton(Button::kX);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetXButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kX);
|
||||
return m_hid->GetRawButtonPressed(Button::kX);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetXButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kX);
|
||||
return m_hid->GetRawButtonReleased(Button::kX);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::X(EventLoop* loop) const {
|
||||
@@ -106,15 +122,15 @@ BooleanEvent NiDsXboxController::X(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetYButton() const {
|
||||
return GetRawButton(Button::kY);
|
||||
return m_hid->GetRawButton(Button::kY);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetYButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kY);
|
||||
return m_hid->GetRawButtonPressed(Button::kY);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetYButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kY);
|
||||
return m_hid->GetRawButtonReleased(Button::kY);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::Y(EventLoop* loop) const {
|
||||
@@ -122,15 +138,15 @@ BooleanEvent NiDsXboxController::Y(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetLeftBumperButton() const {
|
||||
return GetRawButton(Button::kLeftBumper);
|
||||
return m_hid->GetRawButton(Button::kLeftBumper);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetLeftBumperButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kLeftBumper);
|
||||
return m_hid->GetRawButtonPressed(Button::kLeftBumper);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetLeftBumperButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kLeftBumper);
|
||||
return m_hid->GetRawButtonReleased(Button::kLeftBumper);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::LeftBumper(EventLoop* loop) const {
|
||||
@@ -138,15 +154,15 @@ BooleanEvent NiDsXboxController::LeftBumper(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetRightBumperButton() const {
|
||||
return GetRawButton(Button::kRightBumper);
|
||||
return m_hid->GetRawButton(Button::kRightBumper);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetRightBumperButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kRightBumper);
|
||||
return m_hid->GetRawButtonPressed(Button::kRightBumper);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetRightBumperButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kRightBumper);
|
||||
return m_hid->GetRawButtonReleased(Button::kRightBumper);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::RightBumper(EventLoop* loop) const {
|
||||
@@ -154,15 +170,15 @@ BooleanEvent NiDsXboxController::RightBumper(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetBackButton() const {
|
||||
return GetRawButton(Button::kBack);
|
||||
return m_hid->GetRawButton(Button::kBack);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetBackButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kBack);
|
||||
return m_hid->GetRawButtonPressed(Button::kBack);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetBackButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kBack);
|
||||
return m_hid->GetRawButtonReleased(Button::kBack);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::Back(EventLoop* loop) const {
|
||||
@@ -170,15 +186,15 @@ BooleanEvent NiDsXboxController::Back(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetStartButton() const {
|
||||
return GetRawButton(Button::kStart);
|
||||
return m_hid->GetRawButton(Button::kStart);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetStartButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kStart);
|
||||
return m_hid->GetRawButtonPressed(Button::kStart);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetStartButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kStart);
|
||||
return m_hid->GetRawButtonReleased(Button::kStart);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::Start(EventLoop* loop) const {
|
||||
@@ -186,15 +202,15 @@ BooleanEvent NiDsXboxController::Start(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetLeftStickButton() const {
|
||||
return GetRawButton(Button::kLeftStick);
|
||||
return m_hid->GetRawButton(Button::kLeftStick);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetLeftStickButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kLeftStick);
|
||||
return m_hid->GetRawButtonPressed(Button::kLeftStick);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetLeftStickButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kLeftStick);
|
||||
return m_hid->GetRawButtonReleased(Button::kLeftStick);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::LeftStick(EventLoop* loop) const {
|
||||
@@ -202,38 +218,79 @@ BooleanEvent NiDsXboxController::LeftStick(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetRightStickButton() const {
|
||||
return GetRawButton(Button::kRightStick);
|
||||
return m_hid->GetRawButton(Button::kRightStick);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetRightStickButtonPressed() {
|
||||
return GetRawButtonPressed(Button::kRightStick);
|
||||
return m_hid->GetRawButtonPressed(Button::kRightStick);
|
||||
}
|
||||
|
||||
bool NiDsXboxController::GetRightStickButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kRightStick);
|
||||
return m_hid->GetRawButtonReleased(Button::kRightStick);
|
||||
}
|
||||
|
||||
BooleanEvent NiDsXboxController::RightStick(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetRightStickButton(); });
|
||||
}
|
||||
|
||||
bool NiDsXboxController::IsConnected() const {
|
||||
return m_hid->IsConnected();
|
||||
}
|
||||
|
||||
GenericHID::HIDType NiDsXboxController::GetGamepadType() const {
|
||||
return m_hid->GetGamepadType();
|
||||
}
|
||||
|
||||
GenericHID::SupportedOutputs NiDsXboxController::GetSupportedOutputs() const {
|
||||
return m_hid->GetSupportedOutputs();
|
||||
}
|
||||
|
||||
std::string NiDsXboxController::GetName() const {
|
||||
return m_hid->GetName();
|
||||
}
|
||||
|
||||
int NiDsXboxController::GetPort() const {
|
||||
return m_hid->GetPort();
|
||||
}
|
||||
|
||||
void NiDsXboxController::SetRumble(GenericHID::RumbleType type,
|
||||
double value) {
|
||||
m_hid->SetRumble(type, value);
|
||||
}
|
||||
|
||||
void NiDsXboxController::InitSendable(wpi::util::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("HID");
|
||||
builder.PublishConstString("ControllerType", "NiDsXbox");
|
||||
builder.AddDoubleProperty("LeftTrigger Axis", [this] { return GetLeftTriggerAxis(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightTrigger Axis", [this] { return GetRightTriggerAxis(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftX", [this] { return GetLeftX(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightX", [this] { return GetRightX(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftY", [this] { return GetLeftY(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightY", [this] { return GetRightY(); }, nullptr);
|
||||
builder.AddBooleanProperty("A", [this] { return GetAButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("B", [this] { return GetBButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("X", [this] { return GetXButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Y", [this] { return GetYButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("LeftBumper", [this] { return GetLeftBumperButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("RightBumper", [this] { return GetRightBumperButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Back", [this] { return GetBackButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Start", [this] { return GetStartButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("LeftStick", [this] { return GetLeftStickButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("RightStick", [this] { return GetRightStickButton(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftTrigger Axis",
|
||||
[this] { return GetLeftTriggerAxis(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightTrigger Axis",
|
||||
[this] { return GetRightTriggerAxis(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftX",
|
||||
[this] { return GetLeftX(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightX",
|
||||
[this] { return GetRightX(); }, nullptr);
|
||||
builder.AddDoubleProperty("LeftY",
|
||||
[this] { return GetLeftY(); }, nullptr);
|
||||
builder.AddDoubleProperty("RightY",
|
||||
[this] { return GetRightY(); }, nullptr);
|
||||
builder.AddBooleanProperty("A",
|
||||
[this] { return GetAButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("B",
|
||||
[this] { return GetBButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("X",
|
||||
[this] { return GetXButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Y",
|
||||
[this] { return GetYButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("LeftBumper",
|
||||
[this] { return GetLeftBumperButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("RightBumper",
|
||||
[this] { return GetRightBumperButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Back",
|
||||
[this] { return GetBackButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("Start",
|
||||
[this] { return GetStartButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("LeftStick",
|
||||
[this] { return GetLeftStickButton(); }, nullptr);
|
||||
builder.AddBooleanProperty("RightStick",
|
||||
[this] { return GetRightStickButton(); }, nullptr);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
using namespace wpi::sim;
|
||||
|
||||
NiDsPS4ControllerSim::NiDsPS4ControllerSim(const NiDsPS4Controller& joystick)
|
||||
: GenericHIDSim{joystick} {
|
||||
: GenericHIDSim{joystick.GetHID()} {
|
||||
SetAxesMaximumIndex(6);
|
||||
SetButtonsMaximumIndex(14);
|
||||
SetPOVsMaximumIndex(1);
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
using namespace wpi::sim;
|
||||
|
||||
NiDsPS5ControllerSim::NiDsPS5ControllerSim(const NiDsPS5Controller& joystick)
|
||||
: GenericHIDSim{joystick} {
|
||||
: GenericHIDSim{joystick.GetHID()} {
|
||||
SetAxesMaximumIndex(6);
|
||||
SetButtonsMaximumIndex(14);
|
||||
SetPOVsMaximumIndex(1);
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
using namespace wpi::sim;
|
||||
|
||||
NiDsStadiaControllerSim::NiDsStadiaControllerSim(const NiDsStadiaController& joystick)
|
||||
: GenericHIDSim{joystick} {
|
||||
: GenericHIDSim{joystick.GetHID()} {
|
||||
SetAxesMaximumIndex(4);
|
||||
SetButtonsMaximumIndex(15);
|
||||
SetPOVsMaximumIndex(1);
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
using namespace wpi::sim;
|
||||
|
||||
NiDsXboxControllerSim::NiDsXboxControllerSim(const NiDsXboxController& joystick)
|
||||
: GenericHIDSim{joystick} {
|
||||
: GenericHIDSim{joystick.GetHID()} {
|
||||
SetAxesMaximumIndex(6);
|
||||
SetButtonsMaximumIndex(10);
|
||||
SetPOVsMaximumIndex(1);
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "wpi/util/sendable/Sendable.hpp"
|
||||
#include "wpi/util/sendable/SendableHelper.hpp"
|
||||
#include <string>
|
||||
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/driverstation/HIDDevice.hpp"
|
||||
#include "wpi/util/sendable/Sendable.hpp"
|
||||
#include "wpi/util/sendable/SendableHelper.hpp"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
@@ -25,9 +27,10 @@ namespace wpi {
|
||||
* correct mapping, and only through the official NI DS. Sim is not guaranteed
|
||||
* to have the same mapping, as well as any 3rd party controllers.
|
||||
*/
|
||||
class NiDsPS4Controller : public GenericHID,
|
||||
public wpi::util::Sendable,
|
||||
public wpi::util::SendableHelper<NiDsPS4Controller> {
|
||||
class NiDsPS4Controller
|
||||
: public HIDDevice,
|
||||
public wpi::util::Sendable,
|
||||
public wpi::util::SendableHelper<NiDsPS4Controller> {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -39,11 +42,32 @@ class NiDsPS4Controller : public GenericHID,
|
||||
*/
|
||||
explicit NiDsPS4Controller(int port);
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this controller.
|
||||
*/
|
||||
explicit NiDsPS4Controller(GenericHID& hid);
|
||||
|
||||
~NiDsPS4Controller() override = default;
|
||||
|
||||
NiDsPS4Controller(NiDsPS4Controller&&) = default;
|
||||
NiDsPS4Controller& operator=(NiDsPS4Controller&&) = default;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
GenericHID& GetHID() override;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
const GenericHID& GetHID() const override;
|
||||
|
||||
/**
|
||||
* Get the X axis value of left side of the controller. Right is positive.
|
||||
*
|
||||
@@ -570,7 +594,56 @@ class NiDsPS4Controller : public GenericHID,
|
||||
static constexpr int kR2 = 4;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get if the controller is connected.
|
||||
*
|
||||
* @return true if the controller is connected
|
||||
*/
|
||||
bool IsConnected() const;
|
||||
|
||||
/**
|
||||
* Get the type of the controller.
|
||||
*
|
||||
* @return the type of the controller.
|
||||
*/
|
||||
GenericHID::HIDType GetGamepadType() const;
|
||||
|
||||
/**
|
||||
* Get the supported outputs of the controller.
|
||||
*
|
||||
* @return the supported outputs of the controller.
|
||||
*/
|
||||
GenericHID::SupportedOutputs GetSupportedOutputs() const;
|
||||
|
||||
/**
|
||||
* Get the name of the controller.
|
||||
*
|
||||
* @return the name of the controller.
|
||||
*/
|
||||
std::string GetName() const;
|
||||
|
||||
/**
|
||||
* Get the port number of the controller.
|
||||
*
|
||||
* @return The port number of the controller.
|
||||
*/
|
||||
int GetPort() const;
|
||||
|
||||
/**
|
||||
* Set the rumble output for the HID.
|
||||
*
|
||||
* The DS currently supports 4 rumble values: left rumble, right rumble, left
|
||||
* trigger rumble, and right trigger rumble.
|
||||
*
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
void SetRumble(GenericHID::RumbleType type, double value);
|
||||
|
||||
void InitSendable(wpi::util::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
GenericHID* m_hid;
|
||||
};
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "wpi/util/sendable/Sendable.hpp"
|
||||
#include "wpi/util/sendable/SendableHelper.hpp"
|
||||
#include <string>
|
||||
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/driverstation/HIDDevice.hpp"
|
||||
#include "wpi/util/sendable/Sendable.hpp"
|
||||
#include "wpi/util/sendable/SendableHelper.hpp"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
@@ -25,9 +27,10 @@ namespace wpi {
|
||||
* correct mapping, and only through the official NI DS. Sim is not guaranteed
|
||||
* to have the same mapping, as well as any 3rd party controllers.
|
||||
*/
|
||||
class NiDsPS5Controller : public GenericHID,
|
||||
public wpi::util::Sendable,
|
||||
public wpi::util::SendableHelper<NiDsPS5Controller> {
|
||||
class NiDsPS5Controller
|
||||
: public HIDDevice,
|
||||
public wpi::util::Sendable,
|
||||
public wpi::util::SendableHelper<NiDsPS5Controller> {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -39,11 +42,32 @@ class NiDsPS5Controller : public GenericHID,
|
||||
*/
|
||||
explicit NiDsPS5Controller(int port);
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this controller.
|
||||
*/
|
||||
explicit NiDsPS5Controller(GenericHID& hid);
|
||||
|
||||
~NiDsPS5Controller() override = default;
|
||||
|
||||
NiDsPS5Controller(NiDsPS5Controller&&) = default;
|
||||
NiDsPS5Controller& operator=(NiDsPS5Controller&&) = default;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
GenericHID& GetHID() override;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
const GenericHID& GetHID() const override;
|
||||
|
||||
/**
|
||||
* Get the X axis value of left side of the controller. Right is positive.
|
||||
*
|
||||
@@ -570,7 +594,56 @@ class NiDsPS5Controller : public GenericHID,
|
||||
static constexpr int kR2 = 4;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get if the controller is connected.
|
||||
*
|
||||
* @return true if the controller is connected
|
||||
*/
|
||||
bool IsConnected() const;
|
||||
|
||||
/**
|
||||
* Get the type of the controller.
|
||||
*
|
||||
* @return the type of the controller.
|
||||
*/
|
||||
GenericHID::HIDType GetGamepadType() const;
|
||||
|
||||
/**
|
||||
* Get the supported outputs of the controller.
|
||||
*
|
||||
* @return the supported outputs of the controller.
|
||||
*/
|
||||
GenericHID::SupportedOutputs GetSupportedOutputs() const;
|
||||
|
||||
/**
|
||||
* Get the name of the controller.
|
||||
*
|
||||
* @return the name of the controller.
|
||||
*/
|
||||
std::string GetName() const;
|
||||
|
||||
/**
|
||||
* Get the port number of the controller.
|
||||
*
|
||||
* @return The port number of the controller.
|
||||
*/
|
||||
int GetPort() const;
|
||||
|
||||
/**
|
||||
* Set the rumble output for the HID.
|
||||
*
|
||||
* The DS currently supports 4 rumble values: left rumble, right rumble, left
|
||||
* trigger rumble, and right trigger rumble.
|
||||
*
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
void SetRumble(GenericHID::RumbleType type, double value);
|
||||
|
||||
void InitSendable(wpi::util::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
GenericHID* m_hid;
|
||||
};
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "wpi/util/sendable/Sendable.hpp"
|
||||
#include "wpi/util/sendable/SendableHelper.hpp"
|
||||
#include <string>
|
||||
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/driverstation/HIDDevice.hpp"
|
||||
#include "wpi/util/sendable/Sendable.hpp"
|
||||
#include "wpi/util/sendable/SendableHelper.hpp"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
@@ -25,9 +27,10 @@ namespace wpi {
|
||||
* correct mapping, and only through the official NI DS. Sim is not guaranteed
|
||||
* to have the same mapping, as well as any 3rd party controllers.
|
||||
*/
|
||||
class NiDsStadiaController : public GenericHID,
|
||||
public wpi::util::Sendable,
|
||||
public wpi::util::SendableHelper<NiDsStadiaController> {
|
||||
class NiDsStadiaController
|
||||
: public HIDDevice,
|
||||
public wpi::util::Sendable,
|
||||
public wpi::util::SendableHelper<NiDsStadiaController> {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -39,11 +42,32 @@ class NiDsStadiaController : public GenericHID,
|
||||
*/
|
||||
explicit NiDsStadiaController(int port);
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this controller.
|
||||
*/
|
||||
explicit NiDsStadiaController(GenericHID& hid);
|
||||
|
||||
~NiDsStadiaController() override = default;
|
||||
|
||||
NiDsStadiaController(NiDsStadiaController&&) = default;
|
||||
NiDsStadiaController& operator=(NiDsStadiaController&&) = default;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
GenericHID& GetHID() override;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
const GenericHID& GetHID() const override;
|
||||
|
||||
/**
|
||||
* Get the X axis value of left side of the controller. Right is positive.
|
||||
*
|
||||
@@ -583,7 +607,56 @@ class NiDsStadiaController : public GenericHID,
|
||||
static constexpr int kRightY = 4;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get if the controller is connected.
|
||||
*
|
||||
* @return true if the controller is connected
|
||||
*/
|
||||
bool IsConnected() const;
|
||||
|
||||
/**
|
||||
* Get the type of the controller.
|
||||
*
|
||||
* @return the type of the controller.
|
||||
*/
|
||||
GenericHID::HIDType GetGamepadType() const;
|
||||
|
||||
/**
|
||||
* Get the supported outputs of the controller.
|
||||
*
|
||||
* @return the supported outputs of the controller.
|
||||
*/
|
||||
GenericHID::SupportedOutputs GetSupportedOutputs() const;
|
||||
|
||||
/**
|
||||
* Get the name of the controller.
|
||||
*
|
||||
* @return the name of the controller.
|
||||
*/
|
||||
std::string GetName() const;
|
||||
|
||||
/**
|
||||
* Get the port number of the controller.
|
||||
*
|
||||
* @return The port number of the controller.
|
||||
*/
|
||||
int GetPort() const;
|
||||
|
||||
/**
|
||||
* Set the rumble output for the HID.
|
||||
*
|
||||
* The DS currently supports 4 rumble values: left rumble, right rumble, left
|
||||
* trigger rumble, and right trigger rumble.
|
||||
*
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
void SetRumble(GenericHID::RumbleType type, double value);
|
||||
|
||||
void InitSendable(wpi::util::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
GenericHID* m_hid;
|
||||
};
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "wpi/util/sendable/Sendable.hpp"
|
||||
#include "wpi/util/sendable/SendableHelper.hpp"
|
||||
#include <string>
|
||||
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/driverstation/HIDDevice.hpp"
|
||||
#include "wpi/util/sendable/Sendable.hpp"
|
||||
#include "wpi/util/sendable/SendableHelper.hpp"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
@@ -25,9 +27,10 @@ namespace wpi {
|
||||
* correct mapping, and only through the official NI DS. Sim is not guaranteed
|
||||
* to have the same mapping, as well as any 3rd party controllers.
|
||||
*/
|
||||
class NiDsXboxController : public GenericHID,
|
||||
public wpi::util::Sendable,
|
||||
public wpi::util::SendableHelper<NiDsXboxController> {
|
||||
class NiDsXboxController
|
||||
: public HIDDevice,
|
||||
public wpi::util::Sendable,
|
||||
public wpi::util::SendableHelper<NiDsXboxController> {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
@@ -39,11 +42,32 @@ class NiDsXboxController : public GenericHID,
|
||||
*/
|
||||
explicit NiDsXboxController(int port);
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this controller.
|
||||
*/
|
||||
explicit NiDsXboxController(GenericHID& hid);
|
||||
|
||||
~NiDsXboxController() override = default;
|
||||
|
||||
NiDsXboxController(NiDsXboxController&&) = default;
|
||||
NiDsXboxController& operator=(NiDsXboxController&&) = default;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
GenericHID& GetHID() override;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
const GenericHID& GetHID() const override;
|
||||
|
||||
/**
|
||||
* Get the X axis value of left side of the controller. Right is positive.
|
||||
*
|
||||
@@ -482,7 +506,56 @@ class NiDsXboxController : public GenericHID,
|
||||
static constexpr int kRightTrigger = 3;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get if the controller is connected.
|
||||
*
|
||||
* @return true if the controller is connected
|
||||
*/
|
||||
bool IsConnected() const;
|
||||
|
||||
/**
|
||||
* Get the type of the controller.
|
||||
*
|
||||
* @return the type of the controller.
|
||||
*/
|
||||
GenericHID::HIDType GetGamepadType() const;
|
||||
|
||||
/**
|
||||
* Get the supported outputs of the controller.
|
||||
*
|
||||
* @return the supported outputs of the controller.
|
||||
*/
|
||||
GenericHID::SupportedOutputs GetSupportedOutputs() const;
|
||||
|
||||
/**
|
||||
* Get the name of the controller.
|
||||
*
|
||||
* @return the name of the controller.
|
||||
*/
|
||||
std::string GetName() const;
|
||||
|
||||
/**
|
||||
* Get the port number of the controller.
|
||||
*
|
||||
* @return The port number of the controller.
|
||||
*/
|
||||
int GetPort() const;
|
||||
|
||||
/**
|
||||
* Set the rumble output for the HID.
|
||||
*
|
||||
* The DS currently supports 4 rumble values: left rumble, right rumble, left
|
||||
* trigger rumble, and right trigger rumble.
|
||||
*
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
void SetRumble(GenericHID::RumbleType type, double value);
|
||||
|
||||
void InitSendable(wpi::util::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
GenericHID* m_hid;
|
||||
};
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
69
wpilibc/src/main/native/cpp/driverstation/DriverStation.cpp
Normal file
69
wpilibc/src/main/native/cpp/driverstation/DriverStation.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
// 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 "wpi/driverstation/DriverStation.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include "wpi/driverstation/Gamepad.hpp"
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/system/Errors.hpp"
|
||||
|
||||
using namespace wpi;
|
||||
|
||||
namespace {
|
||||
std::mutex dsMutex;
|
||||
std::array<std::unique_ptr<GenericHID>,
|
||||
wpi::internal::DriverStationBackend::JOYSTICK_PORTS>
|
||||
hids;
|
||||
std::array<std::unique_ptr<Gamepad>,
|
||||
wpi::internal::DriverStationBackend::JOYSTICK_PORTS>
|
||||
gamepads;
|
||||
|
||||
void ValidatePort(int port) {
|
||||
if (port < 0 || port >= wpi::internal::DriverStationBackend::JOYSTICK_PORTS) {
|
||||
throw WPILIB_MakeError(warn::BadJoystickIndex, "port {} out of range",
|
||||
port);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
GenericHID& DriverStation::GetGenericHIDUnderLock(int port) {
|
||||
ValidatePort(port);
|
||||
|
||||
if (!hids[port]) {
|
||||
hids[port].reset(new GenericHID(port));
|
||||
}
|
||||
|
||||
return *hids[port];
|
||||
}
|
||||
|
||||
GenericHID& DriverStation::GetGenericHID(int port) {
|
||||
std::scoped_lock lock{dsMutex};
|
||||
return GetGenericHIDUnderLock(port);
|
||||
}
|
||||
|
||||
Gamepad& DriverStation::GetGamepad(int port) {
|
||||
std::scoped_lock lock{dsMutex};
|
||||
ValidatePort(port);
|
||||
|
||||
if (!gamepads[port]) {
|
||||
gamepads[port] = std::make_unique<Gamepad>(GetGenericHIDUnderLock(port));
|
||||
}
|
||||
|
||||
return *gamepads[port];
|
||||
}
|
||||
|
||||
void wpi::internal::DriverStationBackend::ResetCachedHIDData() {
|
||||
std::scoped_lock lock{dsMutex};
|
||||
|
||||
for (auto& gamepad : gamepads) {
|
||||
gamepad.reset();
|
||||
}
|
||||
for (auto& hid : hids) {
|
||||
hid.reset();
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,9 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/event/BooleanEvent.hpp"
|
||||
#include "wpi/hal/UsageReporting.hpp"
|
||||
#include "wpi/math/util/MathUtil.hpp"
|
||||
@@ -21,8 +23,18 @@ static double ClampDeadband(double deadband) {
|
||||
return std::clamp(deadband, 0.0, std::nextafter(1.0, 0.0));
|
||||
}
|
||||
|
||||
Gamepad::Gamepad(int port) : GenericHID(port) {
|
||||
HAL_ReportUsage("HID", port, "Gamepad");
|
||||
Gamepad::Gamepad(int port) : Gamepad{DriverStation::GetGenericHID(port)} {}
|
||||
|
||||
Gamepad::Gamepad(GenericHID& hid) : m_hid{&hid} {
|
||||
HAL_ReportUsage("HID", hid.GetPort(), "Gamepad");
|
||||
}
|
||||
|
||||
GenericHID& Gamepad::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
const GenericHID& Gamepad::GetHID() const {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
double Gamepad::GetLeftX() const {
|
||||
@@ -512,44 +524,88 @@ BooleanEvent Gamepad::Misc6(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool Gamepad::GetButton(Button button) const {
|
||||
return GetRawButton(static_cast<int>(button));
|
||||
return m_hid->GetRawButton(static_cast<int>(button));
|
||||
}
|
||||
|
||||
bool Gamepad::GetButtonPressed(Button button) {
|
||||
return GetRawButtonPressed(static_cast<int>(button));
|
||||
return m_hid->GetRawButtonPressed(static_cast<int>(button));
|
||||
}
|
||||
|
||||
bool Gamepad::GetButtonReleased(Button button) {
|
||||
return GetRawButtonReleased(static_cast<int>(button));
|
||||
return m_hid->GetRawButtonReleased(static_cast<int>(button));
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::ButtonEvent(Button button, EventLoop* loop) const {
|
||||
return GenericHID::Button(static_cast<int>(button), loop);
|
||||
return m_hid->Button(static_cast<int>(button), loop);
|
||||
}
|
||||
|
||||
double Gamepad::GetAxis(Axis axis) const {
|
||||
return GetRawAxis(static_cast<int>(axis));
|
||||
return m_hid->GetRawAxis(static_cast<int>(axis));
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::AxisLessThan(Axis axis, double threshold,
|
||||
EventLoop* loop) const {
|
||||
return GenericHID::AxisLessThan(static_cast<int>(axis), threshold, loop);
|
||||
return m_hid->AxisLessThan(static_cast<int>(axis), threshold, loop);
|
||||
}
|
||||
|
||||
BooleanEvent Gamepad::AxisGreaterThan(Axis axis, double threshold,
|
||||
EventLoop* loop) const {
|
||||
return GenericHID::AxisGreaterThan(static_cast<int>(axis), threshold, loop);
|
||||
return m_hid->AxisGreaterThan(static_cast<int>(axis), threshold, loop);
|
||||
}
|
||||
|
||||
int Gamepad::GetAxesAvailable() const {
|
||||
return m_hid->GetAxesAvailable();
|
||||
}
|
||||
|
||||
uint64_t Gamepad::GetButtonsAvailable() const {
|
||||
return m_hid->GetButtonsAvailable();
|
||||
}
|
||||
|
||||
bool Gamepad::IsConnected() const {
|
||||
return m_hid->IsConnected();
|
||||
}
|
||||
|
||||
GenericHID::HIDType Gamepad::GetGamepadType() const {
|
||||
return m_hid->GetGamepadType();
|
||||
}
|
||||
|
||||
GenericHID::SupportedOutputs Gamepad::GetSupportedOutputs() const {
|
||||
return m_hid->GetSupportedOutputs();
|
||||
}
|
||||
|
||||
std::string Gamepad::GetName() const {
|
||||
return m_hid->GetName();
|
||||
}
|
||||
|
||||
int Gamepad::GetPort() const {
|
||||
return m_hid->GetPort();
|
||||
}
|
||||
|
||||
void Gamepad::SetLeds(int r, int g, int b) {
|
||||
m_hid->SetLeds(r, g, b);
|
||||
}
|
||||
|
||||
void Gamepad::SetRumble(GenericHID::RumbleType type, double value) {
|
||||
m_hid->SetRumble(type, value);
|
||||
}
|
||||
|
||||
bool Gamepad::GetTouchpadFingerAvailable(int touchpad, int finger) const {
|
||||
return m_hid->GetTouchpadFingerAvailable(touchpad, finger);
|
||||
}
|
||||
|
||||
TouchpadFinger Gamepad::GetTouchpadFinger(int touchpad, int finger) const {
|
||||
return m_hid->GetTouchpadFinger(touchpad, finger);
|
||||
}
|
||||
|
||||
double Gamepad::GetAxisForSendable(Axis axis) const {
|
||||
return wpi::internal::DriverStationBackend::GetStickAxisIfAvailable(
|
||||
GetPort(), static_cast<int>(axis))
|
||||
m_hid->GetPort(), static_cast<int>(axis))
|
||||
.value_or(0.0);
|
||||
}
|
||||
|
||||
bool Gamepad::GetButtonForSendable(Button button) const {
|
||||
return wpi::internal::DriverStationBackend::GetStickButtonIfAvailable(
|
||||
GetPort(), static_cast<int>(button))
|
||||
m_hid->GetPort(), static_cast<int>(button))
|
||||
.value_or(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,19 +6,30 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/event/BooleanEvent.hpp"
|
||||
#include "wpi/hal/UsageReporting.hpp"
|
||||
|
||||
using namespace wpi;
|
||||
|
||||
Joystick::Joystick(int port) : GenericHID(port) {
|
||||
Joystick::Joystick(int port) : Joystick{DriverStation::GetGenericHID(port)} {}
|
||||
|
||||
Joystick::Joystick(GenericHID& hid) : m_hid{&hid} {
|
||||
m_axes[Axis::kX] = kDefaultXChannel;
|
||||
m_axes[Axis::kY] = kDefaultYChannel;
|
||||
m_axes[Axis::kZ] = kDefaultZChannel;
|
||||
m_axes[Axis::kTwist] = kDefaultTwistChannel;
|
||||
m_axes[Axis::kThrottle] = kDefaultThrottleChannel;
|
||||
|
||||
HAL_ReportUsage("HID", port, "Joystick");
|
||||
HAL_ReportUsage("HID", hid.GetPort(), "Joystick");
|
||||
}
|
||||
|
||||
GenericHID& Joystick::GetHID() {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
const GenericHID& Joystick::GetHID() const {
|
||||
return *m_hid;
|
||||
}
|
||||
|
||||
void Joystick::SetXChannel(int channel) {
|
||||
@@ -61,36 +72,56 @@ int Joystick::GetThrottleChannel() const {
|
||||
return m_axes[Axis::kThrottle];
|
||||
}
|
||||
|
||||
bool Joystick::GetRawButton(int button) const {
|
||||
return m_hid->GetRawButton(button);
|
||||
}
|
||||
|
||||
bool Joystick::GetRawButtonPressed(int button) {
|
||||
return m_hid->GetRawButtonPressed(button);
|
||||
}
|
||||
|
||||
bool Joystick::GetRawButtonReleased(int button) {
|
||||
return m_hid->GetRawButtonReleased(button);
|
||||
}
|
||||
|
||||
double Joystick::GetRawAxis(int axis) const {
|
||||
return m_hid->GetRawAxis(axis);
|
||||
}
|
||||
|
||||
POVDirection Joystick::GetPOV(int pov) const {
|
||||
return m_hid->GetPOV(pov);
|
||||
}
|
||||
|
||||
double Joystick::GetX() const {
|
||||
return GetRawAxis(m_axes[Axis::kX]);
|
||||
return m_hid->GetRawAxis(m_axes[Axis::kX]);
|
||||
}
|
||||
|
||||
double Joystick::GetY() const {
|
||||
return GetRawAxis(m_axes[Axis::kY]);
|
||||
return m_hid->GetRawAxis(m_axes[Axis::kY]);
|
||||
}
|
||||
|
||||
double Joystick::GetZ() const {
|
||||
return GetRawAxis(m_axes[Axis::kZ]);
|
||||
return m_hid->GetRawAxis(m_axes[Axis::kZ]);
|
||||
}
|
||||
|
||||
double Joystick::GetTwist() const {
|
||||
return GetRawAxis(m_axes[Axis::kTwist]);
|
||||
return m_hid->GetRawAxis(m_axes[Axis::kTwist]);
|
||||
}
|
||||
|
||||
double Joystick::GetThrottle() const {
|
||||
return GetRawAxis(m_axes[Axis::kThrottle]);
|
||||
return m_hid->GetRawAxis(m_axes[Axis::kThrottle]);
|
||||
}
|
||||
|
||||
bool Joystick::GetTrigger() const {
|
||||
return GetRawButton(Button::kTrigger);
|
||||
return m_hid->GetRawButton(Button::kTrigger);
|
||||
}
|
||||
|
||||
bool Joystick::GetTriggerPressed() {
|
||||
return GetRawButtonPressed(Button::kTrigger);
|
||||
return m_hid->GetRawButtonPressed(Button::kTrigger);
|
||||
}
|
||||
|
||||
bool Joystick::GetTriggerReleased() {
|
||||
return GetRawButtonReleased(Button::kTrigger);
|
||||
return m_hid->GetRawButtonReleased(Button::kTrigger);
|
||||
}
|
||||
|
||||
BooleanEvent Joystick::Trigger(EventLoop* loop) const {
|
||||
@@ -98,15 +129,15 @@ BooleanEvent Joystick::Trigger(EventLoop* loop) const {
|
||||
}
|
||||
|
||||
bool Joystick::GetTop() const {
|
||||
return GetRawButton(Button::kTop);
|
||||
return m_hid->GetRawButton(Button::kTop);
|
||||
}
|
||||
|
||||
bool Joystick::GetTopPressed() {
|
||||
return GetRawButtonPressed(Button::kTop);
|
||||
return m_hid->GetRawButtonPressed(Button::kTop);
|
||||
}
|
||||
|
||||
bool Joystick::GetTopReleased() {
|
||||
return GetRawButtonReleased(Button::kTop);
|
||||
return m_hid->GetRawButtonReleased(Button::kTop);
|
||||
}
|
||||
|
||||
BooleanEvent Joystick::Top(EventLoop* loop) const {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "wpi/datalog/DataLog.hpp"
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/hal/DriverStation.h"
|
||||
#include "wpi/hal/DriverStationTypes.h"
|
||||
#include "wpi/hal/HAL.h"
|
||||
@@ -47,6 +48,10 @@ static constexpr int availableToCount(uint64_t available) {
|
||||
return 64 - std::countl_zero(available);
|
||||
}
|
||||
|
||||
GenericHID DriverStationBackend::ConstructGenericHID(int port) {
|
||||
return GenericHID{port};
|
||||
}
|
||||
|
||||
namespace {
|
||||
// A simple class which caches the previous value written to an NT entry
|
||||
// Used to prevent redundant, repeated writes of the same value
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
using namespace wpi;
|
||||
using namespace wpi::sim;
|
||||
|
||||
GamepadSim::GamepadSim(const wpi::Gamepad& joystick) : GenericHIDSim{joystick} {
|
||||
GamepadSim::GamepadSim(const wpi::Gamepad& joystick)
|
||||
: GenericHIDSim{joystick.GetHID()} {
|
||||
SetAxesMaximumIndex(6);
|
||||
SetButtonsMaximumIndex(26);
|
||||
SetPOVsMaximumIndex(1);
|
||||
|
||||
@@ -11,7 +11,7 @@ using namespace wpi;
|
||||
using namespace wpi::sim;
|
||||
|
||||
JoystickSim::JoystickSim(const Joystick& joystick)
|
||||
: GenericHIDSim{joystick}, m_joystick{&joystick} {
|
||||
: GenericHIDSim{joystick.GetHID()}, m_joystick{&joystick} {
|
||||
// default to a reasonable joystick configuration
|
||||
SetAxesMaximumIndex(5);
|
||||
SetButtonsMaximumIndex(12);
|
||||
|
||||
@@ -12,6 +12,9 @@ class DataLog;
|
||||
|
||||
namespace wpi {
|
||||
|
||||
class Gamepad;
|
||||
class GenericHID;
|
||||
|
||||
/**
|
||||
* Provides access to Driver Station functionality.
|
||||
*/
|
||||
@@ -19,6 +22,26 @@ class DriverStation final {
|
||||
public:
|
||||
DriverStation() = delete;
|
||||
|
||||
/**
|
||||
* Gets the GenericHID object for the given port. GenericHID objects are
|
||||
* cached, so this will always return the same object for the same port.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is
|
||||
* plugged into (0-5).
|
||||
* @return The GenericHID object for the given port.
|
||||
*/
|
||||
static GenericHID& GetGenericHID(int port);
|
||||
|
||||
/**
|
||||
* Gets the Gamepad object for the given port. Gamepad objects are cached, so
|
||||
* this will always return the same object for the same port.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is
|
||||
* plugged into (0-5).
|
||||
* @return The Gamepad object for the given port.
|
||||
*/
|
||||
static Gamepad& GetGamepad(int port);
|
||||
|
||||
/**
|
||||
* Starts logging DriverStation data to data log, including joystick data.
|
||||
* Repeated calls are ignored.
|
||||
@@ -57,6 +80,9 @@ class DriverStation final {
|
||||
static void RemoveRefreshedDataEventHandle(WPI_EventHandle handle) {
|
||||
wpi::internal::DriverStationBackend::RemoveRefreshedDataEventHandle(handle);
|
||||
}
|
||||
|
||||
private:
|
||||
static GenericHID& GetGenericHIDUnderLock(int port);
|
||||
};
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/driverstation/HIDDevice.hpp"
|
||||
#include "wpi/util/sendable/Sendable.hpp"
|
||||
#include "wpi/util/sendable/SendableHelper.hpp"
|
||||
|
||||
@@ -22,7 +25,7 @@ namespace wpi {
|
||||
* correct mapping, and only through the official NI DS. Sim is not guaranteed
|
||||
* to have the same mapping, as well as any 3rd party controllers.
|
||||
*/
|
||||
class Gamepad : public GenericHID,
|
||||
class Gamepad : public HIDDevice,
|
||||
public wpi::util::Sendable,
|
||||
public wpi::util::SendableHelper<Gamepad> {
|
||||
public:
|
||||
@@ -108,11 +111,32 @@ class Gamepad : public GenericHID,
|
||||
*/
|
||||
explicit Gamepad(int port);
|
||||
|
||||
/**
|
||||
* Construct an instance of a gamepad with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this gamepad.
|
||||
*/
|
||||
explicit Gamepad(GenericHID& hid);
|
||||
|
||||
~Gamepad() override = default;
|
||||
|
||||
Gamepad(Gamepad&&) = default;
|
||||
Gamepad& operator=(Gamepad&&) = default;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
GenericHID& GetHID() override;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
const GenericHID& GetHID() const override;
|
||||
|
||||
/**
|
||||
* Get the X axis value of left side of the controller. Right is positive.
|
||||
*
|
||||
@@ -1157,6 +1181,92 @@ class Gamepad : public GenericHID,
|
||||
BooleanEvent AxisGreaterThan(Axis axis, double threshold,
|
||||
EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Get the bitmask of axes for the gamepad.
|
||||
*
|
||||
* @return the number of axis for the current gamepad
|
||||
*/
|
||||
int GetAxesAvailable() const;
|
||||
|
||||
/**
|
||||
* For the current gamepad, return the bitmask of available buttons.
|
||||
*
|
||||
* @return the bitmask of buttons for the current gamepad
|
||||
*/
|
||||
uint64_t GetButtonsAvailable() const;
|
||||
|
||||
/**
|
||||
* Get if the gamepad is connected.
|
||||
*
|
||||
* @return true if the gamepad is connected
|
||||
*/
|
||||
bool IsConnected() const;
|
||||
|
||||
/**
|
||||
* Get the type of the gamepad.
|
||||
*
|
||||
* @return the type of the gamepad.
|
||||
*/
|
||||
GenericHID::HIDType GetGamepadType() const;
|
||||
|
||||
/**
|
||||
* Get the supported outputs for the gamepad.
|
||||
*
|
||||
* @return the supported outputs for the gamepad.
|
||||
*/
|
||||
GenericHID::SupportedOutputs GetSupportedOutputs() const;
|
||||
|
||||
/**
|
||||
* Get the name of the gamepad.
|
||||
*
|
||||
* @return the name of the gamepad.
|
||||
*/
|
||||
std::string GetName() const;
|
||||
|
||||
/**
|
||||
* Get the port number of the gamepad.
|
||||
*
|
||||
* @return The port number of the gamepad.
|
||||
*/
|
||||
int GetPort() const;
|
||||
|
||||
/**
|
||||
* Set leds on the gamepad. If only mono is supported, the system will use
|
||||
* the highest value passed in.
|
||||
*
|
||||
* @param r Red value from 0-255
|
||||
* @param g Green value from 0-255
|
||||
* @param b Blue value from 0-255
|
||||
*/
|
||||
void SetLeds(int r, int g, int b);
|
||||
|
||||
/**
|
||||
* Set the rumble output for the HID.
|
||||
*
|
||||
* The DS currently supports 4 rumble values: left rumble, right rumble, left
|
||||
* trigger rumble, and right trigger rumble.
|
||||
*
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
void SetRumble(GenericHID::RumbleType type, double value);
|
||||
|
||||
/**
|
||||
* Check if a touchpad finger is available.
|
||||
* @param touchpad The touchpad to check.
|
||||
* @param finger The finger to check.
|
||||
* @return true if the touchpad finger is available.
|
||||
*/
|
||||
bool GetTouchpadFingerAvailable(int touchpad, int finger) const;
|
||||
|
||||
/**
|
||||
* Get the touchpad finger data.
|
||||
* @param touchpad The touchpad to read.
|
||||
* @param finger The finger to read.
|
||||
* @return The touchpad finger data.
|
||||
*/
|
||||
TouchpadFinger GetTouchpadFinger(int touchpad, int finger) const;
|
||||
|
||||
void InitSendable(wpi::util::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
@@ -1169,6 +1279,7 @@ class Gamepad : public GenericHID,
|
||||
double m_rightYDeadband = 0.1;
|
||||
double m_leftTriggerDeadband = 0.01;
|
||||
double m_rightTriggerDeadband = 0.01;
|
||||
GenericHID* m_hid;
|
||||
};
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "wpi/driverstation/HIDDevice.hpp"
|
||||
#include "wpi/driverstation/POVDirection.hpp"
|
||||
#include "wpi/driverstation/TouchpadFinger.hpp"
|
||||
#include "wpi/driverstation/internal/DriverStationBackend.hpp"
|
||||
@@ -16,7 +17,7 @@ namespace wpi {
|
||||
|
||||
class BooleanEvent;
|
||||
class EventLoop;
|
||||
|
||||
class DriverStation;
|
||||
/**
|
||||
* Handle input from standard HID devices connected to the Driver Station.
|
||||
*
|
||||
@@ -25,8 +26,11 @@ class EventLoop;
|
||||
* single class instance for each device and the mapping of ports to hardware
|
||||
* buttons depends on the code in the Driver Station.
|
||||
*/
|
||||
class GenericHID {
|
||||
class GenericHID final : public HIDDevice {
|
||||
public:
|
||||
friend class DriverStation;
|
||||
friend class internal::DriverStationBackend;
|
||||
|
||||
/**
|
||||
* Represents a rumble output on the Joystick.
|
||||
*/
|
||||
@@ -87,9 +91,24 @@ class GenericHID {
|
||||
SWITCH_JOYCON_PAIR
|
||||
};
|
||||
|
||||
explicit GenericHID(int port);
|
||||
virtual ~GenericHID() = default;
|
||||
~GenericHID() override = default;
|
||||
|
||||
/**
|
||||
* Get this GenericHID object.
|
||||
*
|
||||
* @return this GenericHID object
|
||||
*/
|
||||
GenericHID& GetHID() override { return *this; }
|
||||
|
||||
/**
|
||||
* Get this GenericHID object.
|
||||
*
|
||||
* @return this GenericHID object
|
||||
*/
|
||||
const GenericHID& GetHID() const override { return *this; }
|
||||
|
||||
GenericHID(const GenericHID&) = delete;
|
||||
GenericHID& operator=(const GenericHID&) = delete;
|
||||
GenericHID(GenericHID&&) = default;
|
||||
GenericHID& operator=(GenericHID&&) = default;
|
||||
|
||||
@@ -389,6 +408,7 @@ class GenericHID {
|
||||
TouchpadFinger GetTouchpadFinger(int touchpad, int finger) const;
|
||||
|
||||
private:
|
||||
explicit GenericHID(int port);
|
||||
int m_port;
|
||||
uint16_t m_leftRumble = 0;
|
||||
uint16_t m_rightRumble = 0;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// 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
|
||||
|
||||
namespace wpi {
|
||||
|
||||
class GenericHID;
|
||||
|
||||
/** Interface for device wrappers backed by a GenericHID. */
|
||||
class HIDDevice {
|
||||
public:
|
||||
virtual ~HIDDevice() = default;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
virtual GenericHID& GetHID() = 0;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
virtual const GenericHID& GetHID() const = 0;
|
||||
};
|
||||
|
||||
} // namespace wpi
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <array>
|
||||
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/driverstation/HIDDevice.hpp"
|
||||
#include "wpi/units/angle.hpp"
|
||||
|
||||
namespace wpi {
|
||||
@@ -19,7 +20,7 @@ namespace wpi {
|
||||
* single class instance for each joystick and the mapping of ports to hardware
|
||||
* buttons depends on the code in the Driver Station.
|
||||
*/
|
||||
class Joystick : public GenericHID {
|
||||
class Joystick : public HIDDevice {
|
||||
public:
|
||||
/// Default X axis channel.
|
||||
static constexpr int kDefaultXChannel = 0;
|
||||
@@ -68,11 +69,32 @@ class Joystick : public GenericHID {
|
||||
*/
|
||||
explicit Joystick(int port);
|
||||
|
||||
/**
|
||||
* Construct an instance of a joystick with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this joystick.
|
||||
*/
|
||||
explicit Joystick(GenericHID& hid);
|
||||
|
||||
~Joystick() override = default;
|
||||
|
||||
Joystick(Joystick&&) = default;
|
||||
Joystick& operator=(Joystick&&) = default;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
GenericHID& GetHID() override;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
const GenericHID& GetHID() const override;
|
||||
|
||||
/**
|
||||
* Set the channel associated with the X axis.
|
||||
*
|
||||
@@ -143,6 +165,55 @@ class Joystick : public GenericHID {
|
||||
*/
|
||||
int GetThrottleChannel() const;
|
||||
|
||||
/**
|
||||
* Get the button value (starting at button 1).
|
||||
*
|
||||
* The buttons are returned in a single 16 bit value with one bit representing
|
||||
* the state of each button. The appropriate button is returned as a boolean
|
||||
* value.
|
||||
*
|
||||
* @param button The button number to be read (starting at 1)
|
||||
* @return The state of the button
|
||||
*/
|
||||
bool GetRawButton(int button) const;
|
||||
|
||||
/**
|
||||
* Whether the button was pressed since the last check. Button indexes begin
|
||||
* at 1.
|
||||
*
|
||||
* @param button The button index, beginning at 1.
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
bool GetRawButtonPressed(int button);
|
||||
|
||||
/**
|
||||
* Whether the button was released since the last check. Button indexes begin
|
||||
* at 1.
|
||||
*
|
||||
* @param button The button index, beginning at 1.
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
bool GetRawButtonReleased(int button);
|
||||
|
||||
/**
|
||||
* Get the value of the axis.
|
||||
*
|
||||
* @param axis The axis to read, starting at 0.
|
||||
* @return The value of the axis.
|
||||
*/
|
||||
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).
|
||||
*
|
||||
* @param pov The index of the POV to read, starting at 0.
|
||||
* @return the angle of the POV
|
||||
*/
|
||||
POVDirection GetPOV(int pov = 0) const;
|
||||
|
||||
/**
|
||||
* Get the X value of the current joystick.
|
||||
*
|
||||
@@ -266,6 +337,7 @@ class Joystick : public GenericHID {
|
||||
enum Button { kTrigger = 1, kTop = 2 };
|
||||
|
||||
std::array<int, Axis::kNumAxes> m_axes;
|
||||
GenericHID* m_hid;
|
||||
};
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
@@ -24,6 +24,10 @@ namespace wpi::log {
|
||||
class DataLog;
|
||||
} // namespace wpi::log
|
||||
|
||||
namespace wpi {
|
||||
class GenericHID;
|
||||
} // namespace wpi
|
||||
|
||||
namespace wpi::util {
|
||||
class Color;
|
||||
} // namespace wpi::util
|
||||
@@ -41,6 +45,22 @@ class DriverStationBackend final {
|
||||
/// Number of Joystick ports.
|
||||
static constexpr int JOYSTICK_PORTS = 6;
|
||||
|
||||
/**
|
||||
* Constructs a GenericHID for the given port.
|
||||
*
|
||||
* @param port The port index on the Driver Station.
|
||||
* @return The GenericHID object for the given port.
|
||||
*/
|
||||
static GenericHID ConstructGenericHID(int port);
|
||||
|
||||
/**
|
||||
* Resets cached DriverStation HID wrapper objects.
|
||||
*
|
||||
* This is intended for test cleanup only. Any existing references to cached
|
||||
* GenericHID or Gamepad objects become invalid after this call.
|
||||
*/
|
||||
static void ResetCachedHIDData();
|
||||
|
||||
/**
|
||||
* The state of one joystick button. Button indexes begin at 0.
|
||||
*
|
||||
|
||||
@@ -119,6 +119,7 @@ RobotState = "wpi/driverstation/RobotState.hpp"
|
||||
TouchpadFinger = "wpi/driverstation/TouchpadFinger.hpp"
|
||||
Gamepad = "wpi/driverstation/Gamepad.hpp"
|
||||
GenericHID = "wpi/driverstation/GenericHID.hpp"
|
||||
HIDDevice = "wpi/driverstation/HIDDevice.hpp"
|
||||
Joystick = "wpi/driverstation/Joystick.hpp"
|
||||
NiDsPS4Controller = "wpi/driverstation/NiDsPS4Controller.hpp"
|
||||
NiDsPS5Controller = "wpi/driverstation/NiDsPS5Controller.hpp"
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
extra_includes:
|
||||
- wpi/datalog/DataLog.hpp
|
||||
- wpi/driverstation/Gamepad.hpp
|
||||
- wpi/driverstation/GenericHID.hpp
|
||||
|
||||
classes:
|
||||
wpi::DriverStation:
|
||||
methods:
|
||||
GetGenericHID:
|
||||
return_value_policy: reference_internal
|
||||
GetGamepad:
|
||||
return_value_policy: reference_internal
|
||||
ProvideRefreshedDataEventHandle:
|
||||
RemoveRefreshedDataEventHandle:
|
||||
StartDataLog:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extra_includes:
|
||||
- wpi/datalog/DataLog.hpp
|
||||
- wpi/driverstation/GenericHID.hpp
|
||||
- wpi/util/Color.hpp
|
||||
|
||||
classes:
|
||||
@@ -7,6 +8,8 @@ classes:
|
||||
attributes:
|
||||
JOYSTICK_PORTS:
|
||||
methods:
|
||||
ConstructGenericHID:
|
||||
ResetCachedHIDData:
|
||||
GetStickButton:
|
||||
GetStickButtonIfAvailable:
|
||||
GetStickButtonPressed:
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
extra_includes:
|
||||
- wpi/util/sendable/SendableBuilder.hpp
|
||||
- wpi/event/BooleanEvent.hpp
|
||||
|
||||
classes:
|
||||
wpi::Gamepad:
|
||||
force_no_trampoline: true
|
||||
ignored_bases:
|
||||
- wpi::util::SendableHelper<Gamepad>
|
||||
enums:
|
||||
@@ -7,6 +12,15 @@ classes:
|
||||
Axis:
|
||||
methods:
|
||||
Gamepad:
|
||||
overloads:
|
||||
int:
|
||||
GenericHID&:
|
||||
GetHID:
|
||||
overloads:
|
||||
"":
|
||||
return_value_policy: reference_internal
|
||||
'[const]':
|
||||
ignore: true
|
||||
GetLeftX:
|
||||
SetLeftXDeadband:
|
||||
GetLeftY:
|
||||
@@ -139,4 +153,15 @@ classes:
|
||||
GetAxis:
|
||||
AxisLessThan:
|
||||
AxisGreaterThan:
|
||||
GetAxesAvailable:
|
||||
GetButtonsAvailable:
|
||||
IsConnected:
|
||||
GetGamepadType:
|
||||
GetSupportedOutputs:
|
||||
GetName:
|
||||
GetPort:
|
||||
SetLeds:
|
||||
SetRumble:
|
||||
GetTouchpadFingerAvailable:
|
||||
GetTouchpadFinger:
|
||||
InitSendable:
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
extra_includes:
|
||||
- wpi/driverstation/internal/DriverStationBackend.hpp
|
||||
- wpi/event/BooleanEvent.hpp
|
||||
|
||||
classes:
|
||||
wpi::GenericHID:
|
||||
force_no_trampoline: true
|
||||
enums:
|
||||
RumbleType:
|
||||
SupportedOutputs:
|
||||
arithmetic: true
|
||||
HIDType:
|
||||
methods:
|
||||
GenericHID:
|
||||
GetRawButton:
|
||||
GetRawButtonPressed:
|
||||
GetRawButtonReleased:
|
||||
@@ -47,6 +46,12 @@ classes:
|
||||
GetButtonsAvailable:
|
||||
GetTouchpadFingerAvailable:
|
||||
GetTouchpadFinger:
|
||||
GetHID:
|
||||
overloads:
|
||||
"":
|
||||
return_value_policy: reference_internal
|
||||
'[const]':
|
||||
ignore: true
|
||||
inline_code: |
|
||||
cls_GenericHID
|
||||
.def("__repr__", [](py::handle self) {
|
||||
|
||||
14
wpilibc/src/main/python/semiwrap/HIDDevice.yml
Normal file
14
wpilibc/src/main/python/semiwrap/HIDDevice.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
extra_includes:
|
||||
- wpi/driverstation/GenericHID.hpp
|
||||
|
||||
classes:
|
||||
wpi::HIDDevice:
|
||||
force_no_trampoline: true
|
||||
force_no_default_constructor: true
|
||||
methods:
|
||||
GetHID:
|
||||
overloads:
|
||||
"":
|
||||
return_value_policy: reference_internal
|
||||
'[const]':
|
||||
ignore: true
|
||||
@@ -1,8 +1,9 @@
|
||||
extra_includes:
|
||||
- wpi/driverstation/internal/DriverStationBackend.hpp
|
||||
- wpi/event/BooleanEvent.hpp
|
||||
|
||||
classes:
|
||||
wpi::Joystick:
|
||||
force_no_trampoline: true
|
||||
attributes:
|
||||
kDefaultXChannel:
|
||||
kDefaultYChannel:
|
||||
@@ -14,6 +15,15 @@ classes:
|
||||
ButtonType:
|
||||
methods:
|
||||
Joystick:
|
||||
overloads:
|
||||
int:
|
||||
GenericHID&:
|
||||
GetHID:
|
||||
overloads:
|
||||
"":
|
||||
return_value_policy: reference_internal
|
||||
'[const]':
|
||||
ignore: true
|
||||
SetXChannel:
|
||||
SetYChannel:
|
||||
SetZChannel:
|
||||
@@ -40,6 +50,11 @@ classes:
|
||||
GetMagnitude:
|
||||
GetDirection:
|
||||
rename: getDirectionRadians
|
||||
GetRawButton:
|
||||
GetRawButtonPressed:
|
||||
GetRawButtonReleased:
|
||||
GetRawAxis:
|
||||
GetPOV:
|
||||
inline_code: |
|
||||
.def("getDirectionDegrees", [](const Joystick &self) -> wpi::units::degree_t {
|
||||
return self.GetDirection();
|
||||
|
||||
@@ -4,10 +4,20 @@ extra_includes:
|
||||
|
||||
classes:
|
||||
wpi::NiDsPS4Controller:
|
||||
force_no_trampoline: true
|
||||
ignored_bases:
|
||||
- wpi::util::SendableHelper<NiDsPS4Controller>
|
||||
methods:
|
||||
NiDsPS4Controller:
|
||||
overloads:
|
||||
int:
|
||||
GenericHID&:
|
||||
GetHID:
|
||||
overloads:
|
||||
"":
|
||||
return_value_policy: reference_internal
|
||||
'[const]':
|
||||
ignore: true
|
||||
GetLeftX:
|
||||
GetRightX:
|
||||
GetLeftY:
|
||||
@@ -70,6 +80,12 @@ classes:
|
||||
GetTouchpadButton:
|
||||
GetTouchpadButtonPressed:
|
||||
GetTouchpadButtonReleased:
|
||||
IsConnected:
|
||||
GetGamepadType:
|
||||
GetSupportedOutputs:
|
||||
GetName:
|
||||
GetPort:
|
||||
SetRumble:
|
||||
InitSendable:
|
||||
wpi::NiDsPS4Controller::Button:
|
||||
attributes:
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
extra_includes:
|
||||
- wpi/util/sendable/SendableBuilder.hpp
|
||||
- wpi/event/BooleanEvent.hpp
|
||||
|
||||
classes:
|
||||
wpi::NiDsPS5Controller:
|
||||
force_no_trampoline: true
|
||||
ignored_bases:
|
||||
- wpi::util::SendableHelper<NiDsPS5Controller>
|
||||
methods:
|
||||
NiDsPS5Controller:
|
||||
overloads:
|
||||
int:
|
||||
GenericHID&:
|
||||
GetHID:
|
||||
overloads:
|
||||
"":
|
||||
return_value_policy: reference_internal
|
||||
'[const]':
|
||||
ignore: true
|
||||
GetLeftX:
|
||||
GetRightX:
|
||||
GetLeftY:
|
||||
@@ -69,6 +80,12 @@ classes:
|
||||
GetTouchpadButton:
|
||||
GetTouchpadButtonPressed:
|
||||
GetTouchpadButtonReleased:
|
||||
IsConnected:
|
||||
GetGamepadType:
|
||||
GetSupportedOutputs:
|
||||
GetName:
|
||||
GetPort:
|
||||
SetRumble:
|
||||
InitSendable:
|
||||
wpi::NiDsPS5Controller::Button:
|
||||
attributes:
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
extra_includes:
|
||||
- wpi/util/sendable/SendableBuilder.hpp
|
||||
- wpi/event/BooleanEvent.hpp
|
||||
|
||||
classes:
|
||||
wpi::NiDsStadiaController:
|
||||
force_no_trampoline: true
|
||||
ignored_bases:
|
||||
- wpi::util::SendableHelper<NiDsStadiaController>
|
||||
methods:
|
||||
NiDsStadiaController:
|
||||
overloads:
|
||||
int:
|
||||
GenericHID&:
|
||||
GetHID:
|
||||
overloads:
|
||||
"":
|
||||
return_value_policy: reference_internal
|
||||
'[const]':
|
||||
ignore: true
|
||||
GetLeftX:
|
||||
GetRightX:
|
||||
GetLeftY:
|
||||
@@ -71,6 +82,12 @@ classes:
|
||||
GetRightBumperButton:
|
||||
GetRightBumperButtonPressed:
|
||||
GetRightBumperButtonReleased:
|
||||
IsConnected:
|
||||
GetGamepadType:
|
||||
GetSupportedOutputs:
|
||||
GetName:
|
||||
GetPort:
|
||||
SetRumble:
|
||||
InitSendable:
|
||||
wpi::NiDsStadiaController::Button:
|
||||
attributes:
|
||||
|
||||
@@ -5,10 +5,20 @@ extra_includes:
|
||||
|
||||
classes:
|
||||
wpi::NiDsXboxController:
|
||||
force_no_trampoline: true
|
||||
ignored_bases:
|
||||
- wpi::util::SendableHelper<NiDsXboxController>
|
||||
methods:
|
||||
NiDsXboxController:
|
||||
overloads:
|
||||
int:
|
||||
GenericHID&:
|
||||
GetHID:
|
||||
overloads:
|
||||
"":
|
||||
return_value_policy: reference_internal
|
||||
'[const]':
|
||||
ignore: true
|
||||
GetLeftX:
|
||||
GetRightX:
|
||||
GetLeftY:
|
||||
@@ -63,6 +73,12 @@ classes:
|
||||
GetRightBumperButton:
|
||||
GetRightBumperButtonPressed:
|
||||
GetRightBumperButtonReleased:
|
||||
IsConnected:
|
||||
GetGamepadType:
|
||||
GetSupportedOutputs:
|
||||
GetName:
|
||||
GetPort:
|
||||
SetRumble:
|
||||
InitSendable:
|
||||
wpi::NiDsXboxController::Button:
|
||||
attributes:
|
||||
|
||||
@@ -16,8 +16,10 @@ import wpilib.simulation
|
||||
# TODO: get rid of special-casing.. maybe should register a HAL shutdown hook or something
|
||||
try:
|
||||
import commands2
|
||||
from commands2.button.commandgenerichid import _resetCommandGenericHIDData
|
||||
except ImportError:
|
||||
commands2 = None
|
||||
_resetCommandGenericHIDData = None
|
||||
|
||||
from .controller import RobotTestController
|
||||
|
||||
@@ -98,10 +100,15 @@ class RobotTestingPlugin:
|
||||
|
||||
if commands2 is not None:
|
||||
commands2.CommandScheduler.resetInstance()
|
||||
_resetCommandGenericHIDData()
|
||||
|
||||
# Double-check all objects are destroyed so that HAL handles are released
|
||||
gc.collect()
|
||||
|
||||
# Reset DriverStation cached HID wrapper objects after user and command
|
||||
# references have had a chance to be released.
|
||||
wpilib.DriverStationBackend.resetCachedHIDData()
|
||||
|
||||
# shutdown networktables before other kinds of global cleanup
|
||||
# -> some reset functions will re-register listeners, so it's important
|
||||
# to do this before so that the listeners are active on the current
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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 <string>
|
||||
#include <cstring>
|
||||
#include <tuple>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
@@ -37,7 +37,7 @@ INSTANTIATE_TEST_SUITE_P(IsConnectedTests, IsJoystickConnectedParametersTest,
|
||||
std::make_tuple(4, 10, 1, true)));
|
||||
class JoystickConnectionWarningTest
|
||||
: public ::testing::TestWithParam<
|
||||
std::tuple<bool, bool, bool, std::string>> {};
|
||||
std::tuple<bool, bool, bool, const char*>> {};
|
||||
|
||||
TEST_P(JoystickConnectionWarningTest, JoystickConnectionWarnings) {
|
||||
// Capture all output to stderr.
|
||||
@@ -51,15 +51,17 @@ TEST_P(JoystickConnectionWarningTest, JoystickConnectionWarnings) {
|
||||
|
||||
// Create joystick and attempt to retrieve button.
|
||||
wpi::Joystick joystick(0);
|
||||
joystick.GetRawButton(1);
|
||||
joystick.GetHID().GetRawButton(1);
|
||||
|
||||
wpi::sim::StepTiming(1_s);
|
||||
EXPECT_EQ(wpi::internal::DriverStationBackend::
|
||||
IsJoystickConnectionWarningSilenced(),
|
||||
std::get<2>(GetParam()));
|
||||
EXPECT_EQ(::testing::internal::GetCapturedStderr().substr(
|
||||
0, std::get<3>(GetParam()).size()),
|
||||
std::get<3>(GetParam()));
|
||||
auto expected = std::get<3>(GetParam());
|
||||
EXPECT_STREQ(::testing::internal::GetCapturedStderr()
|
||||
.substr(0, std::strlen(expected))
|
||||
.c_str(),
|
||||
expected);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
||||
@@ -6,13 +6,14 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/driverstation/internal/DriverStationBackend.hpp"
|
||||
#include "wpi/simulation/GenericHIDSim.hpp"
|
||||
|
||||
using namespace wpi;
|
||||
using RumbleType = GenericHID::RumbleType;
|
||||
static constexpr double kEpsilon = 0.0001;
|
||||
TEST(GenericHIDTest, RumbleRange) {
|
||||
GenericHID hid{0};
|
||||
GenericHID hid = internal::DriverStationBackend::ConstructGenericHID(0);
|
||||
sim::GenericHIDSim sim{0};
|
||||
|
||||
for (int i = 0; i <= 100; i++) {
|
||||
@@ -34,7 +35,7 @@ TEST(GenericHIDTest, RumbleRange) {
|
||||
}
|
||||
|
||||
TEST(GenericHIDTest, RumbleTypes) {
|
||||
GenericHID hid{0};
|
||||
GenericHID hid = internal::DriverStationBackend::ConstructGenericHID(0);
|
||||
sim::GenericHIDSim sim{0};
|
||||
|
||||
// Make sure all are off
|
||||
|
||||
67
wpilibc/src/test/python/test_generic_hid.py
Normal file
67
wpilibc/src/test/python/test_generic_hid.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import pytest
|
||||
|
||||
from wpilib import DriverStation, DriverStationBackend, GenericHID
|
||||
from wpilib.simulation import DriverStationSim, GenericHIDSim
|
||||
|
||||
|
||||
RumbleType = GenericHID.RumbleType
|
||||
RUMBLE_TYPES = (
|
||||
RumbleType.LEFT_RUMBLE,
|
||||
RumbleType.RIGHT_RUMBLE,
|
||||
RumbleType.LEFT_TRIGGER_RUMBLE,
|
||||
RumbleType.RIGHT_TRIGGER_RUMBLE,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_driver_station_sim():
|
||||
DriverStationSim.resetData()
|
||||
yield
|
||||
DriverStationBackend.resetCachedHIDData()
|
||||
DriverStationSim.resetData()
|
||||
|
||||
|
||||
def test_rumble_range() -> None:
|
||||
hid = DriverStationBackend.constructGenericHID(0)
|
||||
sim = GenericHIDSim(0)
|
||||
|
||||
for i in range(101):
|
||||
rumble_value = i / 100.0
|
||||
|
||||
for rumble_type in RUMBLE_TYPES:
|
||||
hid.setRumble(rumble_type, rumble_value)
|
||||
assert sim.getRumble(rumble_type) == pytest.approx(
|
||||
rumble_value, abs=0.0001
|
||||
)
|
||||
|
||||
|
||||
def test_rumble_types() -> None:
|
||||
hid = DriverStationBackend.constructGenericHID(0)
|
||||
sim = GenericHIDSim(0)
|
||||
|
||||
for rumble_type in RUMBLE_TYPES:
|
||||
hid.setRumble(rumble_type, 0)
|
||||
|
||||
for rumble_type in RUMBLE_TYPES:
|
||||
assert sim.getRumble(rumble_type) == pytest.approx(0, abs=0.0001)
|
||||
|
||||
for active_rumble_type in RUMBLE_TYPES:
|
||||
hid.setRumble(active_rumble_type, 1)
|
||||
|
||||
for rumble_type in RUMBLE_TYPES:
|
||||
expected = 1 if rumble_type == active_rumble_type else 0
|
||||
assert sim.getRumble(rumble_type) == pytest.approx(
|
||||
expected, abs=0.0001
|
||||
)
|
||||
|
||||
hid.setRumble(active_rumble_type, 0)
|
||||
|
||||
|
||||
def test_cached_hid_data_reset() -> None:
|
||||
DriverStation.getGenericHID(0)
|
||||
DriverStation.getGamepad(0)
|
||||
|
||||
DriverStationBackend.resetCachedHIDData()
|
||||
|
||||
assert DriverStation.getGenericHID(0).getPort() == 0
|
||||
assert DriverStation.getGamepad(0).getPort() == 0
|
||||
@@ -8,6 +8,11 @@
|
||||
{%- endmacro %}
|
||||
package org.wpilib.driverstation;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Objects;
|
||||
import org.wpilib.driverstation.GenericHID.HIDType;
|
||||
import org.wpilib.driverstation.GenericHID.RumbleType;
|
||||
import org.wpilib.driverstation.GenericHID.SupportedOutput;
|
||||
import org.wpilib.event.BooleanEvent;
|
||||
import org.wpilib.event.EventLoop;
|
||||
import org.wpilib.hardware.hal.HAL;
|
||||
@@ -25,7 +30,7 @@ import org.wpilib.util.sendable.SendableBuilder;
|
||||
* only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any
|
||||
* 3rd party controllers.
|
||||
*/
|
||||
public class {{ ConsoleName }}Controller extends GenericHID implements Sendable {
|
||||
public class {{ ConsoleName }}Controller implements HIDDevice, Sendable {
|
||||
/** Represents a digital button on a {{ ConsoleName }}Controller. */
|
||||
public enum Button {
|
||||
{%- for button in buttons %}
|
||||
@@ -91,14 +96,35 @@ public class {{ ConsoleName }}Controller extends GenericHID implements Sendable
|
||||
}
|
||||
}
|
||||
|
||||
private final GenericHID m_hid;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
@Override
|
||||
public GenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is plugged into (0-5).
|
||||
*/
|
||||
public {{ ConsoleName }}Controller(final int port) {
|
||||
super(port);
|
||||
HAL.reportUsage("HID", port, "{{ ConsoleName }}Controller");
|
||||
this(DriverStation.getGenericHID(port));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this controller.
|
||||
*/
|
||||
public {{ ConsoleName }}Controller(final GenericHID hid) {
|
||||
m_hid = Objects.requireNonNull(hid, "Provided HID object cannot be null");
|
||||
HAL.reportUsage("HID", hid.getPort(), "{{ ConsoleName }}Controller");
|
||||
}
|
||||
{% for stick in sticks %}
|
||||
/**
|
||||
@@ -107,7 +133,7 @@ public class {{ ConsoleName }}Controller extends GenericHID implements Sendable
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double get{{ stick.NameParts|map("capitalize")|join }}() {
|
||||
return getRawAxis(Axis.k{{ stick.NameParts|map("capitalize")|join }}.value);
|
||||
return m_hid.getRawAxis(Axis.k{{ stick.NameParts|map("capitalize")|join }}.value);
|
||||
}
|
||||
{% endfor -%}
|
||||
{% for trigger in triggers %}
|
||||
@@ -118,7 +144,7 @@ public class {{ ConsoleName }}Controller extends GenericHID implements Sendable
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double get{{ capitalize_first(trigger.name) }}Axis() {
|
||||
return getRawAxis(Axis.k{{ capitalize_first(trigger.name) }}.value);
|
||||
return m_hid.getRawAxis(Axis.k{{ capitalize_first(trigger.name) }}.value);
|
||||
}
|
||||
{% if trigger.UseThresholdMethods %}
|
||||
/**
|
||||
@@ -132,7 +158,7 @@ public class {{ ConsoleName }}Controller extends GenericHID implements Sendable
|
||||
* threshold, attached to the given event loop
|
||||
*/
|
||||
public BooleanEvent {{ trigger.name }}(double threshold, EventLoop loop) {
|
||||
return axisGreaterThan(Axis.k{{ capitalize_first(trigger.name) }}.value, threshold, loop);
|
||||
return m_hid.axisGreaterThan(Axis.k{{ capitalize_first(trigger.name) }}.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,7 +181,7 @@ public class {{ ConsoleName }}Controller extends GenericHID implements Sendable
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean get{{ capitalize_first(button.name) }}Button() {
|
||||
return getRawButton(Button.k{{ capitalize_first(button.name) }}.value);
|
||||
return m_hid.getRawButton(Button.k{{ capitalize_first(button.name) }}.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,7 +190,7 @@ public class {{ ConsoleName }}Controller extends GenericHID implements Sendable
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean get{{ capitalize_first(button.name) }}ButtonPressed() {
|
||||
return getRawButtonPressed(Button.k{{ capitalize_first(button.name) }}.value);
|
||||
return m_hid.getRawButtonPressed(Button.k{{ capitalize_first(button.name) }}.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,7 +199,7 @@ public class {{ ConsoleName }}Controller extends GenericHID implements Sendable
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean get{{ capitalize_first(button.name) }}ButtonReleased() {
|
||||
return getRawButtonReleased(Button.k{{ capitalize_first(button.name) }}.value);
|
||||
return m_hid.getRawButtonReleased(Button.k{{ capitalize_first(button.name) }}.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,9 +210,67 @@ public class {{ ConsoleName }}Controller extends GenericHID implements Sendable
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent {{ button.name }}(EventLoop loop) {
|
||||
return button(Button.k{{ capitalize_first(button.name) }}.value, loop);
|
||||
return m_hid.button(Button.k{{ capitalize_first(button.name) }}.value, loop);
|
||||
}
|
||||
{% endfor %}
|
||||
/**
|
||||
* Get if the controller is connected.
|
||||
*
|
||||
* @return true if the controller is connected
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
return m_hid.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of the controller.
|
||||
*
|
||||
* @return the type of the controller.
|
||||
*/
|
||||
public HIDType getGamepadType() {
|
||||
return m_hid.getGamepadType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supported outputs of the controller.
|
||||
*
|
||||
* @return the supported outputs of the controller.
|
||||
*/
|
||||
public EnumSet<SupportedOutput> getSupportedOutputs() {
|
||||
return m_hid.getSupportedOutputs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the controller.
|
||||
*
|
||||
* @return the name of the controller.
|
||||
*/
|
||||
public String getName() {
|
||||
return m_hid.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the port number of the controller.
|
||||
*
|
||||
* @return The port number of the controller.
|
||||
*/
|
||||
public int getPort() {
|
||||
return m_hid.getPort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rumble output for the HID.
|
||||
*
|
||||
* <p>The DS currently supports 4 rumble values: left rumble, right rumble, left trigger rumble,
|
||||
* and right trigger rumble.
|
||||
*
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
public void setRumble(RumbleType type, double value) {
|
||||
m_hid.setRumble(type, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("HID");
|
||||
|
||||
@@ -19,7 +19,7 @@ public class {{ ConsoleName }}ControllerSim extends GenericHIDSim {
|
||||
*/
|
||||
@SuppressWarnings("this-escape")
|
||||
public {{ ConsoleName }}ControllerSim({{ ConsoleName }}Controller joystick) {
|
||||
super(joystick);
|
||||
super(joystick.getHID());
|
||||
setAxesMaximumIndex({{ sticks|length + triggers|length }});
|
||||
setButtonsMaximumIndex({{ buttons|length }});
|
||||
setPOVsMaximumIndex(1);
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
|
||||
package org.wpilib.driverstation;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Objects;
|
||||
import org.wpilib.driverstation.GenericHID.HIDType;
|
||||
import org.wpilib.driverstation.GenericHID.RumbleType;
|
||||
import org.wpilib.driverstation.GenericHID.SupportedOutput;
|
||||
import org.wpilib.event.BooleanEvent;
|
||||
import org.wpilib.event.EventLoop;
|
||||
import org.wpilib.hardware.hal.HAL;
|
||||
@@ -23,7 +28,7 @@ import org.wpilib.util.sendable.SendableBuilder;
|
||||
* only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any
|
||||
* 3rd party controllers.
|
||||
*/
|
||||
public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
public class NiDsPS4Controller implements HIDDevice, Sendable {
|
||||
/** Represents a digital button on a NiDsPS4Controller. */
|
||||
public enum Button {
|
||||
/** Square button. */
|
||||
@@ -117,14 +122,35 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
private final GenericHID m_hid;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
@Override
|
||||
public GenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is plugged into (0-5).
|
||||
*/
|
||||
public NiDsPS4Controller(final int port) {
|
||||
super(port);
|
||||
HAL.reportUsage("HID", port, "NiDsPS4Controller");
|
||||
this(DriverStation.getGenericHID(port));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this controller.
|
||||
*/
|
||||
public NiDsPS4Controller(final GenericHID hid) {
|
||||
m_hid = Objects.requireNonNull(hid, "Provided HID object cannot be null");
|
||||
HAL.reportUsage("HID", hid.getPort(), "NiDsPS4Controller");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +159,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return getRawAxis(Axis.kLeftX.value);
|
||||
return m_hid.getRawAxis(Axis.kLeftX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +168,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return getRawAxis(Axis.kLeftY.value);
|
||||
return m_hid.getRawAxis(Axis.kLeftY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,7 +177,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return getRawAxis(Axis.kRightX.value);
|
||||
return m_hid.getRawAxis(Axis.kRightX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +186,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return getRawAxis(Axis.kRightY.value);
|
||||
return m_hid.getRawAxis(Axis.kRightY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +196,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getL2Axis() {
|
||||
return getRawAxis(Axis.kL2.value);
|
||||
return m_hid.getRawAxis(Axis.kL2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,7 +206,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getR2Axis() {
|
||||
return getRawAxis(Axis.kR2.value);
|
||||
return m_hid.getRawAxis(Axis.kR2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,7 +215,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getSquareButton() {
|
||||
return getRawButton(Button.kSquare.value);
|
||||
return m_hid.getRawButton(Button.kSquare.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,7 +224,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getSquareButtonPressed() {
|
||||
return getRawButtonPressed(Button.kSquare.value);
|
||||
return m_hid.getRawButtonPressed(Button.kSquare.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +233,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getSquareButtonReleased() {
|
||||
return getRawButtonReleased(Button.kSquare.value);
|
||||
return m_hid.getRawButtonReleased(Button.kSquare.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +244,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent square(EventLoop loop) {
|
||||
return button(Button.kSquare.value, loop);
|
||||
return m_hid.button(Button.kSquare.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,7 +253,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getCrossButton() {
|
||||
return getRawButton(Button.kCross.value);
|
||||
return m_hid.getRawButton(Button.kCross.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,7 +262,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getCrossButtonPressed() {
|
||||
return getRawButtonPressed(Button.kCross.value);
|
||||
return m_hid.getRawButtonPressed(Button.kCross.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,7 +271,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getCrossButtonReleased() {
|
||||
return getRawButtonReleased(Button.kCross.value);
|
||||
return m_hid.getRawButtonReleased(Button.kCross.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +282,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent cross(EventLoop loop) {
|
||||
return button(Button.kCross.value, loop);
|
||||
return m_hid.button(Button.kCross.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,7 +291,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getCircleButton() {
|
||||
return getRawButton(Button.kCircle.value);
|
||||
return m_hid.getRawButton(Button.kCircle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,7 +300,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getCircleButtonPressed() {
|
||||
return getRawButtonPressed(Button.kCircle.value);
|
||||
return m_hid.getRawButtonPressed(Button.kCircle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,7 +309,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getCircleButtonReleased() {
|
||||
return getRawButtonReleased(Button.kCircle.value);
|
||||
return m_hid.getRawButtonReleased(Button.kCircle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,7 +320,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent circle(EventLoop loop) {
|
||||
return button(Button.kCircle.value, loop);
|
||||
return m_hid.button(Button.kCircle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,7 +329,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getTriangleButton() {
|
||||
return getRawButton(Button.kTriangle.value);
|
||||
return m_hid.getRawButton(Button.kTriangle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,7 +338,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getTriangleButtonPressed() {
|
||||
return getRawButtonPressed(Button.kTriangle.value);
|
||||
return m_hid.getRawButtonPressed(Button.kTriangle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,7 +347,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getTriangleButtonReleased() {
|
||||
return getRawButtonReleased(Button.kTriangle.value);
|
||||
return m_hid.getRawButtonReleased(Button.kTriangle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,7 +358,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent triangle(EventLoop loop) {
|
||||
return button(Button.kTriangle.value, loop);
|
||||
return m_hid.button(Button.kTriangle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,7 +367,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getL1Button() {
|
||||
return getRawButton(Button.kL1.value);
|
||||
return m_hid.getRawButton(Button.kL1.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -350,7 +376,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getL1ButtonPressed() {
|
||||
return getRawButtonPressed(Button.kL1.value);
|
||||
return m_hid.getRawButtonPressed(Button.kL1.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -359,7 +385,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getL1ButtonReleased() {
|
||||
return getRawButtonReleased(Button.kL1.value);
|
||||
return m_hid.getRawButtonReleased(Button.kL1.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -370,7 +396,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent L1(EventLoop loop) {
|
||||
return button(Button.kL1.value, loop);
|
||||
return m_hid.button(Button.kL1.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -379,7 +405,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getR1Button() {
|
||||
return getRawButton(Button.kR1.value);
|
||||
return m_hid.getRawButton(Button.kR1.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -388,7 +414,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getR1ButtonPressed() {
|
||||
return getRawButtonPressed(Button.kR1.value);
|
||||
return m_hid.getRawButtonPressed(Button.kR1.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -397,7 +423,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getR1ButtonReleased() {
|
||||
return getRawButtonReleased(Button.kR1.value);
|
||||
return m_hid.getRawButtonReleased(Button.kR1.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -408,7 +434,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent R1(EventLoop loop) {
|
||||
return button(Button.kR1.value, loop);
|
||||
return m_hid.button(Button.kR1.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -417,7 +443,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getL2Button() {
|
||||
return getRawButton(Button.kL2.value);
|
||||
return m_hid.getRawButton(Button.kL2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -426,7 +452,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getL2ButtonPressed() {
|
||||
return getRawButtonPressed(Button.kL2.value);
|
||||
return m_hid.getRawButtonPressed(Button.kL2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,7 +461,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getL2ButtonReleased() {
|
||||
return getRawButtonReleased(Button.kL2.value);
|
||||
return m_hid.getRawButtonReleased(Button.kL2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -446,7 +472,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent L2(EventLoop loop) {
|
||||
return button(Button.kL2.value, loop);
|
||||
return m_hid.button(Button.kL2.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -455,7 +481,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getR2Button() {
|
||||
return getRawButton(Button.kR2.value);
|
||||
return m_hid.getRawButton(Button.kR2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -464,7 +490,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getR2ButtonPressed() {
|
||||
return getRawButtonPressed(Button.kR2.value);
|
||||
return m_hid.getRawButtonPressed(Button.kR2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -473,7 +499,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getR2ButtonReleased() {
|
||||
return getRawButtonReleased(Button.kR2.value);
|
||||
return m_hid.getRawButtonReleased(Button.kR2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -484,7 +510,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent R2(EventLoop loop) {
|
||||
return button(Button.kR2.value, loop);
|
||||
return m_hid.button(Button.kR2.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,7 +519,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getShareButton() {
|
||||
return getRawButton(Button.kShare.value);
|
||||
return m_hid.getRawButton(Button.kShare.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -502,7 +528,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getShareButtonPressed() {
|
||||
return getRawButtonPressed(Button.kShare.value);
|
||||
return m_hid.getRawButtonPressed(Button.kShare.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -511,7 +537,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getShareButtonReleased() {
|
||||
return getRawButtonReleased(Button.kShare.value);
|
||||
return m_hid.getRawButtonReleased(Button.kShare.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -522,7 +548,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent share(EventLoop loop) {
|
||||
return button(Button.kShare.value, loop);
|
||||
return m_hid.button(Button.kShare.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -531,7 +557,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getOptionsButton() {
|
||||
return getRawButton(Button.kOptions.value);
|
||||
return m_hid.getRawButton(Button.kOptions.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -540,7 +566,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getOptionsButtonPressed() {
|
||||
return getRawButtonPressed(Button.kOptions.value);
|
||||
return m_hid.getRawButtonPressed(Button.kOptions.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -549,7 +575,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getOptionsButtonReleased() {
|
||||
return getRawButtonReleased(Button.kOptions.value);
|
||||
return m_hid.getRawButtonReleased(Button.kOptions.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -560,7 +586,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent options(EventLoop loop) {
|
||||
return button(Button.kOptions.value, loop);
|
||||
return m_hid.button(Button.kOptions.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -569,7 +595,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getL3Button() {
|
||||
return getRawButton(Button.kL3.value);
|
||||
return m_hid.getRawButton(Button.kL3.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -578,7 +604,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getL3ButtonPressed() {
|
||||
return getRawButtonPressed(Button.kL3.value);
|
||||
return m_hid.getRawButtonPressed(Button.kL3.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -587,7 +613,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getL3ButtonReleased() {
|
||||
return getRawButtonReleased(Button.kL3.value);
|
||||
return m_hid.getRawButtonReleased(Button.kL3.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -598,7 +624,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent L3(EventLoop loop) {
|
||||
return button(Button.kL3.value, loop);
|
||||
return m_hid.button(Button.kL3.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -607,7 +633,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getR3Button() {
|
||||
return getRawButton(Button.kR3.value);
|
||||
return m_hid.getRawButton(Button.kR3.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -616,7 +642,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getR3ButtonPressed() {
|
||||
return getRawButtonPressed(Button.kR3.value);
|
||||
return m_hid.getRawButtonPressed(Button.kR3.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -625,7 +651,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getR3ButtonReleased() {
|
||||
return getRawButtonReleased(Button.kR3.value);
|
||||
return m_hid.getRawButtonReleased(Button.kR3.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -636,7 +662,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent R3(EventLoop loop) {
|
||||
return button(Button.kR3.value, loop);
|
||||
return m_hid.button(Button.kR3.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -645,7 +671,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getPSButton() {
|
||||
return getRawButton(Button.kPS.value);
|
||||
return m_hid.getRawButton(Button.kPS.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -654,7 +680,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getPSButtonPressed() {
|
||||
return getRawButtonPressed(Button.kPS.value);
|
||||
return m_hid.getRawButtonPressed(Button.kPS.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -663,7 +689,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getPSButtonReleased() {
|
||||
return getRawButtonReleased(Button.kPS.value);
|
||||
return m_hid.getRawButtonReleased(Button.kPS.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -674,7 +700,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent PS(EventLoop loop) {
|
||||
return button(Button.kPS.value, loop);
|
||||
return m_hid.button(Button.kPS.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -683,7 +709,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getTouchpadButton() {
|
||||
return getRawButton(Button.kTouchpad.value);
|
||||
return m_hid.getRawButton(Button.kTouchpad.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -692,7 +718,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getTouchpadButtonPressed() {
|
||||
return getRawButtonPressed(Button.kTouchpad.value);
|
||||
return m_hid.getRawButtonPressed(Button.kTouchpad.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -701,7 +727,7 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getTouchpadButtonReleased() {
|
||||
return getRawButtonReleased(Button.kTouchpad.value);
|
||||
return m_hid.getRawButtonReleased(Button.kTouchpad.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -712,7 +738,65 @@ public class NiDsPS4Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent touchpad(EventLoop loop) {
|
||||
return button(Button.kTouchpad.value, loop);
|
||||
return m_hid.button(Button.kTouchpad.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the controller is connected.
|
||||
*
|
||||
* @return true if the controller is connected
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
return m_hid.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of the controller.
|
||||
*
|
||||
* @return the type of the controller.
|
||||
*/
|
||||
public HIDType getGamepadType() {
|
||||
return m_hid.getGamepadType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supported outputs of the controller.
|
||||
*
|
||||
* @return the supported outputs of the controller.
|
||||
*/
|
||||
public EnumSet<SupportedOutput> getSupportedOutputs() {
|
||||
return m_hid.getSupportedOutputs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the controller.
|
||||
*
|
||||
* @return the name of the controller.
|
||||
*/
|
||||
public String getName() {
|
||||
return m_hid.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the port number of the controller.
|
||||
*
|
||||
* @return The port number of the controller.
|
||||
*/
|
||||
public int getPort() {
|
||||
return m_hid.getPort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rumble output for the HID.
|
||||
*
|
||||
* <p>The DS currently supports 4 rumble values: left rumble, right rumble, left trigger rumble,
|
||||
* and right trigger rumble.
|
||||
*
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
public void setRumble(RumbleType type, double value) {
|
||||
m_hid.setRumble(type, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
|
||||
package org.wpilib.driverstation;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Objects;
|
||||
import org.wpilib.driverstation.GenericHID.HIDType;
|
||||
import org.wpilib.driverstation.GenericHID.RumbleType;
|
||||
import org.wpilib.driverstation.GenericHID.SupportedOutput;
|
||||
import org.wpilib.event.BooleanEvent;
|
||||
import org.wpilib.event.EventLoop;
|
||||
import org.wpilib.hardware.hal.HAL;
|
||||
@@ -23,7 +28,7 @@ import org.wpilib.util.sendable.SendableBuilder;
|
||||
* only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any
|
||||
* 3rd party controllers.
|
||||
*/
|
||||
public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
public class NiDsPS5Controller implements HIDDevice, Sendable {
|
||||
/** Represents a digital button on a NiDsPS5Controller. */
|
||||
public enum Button {
|
||||
/** Square button. */
|
||||
@@ -117,14 +122,35 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
private final GenericHID m_hid;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
@Override
|
||||
public GenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is plugged into (0-5).
|
||||
*/
|
||||
public NiDsPS5Controller(final int port) {
|
||||
super(port);
|
||||
HAL.reportUsage("HID", port, "NiDsPS5Controller");
|
||||
this(DriverStation.getGenericHID(port));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this controller.
|
||||
*/
|
||||
public NiDsPS5Controller(final GenericHID hid) {
|
||||
m_hid = Objects.requireNonNull(hid, "Provided HID object cannot be null");
|
||||
HAL.reportUsage("HID", hid.getPort(), "NiDsPS5Controller");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +159,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return getRawAxis(Axis.kLeftX.value);
|
||||
return m_hid.getRawAxis(Axis.kLeftX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +168,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return getRawAxis(Axis.kLeftY.value);
|
||||
return m_hid.getRawAxis(Axis.kLeftY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,7 +177,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return getRawAxis(Axis.kRightX.value);
|
||||
return m_hid.getRawAxis(Axis.kRightX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +186,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return getRawAxis(Axis.kRightY.value);
|
||||
return m_hid.getRawAxis(Axis.kRightY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +196,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getL2Axis() {
|
||||
return getRawAxis(Axis.kL2.value);
|
||||
return m_hid.getRawAxis(Axis.kL2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,7 +206,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getR2Axis() {
|
||||
return getRawAxis(Axis.kR2.value);
|
||||
return m_hid.getRawAxis(Axis.kR2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,7 +215,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getSquareButton() {
|
||||
return getRawButton(Button.kSquare.value);
|
||||
return m_hid.getRawButton(Button.kSquare.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,7 +224,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getSquareButtonPressed() {
|
||||
return getRawButtonPressed(Button.kSquare.value);
|
||||
return m_hid.getRawButtonPressed(Button.kSquare.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +233,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getSquareButtonReleased() {
|
||||
return getRawButtonReleased(Button.kSquare.value);
|
||||
return m_hid.getRawButtonReleased(Button.kSquare.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +244,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent square(EventLoop loop) {
|
||||
return button(Button.kSquare.value, loop);
|
||||
return m_hid.button(Button.kSquare.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,7 +253,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getCrossButton() {
|
||||
return getRawButton(Button.kCross.value);
|
||||
return m_hid.getRawButton(Button.kCross.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,7 +262,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getCrossButtonPressed() {
|
||||
return getRawButtonPressed(Button.kCross.value);
|
||||
return m_hid.getRawButtonPressed(Button.kCross.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,7 +271,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getCrossButtonReleased() {
|
||||
return getRawButtonReleased(Button.kCross.value);
|
||||
return m_hid.getRawButtonReleased(Button.kCross.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +282,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent cross(EventLoop loop) {
|
||||
return button(Button.kCross.value, loop);
|
||||
return m_hid.button(Button.kCross.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,7 +291,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getCircleButton() {
|
||||
return getRawButton(Button.kCircle.value);
|
||||
return m_hid.getRawButton(Button.kCircle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,7 +300,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getCircleButtonPressed() {
|
||||
return getRawButtonPressed(Button.kCircle.value);
|
||||
return m_hid.getRawButtonPressed(Button.kCircle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,7 +309,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getCircleButtonReleased() {
|
||||
return getRawButtonReleased(Button.kCircle.value);
|
||||
return m_hid.getRawButtonReleased(Button.kCircle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,7 +320,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent circle(EventLoop loop) {
|
||||
return button(Button.kCircle.value, loop);
|
||||
return m_hid.button(Button.kCircle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,7 +329,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getTriangleButton() {
|
||||
return getRawButton(Button.kTriangle.value);
|
||||
return m_hid.getRawButton(Button.kTriangle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,7 +338,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getTriangleButtonPressed() {
|
||||
return getRawButtonPressed(Button.kTriangle.value);
|
||||
return m_hid.getRawButtonPressed(Button.kTriangle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,7 +347,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getTriangleButtonReleased() {
|
||||
return getRawButtonReleased(Button.kTriangle.value);
|
||||
return m_hid.getRawButtonReleased(Button.kTriangle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,7 +358,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent triangle(EventLoop loop) {
|
||||
return button(Button.kTriangle.value, loop);
|
||||
return m_hid.button(Button.kTriangle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,7 +367,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getL1Button() {
|
||||
return getRawButton(Button.kL1.value);
|
||||
return m_hid.getRawButton(Button.kL1.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -350,7 +376,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getL1ButtonPressed() {
|
||||
return getRawButtonPressed(Button.kL1.value);
|
||||
return m_hid.getRawButtonPressed(Button.kL1.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -359,7 +385,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getL1ButtonReleased() {
|
||||
return getRawButtonReleased(Button.kL1.value);
|
||||
return m_hid.getRawButtonReleased(Button.kL1.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -370,7 +396,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent L1(EventLoop loop) {
|
||||
return button(Button.kL1.value, loop);
|
||||
return m_hid.button(Button.kL1.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -379,7 +405,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getR1Button() {
|
||||
return getRawButton(Button.kR1.value);
|
||||
return m_hid.getRawButton(Button.kR1.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -388,7 +414,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getR1ButtonPressed() {
|
||||
return getRawButtonPressed(Button.kR1.value);
|
||||
return m_hid.getRawButtonPressed(Button.kR1.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -397,7 +423,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getR1ButtonReleased() {
|
||||
return getRawButtonReleased(Button.kR1.value);
|
||||
return m_hid.getRawButtonReleased(Button.kR1.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -408,7 +434,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent R1(EventLoop loop) {
|
||||
return button(Button.kR1.value, loop);
|
||||
return m_hid.button(Button.kR1.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -417,7 +443,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getL2Button() {
|
||||
return getRawButton(Button.kL2.value);
|
||||
return m_hid.getRawButton(Button.kL2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -426,7 +452,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getL2ButtonPressed() {
|
||||
return getRawButtonPressed(Button.kL2.value);
|
||||
return m_hid.getRawButtonPressed(Button.kL2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,7 +461,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getL2ButtonReleased() {
|
||||
return getRawButtonReleased(Button.kL2.value);
|
||||
return m_hid.getRawButtonReleased(Button.kL2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -446,7 +472,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent L2(EventLoop loop) {
|
||||
return button(Button.kL2.value, loop);
|
||||
return m_hid.button(Button.kL2.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -455,7 +481,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getR2Button() {
|
||||
return getRawButton(Button.kR2.value);
|
||||
return m_hid.getRawButton(Button.kR2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -464,7 +490,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getR2ButtonPressed() {
|
||||
return getRawButtonPressed(Button.kR2.value);
|
||||
return m_hid.getRawButtonPressed(Button.kR2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -473,7 +499,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getR2ButtonReleased() {
|
||||
return getRawButtonReleased(Button.kR2.value);
|
||||
return m_hid.getRawButtonReleased(Button.kR2.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -484,7 +510,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent R2(EventLoop loop) {
|
||||
return button(Button.kR2.value, loop);
|
||||
return m_hid.button(Button.kR2.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,7 +519,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getCreateButton() {
|
||||
return getRawButton(Button.kCreate.value);
|
||||
return m_hid.getRawButton(Button.kCreate.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -502,7 +528,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getCreateButtonPressed() {
|
||||
return getRawButtonPressed(Button.kCreate.value);
|
||||
return m_hid.getRawButtonPressed(Button.kCreate.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -511,7 +537,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getCreateButtonReleased() {
|
||||
return getRawButtonReleased(Button.kCreate.value);
|
||||
return m_hid.getRawButtonReleased(Button.kCreate.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -522,7 +548,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent create(EventLoop loop) {
|
||||
return button(Button.kCreate.value, loop);
|
||||
return m_hid.button(Button.kCreate.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -531,7 +557,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getOptionsButton() {
|
||||
return getRawButton(Button.kOptions.value);
|
||||
return m_hid.getRawButton(Button.kOptions.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -540,7 +566,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getOptionsButtonPressed() {
|
||||
return getRawButtonPressed(Button.kOptions.value);
|
||||
return m_hid.getRawButtonPressed(Button.kOptions.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -549,7 +575,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getOptionsButtonReleased() {
|
||||
return getRawButtonReleased(Button.kOptions.value);
|
||||
return m_hid.getRawButtonReleased(Button.kOptions.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -560,7 +586,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent options(EventLoop loop) {
|
||||
return button(Button.kOptions.value, loop);
|
||||
return m_hid.button(Button.kOptions.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -569,7 +595,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getL3Button() {
|
||||
return getRawButton(Button.kL3.value);
|
||||
return m_hid.getRawButton(Button.kL3.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -578,7 +604,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getL3ButtonPressed() {
|
||||
return getRawButtonPressed(Button.kL3.value);
|
||||
return m_hid.getRawButtonPressed(Button.kL3.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -587,7 +613,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getL3ButtonReleased() {
|
||||
return getRawButtonReleased(Button.kL3.value);
|
||||
return m_hid.getRawButtonReleased(Button.kL3.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -598,7 +624,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent L3(EventLoop loop) {
|
||||
return button(Button.kL3.value, loop);
|
||||
return m_hid.button(Button.kL3.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -607,7 +633,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getR3Button() {
|
||||
return getRawButton(Button.kR3.value);
|
||||
return m_hid.getRawButton(Button.kR3.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -616,7 +642,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getR3ButtonPressed() {
|
||||
return getRawButtonPressed(Button.kR3.value);
|
||||
return m_hid.getRawButtonPressed(Button.kR3.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -625,7 +651,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getR3ButtonReleased() {
|
||||
return getRawButtonReleased(Button.kR3.value);
|
||||
return m_hid.getRawButtonReleased(Button.kR3.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -636,7 +662,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent R3(EventLoop loop) {
|
||||
return button(Button.kR3.value, loop);
|
||||
return m_hid.button(Button.kR3.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -645,7 +671,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getPSButton() {
|
||||
return getRawButton(Button.kPS.value);
|
||||
return m_hid.getRawButton(Button.kPS.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -654,7 +680,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getPSButtonPressed() {
|
||||
return getRawButtonPressed(Button.kPS.value);
|
||||
return m_hid.getRawButtonPressed(Button.kPS.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -663,7 +689,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getPSButtonReleased() {
|
||||
return getRawButtonReleased(Button.kPS.value);
|
||||
return m_hid.getRawButtonReleased(Button.kPS.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -674,7 +700,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent PS(EventLoop loop) {
|
||||
return button(Button.kPS.value, loop);
|
||||
return m_hid.button(Button.kPS.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -683,7 +709,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getTouchpadButton() {
|
||||
return getRawButton(Button.kTouchpad.value);
|
||||
return m_hid.getRawButton(Button.kTouchpad.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -692,7 +718,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getTouchpadButtonPressed() {
|
||||
return getRawButtonPressed(Button.kTouchpad.value);
|
||||
return m_hid.getRawButtonPressed(Button.kTouchpad.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -701,7 +727,7 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getTouchpadButtonReleased() {
|
||||
return getRawButtonReleased(Button.kTouchpad.value);
|
||||
return m_hid.getRawButtonReleased(Button.kTouchpad.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -712,7 +738,65 @@ public class NiDsPS5Controller extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent touchpad(EventLoop loop) {
|
||||
return button(Button.kTouchpad.value, loop);
|
||||
return m_hid.button(Button.kTouchpad.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the controller is connected.
|
||||
*
|
||||
* @return true if the controller is connected
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
return m_hid.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of the controller.
|
||||
*
|
||||
* @return the type of the controller.
|
||||
*/
|
||||
public HIDType getGamepadType() {
|
||||
return m_hid.getGamepadType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supported outputs of the controller.
|
||||
*
|
||||
* @return the supported outputs of the controller.
|
||||
*/
|
||||
public EnumSet<SupportedOutput> getSupportedOutputs() {
|
||||
return m_hid.getSupportedOutputs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the controller.
|
||||
*
|
||||
* @return the name of the controller.
|
||||
*/
|
||||
public String getName() {
|
||||
return m_hid.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the port number of the controller.
|
||||
*
|
||||
* @return The port number of the controller.
|
||||
*/
|
||||
public int getPort() {
|
||||
return m_hid.getPort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rumble output for the HID.
|
||||
*
|
||||
* <p>The DS currently supports 4 rumble values: left rumble, right rumble, left trigger rumble,
|
||||
* and right trigger rumble.
|
||||
*
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
public void setRumble(RumbleType type, double value) {
|
||||
m_hid.setRumble(type, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
|
||||
package org.wpilib.driverstation;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Objects;
|
||||
import org.wpilib.driverstation.GenericHID.HIDType;
|
||||
import org.wpilib.driverstation.GenericHID.RumbleType;
|
||||
import org.wpilib.driverstation.GenericHID.SupportedOutput;
|
||||
import org.wpilib.event.BooleanEvent;
|
||||
import org.wpilib.event.EventLoop;
|
||||
import org.wpilib.hardware.hal.HAL;
|
||||
@@ -23,7 +28,7 @@ import org.wpilib.util.sendable.SendableBuilder;
|
||||
* only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any
|
||||
* 3rd party controllers.
|
||||
*/
|
||||
public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
public class NiDsStadiaController implements HIDDevice, Sendable {
|
||||
/** Represents a digital button on a NiDsStadiaController. */
|
||||
public enum Button {
|
||||
/** A button. */
|
||||
@@ -115,14 +120,35 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
private final GenericHID m_hid;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
@Override
|
||||
public GenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is plugged into (0-5).
|
||||
*/
|
||||
public NiDsStadiaController(final int port) {
|
||||
super(port);
|
||||
HAL.reportUsage("HID", port, "NiDsStadiaController");
|
||||
this(DriverStation.getGenericHID(port));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this controller.
|
||||
*/
|
||||
public NiDsStadiaController(final GenericHID hid) {
|
||||
m_hid = Objects.requireNonNull(hid, "Provided HID object cannot be null");
|
||||
HAL.reportUsage("HID", hid.getPort(), "NiDsStadiaController");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +157,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return getRawAxis(Axis.kLeftX.value);
|
||||
return m_hid.getRawAxis(Axis.kLeftX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,7 +166,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return getRawAxis(Axis.kRightX.value);
|
||||
return m_hid.getRawAxis(Axis.kRightX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +175,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return getRawAxis(Axis.kLeftY.value);
|
||||
return m_hid.getRawAxis(Axis.kLeftY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +184,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return getRawAxis(Axis.kRightY.value);
|
||||
return m_hid.getRawAxis(Axis.kRightY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +193,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getAButton() {
|
||||
return getRawButton(Button.kA.value);
|
||||
return m_hid.getRawButton(Button.kA.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,7 +202,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getAButtonPressed() {
|
||||
return getRawButtonPressed(Button.kA.value);
|
||||
return m_hid.getRawButtonPressed(Button.kA.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,7 +211,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getAButtonReleased() {
|
||||
return getRawButtonReleased(Button.kA.value);
|
||||
return m_hid.getRawButtonReleased(Button.kA.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,7 +222,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent a(EventLoop loop) {
|
||||
return button(Button.kA.value, loop);
|
||||
return m_hid.button(Button.kA.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,7 +231,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getBButton() {
|
||||
return getRawButton(Button.kB.value);
|
||||
return m_hid.getRawButton(Button.kB.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -214,7 +240,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getBButtonPressed() {
|
||||
return getRawButtonPressed(Button.kB.value);
|
||||
return m_hid.getRawButtonPressed(Button.kB.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,7 +249,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getBButtonReleased() {
|
||||
return getRawButtonReleased(Button.kB.value);
|
||||
return m_hid.getRawButtonReleased(Button.kB.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,7 +260,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent b(EventLoop loop) {
|
||||
return button(Button.kB.value, loop);
|
||||
return m_hid.button(Button.kB.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,7 +269,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getXButton() {
|
||||
return getRawButton(Button.kX.value);
|
||||
return m_hid.getRawButton(Button.kX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,7 +278,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getXButtonPressed() {
|
||||
return getRawButtonPressed(Button.kX.value);
|
||||
return m_hid.getRawButtonPressed(Button.kX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,7 +287,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getXButtonReleased() {
|
||||
return getRawButtonReleased(Button.kX.value);
|
||||
return m_hid.getRawButtonReleased(Button.kX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,7 +298,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent x(EventLoop loop) {
|
||||
return button(Button.kX.value, loop);
|
||||
return m_hid.button(Button.kX.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -281,7 +307,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getYButton() {
|
||||
return getRawButton(Button.kY.value);
|
||||
return m_hid.getRawButton(Button.kY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,7 +316,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getYButtonPressed() {
|
||||
return getRawButtonPressed(Button.kY.value);
|
||||
return m_hid.getRawButtonPressed(Button.kY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,7 +325,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getYButtonReleased() {
|
||||
return getRawButtonReleased(Button.kY.value);
|
||||
return m_hid.getRawButtonReleased(Button.kY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -310,7 +336,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent y(EventLoop loop) {
|
||||
return button(Button.kY.value, loop);
|
||||
return m_hid.button(Button.kY.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,7 +345,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getLeftBumperButton() {
|
||||
return getRawButton(Button.kLeftBumper.value);
|
||||
return m_hid.getRawButton(Button.kLeftBumper.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -328,7 +354,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getLeftBumperButtonPressed() {
|
||||
return getRawButtonPressed(Button.kLeftBumper.value);
|
||||
return m_hid.getRawButtonPressed(Button.kLeftBumper.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -337,7 +363,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getLeftBumperButtonReleased() {
|
||||
return getRawButtonReleased(Button.kLeftBumper.value);
|
||||
return m_hid.getRawButtonReleased(Button.kLeftBumper.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -348,7 +374,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent leftBumper(EventLoop loop) {
|
||||
return button(Button.kLeftBumper.value, loop);
|
||||
return m_hid.button(Button.kLeftBumper.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -357,7 +383,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getRightBumperButton() {
|
||||
return getRawButton(Button.kRightBumper.value);
|
||||
return m_hid.getRawButton(Button.kRightBumper.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -366,7 +392,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getRightBumperButtonPressed() {
|
||||
return getRawButtonPressed(Button.kRightBumper.value);
|
||||
return m_hid.getRawButtonPressed(Button.kRightBumper.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,7 +401,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getRightBumperButtonReleased() {
|
||||
return getRawButtonReleased(Button.kRightBumper.value);
|
||||
return m_hid.getRawButtonReleased(Button.kRightBumper.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -386,7 +412,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent rightBumper(EventLoop loop) {
|
||||
return button(Button.kRightBumper.value, loop);
|
||||
return m_hid.button(Button.kRightBumper.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -395,7 +421,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getLeftStickButton() {
|
||||
return getRawButton(Button.kLeftStick.value);
|
||||
return m_hid.getRawButton(Button.kLeftStick.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -404,7 +430,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getLeftStickButtonPressed() {
|
||||
return getRawButtonPressed(Button.kLeftStick.value);
|
||||
return m_hid.getRawButtonPressed(Button.kLeftStick.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -413,7 +439,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getLeftStickButtonReleased() {
|
||||
return getRawButtonReleased(Button.kLeftStick.value);
|
||||
return m_hid.getRawButtonReleased(Button.kLeftStick.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -424,7 +450,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent leftStick(EventLoop loop) {
|
||||
return button(Button.kLeftStick.value, loop);
|
||||
return m_hid.button(Button.kLeftStick.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -433,7 +459,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getRightStickButton() {
|
||||
return getRawButton(Button.kRightStick.value);
|
||||
return m_hid.getRawButton(Button.kRightStick.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -442,7 +468,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getRightStickButtonPressed() {
|
||||
return getRawButtonPressed(Button.kRightStick.value);
|
||||
return m_hid.getRawButtonPressed(Button.kRightStick.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -451,7 +477,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getRightStickButtonReleased() {
|
||||
return getRawButtonReleased(Button.kRightStick.value);
|
||||
return m_hid.getRawButtonReleased(Button.kRightStick.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -462,7 +488,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent rightStick(EventLoop loop) {
|
||||
return button(Button.kRightStick.value, loop);
|
||||
return m_hid.button(Button.kRightStick.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -471,7 +497,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getEllipsesButton() {
|
||||
return getRawButton(Button.kEllipses.value);
|
||||
return m_hid.getRawButton(Button.kEllipses.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -480,7 +506,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getEllipsesButtonPressed() {
|
||||
return getRawButtonPressed(Button.kEllipses.value);
|
||||
return m_hid.getRawButtonPressed(Button.kEllipses.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -489,7 +515,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getEllipsesButtonReleased() {
|
||||
return getRawButtonReleased(Button.kEllipses.value);
|
||||
return m_hid.getRawButtonReleased(Button.kEllipses.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -500,7 +526,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent ellipses(EventLoop loop) {
|
||||
return button(Button.kEllipses.value, loop);
|
||||
return m_hid.button(Button.kEllipses.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -509,7 +535,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getHamburgerButton() {
|
||||
return getRawButton(Button.kHamburger.value);
|
||||
return m_hid.getRawButton(Button.kHamburger.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -518,7 +544,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getHamburgerButtonPressed() {
|
||||
return getRawButtonPressed(Button.kHamburger.value);
|
||||
return m_hid.getRawButtonPressed(Button.kHamburger.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -527,7 +553,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getHamburgerButtonReleased() {
|
||||
return getRawButtonReleased(Button.kHamburger.value);
|
||||
return m_hid.getRawButtonReleased(Button.kHamburger.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -538,7 +564,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent hamburger(EventLoop loop) {
|
||||
return button(Button.kHamburger.value, loop);
|
||||
return m_hid.button(Button.kHamburger.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -547,7 +573,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getStadiaButton() {
|
||||
return getRawButton(Button.kStadia.value);
|
||||
return m_hid.getRawButton(Button.kStadia.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -556,7 +582,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getStadiaButtonPressed() {
|
||||
return getRawButtonPressed(Button.kStadia.value);
|
||||
return m_hid.getRawButtonPressed(Button.kStadia.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -565,7 +591,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getStadiaButtonReleased() {
|
||||
return getRawButtonReleased(Button.kStadia.value);
|
||||
return m_hid.getRawButtonReleased(Button.kStadia.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -576,7 +602,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent stadia(EventLoop loop) {
|
||||
return button(Button.kStadia.value, loop);
|
||||
return m_hid.button(Button.kStadia.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -585,7 +611,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getRightTriggerButton() {
|
||||
return getRawButton(Button.kRightTrigger.value);
|
||||
return m_hid.getRawButton(Button.kRightTrigger.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -594,7 +620,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getRightTriggerButtonPressed() {
|
||||
return getRawButtonPressed(Button.kRightTrigger.value);
|
||||
return m_hid.getRawButtonPressed(Button.kRightTrigger.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -603,7 +629,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getRightTriggerButtonReleased() {
|
||||
return getRawButtonReleased(Button.kRightTrigger.value);
|
||||
return m_hid.getRawButtonReleased(Button.kRightTrigger.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -614,7 +640,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent rightTrigger(EventLoop loop) {
|
||||
return button(Button.kRightTrigger.value, loop);
|
||||
return m_hid.button(Button.kRightTrigger.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -623,7 +649,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getLeftTriggerButton() {
|
||||
return getRawButton(Button.kLeftTrigger.value);
|
||||
return m_hid.getRawButton(Button.kLeftTrigger.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -632,7 +658,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getLeftTriggerButtonPressed() {
|
||||
return getRawButtonPressed(Button.kLeftTrigger.value);
|
||||
return m_hid.getRawButtonPressed(Button.kLeftTrigger.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -641,7 +667,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getLeftTriggerButtonReleased() {
|
||||
return getRawButtonReleased(Button.kLeftTrigger.value);
|
||||
return m_hid.getRawButtonReleased(Button.kLeftTrigger.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -652,7 +678,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent leftTrigger(EventLoop loop) {
|
||||
return button(Button.kLeftTrigger.value, loop);
|
||||
return m_hid.button(Button.kLeftTrigger.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -661,7 +687,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getGoogleButton() {
|
||||
return getRawButton(Button.kGoogle.value);
|
||||
return m_hid.getRawButton(Button.kGoogle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -670,7 +696,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getGoogleButtonPressed() {
|
||||
return getRawButtonPressed(Button.kGoogle.value);
|
||||
return m_hid.getRawButtonPressed(Button.kGoogle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -679,7 +705,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getGoogleButtonReleased() {
|
||||
return getRawButtonReleased(Button.kGoogle.value);
|
||||
return m_hid.getRawButtonReleased(Button.kGoogle.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -690,7 +716,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent google(EventLoop loop) {
|
||||
return button(Button.kGoogle.value, loop);
|
||||
return m_hid.button(Button.kGoogle.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -699,7 +725,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getFrameButton() {
|
||||
return getRawButton(Button.kFrame.value);
|
||||
return m_hid.getRawButton(Button.kFrame.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -708,7 +734,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getFrameButtonPressed() {
|
||||
return getRawButtonPressed(Button.kFrame.value);
|
||||
return m_hid.getRawButtonPressed(Button.kFrame.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -717,7 +743,7 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getFrameButtonReleased() {
|
||||
return getRawButtonReleased(Button.kFrame.value);
|
||||
return m_hid.getRawButtonReleased(Button.kFrame.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -728,7 +754,65 @@ public class NiDsStadiaController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent frame(EventLoop loop) {
|
||||
return button(Button.kFrame.value, loop);
|
||||
return m_hid.button(Button.kFrame.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the controller is connected.
|
||||
*
|
||||
* @return true if the controller is connected
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
return m_hid.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of the controller.
|
||||
*
|
||||
* @return the type of the controller.
|
||||
*/
|
||||
public HIDType getGamepadType() {
|
||||
return m_hid.getGamepadType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supported outputs of the controller.
|
||||
*
|
||||
* @return the supported outputs of the controller.
|
||||
*/
|
||||
public EnumSet<SupportedOutput> getSupportedOutputs() {
|
||||
return m_hid.getSupportedOutputs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the controller.
|
||||
*
|
||||
* @return the name of the controller.
|
||||
*/
|
||||
public String getName() {
|
||||
return m_hid.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the port number of the controller.
|
||||
*
|
||||
* @return The port number of the controller.
|
||||
*/
|
||||
public int getPort() {
|
||||
return m_hid.getPort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rumble output for the HID.
|
||||
*
|
||||
* <p>The DS currently supports 4 rumble values: left rumble, right rumble, left trigger rumble,
|
||||
* and right trigger rumble.
|
||||
*
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
public void setRumble(RumbleType type, double value) {
|
||||
m_hid.setRumble(type, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
|
||||
package org.wpilib.driverstation;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Objects;
|
||||
import org.wpilib.driverstation.GenericHID.HIDType;
|
||||
import org.wpilib.driverstation.GenericHID.RumbleType;
|
||||
import org.wpilib.driverstation.GenericHID.SupportedOutput;
|
||||
import org.wpilib.event.BooleanEvent;
|
||||
import org.wpilib.event.EventLoop;
|
||||
import org.wpilib.hardware.hal.HAL;
|
||||
@@ -23,7 +28,7 @@ import org.wpilib.util.sendable.SendableBuilder;
|
||||
* only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any
|
||||
* 3rd party controllers.
|
||||
*/
|
||||
public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
public class NiDsXboxController implements HIDDevice, Sendable {
|
||||
/** Represents a digital button on a NiDsXboxController. */
|
||||
public enum Button {
|
||||
/** A button. */
|
||||
@@ -109,14 +114,35 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
private final GenericHID m_hid;
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
@Override
|
||||
public GenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is plugged into (0-5).
|
||||
*/
|
||||
public NiDsXboxController(final int port) {
|
||||
super(port);
|
||||
HAL.reportUsage("HID", port, "NiDsXboxController");
|
||||
this(DriverStation.getGenericHID(port));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this controller.
|
||||
*/
|
||||
public NiDsXboxController(final GenericHID hid) {
|
||||
m_hid = Objects.requireNonNull(hid, "Provided HID object cannot be null");
|
||||
HAL.reportUsage("HID", hid.getPort(), "NiDsXboxController");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +151,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftX() {
|
||||
return getRawAxis(Axis.kLeftX.value);
|
||||
return m_hid.getRawAxis(Axis.kLeftX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,7 +160,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightX() {
|
||||
return getRawAxis(Axis.kRightX.value);
|
||||
return m_hid.getRawAxis(Axis.kRightX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,7 +169,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftY() {
|
||||
return getRawAxis(Axis.kLeftY.value);
|
||||
return m_hid.getRawAxis(Axis.kLeftY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +178,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightY() {
|
||||
return getRawAxis(Axis.kRightY.value);
|
||||
return m_hid.getRawAxis(Axis.kRightY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,7 +188,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getLeftTriggerAxis() {
|
||||
return getRawAxis(Axis.kLeftTrigger.value);
|
||||
return m_hid.getRawAxis(Axis.kLeftTrigger.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,7 +202,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* threshold, attached to the given event loop
|
||||
*/
|
||||
public BooleanEvent leftTrigger(double threshold, EventLoop loop) {
|
||||
return axisGreaterThan(Axis.kLeftTrigger.value, threshold, loop);
|
||||
return m_hid.axisGreaterThan(Axis.kLeftTrigger.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,7 +224,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double getRightTriggerAxis() {
|
||||
return getRawAxis(Axis.kRightTrigger.value);
|
||||
return m_hid.getRawAxis(Axis.kRightTrigger.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,7 +238,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* threshold, attached to the given event loop
|
||||
*/
|
||||
public BooleanEvent rightTrigger(double threshold, EventLoop loop) {
|
||||
return axisGreaterThan(Axis.kRightTrigger.value, threshold, loop);
|
||||
return m_hid.axisGreaterThan(Axis.kRightTrigger.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,7 +259,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getAButton() {
|
||||
return getRawButton(Button.kA.value);
|
||||
return m_hid.getRawButton(Button.kA.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,7 +268,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getAButtonPressed() {
|
||||
return getRawButtonPressed(Button.kA.value);
|
||||
return m_hid.getRawButtonPressed(Button.kA.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,7 +277,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getAButtonReleased() {
|
||||
return getRawButtonReleased(Button.kA.value);
|
||||
return m_hid.getRawButtonReleased(Button.kA.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,7 +288,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent a(EventLoop loop) {
|
||||
return button(Button.kA.value, loop);
|
||||
return m_hid.button(Button.kA.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,7 +297,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getBButton() {
|
||||
return getRawButton(Button.kB.value);
|
||||
return m_hid.getRawButton(Button.kB.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,7 +306,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getBButtonPressed() {
|
||||
return getRawButtonPressed(Button.kB.value);
|
||||
return m_hid.getRawButtonPressed(Button.kB.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -289,7 +315,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getBButtonReleased() {
|
||||
return getRawButtonReleased(Button.kB.value);
|
||||
return m_hid.getRawButtonReleased(Button.kB.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,7 +326,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent b(EventLoop loop) {
|
||||
return button(Button.kB.value, loop);
|
||||
return m_hid.button(Button.kB.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -309,7 +335,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getXButton() {
|
||||
return getRawButton(Button.kX.value);
|
||||
return m_hid.getRawButton(Button.kX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -318,7 +344,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getXButtonPressed() {
|
||||
return getRawButtonPressed(Button.kX.value);
|
||||
return m_hid.getRawButtonPressed(Button.kX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,7 +353,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getXButtonReleased() {
|
||||
return getRawButtonReleased(Button.kX.value);
|
||||
return m_hid.getRawButtonReleased(Button.kX.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,7 +364,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent x(EventLoop loop) {
|
||||
return button(Button.kX.value, loop);
|
||||
return m_hid.button(Button.kX.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,7 +373,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getYButton() {
|
||||
return getRawButton(Button.kY.value);
|
||||
return m_hid.getRawButton(Button.kY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -356,7 +382,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getYButtonPressed() {
|
||||
return getRawButtonPressed(Button.kY.value);
|
||||
return m_hid.getRawButtonPressed(Button.kY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -365,7 +391,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getYButtonReleased() {
|
||||
return getRawButtonReleased(Button.kY.value);
|
||||
return m_hid.getRawButtonReleased(Button.kY.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -376,7 +402,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent y(EventLoop loop) {
|
||||
return button(Button.kY.value, loop);
|
||||
return m_hid.button(Button.kY.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,7 +411,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getLeftBumperButton() {
|
||||
return getRawButton(Button.kLeftBumper.value);
|
||||
return m_hid.getRawButton(Button.kLeftBumper.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -394,7 +420,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getLeftBumperButtonPressed() {
|
||||
return getRawButtonPressed(Button.kLeftBumper.value);
|
||||
return m_hid.getRawButtonPressed(Button.kLeftBumper.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -403,7 +429,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getLeftBumperButtonReleased() {
|
||||
return getRawButtonReleased(Button.kLeftBumper.value);
|
||||
return m_hid.getRawButtonReleased(Button.kLeftBumper.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -414,7 +440,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent leftBumper(EventLoop loop) {
|
||||
return button(Button.kLeftBumper.value, loop);
|
||||
return m_hid.button(Button.kLeftBumper.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -423,7 +449,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getRightBumperButton() {
|
||||
return getRawButton(Button.kRightBumper.value);
|
||||
return m_hid.getRawButton(Button.kRightBumper.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -432,7 +458,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getRightBumperButtonPressed() {
|
||||
return getRawButtonPressed(Button.kRightBumper.value);
|
||||
return m_hid.getRawButtonPressed(Button.kRightBumper.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -441,7 +467,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getRightBumperButtonReleased() {
|
||||
return getRawButtonReleased(Button.kRightBumper.value);
|
||||
return m_hid.getRawButtonReleased(Button.kRightBumper.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -452,7 +478,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent rightBumper(EventLoop loop) {
|
||||
return button(Button.kRightBumper.value, loop);
|
||||
return m_hid.button(Button.kRightBumper.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -461,7 +487,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getBackButton() {
|
||||
return getRawButton(Button.kBack.value);
|
||||
return m_hid.getRawButton(Button.kBack.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -470,7 +496,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getBackButtonPressed() {
|
||||
return getRawButtonPressed(Button.kBack.value);
|
||||
return m_hid.getRawButtonPressed(Button.kBack.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -479,7 +505,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getBackButtonReleased() {
|
||||
return getRawButtonReleased(Button.kBack.value);
|
||||
return m_hid.getRawButtonReleased(Button.kBack.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -490,7 +516,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent back(EventLoop loop) {
|
||||
return button(Button.kBack.value, loop);
|
||||
return m_hid.button(Button.kBack.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -499,7 +525,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getStartButton() {
|
||||
return getRawButton(Button.kStart.value);
|
||||
return m_hid.getRawButton(Button.kStart.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -508,7 +534,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getStartButtonPressed() {
|
||||
return getRawButtonPressed(Button.kStart.value);
|
||||
return m_hid.getRawButtonPressed(Button.kStart.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -517,7 +543,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getStartButtonReleased() {
|
||||
return getRawButtonReleased(Button.kStart.value);
|
||||
return m_hid.getRawButtonReleased(Button.kStart.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -528,7 +554,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent start(EventLoop loop) {
|
||||
return button(Button.kStart.value, loop);
|
||||
return m_hid.button(Button.kStart.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -537,7 +563,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getLeftStickButton() {
|
||||
return getRawButton(Button.kLeftStick.value);
|
||||
return m_hid.getRawButton(Button.kLeftStick.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -546,7 +572,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getLeftStickButtonPressed() {
|
||||
return getRawButtonPressed(Button.kLeftStick.value);
|
||||
return m_hid.getRawButtonPressed(Button.kLeftStick.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -555,7 +581,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getLeftStickButtonReleased() {
|
||||
return getRawButtonReleased(Button.kLeftStick.value);
|
||||
return m_hid.getRawButtonReleased(Button.kLeftStick.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -566,7 +592,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent leftStick(EventLoop loop) {
|
||||
return button(Button.kLeftStick.value, loop);
|
||||
return m_hid.button(Button.kLeftStick.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -575,7 +601,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getRightStickButton() {
|
||||
return getRawButton(Button.kRightStick.value);
|
||||
return m_hid.getRawButton(Button.kRightStick.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -584,7 +610,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getRightStickButtonPressed() {
|
||||
return getRawButtonPressed(Button.kRightStick.value);
|
||||
return m_hid.getRawButtonPressed(Button.kRightStick.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -593,7 +619,7 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getRightStickButtonReleased() {
|
||||
return getRawButtonReleased(Button.kRightStick.value);
|
||||
return m_hid.getRawButtonReleased(Button.kRightStick.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -604,7 +630,65 @@ public class NiDsXboxController extends GenericHID implements Sendable {
|
||||
* attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent rightStick(EventLoop loop) {
|
||||
return button(Button.kRightStick.value, loop);
|
||||
return m_hid.button(Button.kRightStick.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the controller is connected.
|
||||
*
|
||||
* @return true if the controller is connected
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
return m_hid.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of the controller.
|
||||
*
|
||||
* @return the type of the controller.
|
||||
*/
|
||||
public HIDType getGamepadType() {
|
||||
return m_hid.getGamepadType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supported outputs of the controller.
|
||||
*
|
||||
* @return the supported outputs of the controller.
|
||||
*/
|
||||
public EnumSet<SupportedOutput> getSupportedOutputs() {
|
||||
return m_hid.getSupportedOutputs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the controller.
|
||||
*
|
||||
* @return the name of the controller.
|
||||
*/
|
||||
public String getName() {
|
||||
return m_hid.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the port number of the controller.
|
||||
*
|
||||
* @return The port number of the controller.
|
||||
*/
|
||||
public int getPort() {
|
||||
return m_hid.getPort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rumble output for the HID.
|
||||
*
|
||||
* <p>The DS currently supports 4 rumble values: left rumble, right rumble, left trigger rumble,
|
||||
* and right trigger rumble.
|
||||
*
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
public void setRumble(RumbleType type, double value) {
|
||||
m_hid.setRumble(type, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,7 @@ public class NiDsPS4ControllerSim extends GenericHIDSim {
|
||||
*/
|
||||
@SuppressWarnings("this-escape")
|
||||
public NiDsPS4ControllerSim(NiDsPS4Controller joystick) {
|
||||
super(joystick);
|
||||
super(joystick.getHID());
|
||||
setAxesMaximumIndex(6);
|
||||
setButtonsMaximumIndex(14);
|
||||
setPOVsMaximumIndex(1);
|
||||
|
||||
@@ -17,7 +17,7 @@ public class NiDsPS5ControllerSim extends GenericHIDSim {
|
||||
*/
|
||||
@SuppressWarnings("this-escape")
|
||||
public NiDsPS5ControllerSim(NiDsPS5Controller joystick) {
|
||||
super(joystick);
|
||||
super(joystick.getHID());
|
||||
setAxesMaximumIndex(6);
|
||||
setButtonsMaximumIndex(14);
|
||||
setPOVsMaximumIndex(1);
|
||||
|
||||
@@ -17,7 +17,7 @@ public class NiDsStadiaControllerSim extends GenericHIDSim {
|
||||
*/
|
||||
@SuppressWarnings("this-escape")
|
||||
public NiDsStadiaControllerSim(NiDsStadiaController joystick) {
|
||||
super(joystick);
|
||||
super(joystick.getHID());
|
||||
setAxesMaximumIndex(4);
|
||||
setButtonsMaximumIndex(15);
|
||||
setPOVsMaximumIndex(1);
|
||||
|
||||
@@ -17,7 +17,7 @@ public class NiDsXboxControllerSim extends GenericHIDSim {
|
||||
*/
|
||||
@SuppressWarnings("this-escape")
|
||||
public NiDsXboxControllerSim(NiDsXboxController joystick) {
|
||||
super(joystick);
|
||||
super(joystick.getHID());
|
||||
setAxesMaximumIndex(6);
|
||||
setButtonsMaximumIndex(10);
|
||||
setPOVsMaximumIndex(1);
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
package org.wpilib.driverstation;
|
||||
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.wpilib.datalog.DataLog;
|
||||
import org.wpilib.driverstation.internal.DriverStationBackend;
|
||||
|
||||
@@ -11,6 +13,56 @@ import org.wpilib.driverstation.internal.DriverStationBackend;
|
||||
public final class DriverStation {
|
||||
private DriverStation() {}
|
||||
|
||||
private static final Lock m_dsLock = new ReentrantLock();
|
||||
private static final GenericHID[] m_hids = new GenericHID[DriverStationBackend.JOYSTICK_PORTS];
|
||||
private static final Gamepad[] m_gamepads = new Gamepad[DriverStationBackend.JOYSTICK_PORTS];
|
||||
|
||||
private static GenericHID getGenericHIDUnderLock(int port) {
|
||||
GenericHID toRet = m_hids[port];
|
||||
if (toRet == null) {
|
||||
toRet = new GenericHID(port);
|
||||
m_hids[port] = toRet;
|
||||
}
|
||||
return toRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the GenericHID object for the given port. GenericHID objects are cached, so this will
|
||||
* always return the same object for the same port.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is plugged into (0-5).
|
||||
* @return The GenericHID object for the given port.
|
||||
*/
|
||||
public static GenericHID getGenericHID(int port) {
|
||||
m_dsLock.lock();
|
||||
try {
|
||||
return getGenericHIDUnderLock(port);
|
||||
} finally {
|
||||
m_dsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Gamepad object for the given port. Gamepad objects are cached, so this will always
|
||||
* return the same object for the same port.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is plugged into (0-5).
|
||||
* @return The Gamepad object for the given port.
|
||||
*/
|
||||
public static Gamepad getGamepad(int port) {
|
||||
m_dsLock.lock();
|
||||
try {
|
||||
Gamepad toRet = m_gamepads[port];
|
||||
if (toRet == null) {
|
||||
toRet = new Gamepad(getGenericHIDUnderLock(port));
|
||||
m_gamepads[port] = toRet;
|
||||
}
|
||||
return toRet;
|
||||
} finally {
|
||||
m_dsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts logging DriverStation data to data log, including joystick data. Repeated calls are
|
||||
* ignored.
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
|
||||
package org.wpilib.driverstation;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Objects;
|
||||
import org.wpilib.driverstation.GenericHID.HIDType;
|
||||
import org.wpilib.driverstation.GenericHID.RumbleType;
|
||||
import org.wpilib.driverstation.GenericHID.SupportedOutput;
|
||||
import org.wpilib.driverstation.internal.DriverStationBackend;
|
||||
import org.wpilib.event.BooleanEvent;
|
||||
import org.wpilib.event.EventLoop;
|
||||
@@ -18,12 +23,8 @@ import org.wpilib.util.sendable.SendableBuilder;
|
||||
* <p>This class handles Gamepad input that comes from the Driver Station. Each time a value is
|
||||
* requested the most recent value is returned. There is a single class instance for each controller
|
||||
* and the mapping of ports to hardware buttons depends on the code in the Driver Station.
|
||||
*
|
||||
* <p>Only first party controllers from Generic are guaranteed to have the correct mapping, and only
|
||||
* through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any 3rd
|
||||
* party controllers.
|
||||
*/
|
||||
public class Gamepad extends GenericHID implements Sendable {
|
||||
public class Gamepad implements HIDDevice, Sendable {
|
||||
private static final double MAX_DEADBAND = Math.nextDown(1.0);
|
||||
|
||||
/** Represents a digital button on a Gamepad. */
|
||||
@@ -156,14 +157,35 @@ public class Gamepad extends GenericHID implements Sendable {
|
||||
return Math.clamp(deadband, 0.0, MAX_DEADBAND);
|
||||
}
|
||||
|
||||
private final GenericHID m_hid;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is plugged into (0-5).
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
@Override
|
||||
public GenericHID getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a gamepad.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the gamepad is plugged into (0-5).
|
||||
*/
|
||||
public Gamepad(final int port) {
|
||||
super(port);
|
||||
HAL.reportUsage("HID", port, "Gamepad");
|
||||
this(DriverStation.getGenericHID(port));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of a gamepad with a GenericHID object.
|
||||
*
|
||||
* @param hid The GenericHID object to use for this gamepad.
|
||||
*/
|
||||
public Gamepad(final GenericHID hid) {
|
||||
m_hid = Objects.requireNonNull(hid, "Provided HID object cannot be null");
|
||||
HAL.reportUsage("HID", hid.getPort(), "Gamepad");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1350,7 +1372,7 @@ public class Gamepad extends GenericHID implements Sendable {
|
||||
* @return The state of the button.
|
||||
*/
|
||||
public boolean getButton(Button button) {
|
||||
return getRawButton(button.value);
|
||||
return m_hid.getRawButton(button.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1364,7 +1386,7 @@ public class Gamepad extends GenericHID implements Sendable {
|
||||
* @return Whether the button was pressed since the last check.
|
||||
*/
|
||||
public boolean getButtonPressed(Button button) {
|
||||
return getRawButtonPressed(button.value);
|
||||
return m_hid.getRawButtonPressed(button.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1378,7 +1400,7 @@ public class Gamepad extends GenericHID implements Sendable {
|
||||
* @return Whether the button was released since the last check.
|
||||
*/
|
||||
public boolean getButtonReleased(Button button) {
|
||||
return getRawButtonReleased(button.value);
|
||||
return m_hid.getRawButtonReleased(button.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1389,7 +1411,7 @@ public class Gamepad extends GenericHID implements Sendable {
|
||||
* @return an event instance representing the button's digital signal attached to the given loop.
|
||||
*/
|
||||
public BooleanEvent button(Button button, EventLoop loop) {
|
||||
return super.button(button.value, loop);
|
||||
return m_hid.button(button.value, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1399,7 +1421,7 @@ public class Gamepad extends GenericHID implements Sendable {
|
||||
* @return The value of the axis.
|
||||
*/
|
||||
public double getAxis(Axis axis) {
|
||||
return getRawAxis(axis.value);
|
||||
return m_hid.getRawAxis(axis.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1412,7 +1434,7 @@ public class Gamepad extends GenericHID implements Sendable {
|
||||
* @return an event instance that is true when the axis value is less than the provided threshold.
|
||||
*/
|
||||
public BooleanEvent axisLessThan(Axis axis, double threshold, EventLoop loop) {
|
||||
return super.axisLessThan(axis.value, threshold, loop);
|
||||
return m_hid.axisLessThan(axis.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1426,15 +1448,115 @@ public class Gamepad extends GenericHID implements Sendable {
|
||||
* threshold.
|
||||
*/
|
||||
public BooleanEvent axisGreaterThan(Axis axis, double threshold, EventLoop loop) {
|
||||
return super.axisGreaterThan(axis.value, threshold, loop);
|
||||
return m_hid.axisGreaterThan(axis.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bitmask of axes for the gamepad.
|
||||
*
|
||||
* @return the number of axis for the current gamepad
|
||||
*/
|
||||
public int getAxesAvailable() {
|
||||
return m_hid.getAxesAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
* For the current gamepad, return the bitmask of available buttons.
|
||||
*
|
||||
* @return the bitmask of buttons for the current gamepad
|
||||
*/
|
||||
public long getButtonsAvailable() {
|
||||
return m_hid.getButtonsAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the gamepad is connected.
|
||||
*
|
||||
* @return true if the gamepad is connected
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
return m_hid.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of the gamepad.
|
||||
*
|
||||
* @return the type of the gamepad.
|
||||
*/
|
||||
public HIDType getGamepadType() {
|
||||
return m_hid.getGamepadType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supported outputs for the gamepad.
|
||||
*
|
||||
* @return the supported outputs for the gamepad.
|
||||
*/
|
||||
public EnumSet<SupportedOutput> getSupportedOutputs() {
|
||||
return m_hid.getSupportedOutputs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the gamepad.
|
||||
*
|
||||
* @return the name of the gamepad.
|
||||
*/
|
||||
public String getName() {
|
||||
return m_hid.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set leds on the gamepad. If only mono is supported, the system will use the highest value
|
||||
* passed in.
|
||||
*
|
||||
* @param r Red value from 0-255
|
||||
* @param g Green value from 0-255
|
||||
* @param b Blue value from 0-255
|
||||
*/
|
||||
public void setLeds(int r, int g, int b) {
|
||||
m_hid.setLeds(r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rumble output for the HID. The DS currently supports 4 rumble values: left rumble,
|
||||
* right rumble, left trigger rumble, and right trigger rumble.
|
||||
*
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
public void setRumble(RumbleType type, double value) {
|
||||
m_hid.setRumble(type, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a touchpad finger is available.
|
||||
*
|
||||
* @param touchpad The touchpad to check.
|
||||
* @param finger The finger to check.
|
||||
* @return true if the touchpad finger is available.
|
||||
*/
|
||||
public boolean getTouchpadFingerAvailable(int touchpad, int finger) {
|
||||
return m_hid.getTouchpadFingerAvailable(touchpad, finger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the touchpad finger data.
|
||||
*
|
||||
* @param touchpad The touchpad to read.
|
||||
* @param finger The finger to read.
|
||||
* @return The touchpad finger data.
|
||||
*/
|
||||
public TouchpadFinger getTouchpadFinger(int touchpad, int finger) {
|
||||
return m_hid.getTouchpadFinger(touchpad, finger);
|
||||
}
|
||||
|
||||
private double getAxisForSendable(Axis axis) {
|
||||
return DriverStationBackend.getStickAxisIfAvailable(getPort(), axis.value).orElse(0.0);
|
||||
return DriverStationBackend.getStickAxisIfAvailable(m_hid.getPort(), axis.value).orElse(0.0);
|
||||
}
|
||||
|
||||
private boolean getButtonForSendable(Button button) {
|
||||
return DriverStationBackend.getStickButtonIfAvailable(getPort(), button.value).orElse(false);
|
||||
return DriverStationBackend.getStickButtonIfAvailable(m_hid.getPort(), button.value)
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user