Zoltan Hudak / UsbHostMAX3421E

Dependents:   UsbHostMAX3421E_Hello

Embed: (wiki syntax)

« Back to documentation index

XBOXRECV Class Reference

This class implements support for a Xbox Wireless receiver. More...

#include <XBOXRECV.h>

Inherits USBDeviceConfig.

Public Member Functions

 XBOXRECV (Usb *pUsb)
 Constructor for the XBOXRECV class.
USBDeviceConfig implementation
uint8_t ConfigureDevice (uint8_t parent, uint8_t port, bool lowspeed)
 Address assignment and basic initilization is done here.
uint8_t Init (uint8_t parent, uint8_t port, bool lowspeed)
 Initialize the Xbox wireless receiver.
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, uint8_t controller=0)
 getButtonPress(uint8_t controller, ButtonEnum b) will return true as long as the button is held down.
bool getButtonClick (ButtonEnum b, uint8_t controller=0)
int16_t getAnalogHat (AnalogHatEnum a, uint8_t controller=0)
 Return the analog value from the joysticks on the controller.
void disconnect (uint8_t controller=0)
 Used to disconnect any of the controllers.
void setAllOff (uint8_t controller=0)
 Turn rumble off and all the LEDs on the specific controller.
void setRumbleOff (uint8_t controller=0)
 Turn rumble off the specific controller.
void setRumbleOn (uint8_t lValue, uint8_t rValue, uint8_t controller=0)
 Turn rumble on.
void setLedRaw (uint8_t value, uint8_t controller=0)
 Set LED value.
void setLedOff (uint8_t controller=0)
 Turn all LEDs off the specific controller.
void setLedOn (LEDEnum l, uint8_t controller=0)
 Turn on a LED by using LEDEnum.
void setLedBlink (LEDEnum l, uint8_t controller=0)
 Turn on a LED by using LEDEnum.
void setLedMode (LEDModeEnum lm, uint8_t controller=0)
 Used to set special LED modes supported by the Xbox controller.
uint8_t getBatteryLevel (uint8_t controller=0)
 Used to get the battery level from the controller.
bool buttonChanged (uint8_t controller=0)
 Used to check if a button has changed.
void attachOnInit (void(*funcOnInit)(void))
 Used to call your own function when the controller is successfully initialized.

Data Fields

bool XboxReceiverConnected
 True if a wireless receiver is connected.
uint8_t Xbox360Connected [4]
 Variable used to indicate if the XBOX 360 controller is successfully 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 Wireless receiver.

Up to four controllers can connect to one receiver, if more is needed one can use a second receiver via the USBHub class.

Definition at line 55 of file XBOXRECV.h.


Constructor & Destructor Documentation

XBOXRECV ( Usb *  pUsb )

Constructor for the XBOXRECV class.

Parameters:
pUsbPointer to USB class instance.

Definition at line 25 of file XBOXRECV.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 223 of file XBOXRECV.h.

bool buttonChanged ( uint8_t  controller = 0 )

Used to check if a button has changed.

Parameters:
controllerThe controller to read from. Default to 0.
Returns:
True if a button has changed.

Definition at line 442 of file XBOXRECV.cpp.

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

Address assignment and basic initilization is done here.

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

Definition at line 41 of file XBOXRECV.cpp.

void disconnect ( uint8_t  controller = 0 )

Used to disconnect any of the controllers.

Parameters:
controllerThe controller to disconnect. Default to 0.

Definition at line 498 of file XBOXRECV.cpp.

virtual uint8_t GetAddress (  ) [virtual]

Get the device address.

Returns:
The device address.

Definition at line 95 of file XBOXRECV.h.

int16_t getAnalogHat ( AnalogHatEnum  a,
uint8_t  controller = 0 
)

Return the analog value from the joysticks on the controller.

Parameters:
aEither LeftHatX, LeftHatY, RightHatX or RightHatY.
controllerThe controller to read from. Default to 0.
Returns:
Returns a signed 16-bit integer.

Definition at line 438 of file XBOXRECV.cpp.

uint8_t getBatteryLevel ( uint8_t  controller = 0 )

Used to get the battery level from the controller.

Parameters:
controllerThe controller to read from. Default to 0.
Returns:
Returns the battery level as an integer in the range of 0-3.

