Zoltan Hudak / UsbHostMAX3421E

Dependents:   UsbHostMAX3421E_Hello

Embed: (wiki syntax)

« Back to documentation index

XBOXONE Class Reference

This class implements support for a Xbox ONE controller connected via USB. More...

#include <XBOXONE.h>

Inherits USBDeviceConfig, and UsbConfigXtracter.

Public Member Functions

 XBOXONE (Usb *pUsb)
 Constructor for the XBOXONE class.
USBDeviceConfig implementation
virtual uint8_t Init (uint8_t parent, uint8_t port, bool lowspeed)
 Initialize the Xbox Controller.
virtual uint8_t Release ()
 Release the USB device.
virtual uint8_t Poll ()
 Poll the USB Input endpoins and run the state machines.
virtual uint8_t GetAddress ()
 Get the device address.
virtual bool isReady ()
 Used to check if the controller has been initialized.
uint8_t readPollInterval ()
 Read the poll interval taken from the endpoint descriptors.
virtual bool VIDPIDOK (uint16_t vid, uint16_t pid)
 Used by the USB core to check what this driver support.
Xbox Controller functions
uint16_t getButtonPress (ButtonEnum b)
 getButtonPress(ButtonEnum b) will return true as long as the button is held down.
bool getButtonClick (ButtonEnum b)
int16_t getAnalogHat (AnalogHatEnum a)
 Return the analog value from the joysticks on the controller.
void attachOnInit (void(*funcOnInit)(void))
 Used to call your own function when the controller is successfully initialized.
void setRumbleOff ()
 Used to set the rumble off.
void setRumbleOn (uint8_t leftTrigger, uint8_t rightTrigger, uint8_t leftMotor, uint8_t rightMotor)
 Used to turn on rumble continuously.

Data Fields

bool XboxOneConnected
 True if a Xbox ONE controller is connected.

Protected Member Functions

void PrintEndpointDescriptor (const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
 Used to print the USB Endpoint Descriptor.
UsbConfigXtracter implementation
void EndpointXtract (uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
 UsbConfigXtracter implementation, used to extract endpoint information.

Protected Attributes

Usb * pUsb
 Pointer to USB class instance.
uint8_t bAddress
 Device address.
EpInfo epInfo [XBOX_ONE_MAX_ENDPOINTS]
 Endpoint info structure.
uint8_t bConfNum
 Configuration number.
uint8_t bNumEP
 Total number of endpoints in the configuration.
uint32_t qNextPollTime
 Next poll time based on poll interval taken from the USB descriptor.

Detailed Description

This class implements support for a Xbox ONE controller connected via USB.

Definition at line 66 of file XBOXONE.h.


Constructor & Destructor Documentation

XBOXONE ( Usb *  pUsb )

Constructor for the XBOXONE class.

Parameters:
pUsbPointer to USB class instance.

Definition at line 27 of file XBOXONE.cpp.


Member Function Documentation

void attachOnInit ( void(*)(void)  funcOnInit )

Used to call your own function when the controller is successfully initialized.

Parameters:
funcOnInitFunction to call.

Definition at line 157 of file XBOXONE.h.

void EndpointXtract ( uint8_t  conf,
uint8_t  iface,
uint8_t  alt,
uint8_t  proto,
const USB_ENDPOINT_DESCRIPTOR *  ep 
) [protected]

UsbConfigXtracter implementation, used to extract endpoint information.

Parameters:
confConfiguration value.
ifaceInterface number.
altAlternate setting.
protoInterface Protocol.
epEndpoint Descriptor.
virtual uint8_t GetAddress (  ) [virtual]

Get the device address.

Returns:
The device address.

Definition at line 98 of file XBOXONE.h.

int16_t getAnalogHat ( AnalogHatEnum  a )

Return the analog value from the joysticks on the controller.

Parameters:
aEither LeftHatX, LeftHatY, RightHatX or RightHatY.
Returns:
Returns a signed 16-bit integer.

Definition at line 408 of file XBOXONE.cpp.

uint16_t getButtonPress ( ButtonEnum  b )

getButtonPress(ButtonEnum b) will return true as long as the button is held down.

While getButtonClick(ButtonEnum b) will only return it once.

So you instance if you need to increase a variable once you would use getButtonClick(ButtonEnum b), but if you need to drive a robot forward you would use getButtonPress(ButtonEnum b).

Parameters:
bButtonEnum to read.
Returns:
getButtonClick(ButtonEnum b) will return a bool, while getButtonPress(ButtonEnum b) will return a word if reading L2 or R2.

Definition at line 380 of file XBOXONE.cpp.

uint8_t Init ( uint8_t  parent,
uint8_t  port,
bool  lowspeed 
) [virtual]

Initialize the Xbox Controller.

Parameters:
parentHub number.
portPort number on the hub.
lowspeedSpeed of the device.
Returns:
0 on success.

Definition at line 46 of file XBOXONE.cpp.

virtual bool isReady (  ) [virtual]

Used to check if the controller has been initialized.

Returns:
True if it's ready.

Definition at line 106 of file XBOXONE.h.

uint8_t Poll (  ) [virtual]

Poll the USB Input endpoins and run the state machines.

Returns:
0 on success.

Definition at line 300 of file XBOXONE.cpp.

void PrintEndpointDescriptor ( const USB_ENDPOINT_DESCRIPTOR *  ep_ptr ) [protected]

Used to print the USB Endpoint Descriptor.

Parameters:
ep_ptrPointer to USB Endpoint Descriptor.
uint8_t readPollInterval (  )

Read the poll interval taken from the endpoint descriptors.

Returns:
The poll interval in ms.

Definition at line 114 of file XBOXONE.h.

uint8_t Release (  ) [virtual]

Release the USB device.

Returns:
0 on success.

Definition at line 286 of file XBOXONE.cpp.

void setRumbleOff (  )

Used to set the rumble off.

Definition at line 450 of file XBOXONE.cpp.

void setRumbleOn ( uint8_t  leftTrigger,
uint8_t  rightTrigger,
uint8_t  leftMotor,
uint8_t  rightMotor 
)

Used to turn on rumble continuously.

Parameters:
leftTriggerLeft trigger force.
rightTriggerRight trigger force.
leftMotorLeft motor force.
rightMotorRight motor force.

Definition at line 472 of file XBOXONE.cpp.

virtual bool VIDPIDOK ( uint16_t  vid,
uint16_t  pid 
) [virtual]

Used by the USB core to check what this driver support.

Parameters:
vidThe device's VID.
pidThe device's PID.
Returns:
Returns true if the device's VID and PID matches this driver.

Definition at line 124 of file XBOXONE.h.


Field Documentation

uint8_t bAddress [protected]

Device address.

Definition at line 181 of file XBOXONE.h.

uint8_t bConfNum [protected]

Configuration number.

Definition at line 186 of file XBOXONE.h.

uint8_t bNumEP [protected]

Total number of endpoints in the configuration.

Definition at line 188 of file XBOXONE.h.

EpInfo epInfo[XBOX_ONE_MAX_ENDPOINTS] [protected]

Endpoint info structure.

Definition at line 183 of file XBOXONE.h.

Usb* pUsb [protected]

Pointer to USB class instance.

Definition at line 179 of file XBOXONE.h.

uint32_t qNextPollTime [protected]

Next poll time based on poll interval taken from the USB descriptor.

Definition at line 190 of file XBOXONE.h.

True if a Xbox ONE controller is connected.

Definition at line 175 of file XBOXONE.h.