Skip to main content

Joystick Class

NuGet: GHIElectronics.TinyCLR.Devices.UsbHost
Assembly: GHIElectronics.TinyCLR.Devices.UsbHost
Namespace: GHIElectronics.TinyCLR.Devices.UsbHost

Allows a usb device to be used as a joystick.

public class Joystick : BaseDevice

Constructors​

Joystick(uint id, byte interfaceIndex)​

public Joystick(uint id, byte interfaceIndex) : base(id, interfaceIndex, DeviceType.Joystick)

Creates a new joystick.

ParameterTypeDescription
iduintThe device id.
interfaceIndexbyteThe device interface index.

Properties​

Capabilities​

public DeviceCapabilities Capabilities { get; }

The capabilities of the joystick.

CursorPosition​

public Position CursorPosition { get; }

The current position of the first cursor.

Cursor2Position​

public Position Cursor2Position { get; }

The current position of the second cursor.

CurrentHatSwitchDirection​

public HatSwitchDirection CurrentHatSwitchDirection { get; }

The current direction of the hat switch.

byte​

public enum DeviceCapabilities : byte { }

Joystick capabilities.

Methods​

SetCursorBounds(Cursor cursor, int minX, int maxX, int minY, int maxY)​

public void SetCursorBounds(Cursor cursor, int minX, int maxX, int minY, int maxY)

Sets the bounds for given cursor.

ParameterTypeDescription
cursorCursorThe cursor for which to set the bounds.
minXintThe minimum X value.
maxXintThe maximum X value.
minYintThe minimum Y value.
maxYintThe maximum Y value.

GetButtonState(int buttonNumber)​

public ButtonState GetButtonState(int buttonNumber)

Gets the current button state.

ParameterTypeDescription
buttonNumberintThe button number to query.

Returns ButtonState — The state of the button.

Dispose(bool disposing)​

protected override void Dispose(bool disposing)

Disposes the joystick.

ParameterTypeDescription
disposingboolWhether or not this is called from Dispose.

CheckEvents(object sender)​

protected override void CheckEvents(object sender)

Repeatedly called with a period defined by WorkerInterval. Used to poll the device for data and raise any desired events.

ParameterTypeDescription
senderobjectAlways null.

Events​

ButtonChanged​

public event ButtonChangedEventHandler ButtonChanged

The event fired when one of the joystick's buttons is pressed or released.

CursorMoved​

public event CursorMovedEventHandler CursorMoved

The event fired when the joystick's cursor has moved.

HatSwitchPressed​

public event HatSwitchPressedEventHandler HatSwitchPressed

The event fired when the joystick's hat switch has been pressed.