Zoltan Hudak / UsbHostMAX3421E

Dependents:   UsbHostMAX3421E_Hello

Embed: (wiki syntax)

« Back to documentation index

XBOXUSB Class Reference

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

#include <XBOXUSB.h>

Inherits USBDeviceConfig.

Public Member Functions

 XBOXUSB (Usb *pUsb)
 Constructor for the XBOXUSB class.
USBDeviceConfig implementation
uint8_t Init (uint8_t parent, uint8_t port, bool lowspeed)
 Initialize the Xbox Controller.
uint8_t Release ()
 Release the USB device.
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.
virtual bool VIDPIDOK (uint16_t vid, uint16_t pid)
 Used by the USB core to check what this driver support.
Xbox Controller functions
uint8_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 setAllOff ()
 Turn rumble off and all the LEDs on the controller.
void setRumbleOff ()
 Turn rumble off the controller.
void setRumbleOn (uint8_t lValue, uint8_t rValue)
 Turn rumble on.
void setLedRaw (uint8_t value)
 Set LED value.
void setLedOff ()
 Turn all LEDs off the controller.
void setLedOn (LEDEnum l)
 Turn on a LED by using LEDEnum.
void setLedBlink (LEDEnum l)
 Turn on a LED by using LEDEnum.
void setLedMode (LEDModeEnum lm)
 Used to set special LED modes supported by the Xbox controller.
void attachOnInit (void(*funcOnInit)(void))
 Used to call your own function when the controller is successfully initialized.

Data Fields

bool Xbox360Connected
 True if a Xbox 360 controller is connected.

Protected Attributes

Usb * pUsb
 Pointer to USB class instance.
uint8_t bAddress
 Device address.
EpInfo epInfo [XBOX_MAX_ENDPOINTS]
 Endpoint info structure.

Detailed Description

This class implements support for a Xbox wired controller via USB.

Definition at line 53 of file XBOXUSB.h.


Constructor & Destructor Documentation

XBOXUSB ( Usb *  pUsb )

Constructor for the XBOXUSB class.

Parameters:
pUsbPointer to USB class instance.

Definition at line 23 of file XBOXUSB.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 179 of file XBOXUSB.h.

virtual uint8_t GetAddress (  ) [virtual]

Get the device address.

Returns:
The device address.

Definition at line 85 of file XBOXUSB.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 311 of file XBOXUSB.cpp.

uint8_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 byte if reading L2 or R2.

Definition at line 283 of file XBOXUSB.cpp.

uint8_t Init ( uint8_t  parent,
uint8_t  port,
bool  lowspeed 
)

Initialize the Xbox Controller.

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

Definition at line 39 of file XBOXUSB.cpp.

virtual bool isReady (  ) [virtual]

Used to check if the controller has been initialized.

Returns:
True if it's ready.

Definition at line 93 of file XBOXUSB.h.

uint8_t Poll (  )

Poll the USB Input endpoins and run the state machines.

Returns:
0 on success.

Definition at line 232 of file XBOXUSB.cpp.

uint8_t Release (  )

Release the USB device.

Returns:
0 on success.

Definition at line 224 of file XBOXUSB.cpp.

void setAllOff (  )

Turn rumble off and all the LEDs on the controller.

Definition at line 132 of file XBOXUSB.h.

void setLedBlink ( LEDEnum  l )

Turn on a LED by using LEDEnum.

Parameters:
lALL, LED1, LED2, LED3 and LED4 is supported by the Xbox controller.

Definition at line 336 of file XBOXUSB.cpp.

void setLedMode ( LEDModeEnum  lm )

Used to set special LED modes supported by the Xbox controller.

Parameters:
lmSee LEDModeEnum.

Definition at line 340 of file XBOXUSB.cpp.

void setLedOff (  )

Turn all LEDs off the controller.

Definition at line 156 of file XBOXUSB.h.

void setLedOn ( LEDEnum  l )

Turn on a LED by using LEDEnum.

Parameters:
lOFF, LED1, LED2, LED3 and LED4 is supported by the Xbox controller.

Definition at line 329 of file XBOXUSB.cpp.

void setLedRaw ( uint8_t  value )

Set LED value.

Without using the LEDEnum or LEDModeEnum.

Parameters:
valueSee: setLedOff(), setLedOn(LEDEnum l), setLedBlink(LEDEnum l), and setLedMode(LEDModeEnum lm).

Definition at line 321 of file XBOXUSB.cpp.

void setRumbleOff (  )

Turn rumble off the controller.

Definition at line 138 of file XBOXUSB.h.

void setRumbleOn ( uint8_t  lValue,
uint8_t  rValue 
)

Turn rumble on.

Parameters:
lValueLeft motor (big weight) inside the controller.
rValueRight motor (small weight) inside the controller.

Definition at line 344 of file XBOXUSB.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 103 of file XBOXUSB.h.


Field Documentation

uint8_t bAddress [protected]

Device address.

Definition at line 191 of file XBOXUSB.h.

EpInfo epInfo[XBOX_MAX_ENDPOINTS] [protected]

Endpoint info structure.

Definition at line 193 of file XBOXUSB.h.

Usb* pUsb [protected]

Pointer to USB class instance.

Definition at line 189 of file XBOXUSB.h.

True if a Xbox 360 controller is connected.

Definition at line 181 of file XBOXUSB.h.