Switch2GCController

class wpilib.Switch2GCController(*args, **kwargs)

Bases: HIDDevice, Sendable

Handle input from Switch2GC controllers connected to the Driver Station.

This class handles Switch2GC input that comes from the Driver Station. Each time a value is requested the most recent value is returned.

Overloaded function.

  1. __init__(self: wpilib._wpilib.Switch2GCController, port: typing.SupportsInt | typing.SupportsIndex) -> None

Construct an instance of a controller.

The controller index is the USB port on the Driver Station.

Parameters:

port – The port on the Driver Station that the controller is plugged into.

  1. __init__(self: wpilib._wpilib.Switch2GCController, hid: wpilib._wpilib.GenericHID) -> None

Construct an instance of a controller with a GenericHID object.

Parameters:

hid – The GenericHID object to use for this controller.

class Axis(value: SupportsInt | SupportsIndex)

Bases: pybind11_object

Represents an axis on a Switch2GCController.

Members:

LEFT_X : Left X.

LEFT_Y : Left Y.

C_STICK_X : C Stick X.

C_STICK_Y : C Stick Y.

L_TRIGGER : L Trigger.

R_TRIGGER : R Trigger.

C_STICK_X = <Axis.C_STICK_X: 2>
C_STICK_Y = <Axis.C_STICK_Y: 3>
LEFT_X = <Axis.LEFT_X: 0>
LEFT_Y = <Axis.LEFT_Y: 1>
L_TRIGGER = <Axis.L_TRIGGER: 4>
R_TRIGGER = <Axis.R_TRIGGER: 5>
Switch2GCController.Axis.name -> str
property value
class Button(value: SupportsInt | SupportsIndex)

Bases: pybind11_object

Represents a digital button on a Switch2GCController.

Members:

A : A button.

X : X button.

B : B button.

Y : Y button.

HOME : Home button.

START : Start button.

ZL : ZL button.

Z : Z button.

DPAD_UP : Dpad Up button.

DPAD_DOWN : Dpad Down button.

DPAD_LEFT : Dpad Left button.

DPAD_RIGHT : Dpad Right button.

CAPTURE : Capture button.

C : C button.

L : L button.

R : R button.

