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 == {}
|
||||
Reference in New Issue
Block a user