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

#include <XBOXOLD.h>

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

Public Member Functions

 XBOXOLD (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 ()
 
uint8_t readPollInterval ()
 
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 setRumbleOff ()
 
void setRumbleOn (uint8_t lValue, uint8_t rValue)
 
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 XboxConnected
 

Protected Member Functions

void PrintEndpointDescriptor (const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
 
UsbConfigXtracter implementation
void EndpointXtract (uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
 

Protected Attributes

USBpUsb
 
uint8_t bAddress
 
EpInfo epInfo [XBOX_MAX_ENDPOINTS]
 
uint8_t bConfNum
 
uint8_t bNumEP
 
uint32_t qNextPollTime
 

Detailed Description

This class implements support for a the original Xbox controller via USB.

Definition at line 48 of file XBOXOLD.h.

Constructor & Destructor Documentation

◆ XBOXOLD()

XBOXOLD::XBOXOLD ( USB pUsb)

Constructor for the XBOXOLD class.

Parameters
pUsbPointer to USB class instance.

Definition at line 47 of file XBOXOLD.cpp.

Member Function Documentation

◆ Init()

uint8_t XBOXOLD::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 66 of file XBOXOLD.cpp.

◆ Release()

uint8_t XBOXOLD::Release ( )
virtual

Release the USB device.

Returns
0 on success.

Reimplemented from USBDeviceConfig.

Definition at line 300 of file XBOXOLD.cpp.

◆ Poll()

uint8_t XBOXOLD::Poll ( )
virtual

Poll the USB Input endpoins and run the state machines.

Returns
0 on success.

Reimplemented from USBDeviceConfig.

Definition at line 314 of file XBOXOLD.cpp.

◆ GetAddress()

virtual uint8_t XBOXOLD::GetAddress ( )
inlinevirtual

Get the device address.

Returns
The device address.

Reimplemented from USBDeviceConfig.

Definition at line 80 of file XBOXOLD.h.

◆ isReady()

virtual bool XBOXOLD::isReady ( )
inlinevirtual

Used to check if the controller has been initialized.

Returns
True if it's ready.

Definition at line 88 of file XBOXOLD.h.

◆ readPollInterval()

uint8_t XBOXOLD::readPollInterval ( )
inline

Read the poll interval taken from the endpoint descriptors.

Returns
The poll interval in ms.

Definition at line 96 of file XBOXOLD.h.

◆ VIDPIDOK()

virtual bool XBOXOLD::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 106 of file XBOXOLD.h.

◆ getButtonPress()

uint8_t XBOXOLD::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 431 of file XBOXOLD.cpp.

◆ getButtonClick()

bool XBOXOLD::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 445 of file XBOXOLD.cpp.

◆ getAnalogHat()

int16_t XBOXOLD::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 465 of file XBOXOLD.cpp.

◆ setRumbleOff()

void XBOXOLD::setRumbleOff ( )
inline

Turn rumble off the controller.

Definition at line 135 of file XBOXOLD.h.

◆ setRumbleOn()

void XBOXOLD::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 475 of file XBOXOLD.cpp.

◆ attachOnInit()

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

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

Parameters
funcOnInitFunction to call.

Definition at line 149 of file XBOXOLD.h.

◆ EndpointXtract()

void XBOXOLD::EndpointXtract ( uint8_t  conf,
uint8_t  iface,
uint8_t  alt,
uint8_t  proto,
const USB_ENDPOINT_DESCRIPTOR ep 
)
protectedvirtual

UsbConfigXtracter implementation, used to extract endpoint information.

Parameters
confConfiguration value.
ifaceInterface number.
altAlternate setting.
protoInterface Protocol.
epEndpoint Descriptor.

Reimplemented from UsbConfigXtracter.

Definition at line 254 of file XBOXOLD.cpp.

◆ PrintEndpointDescriptor()

void XBOXOLD::PrintEndpointDescriptor ( const USB_ENDPOINT_DESCRIPTOR ep_ptr)
protected

Used to print the USB Endpoint Descriptor.

Parameters
ep_ptrPointer to USB Endpoint Descriptor.

Definition at line 279 of file XBOXOLD.cpp.

Member Data Documentation

◆ XboxConnected

bool XBOXOLD::XboxConnected

True if a Xbox controller is connected.

Definition at line 155 of file XBOXOLD.h.

◆ pUsb

USB* XBOXOLD::pUsb
protected

Pointer to USB class instance.

Definition at line 159 of file XBOXOLD.h.

◆ bAddress

uint8_t XBOXOLD::bAddress
protected

Device address.

Definition at line 161 of file XBOXOLD.h.

◆ epInfo

EpInfo XBOXOLD::epInfo[XBOX_MAX_ENDPOINTS]
protected

Endpoint info structure.

Definition at line 163 of file XBOXOLD.h.

◆ bConfNum

uint8_t XBOXOLD::bConfNum
protected

Configuration number.

Definition at line 166 of file XBOXOLD.h.

◆ bNumEP

uint8_t XBOXOLD::bNumEP
protected

Total number of endpoints in the configuration.

Definition at line 168 of file XBOXOLD.h.

◆ qNextPollTime

uint32_t XBOXOLD::qNextPollTime
protected

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

Definition at line 170 of file XBOXOLD.h.


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