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

#include <XBOXUSB.h>

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

Public Member Functions

 XBOXUSB (USB *pUsb)
 
USBDeviceConfig implementation
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)
 
bool getButtonClick (ButtonEnum b)
 
int16_t getAnalogHat (AnalogHatEnum a)
 
void setAllOff ()
 
void setRumbleOff ()
 
void setRumbleOn (uint8_t lValue, uint8_t rValue)
 
void setLedRaw (uint8_t value)
 
void setLedOff ()
 
void setLedOn (LEDEnum l)
 
void setLedBlink (LEDEnum l)
 
void setLedMode (LEDModeEnum lm)
 
void attachOnInit (void(*funcOnInit)(void))
 
- Public Member Functions inherited from USBDeviceConfig
virtual uint8_t ConfigureDevice (uint8_t parent, uint8_t port, bool lowspeed)
 
virtual void ResetHubPort (uint8_t port)
 
virtual bool DEVCLASSOK (uint8_t klass)
 
virtual bool DEVSUBCLASSOK (uint8_t subklass)
 

Public Attributes

bool Xbox360Connected
 

Protected Attributes

USBpUsb
 
uint8_t bAddress
 
EpInfo epInfo [XBOX_MAX_ENDPOINTS]
 

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()

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

◆ Init()

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

Reimplemented from USBDeviceConfig.

Definition at line 39 of file XBOXUSB.cpp.

◆ Release()

uint8_t XBOXUSB::Release ( )
virtual

Release the USB device.

Returns
0 on success.

Reimplemented from USBDeviceConfig.

Definition at line 224 of file XBOXUSB.cpp.

◆ Poll()

uint8_t XBOXUSB::Poll ( )
virtual

Poll the USB Input endpoins and run the state machines.

Returns
0 on success.

Reimplemented from USBDeviceConfig.

Definition at line 232 of file XBOXUSB.cpp.

◆ GetAddress()

virtual uint8_t XBOXUSB::GetAddress ( )
inlinevirtual

Get the device address.

Returns
The device address.

Reimplemented from USBDeviceConfig.

Definition at line 85 of file XBOXUSB.h.

◆ isReady()

virtual bool XBOXUSB::isReady ( )
inlinevirtual

Used to check if the controller has been initialized.

Returns
True if it's ready.

Definition at line 93 of file XBOXUSB.h.

◆ VIDPIDOK()

virtual bool XBOXUSB::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 103 of file XBOXUSB.h.

◆ getButtonPress()

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

◆ getButtonClick()

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

◆ getAnalogHat()

int16_t XBOXUSB::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 313 of file XBOXUSB.cpp.

◆ setAllOff()

void XBOXUSB::setAllOff ( )
inline

Turn rumble off and all the LEDs on the controller.

Definition at line 132 of file XBOXUSB.h.

◆ setRumbleOff()

void XBOXUSB::setRumbleOff ( )
inline

Turn rumble off the controller.

Definition at line 138 of file XBOXUSB.h.

◆ setRumbleOn()

void XBOXUSB::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 346 of file XBOXUSB.cpp.

◆ setLedRaw()

void XBOXUSB::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 323 of file XBOXUSB.cpp.

◆ setLedOff()

void XBOXUSB::setLedOff ( )
inline

Turn all LEDs off the controller.

Definition at line 156 of file XBOXUSB.h.

◆ setLedOn()

void XBOXUSB::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 331 of file XBOXUSB.cpp.

◆ setLedBlink()

void XBOXUSB::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 338 of file XBOXUSB.cpp.

◆ setLedMode()

void XBOXUSB::setLedMode ( LEDModeEnum  lm)

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

Parameters
lmSee LEDModeEnum.

Definition at line 342 of file XBOXUSB.cpp.

◆ attachOnInit()

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

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

Parameters
funcOnInitFunction to call.

Definition at line 179 of file XBOXUSB.h.

Member Data Documentation

◆ Xbox360Connected

bool XBOXUSB::Xbox360Connected

True if a Xbox 360 controller is connected.

Definition at line 185 of file XBOXUSB.h.

◆ pUsb

USB* XBOXUSB::pUsb
protected

Pointer to USB class instance.

Definition at line 189 of file XBOXUSB.h.

◆ bAddress

uint8_t XBOXUSB::bAddress
protected

Device address.

Definition at line 191 of file XBOXUSB.h.

◆ epInfo

EpInfo XBOXUSB::epInfo[XBOX_MAX_ENDPOINTS]
protected

Endpoint info structure.

Definition at line 193 of file XBOXUSB.h.


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