mirror of
https://github.com/Team4388/2024AcrossTheRidgebotiverse.git
synced 2026-06-09 08:48:03 -06:00
Merge branch 'virtualController' into shooter-test
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package frc4388.utility;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class DataUtils {
|
||||
public static byte[] doubleToByteArray(double value) {
|
||||
byte[] bytes = new byte[8];
|
||||
ByteBuffer.wrap(bytes).putDouble(value);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static double byteArrayToDouble(byte[] bytes) {
|
||||
return ByteBuffer.wrap(bytes).getDouble();
|
||||
}
|
||||
|
||||
public static byte[] intToByteArray(int value) {
|
||||
byte[] bytes = new byte[4];
|
||||
ByteBuffer.wrap(bytes).putInt(value);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static int byteArrayToInt(byte[] bytes) {
|
||||
return ByteBuffer.wrap(bytes).getInt();
|
||||
}
|
||||
|
||||
public static byte[] shortToByteArray(short value) {
|
||||
byte[] bytes = new byte[2];
|
||||
ByteBuffer.wrap(bytes).putShort(value);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static short byteArrayToShort(byte[] bytes) {
|
||||
return ByteBuffer.wrap(bytes).getShort();
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,14 @@ public class UtilityStructs {
|
||||
|
||||
public long timedOffset = 0;
|
||||
}
|
||||
public static class AutoRecordingControllerFrame {
|
||||
public double[] axes = new double[6];
|
||||
public short button = 0;
|
||||
public short[] POV = new short[1];
|
||||
|
||||
}
|
||||
public static class AutoRecordingFrame {
|
||||
public AutoRecordingControllerFrame[] controllerFrames = new AutoRecordingControllerFrame[2];
|
||||
public int timeStamp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package frc4388.utility.configurable;
|
||||
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
public class ConfigurableDouble {
|
||||
private double defualtValue;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Creates an new ConfigurableDouble through Smart Dashboard.
|
||||
* @param name the name of the Smart Dashboard key.
|
||||
* @param defualtValue the initilization value
|
||||
*/
|
||||
public ConfigurableDouble(String name, double defualtValue) {
|
||||
this.name = name;
|
||||
this.defualtValue = defualtValue;
|
||||
SmartDashboard.putNumber(name, defualtValue);
|
||||
}
|
||||
|
||||
public double get() {
|
||||
return SmartDashboard.getNumber(name, defualtValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package frc4388.utility.configurable;
|
||||
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
public class ConfigurableString {
|
||||
private String defualtValue;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Creates an new ConfigurableString through Smart Dashboard.
|
||||
* @param name the name of the Smart Dashboard key.
|
||||
* @param defualtValue the initilization value
|
||||
*/
|
||||
public ConfigurableString(String name, String defualtValue) {
|
||||
this.name = name;
|
||||
this.defualtValue = defualtValue;
|
||||
SmartDashboard.putString(name, defualtValue);
|
||||
}
|
||||
|
||||
public String get() {
|
||||
return SmartDashboard.getString(name, defualtValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package frc4388.utility.controller;
|
||||
|
||||
import edu.wpi.first.wpilibj.GenericHID;
|
||||
|
||||
public class VirtualController extends GenericHID {
|
||||
private short m_buttonStates = 0;
|
||||
private short m_buttonStatesLastFrame = 0;
|
||||
private double[] m_axes = new double[6];
|
||||
private short[] m_pov = new short[1];
|
||||
|
||||
public VirtualController(int port) {
|
||||
super(port);
|
||||
}
|
||||
|
||||
public void setFrame(double[] axes, short buttonFlags, short[] pov) {
|
||||
m_axes = axes;
|
||||
setOutputs(buttonFlags);
|
||||
m_pov = pov;
|
||||
}
|
||||
|
||||
public void zeroControls() {
|
||||
m_axes = new double[6];
|
||||
m_buttonStates = 0;
|
||||
m_buttonStatesLastFrame = 0;
|
||||
m_pov = new short[1];
|
||||
}
|
||||
|
||||
public static boolean getFlag(int value, int index) {
|
||||
return ((value & 1 << index) != 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRawButton(int button) { // man why are buttons indexed at 1.
|
||||
return getFlag(m_buttonStates, button - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRawButtonPressed(int button) {
|
||||
return (!getFlag(m_buttonStatesLastFrame, button - 1) && getRawButton(button));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRawButtonReleased(int button) {
|
||||
return (getFlag(m_buttonStatesLastFrame, button - 1) && !getRawButton(button));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getRawAxis(int axis) {
|
||||
return m_axes[axis];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPOV(int pov) {
|
||||
return m_pov[pov];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAxisCount() {
|
||||
return m_axes.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPOVCount() {
|
||||
return m_pov.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getButtonCount() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HIDType getType() {
|
||||
return HIDType.kXInputGamepad;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Virtual Controller";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAxisType(int axis) {
|
||||
return 1; /* ! Warning, does not return accurate data.
|
||||
Hopefully this isn't a problem */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOutput(int outputNumber, boolean value) {
|
||||
// do not use
|
||||
//m_buttonStatesLastFrame[outputNumber - 1] = m_buttonStates[outputNumber - 1];
|
||||
//m_buttonStates[outputNumber - 1] = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOutputs(int value) {
|
||||
m_buttonStatesLastFrame = m_buttonStates;
|
||||
m_buttonStates = (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRumble(RumbleType type, double value) {
|
||||
System.out.println("Why are you Setting rumble on an virtual controller?");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user