Class Switch2GCController
- All Implemented Interfaces:
HIDDevice, TelemetryLoggable
This class handles Switch2GC input that comes from the Driver Station. Each time a value is requested the most recent value is returned.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents an axis on a Switch2GCController.static enumRepresents a digital button on a Switch2GCController. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanWhether this controller supports mono LED output.static final booleanWhether this controller supports RGB LED output.static final booleanWhether this controller supports main rumble motors.static final booleanWhether this controller supports trigger rumble motors.static final intThe number of touchpads supported by this controller. -
Constructor Summary
ConstructorsConstructorDescriptionSwitch2GCController(int port) Construct an instance of a controller.Construct an instance of a controller with a GenericHID object. -
Method Summary
Modifier and TypeMethodDescriptionConstructs an event instance around the A button's digital signal.axisGreaterThan(Switch2GCController.Axis axis, double threshold, EventLoop loop) Constructs an event instance that is true when the axis value is greater thanthreshold.axisLessThan(Switch2GCController.Axis axis, double threshold, EventLoop loop) Constructs an event instance that is true when the axis value is less thanthreshold.Constructs an event instance around the B button's digital signal.button(Switch2GCController.Button button, EventLoop loop) Constructs an event instance around this button's digital signal.Constructs an event instance around the C button's digital signal.Constructs an event instance around the Capture button's digital signal.Constructs an event instance around the Dpad Down button's digital signal.Constructs an event instance around the Dpad Left button's digital signal.Constructs an event instance around the Dpad Right button's digital signal.Constructs an event instance around the Dpad Up button's digital signal.booleanRead the value of the A button on the controller.booleanWhether the A button was pressed since the last check.booleanWhether the A button was released since the last check.doubleGet the value of the axis.booleanRead the value of the B button on the controller.booleanWhether the B button was pressed since the last check.booleanWhether the B button was released since the last check.booleangetButton(Switch2GCController.Button button) Get the button value.booleanWhether the button was pressed since the last check.booleanWhether the button was released since the last check.booleanRead the value of the Capture button on the controller.booleanWhether the Capture button was pressed since the last check.booleanWhether the Capture button was released since the last check.booleanRead the value of the C button on the controller.booleanWhether the C button was pressed since the last check.booleanWhether the C button was released since the last check.doubleGet the C Stick X value of the controller.doubleGet the C Stick Y value of the controller.booleanRead the value of the Dpad Down button on the controller.booleanWhether the Dpad Down button was pressed since the last check.booleanWhether the Dpad Down button was released since the last check.booleanRead the value of the Dpad Left button on the controller.booleanWhether the Dpad Left button was pressed since the last check.booleanWhether the Dpad Left button was released since the last check.booleanRead the value of the Dpad Right button on the controller.booleanWhether the Dpad Right button was pressed since the last check.booleanWhether the Dpad Right button was released since the last check.booleanRead the value of the Dpad Up button on the controller.booleanWhether the Dpad Up button was pressed since the last check.booleanWhether the Dpad Up button was released since the last check.getHID()Get the underlying GenericHID object.booleanRead the value of the Home button on the controller.booleanWhether the Home button was pressed since the last check.booleanWhether the Home button was released since the last check.booleanRead the value of the L button on the controller.booleanWhether the L button was pressed since the last check.booleanWhether the L button was released since the last check.doublegetLeftX()Get the Left X value of the controller.doublegetLeftY()Get the Left Y value of the controller.doubleGet the L Trigger value of the controller.intgetPort()Get the port number of the HID.booleanRead the value of the R button on the controller.booleanWhether the R button was pressed since the last check.booleanWhether the R button was released since the last check.doubleGet the R Trigger value of the controller.booleanRead the value of the Start button on the controller.booleanWhether the Start button was pressed since the last check.booleanWhether the Start button was released since the last check.static EnumSet<GenericHID.SupportedOutput> Get the supported outputs expected for this controller type.Gets the telemetry table type.booleanRead the value of the X button on the controller.booleanWhether the X button was pressed since the last check.booleanWhether the X button was released since the last check.booleanRead the value of the Y button on the controller.booleanWhether the Y button was pressed since the last check.booleanWhether the Y button was released since the last check.booleanRead the value of the Z button on the controller.booleanWhether the Z button was pressed since the last check.booleanWhether the Z button was released since the last check.booleanRead the value of the ZL button on the controller.booleanWhether the ZL button was pressed since the last check.booleanWhether the ZL button was released since the last check.Constructs an event instance around the Home button's digital signal.booleanGet if the HID is connected.Constructs an event instance around the L button's digital signal.voidlogTo(TelemetryTable table) Logs the object to aTelemetryTable.Constructs an event instance around the R button's digital signal.voidsetCStickXDeadband(double deadband) Set the deadband for the C Stick X axis.voidsetCStickYDeadband(double deadband) Set the deadband for the C Stick Y axis.voidsetLeds(int r, int g, int b) Set leds on the controller.voidsetLeftXDeadband(double deadband) Set the deadband for the Left X axis.voidsetLeftYDeadband(double deadband) Set the deadband for the Left Y axis.voidsetLTriggerDeadband(double deadband) Set the deadband for the L Trigger axis.voidsetRTriggerDeadband(double deadband) Set the deadband for the R Trigger axis.voidsetRumble(GenericHID.RumbleType type, double value) Set the rumble output for the HID.Constructs an event instance around the Start button's digital signal.Constructs an event instance around the X button's digital signal.Constructs an event instance around the Y button's digital signal.Constructs an event instance around the Z button's digital signal.Constructs an event instance around the ZL button's digital signal.
-
Field Details
-
TOUCHPAD_COUNT
public static final int TOUCHPAD_COUNTThe number of touchpads supported by this controller.- See Also:
-
SUPPORTS_RUMBLE
public static final boolean SUPPORTS_RUMBLEWhether this controller supports main rumble motors.- See Also:
-
SUPPORTS_TRIGGER_RUMBLE
public static final boolean SUPPORTS_TRIGGER_RUMBLEWhether this controller supports trigger rumble motors.- See Also:
-
SUPPORTS_MONO_LED
public static final boolean SUPPORTS_MONO_LEDWhether this controller supports mono LED output.- See Also:
-
SUPPORTS_RGB_LED
public static final boolean SUPPORTS_RGB_LEDWhether this controller supports RGB LED output.- See Also:
-
-
Constructor Details
-
Switch2GCController
public Switch2GCController(int port) Construct an instance of a controller.- Parameters:
port- The port index on the Driver Station that the controller is plugged into.
-
Switch2GCController
Construct an instance of a controller with a GenericHID object.- Parameters:
hid- The GenericHID object to use for this controller.
-
-
Method Details
-
getHID
Get the underlying GenericHID object. -
getSupportedOutputCapabilities
Get the supported outputs expected for this controller type.- Returns:
- the expected supported outputs
-
getPort
public int getPort()Get the port number of the HID.- Returns:
- The port number of the HID.
-
isConnected
public boolean isConnected()Get if the HID is connected.- Returns:
- true if the HID is connected
-
getLeftX
public double getLeftX()Get the Left X value of the controller.A deadband of 0.1 is applied by default. Use
setLeftXDeadband(double)to change it.- Returns:
- The axis value.
-
setLeftXDeadband
public void setLeftXDeadband(double deadband) Set the deadband for the Left X axis.The deadband is clamped to [0, 1).
- Parameters:
deadband- The deadband to apply.
-
getLeftY
public double getLeftY()Get the Left Y value of the controller.A deadband of 0.1 is applied by default. Use
setLeftYDeadband(double)to change it.- Returns:
- The axis value.
-
setLeftYDeadband
public void setLeftYDeadband(double deadband) Set the deadband for the Left Y axis.The deadband is clamped to [0, 1).
- Parameters:
deadband- The deadband to apply.
-
getCStickX
public double getCStickX()Get the C Stick X value of the controller.A deadband of 0.1 is applied by default. Use
setCStickXDeadband(double)to change it.- Returns:
- The axis value.
-
setCStickXDeadband
public void setCStickXDeadband(double deadband) Set the deadband for the C Stick X axis.The deadband is clamped to [0, 1).
- Parameters:
deadband- The deadband to apply.
-
getCStickY
public double getCStickY()Get the C Stick Y value of the controller.A deadband of 0.1 is applied by default. Use
setCStickYDeadband(double)to change it.- Returns:
- The axis value.
-
setCStickYDeadband
public void setCStickYDeadband(double deadband) Set the deadband for the C Stick Y axis.The deadband is clamped to [0, 1).
- Parameters:
deadband- The deadband to apply.
-
getLTrigger
public double getLTrigger()Get the L Trigger value of the controller.A deadband of 0.01 is applied by default. Use
setLTriggerDeadband(double)to change it.- Returns:
- The axis value.
-
setLTriggerDeadband
public void setLTriggerDeadband(double deadband) Set the deadband for the L Trigger axis.The deadband is clamped to [0, 1).
- Parameters:
deadband- The deadband to apply.
-
getRTrigger
public double getRTrigger()Get the R Trigger value of the controller.A deadband of 0.01 is applied by default. Use
setRTriggerDeadband(double)to change it.- Returns:
- The axis value.
-
setRTriggerDeadband
public void setRTriggerDeadband(double deadband) Set the deadband for the R Trigger axis.The deadband is clamped to [0, 1).
- Parameters:
deadband- The deadband to apply.
-
getAxis
Get the value of the axis.- Parameters:
axis- The axis to read- Returns:
- The axis value.
-
axisLessThan
Constructs an event instance that is true when the axis value is less thanthreshold.- Parameters:
axis- The axis to read.threshold- The value below which this event should return true.loop- the event loop instance to attach the event to.- Returns:
- an event instance that is true when the axis value is less than the provided threshold.
-
axisGreaterThan
public BooleanEvent axisGreaterThan(Switch2GCController.Axis axis, double threshold, EventLoop loop) Constructs an event instance that is true when the axis value is greater thanthreshold.- Parameters:
axis- The axis to read.threshold- The value above which this event should return true.loop- the event loop instance to attach the event to.- Returns:
- an event instance that is true when the axis value is greater than the provided threshold.
-
getAButton
public boolean getAButton()Read the value of the A button on the controller.- Returns:
- The state of the button.
-
getAButtonPressed
public boolean getAButtonPressed()Whether the A button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getAButtonReleased
public boolean getAButtonReleased()Whether the A button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
a
Constructs an event instance around the A button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the A button's digital signal attached to the given loop.
-
getXButton
public boolean getXButton()Read the value of the X button on the controller.- Returns:
- The state of the button.
-
getXButtonPressed
public boolean getXButtonPressed()Whether the X button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getXButtonReleased
public boolean getXButtonReleased()Whether the X button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
x
Constructs an event instance around the X button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the X button's digital signal attached to the given loop.
-
getBButton
public boolean getBButton()Read the value of the B button on the controller.- Returns:
- The state of the button.
-
getBButtonPressed
public boolean getBButtonPressed()Whether the B button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getBButtonReleased
public boolean getBButtonReleased()Whether the B button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
b
Constructs an event instance around the B button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the B button's digital signal attached to the given loop.
-
getYButton
public boolean getYButton()Read the value of the Y button on the controller.- Returns:
- The state of the button.
-
getYButtonPressed
public boolean getYButtonPressed()Whether the Y button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getYButtonReleased
public boolean getYButtonReleased()Whether the Y button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
y
Constructs an event instance around the Y button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the Y button's digital signal attached to the given loop.
-
getHomeButton
public boolean getHomeButton()Read the value of the Home button on the controller.- Returns:
- The state of the button.
-
getHomeButtonPressed
public boolean getHomeButtonPressed()Whether the Home button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getHomeButtonReleased
public boolean getHomeButtonReleased()Whether the Home button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
home
Constructs an event instance around the Home button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the Home button's digital signal attached to the given loop.
-
getStartButton
public boolean getStartButton()Read the value of the Start button on the controller.- Returns:
- The state of the button.
-
getStartButtonPressed
public boolean getStartButtonPressed()Whether the Start button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getStartButtonReleased
public boolean getStartButtonReleased()Whether the Start button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
start
Constructs an event instance around the Start button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the Start button's digital signal attached to the given loop.
-
getZLButton
public boolean getZLButton()Read the value of the ZL button on the controller.- Returns:
- The state of the button.
-
getZLButtonPressed
public boolean getZLButtonPressed()Whether the ZL button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getZLButtonReleased
public boolean getZLButtonReleased()Whether the ZL button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
ZL
Constructs an event instance around the ZL button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the ZL button's digital signal attached to the given loop.
-
getZButton
public boolean getZButton()Read the value of the Z button on the controller.- Returns:
- The state of the button.
-
getZButtonPressed
public boolean getZButtonPressed()Whether the Z button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getZButtonReleased
public boolean getZButtonReleased()Whether the Z button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
Z
Constructs an event instance around the Z button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the Z button's digital signal attached to the given loop.
-
getDpadUpButton
public boolean getDpadUpButton()Read the value of the Dpad Up button on the controller.- Returns:
- The state of the button.
-
getDpadUpButtonPressed
public boolean getDpadUpButtonPressed()Whether the Dpad Up button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getDpadUpButtonReleased
public boolean getDpadUpButtonReleased()Whether the Dpad Up button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
dpadUp
Constructs an event instance around the Dpad Up button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the Dpad Up button's digital signal attached to the given loop.
-
getDpadDownButton
public boolean getDpadDownButton()Read the value of the Dpad Down button on the controller.- Returns:
- The state of the button.
-
getDpadDownButtonPressed
public boolean getDpadDownButtonPressed()Whether the Dpad Down button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getDpadDownButtonReleased
public boolean getDpadDownButtonReleased()Whether the Dpad Down button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
dpadDown
Constructs an event instance around the Dpad Down button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the Dpad Down button's digital signal attached to the given loop.
-
getDpadLeftButton
public boolean getDpadLeftButton()Read the value of the Dpad Left button on the controller.- Returns:
- The state of the button.
-
getDpadLeftButtonPressed
public boolean getDpadLeftButtonPressed()Whether the Dpad Left button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getDpadLeftButtonReleased
public boolean getDpadLeftButtonReleased()Whether the Dpad Left button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
dpadLeft
Constructs an event instance around the Dpad Left button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the Dpad Left button's digital signal attached to the given loop.
-
getDpadRightButton
public boolean getDpadRightButton()Read the value of the Dpad Right button on the controller.- Returns:
- The state of the button.
-
getDpadRightButtonPressed
public boolean getDpadRightButtonPressed()Whether the Dpad Right button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getDpadRightButtonReleased
public boolean getDpadRightButtonReleased()Whether the Dpad Right button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
dpadRight
Constructs an event instance around the Dpad Right button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the Dpad Right button's digital signal attached to the given loop.
-
getCaptureButton
public boolean getCaptureButton()Read the value of the Capture button on the controller.- Returns:
- The state of the button.
-
getCaptureButtonPressed
public boolean getCaptureButtonPressed()Whether the Capture button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getCaptureButtonReleased
public boolean getCaptureButtonReleased()Whether the Capture button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
capture
Constructs an event instance around the Capture button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the Capture button's digital signal attached to the given loop.
-
getCButton
public boolean getCButton()Read the value of the C button on the controller.- Returns:
- The state of the button.
-
getCButtonPressed
public boolean getCButtonPressed()Whether the C button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getCButtonReleased
public boolean getCButtonReleased()Whether the C button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
C
Constructs an event instance around the C button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the C button's digital signal attached to the given loop.
-
getLButton
public boolean getLButton()Read the value of the L button on the controller.- Returns:
- The state of the button.
-
getLButtonPressed
public boolean getLButtonPressed()Whether the L button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getLButtonReleased
public boolean getLButtonReleased()Whether the L button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
L
Constructs an event instance around the L button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the L button's digital signal attached to the given loop.
-
getRButton
public boolean getRButton()Read the value of the R button on the controller.- Returns:
- The state of the button.
-
getRButtonPressed
public boolean getRButtonPressed()Whether the R button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getRButtonReleased
public boolean getRButtonReleased()Whether the R button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
R
Constructs an event instance around the R button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the R button's digital signal attached to the given loop.
-
getButton
Get the button value.- Parameters:
button- The button to read- Returns:
- The state of the button.
-
getButtonPressed
Whether the button was pressed since the last check.- Parameters:
button- The button to read- Returns:
- Whether the button was pressed since the last check.
-
getButtonReleased
Whether the button was released since the last check.- Parameters:
button- The button to read- Returns:
- Whether the button was released since the last check.
-
button
Constructs an event instance around this button's digital signal.- Parameters:
button- the buttonloop- the event loop instance to attach the event to.- Returns:
- an event instance representing the button's digital signal attached to the given loop.
-
setLeds
public void setLeds(int r, int g, int b) Set leds on the controller.- Parameters:
r- Red value from 0-255g- Green value from 0-255b- Blue value from 0-255
-
setRumble
Set the rumble output for the HID.- Parameters:
type- Which rumble value to setvalue- The normalized value (0 to 1) to set the rumble to
-
getTelemetryType
Description copied from interface:TelemetryLoggableGets the telemetry table type. Default is no specified table type (null). A mismatch in type during logging results in a reported warning, so this should always return the same value.- Specified by:
getTelemetryTypein interfaceTelemetryLoggable- Returns:
- Table type
-
logTo
Description copied from interface:TelemetryLoggableLogs the object to aTelemetryTable.- Specified by:
logToin interfaceTelemetryLoggable- Parameters:
table- telemetry table
-