USB Host Shield 2.0
Public Member Functions | Public Attributes | Protected Attributes | List of all members
XBOXRECV Class Reference

#include <XBOXRECV.h>

Inheritance diagram for XBOXRECV:
Inheritance graph
[legend]
Collaboration diagram for XBOXRECV:
Collaboration graph
[legend]

Public Member Functions

 XBOXRECV (USB *pUsb)
 
USBDeviceConfig implementation
uint8_t ConfigureDevice (uint8_t parent, uint8_t port, bool lowspeed)
 
uint8_t Init (uint8_t parent, uint8_t port, bool lowspeed)
 
uint8_t Release ()
 
uint8_t Poll ()
 
virtual uint8_t GetAddress ()
 
virtual bool isReady ()
 
virtual bool VIDPIDOK (uint16_t vid, uint16_t pid)
 
Xbox Controller functions
uint8_t getButtonPress (ButtonEnum b, uint8_t controller=0)
 
bool getButtonClick (ButtonEnum b, uint8_t controller=0)
 
int16_t getAnalogHat (AnalogHatEnum a, uint8_t controller=0)
 
void disconnect (uint8_t controller=0)
 
void setAllOff (uint8_t controller=0)
 
void setRumbleOff (uint8_t controller=0)
 
void setRumbleOn (uint8_t lValue, uint8_t rValue, uint8_t controller=0)
 
void setLedRaw (uint8_t value, uint8_t controller=0)
 
void setLedOff (uint8_t controller=0)
 
void setLedOn (LEDEnum l, uint8_t controller=0)
 
void setLedBlink (LEDEnum l, uint8_t controller=0)
 
void setLedMode (LEDModeEnum lm, uint8_t controller=0)
 
uint8_t getBatteryLevel (uint8_t controller=0)
 
bool buttonChanged (uint8_t controller=0)
 
void attachOnInit (void(*funcOnInit)(void))
 
- Public Member Functions inherited from USBDeviceConfig
virtual void ResetHubPort (uint8_t port)
 
virtual bool DEVCLASSOK (uint8_t klass)
 
virtual bool DEVSUBCLASSOK (uint8_t subklass)
 

Public Attributes

bool XboxReceiverConnected
 
uint8_t Xbox360Connected [4]
 

Protected Attributes

USBpUsb
 
uint8_t bAddress
 
EpInfo epInfo [XBOX_MAX_ENDPOINTS]
 

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 56 of file XBOXRECV.h.

Constructor & Destructor Documentation

◆ XBOXRECV()

XBOXRECV::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

◆ ConfigureDevice()

uint8_t XBOXRECV::ConfigureDevice ( uint8_t  parent,
uint8_t  port,
bool  lowspeed 
)
virtual

Address assignment and basic initilization is done here.

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

Reimplemented from USBDeviceConfig.

Definition at line 41 of file XBOXRECV.cpp.

◆ Init()

uint8_t XBOXRECV::Init ( uint8_t  parent,
uint8_t  port,
bool  lowspeed 
)
virtual

Initialize the Xbox wireless receiver.

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

Reimplemented from USBDeviceConfig.

Definition at line 138 of file XBOXRECV.cpp.

◆ Release()

uint8_t XBOXRECV::Release ( )
virtual

Release the USB device.

Returns
0 on success.

Reimplemented from USBDeviceConfig.

Definition at line 283 of file XBOXRECV.cpp.

◆ Poll()

uint8_t XBOXRECV::Poll ( )
virtual

Poll the USB Input endpoins and run the state machines.

Returns
0 on success.

Reimplemented from USBDeviceConfig.

Definition at line 293 of file XBOXRECV.cpp.

◆ GetAddress()

virtual uint8_t XBOXRECV::GetAddress ( )
inlinevirtual

Get the device address.

Returns
The device address.

Reimplemented from USBDeviceConfig.

Definition at line 96 of file XBOXRECV.h.

◆ isReady()

virtual bool XBOXRECV::isReady ( )
inlinevirtual

Used to check if the controller has been initialized.

Returns
True if it's ready.

Definition at line 104 of file XBOXRECV.h.

◆ VIDPIDOK()

virtual bool XBOXRECV::VIDPIDOK ( uint16_t  vid,
uint16_t  pid 
)
inlinevirtual

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.

Reimplemented from USBDeviceConfig.

Definition at line 114 of file XBOXRECV.h.

◆ getButtonPress()

uint8_t XBOXRECV::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.

◆ getButtonClick()

bool XBOXRECV::getButtonClick ( 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 419 of file XBOXRECV.cpp.

◆ getAnalogHat()

int16_t XBOXRECV::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 440 of file XBOXRECV.cpp.

◆ disconnect()

void XBOXRECV::disconnect ( uint8_t  controller = 0)

Used to disconnect any of the controllers.

Parameters
controllerThe controller to disconnect. Default to 0.

Definition at line 500 of file XBOXRECV.cpp.

◆ setAllOff()

void XBOXRECV::setAllOff ( uint8_t  controller = 0)
inline

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

Parameters
controllerThe controller to write to. Default to 0.

Definition at line 154 of file XBOXRECV.h.

◆ setRumbleOff()

void XBOXRECV::setRumbleOff ( uint8_t  controller = 0)
inline

Turn rumble off the specific controller.

Parameters
controllerThe controller to write to. Default to 0.

Definition at line 163 of file XBOXRECV.h.

◆ setRumbleOn()

void XBOXRECV::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 559 of file XBOXRECV.cpp.

◆ setLedRaw()

void XBOXRECV::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 509 of file XBOXRECV.cpp.

◆ setLedOff()

void XBOXRECV::setLedOff ( uint8_t  controller = 0)
inline

Turn all LEDs off the specific controller.

Parameters
controllerThe controller to write to. Default to 0.

Definition at line 186 of file XBOXRECV.h.

◆ setLedOn()

void XBOXRECV::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 518 of file XBOXRECV.cpp.

◆ setLedBlink()

void XBOXRECV::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 525 of file XBOXRECV.cpp.

◆ setLedMode()

void XBOXRECV::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 529 of file XBOXRECV.cpp.

◆ getBatteryLevel()

uint8_t XBOXRECV::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 469 of file XBOXRECV.cpp.

◆ buttonChanged()

bool XBOXRECV::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 444 of file XBOXRECV.cpp.

◆ attachOnInit()

void XBOXRECV::attachOnInit ( void(*)(void)  funcOnInit)
inline

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

Parameters
funcOnInitFunction to call.

Definition at line 224 of file XBOXRECV.h.

Member Data Documentation

◆ XboxReceiverConnected

bool XBOXRECV::XboxReceiverConnected

True if a wireless receiver is connected.

Definition at line 230 of file XBOXRECV.h.

◆ Xbox360Connected

uint8_t XBOXRECV::Xbox360Connected[4]

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

Definition at line 232 of file XBOXRECV.h.

◆ pUsb

USB* XBOXRECV::pUsb
protected

Pointer to USB class instance.

Definition at line 236 of file XBOXRECV.h.

◆ bAddress

uint8_t XBOXRECV::bAddress
protected

Device address.

Definition at line 238 of file XBOXRECV.h.

◆ epInfo

EpInfo XBOXRECV::epInfo[XBOX_MAX_ENDPOINTS]
protected

Endpoint info structure.

Definition at line 240 of file XBOXRECV.h.


The documentation for this class was generated from the following files: