From c036f042d92a418f11c81a80a711413813f82cfb Mon Sep 17 00:00:00 2001 From: Zachary Robinson Date: Fri, 21 Dec 2018 22:51:16 -0800 Subject: [PATCH] Fix #100: Better support for XboxController It turns out that GenericHID (which both XboxController and Joystick inherit from) possesses all the methods needed in the various trigger utilities. So, this is a simple type migration and also completely backwards-compatible. --- .../java/org/team1540/rooster/triggers/AxisButton.java | 7 ++++--- .../java/org/team1540/rooster/triggers/DPadButton.java | 10 +++++----- .../team1540/rooster/triggers/StrictDPadButton.java | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/src/main/java/org/team1540/rooster/triggers/AxisButton.java b/lib/src/main/java/org/team1540/rooster/triggers/AxisButton.java index bf9d74c2..deda117d 100644 --- a/lib/src/main/java/org/team1540/rooster/triggers/AxisButton.java +++ b/lib/src/main/java/org/team1540/rooster/triggers/AxisButton.java @@ -1,6 +1,6 @@ package org.team1540.rooster.triggers; -import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.buttons.Button; import java.util.Objects; import org.jetbrains.annotations.NotNull; @@ -10,7 +10,8 @@ * joystick. */ public class AxisButton extends Button { - private Joystick stick; + + private GenericHID stick; private double threshold; private int axis; @@ -22,7 +23,7 @@ public class AxisButton extends Button { * @param threshold The threshold for the button to be triggered * @throws NullPointerException If {@code stick} is {@code null}. */ - public AxisButton(@NotNull Joystick stick, double threshold, int axis) { + public AxisButton(@NotNull GenericHID stick, double threshold, int axis) { this.stick = Objects.requireNonNull(stick); this.threshold = threshold; this.axis = axis; diff --git a/lib/src/main/java/org/team1540/rooster/triggers/DPadButton.java b/lib/src/main/java/org/team1540/rooster/triggers/DPadButton.java index 45a4941a..f97ea0ff 100644 --- a/lib/src/main/java/org/team1540/rooster/triggers/DPadButton.java +++ b/lib/src/main/java/org/team1540/rooster/triggers/DPadButton.java @@ -1,6 +1,6 @@ package org.team1540.rooster.triggers; -import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.buttons.Button; import java.util.Objects; import org.jetbrains.annotations.Contract; @@ -21,7 +21,7 @@ public enum DPadAxis { UP, DOWN, LEFT, RIGHT } - private Joystick stick; + private GenericHID stick; private int pad; private org.team1540.rooster.triggers.DPadAxis axis; @@ -29,14 +29,14 @@ public enum DPadAxis { /** * Constructs a {@link DPadButton}. * - * @deprecated Use {@link #DPadButton(Joystick, int, org.team1540.rooster.triggers.DPadAxis)} + * @deprecated Use {@link #DPadButton(GenericHID, int, org.team1540.rooster.triggers.DPadAxis)} * * @param stick The joystick with the button. * @param pad The ID of the d-pad. * @param axis The axis of the button. */ @Deprecated - public DPadButton(Joystick stick, int pad, DPadAxis axis) { + public DPadButton(GenericHID stick, int pad, DPadAxis axis) { super(); this.stick = stick; this.pad = pad; @@ -65,7 +65,7 @@ public DPadButton(Joystick stick, int pad, DPadAxis axis) { * @throws NullPointerException If {@code stick} or {@code axis} is {@code null}. * @throws IllegalArgumentException If {@code pad} is negative. */ - public DPadButton(@NotNull Joystick stick, int pad, + public DPadButton(@NotNull GenericHID stick, int pad, @NotNull org.team1540.rooster.triggers.DPadAxis axis) { super(); if (pad < 0) { diff --git a/lib/src/main/java/org/team1540/rooster/triggers/StrictDPadButton.java b/lib/src/main/java/org/team1540/rooster/triggers/StrictDPadButton.java index a9287d77..6267f466 100644 --- a/lib/src/main/java/org/team1540/rooster/triggers/StrictDPadButton.java +++ b/lib/src/main/java/org/team1540/rooster/triggers/StrictDPadButton.java @@ -1,6 +1,6 @@ package org.team1540.rooster.triggers; -import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.buttons.Button; import java.util.Objects; import org.jetbrains.annotations.Contract; @@ -11,7 +11,7 @@ */ public class StrictDPadButton extends Button { - private Joystick stick; + private @NotNull GenericHID stick; private int pad; private DPadAxis axis; @@ -25,7 +25,7 @@ public class StrictDPadButton extends Button { * @throws NullPointerException If {@code stick} or {@code axis} is {@code null}. * @throws IllegalArgumentException If {@code pad} is negative. */ - public StrictDPadButton(@NotNull Joystick stick, int pad, + public StrictDPadButton(@NotNull GenericHID stick, int pad, @NotNull org.team1540.rooster.triggers.DPadAxis axis) { super(); if (pad < 0) {