Definition at line 467 of file XBOXRECV.cpp.

uint8_t getButtonPress ( ButtonEnum  b,
uint8_t  controller = 0 
)

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

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

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

Parameters:
bButtonEnum to read.
controllerThe controller to read from. Default to 0.
Returns:
getButtonClick(uint8_t controller, ButtonEnum b) will return a bool, while getButtonPress(uint8_t controller, ButtonEnum b) will return a byte if reading L2 or R2.

Definition at line 410 of file XBOXRECV.cpp.

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

Initialize the Xbox wireless receiver.

Parameters:
parentHub number.
portPort number on the hub.
lowspeedSpeed of the device.
Returns:
0 on success.
virtual bool isReady (  ) [virtual]

Used to check if the controller has been initialized.

Returns:
True if it's ready.

Definition at line 103 of file XBOXRECV.h.

uint8_t Poll (  )

Poll the USB Input endpoins and run the state machines.

Returns:
0 on success.

Definition at line 293 of file XBOXRECV.cpp.

uint8_t Release (  )

Release the USB device.

Returns:
0 on success.

Definition at line 283 of file XBOXRECV.cpp.

void setAllOff ( uint8_t  controller = 0 )

Turn rumble off and all the LEDs on the specific controller.

Parameters:
controllerThe controller to write to. Default to 0.

Definition at line 153 of file XBOXRECV.h.

void setLedBlink ( LEDEnum  l,
uint8_t  controller = 0 
)

Turn on a LED by using LEDEnum.

Parameters:
lALL, LED1, LED2, LED3 and LED4 is supported by the Xbox controller.
controllerThe controller to write to. Default to 0.

Definition at line 523 of file XBOXRECV.cpp.

void setLedMode ( LEDModeEnum  lm,
uint8_t  controller = 0 
)

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

Parameters:
lmSee LEDModeEnum.
controllerThe controller to write to. Default to 0.

Definition at line 527 of file XBOXRECV.cpp.

void setLedOff ( uint8_t  controller = 0 )

Turn all LEDs off the specific controller.

Parameters:
controllerThe controller to write to. Default to 0.

Definition at line 185 of file XBOXRECV.h.

void setLedOn ( LEDEnum  l,
uint8_t  controller = 0 
)

Turn on a LED by using LEDEnum.

Parameters:
lOFF, LED1, LED2, LED3 and LED4 is supported by the Xbox controller.
controllerThe controller to write to. Default to 0.

Definition at line 516 of file XBOXRECV.cpp.

void setLedRaw ( uint8_t  value,
uint8_t  controller = 0 
)

Set LED value.

Without using the LEDEnum or LEDModeEnum.

Parameters:
valueSee: setLedOff(uint8_t controller), setLedOn(uint8_t controller, LED l), setLedBlink(uint8_t controller, LED l), and setLedMode(uint8_t controller, LEDMode lm).
controllerThe controller to write to. Default to 0.

Definition at line 507 of file XBOXRECV.cpp.

void setRumbleOff ( uint8_t  controller = 0 )

Turn rumble off the specific controller.

Parameters:
controllerThe controller to write to. Default to 0.

Definition at line 162 of file XBOXRECV.h.

void setRumbleOn ( uint8_t  lValue,
uint8_t  rValue,
uint8_t  controller = 0 
)

Turn rumble on.

Parameters:
lValueLeft motor (big weight) inside the controller.
rValueRight motor (small weight) inside the controller.
controllerThe controller to write to. Default to 0.

Definition at line 557 of file XBOXRECV.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 113 of file XBOXRECV.h.


Field Documentation

uint8_t bAddress [protected]

Device address.

Definition at line 237 of file XBOXRECV.h.

EpInfo epInfo[XBOX_MAX_ENDPOINTS] [protected]

Endpoint info structure.

Definition at line 239 of file XBOXRECV.h.

Usb* pUsb [protected]

Pointer to USB class instance.

Definition at line 235 of file XBOXRECV.h.

uint8_t Xbox360Connected[4]

Variable used to indicate if the XBOX 360 controller is successfully connected.

Definition at line 231 of file XBOXRECV.h.

True if a wireless receiver is connected.

Definition at line 225 of file XBOXRECV.h.