A = <Button.A: 0>
B = <Button.B: 2>
C = <Button.C: 21>
CAPTURE = <Button.CAPTURE: 15>
DPAD_DOWN = <Button.DPAD_DOWN: 12>
DPAD_LEFT = <Button.DPAD_LEFT: 13>
DPAD_RIGHT = <Button.DPAD_RIGHT: 14>
DPAD_UP = <Button.DPAD_UP: 11>
HOME = <Button.HOME: 5>
L = <Button.L: 22>
R = <Button.R: 23>
START = <Button.START: 6>
X = <Button.X: 1>
Y = <Button.Y: 3>
Z = <Button.Z: 10>
ZL = <Button.ZL: 9>
Switch2GCController.Button.name -> str
property value
SUPPORTED_OUTPUTS = <SupportedOutputs.RUMBLE: 8>
SUPPORTS_MONO_LED = False
SUPPORTS_RGB_LED = False
SUPPORTS_RUMBLE = True
SUPPORTS_TRIGGER_RUMBLE = False
TOUCHPAD_COUNT = 0
a(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

axis_greater_than(axis: wpilib._wpilib.Switch2GCController.Axis, threshold: SupportsFloat | SupportsIndex, loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance that is true when the axis value is greater than threshold.

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.

axis_less_than(axis: wpilib._wpilib.Switch2GCController.Axis, threshold: SupportsFloat | SupportsIndex, loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance that is true when the axis value is less than threshold.

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.

b(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

button(button: wpilib._wpilib.Switch2GCController.Button, loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance around this button’s digital signal.

Parameters:
  • button – the button

  • loop – the event loop instance to attach the event to.

Returns:

an event instance representing the button’s digital signal attached to the given loop.

c(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

capture(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

dpad_down(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

dpad_left(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

dpad_right(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

dpad_up(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

get_a_button() bool

Read the value of the A button on the controller.

Returns:

The state of the button.

get_a_button_pressed() bool

Whether the A button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_a_button_released() bool

Whether the A button was released since the last check.

Returns:

Whether the button was released since the last check.

get_axis(axis: wpilib._wpilib.Switch2GCController.Axis) float

Get the value of the axis.

Parameters:

axis – The axis to read

Returns:

the axis value.

get_b_button() bool

Read the value of the B button on the controller.

Returns:

The state of the button.

get_b_button_pressed() bool

Whether the B button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_b_button_released() bool

Whether the B button was released since the last check.

Returns:

Whether the button was released since the last check.

get_button(button: wpilib._wpilib.Switch2GCController.Button) bool

Get the button value.

Parameters:

button – The button to read

Returns:

The state of the button.

get_button_pressed(button: wpilib._wpilib.Switch2GCController.Button) bool

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.

get_button_released(button: wpilib._wpilib.Switch2GCController.Button) bool

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.

get_c_button() bool

Read the value of the C button on the controller.

Returns:

The state of the button.

get_c_button_pressed() bool

Whether the C button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_c_button_released() bool

Whether the C button was released since the last check.

Returns:

Whether the button was released since the last check.

get_c_stick_x() float

Get the C Stick X value of the controller.

Returns:

the axis value.

get_c_stick_y() float

Get the C Stick Y value of the controller.

Returns:

the axis value.

get_capture_button() bool

Read the value of the Capture button on the controller.

Returns:

The state of the button.

get_capture_button_pressed() bool

Whether the Capture button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_capture_button_released() bool

Whether the Capture button was released since the last check.

Returns:

Whether the button was released since the last check.

get_dpad_down_button() bool

Read the value of the Dpad Down button on the controller.

Returns:

The state of the button.

get_dpad_down_button_pressed() bool

Whether the Dpad Down button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_dpad_down_button_released() bool

Whether the Dpad Down button was released since the last check.

Returns:

Whether the button was released since the last check.

get_dpad_left_button() bool

Read the value of the Dpad Left button on the controller.

Returns:

The state of the button.

get_dpad_left_button_pressed() bool

Whether the Dpad Left button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_dpad_left_button_released() bool

Whether the Dpad Left button was released since the last check.

Returns:

Whether the button was released since the last check.

get_dpad_right_button() bool

Read the value of the Dpad Right button on the controller.

Returns:

The state of the button.

get_dpad_right_button_pressed() bool

Whether the Dpad Right button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_dpad_right_button_released() bool

Whether the Dpad Right button was released since the last check.

Returns:

Whether the button was released since the last check.

get_dpad_up_button() bool

Read the value of the Dpad Up button on the controller.

Returns:

The state of the button.

get_dpad_up_button_pressed() bool

Whether the Dpad Up button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_dpad_up_button_released() bool

Whether the Dpad Up button was released since the last check.

Returns:

Whether the button was released since the last check.

get_hid() wpilib._wpilib.GenericHID

Get the underlying GenericHID object.

Returns:

the wrapped GenericHID object

get_home_button() bool

Read the value of the Home button on the controller.

Returns:

The state of the button.

get_home_button_pressed() bool

Whether the Home button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_home_button_released() bool

Whether the Home button was released since the last check.

Returns:

Whether the button was released since the last check.

get_l_button() bool

Read the value of the L button on the controller.

Returns:

The state of the button.

get_l_button_pressed() bool

Whether the L button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_l_button_released() bool

Whether the L button was released since the last check.

Returns:

Whether the button was released since the last check.

get_l_trigger() float

Get the L Trigger value of the controller.

Returns:

the axis value.

get_left_x() float

Get the Left X value of the controller.

Returns:

the axis value.

get_left_y() float

Get the Left Y value of the controller.

Returns:

the axis value.

get_port() int

Get the port number of the HID.

Returns:

The port number of the HID.

get_r_button() bool

Read the value of the R button on the controller.

Returns:

The state of the button.

get_r_button_pressed() bool

Whether the R button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_r_button_released() bool

Whether the R button was released since the last check.

Returns:

Whether the button was released since the last check.

get_r_trigger() float

Get the R Trigger value of the controller.

Returns:

the axis value.

get_start_button() bool

Read the value of the Start button on the controller.

Returns:

The state of the button.

get_start_button_pressed() bool

Whether the Start button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_start_button_released() bool

Whether the Start button was released since the last check.

Returns:

Whether the button was released since the last check.

get_x_button() bool

Read the value of the X button on the controller.

Returns:

The state of the button.

get_x_button_pressed() bool

Whether the X button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_x_button_released() bool

Whether the X button was released since the last check.

Returns:

Whether the button was released since the last check.

get_y_button() bool

Read the value of the Y button on the controller.

Returns:

The state of the button.

get_y_button_pressed() bool

Whether the Y button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_y_button_released() bool

Whether the Y button was released since the last check.

Returns:

Whether the button was released since the last check.

get_z_button() bool

Read the value of the Z button on the controller.

Returns:

The state of the button.

get_z_button_pressed() bool

Whether the Z button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_z_button_released() bool

Whether the Z button was released since the last check.

Returns:

Whether the button was released since the last check.

get_zl_button() bool

Read the value of the ZL button on the controller.

Returns:

The state of the button.

get_zl_button_pressed() bool

Whether the ZL button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_zl_button_released() bool

Whether the ZL button was released since the last check.

Returns:

Whether the button was released since the last check.

home(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

init_sendable(builder: wpiutil._wpiutil.SendableBuilder) None
is_connected() bool

Get if the HID is connected.

Returns:

true if the HID is connected

l(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

r(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

set_leds(r: SupportsInt | SupportsIndex, g: SupportsInt | SupportsIndex, b: SupportsInt | SupportsIndex) None

Set leds on the controller.

Parameters:
  • r – Red value from 0-255

  • g – Green value from 0-255

  • b – Blue value from 0-255

set_rumble(type: wpilib._wpilib.GenericHID.RumbleType, value: SupportsFloat | SupportsIndex) None

Set the rumble output for the HID.

Parameters:
  • type – Which rumble value to set

  • value – The normalized value (0 to 1) to set the rumble to

start(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

x(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

y(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

z(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

zl(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.