Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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:
-
pUsb Pointer to USB class instance.
Definition at line 23 of file XBOXUSB.cpp.
Member Function Documentation
| void attachOnInit | ( | void(*)(void) | funcOnInit ) |
| virtual uint8_t GetAddress | ( | ) | [virtual] |
| int16_t getAnalogHat | ( | AnalogHatEnum | a ) |
Return the analog value from the joysticks on the controller.
- Parameters:
-
a Either 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:
-
b ButtonEnum 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:
-
parent Hub number. port Port number on the hub. lowspeed Speed of the device.
- Returns:
- 0 on success.
Definition at line 39 of file XBOXUSB.cpp.
| virtual bool isReady | ( | ) | [virtual] |
| 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 | ( | ) |
| void setAllOff | ( | ) |
| void setLedBlink | ( | LEDEnum | l ) |
Turn on a LED by using LEDEnum.
- Parameters:
-
l ALL, 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:
-
lm See LEDModeEnum.
Definition at line 340 of file XBOXUSB.cpp.
| void setLedOn | ( | LEDEnum | l ) |
Turn on a LED by using LEDEnum.
- Parameters:
-
l OFF, 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:
-
value See: setLedOff(), setLedOn(LEDEnum l), setLedBlink(LEDEnum l), and setLedMode(LEDModeEnum lm).
Definition at line 321 of file XBOXUSB.cpp.
| void setRumbleOn | ( | uint8_t | lValue, |
| uint8_t | rValue | ||
| ) |
Turn rumble on.
- Parameters:
-
lValue Left motor (big weight) inside the controller. rValue Right motor (small weight) inside the controller.
Definition at line 344 of file XBOXUSB.cpp.
| virtual bool VIDPIDOK | ( | uint16_t | vid, |
| uint16_t | pid | ||
| ) | [virtual] |
Field Documentation
EpInfo epInfo[XBOX_MAX_ENDPOINTS] [protected] |
| bool Xbox360Connected |
Generated on Thu Jul 14 2022 08:33:41 by
1.7.2