integrated xboxraw

This commit is contained in:
Ryan Manley
2022-01-15 15:52:38 -07:00
parent 45574a2a06
commit 3061563db3
8 changed files with 93 additions and 54 deletions
@@ -18,4 +18,6 @@ public interface IHandController {
public double getRightTriggerAxis();
public int getDpadAngle();
public void updateInput();
}
@@ -53,6 +53,8 @@ public class XboxController implements IHandController
private Joystick m_stick;
public void updateInput() {}
public static double[] ClampJoystickAxis(double x, double y) {
double square_mag = x * x + y * y;
double[] ret = {x,y};
@@ -25,15 +25,22 @@ public class XboxControllerRaw implements IHandController {
public static final int LEFT_JOYSTICK_BUTTON = 8;
public static final int RIGHT_JOYSTICK_BUTTON = 9;
private static final double DEADZONE = 0.1;
private static final double DEADZONE = 0.08;
private int m_ID;
private int m_buttons = 0;
private int m_numButtons;
private ByteBuffer m_buttonCountBuffer = ByteBuffer.allocateDirect(1);
float[] m_axes = new float[HAL.kMaxJoystickAxes];
public XboxControllerRaw(int id) {
m_ID = id;
}
public void updateInput() {
HAL.getJoystickAxes((byte) 0, m_axes);
m_buttons = HAL.getJoystickButtons((byte) 0, m_buttonCountBuffer);
HAL.getJoystickAxes((byte) m_ID, m_axes);
m_buttons = HAL.getJoystickButtons((byte) m_ID, m_buttonCountBuffer);
m_numButtons = m_buttonCountBuffer.get(0);
}
@@ -0,0 +1,18 @@
package frc4388.utility.controller;
import edu.wpi.first.wpilibj2.command.button.Button;
public class XboxControllerRawButton extends Button {
private final XboxControllerRaw m_controller;
private final int m_buttonNumber;
public XboxControllerRawButton(XboxControllerRaw controller, int buttonNumber) {
m_controller = controller;
m_buttonNumber = buttonNumber;
}
@Override
public boolean get() {
return m_controller.getButton(m_buttonNumber);
}
}