![]() |
peripherals
1.4.2
RoadNarrows Robotics Hardware Peripherals Package
|
Xbox360 controller HID input class. More...
#include <HIDXbox360.h>
Classes | |
| struct | UsbPkt_T |
| USB application packet transfer structure. More... | |
Public Types | |
| enum | ThreadState { ThreadStateNone, ThreadStateRunning, ThreadStateExit } |
| Update thread states. More... | |
| enum | UsbPktId { UsbPktIdInput = 0, UsbPktIdRumble, UsbPktIdLED, UsbPktIdGoad, UsbPktIdNumOf } |
| USB transfer packet purpose. More... | |
Public Types inherited from rnr::HIDInput | |
| typedef std::map< int, int > | FeatMap_T |
| device feature id - mnemonic map More... | |
Public Member Functions | |
| HIDXbox360 (int usbDebugLevel=0) | |
| Default initialization constructor. More... | |
| ~HIDXbox360 () | |
| Destructor. More... | |
| virtual int | getFeatureVal (int iMnem) |
| Get the value associated with the mapped user mnemonic. More... | |
| virtual int | setFeatureVal (int iMnem, int nVal) |
| Set the value associated with the mapped user mnemonic. More... | |
| virtual int | getFeatureProp (int iMnem, HIDFeatType &eFeatType, int &nDir, int &nMin, int &nMax, int &nStep) |
| Get the feature properties. More... | |
| virtual void * | getCurrentState () |
| Get the current full state of the device. More... | |
| virtual bool | ping () |
| Ping device if it is connected and is responding. More... | |
| virtual const char * | getStrError (int nError) const |
| Get the string associated with the error number. More... | |
| virtual int | open () |
| Open connection to an USB Xbox360 controller. More... | |
| virtual int | close () |
| Close connection to an opened USB Xbox360 controller. More... | |
| virtual int | run (float hz=30.0) |
| Create and run USB update in thread. More... | |
| virtual int | stop () |
| Stop and destroy USB update thread. More... | |
| virtual int | update (uint_t uMSec=T_UPDATE_DFT) |
| Read device and update HID state. More... | |
| int | setRumble (int nLeftMot, int nRightMot) |
| Set the rumble instensity. More... | |
| int | setLED (int nPattern) |
| Set the LED pattern. More... | |
| void | calibrateJoySticks (int nLeftDeadZone, int nRightDeadZone) |
| Set joysticks calibration. More... | |
| void | setErrorThresholds (int nErrorRcvTimeoutTh=NErrorRcvTimeoutThDft, int nErrorRcvTh=NErrorRcvThDft, int nErrorTotalTh=NErrorTotalThDft) |
| Set error count thresholds. More... | |
| bool | isWireless () |
| Check if Xbox360 hardware is wireless. More... | |
| void | debugPrintHdr () |
| Simple debug print header. More... | |
| void | debugPrintState () |
| Simple debug print state. More... | |
Public Member Functions inherited from rnr::HIDInput | |
| HIDInput (HIDClass eHIDClass=HIDClassUnknown) | |
| Default initialization constructor. More... | |
| virtual | ~HIDInput () |
| Destructor. More... | |
| virtual HIDClass | getHIDClass () |
| Get the HID class. More... | |
| virtual bool | isConnected () |
| Query if HID is connected. More... | |
| virtual bool | isLinked () |
| Query if HID is linked. More... | |
| virtual int | assocFeature (int iFeatId, int iMnem) |
| Associate user mnemonic to the device feature (e.g. button) id. More... | |
| virtual bool | isFatal () const |
| Test to see if HID is in a fatal errored state. More... | |
| virtual int | getError () const |
| Get the last HID-specific error number. More... | |
| virtual std::string | getProdName () |
| Get HID product name. More... | |
Static Public Attributes | |
| static const int | UsbTransferBufSize = 32 |
| Transfer buffer maximum byte size. More... | |
| static const int | NErrorRcvTimeoutThDft = 0 |
| Consecutive receive timeouts threshold default. More... | |
| static const int | NErrorRcvThDft = 5 |
| Consecutive receive errors threshold default. More... | |
| static const int | NErrorTotalThDft = 0 |
| Total receive errors threshold default. More... | |
Static Public Attributes inherited from rnr::HIDInput | |
| static const int | MNEM_START = 1024 |
| user mapped mnemonic starting index More... | |
| static const int | T_UPDATE_DFT = 33 |
| default update timeout (msec) More... | |
Protected Member Functions | |
| virtual void | setLinkState (bool bNewState) |
| Set new link state. More... | |
| int | openXbox () |
| Open Xbox360 connection. More... | |
| int | claimXboxInterfaces () |
| Claim all Xbox USB interfaces. More... | |
| int | initTransferPkts () |
| Allocate and initialize all USB transfer packets. More... | |
| void | freeTransferPkts () |
| Free all USB transfer packets. More... | |
| int | submitReadTransfer () |
| Submit read Xbox input asynchronous transfer. More... | |
| void | flushInput () |
| Flush any pending input transfer buffers. More... | |
| void | cancelTransfers () |
| Cancel all pending USB transfers. More... | |
| void | goad () |
| Goad the Xbox360 to send a message. More... | |
| bool | parseWireless (byte_t buf[], ssize_t n) |
| Parse wireless Xbox360 input events. More... | |
| bool | parseWired (byte_t buf[], ssize_t n) |
| Parse wired Xbox360 input events. More... | |
| void | updateButtonState (byte_t msg[], ssize_t n) |
| Update the controller input button state. More... | |
| void | updateRumbleState (byte_t msg[], ssize_t n) |
| Update the rumble motors state. More... | |
| void | updateLEDState (byte_t buf[], ssize_t n) |
| Update the LED pattern state. More... | |
| void | clearErrorCnts () |
| Clear error counts. More... | |
| bool | checkErrorThresholds () |
| Check errors against thresholds. More... | |
| void | zeroState () |
| Zero controller shadowed state. More... | |
| int | updown (int nBit) |
| Convert bit value to button up/down state. More... | |
| int | convertToInt (byte_t lsb, byte_t msb) |
| Convert two bytes to signed integer. More... | |
| int | createUpdateThread () |
| Create USB update thread. More... | |
| int | cancelUpdateThread () |
| Cancel (destroy) USB update thread. More... | |
| void | lock () |
| Lock update thread. More... | |
| void | unlock () |
| Unlock the update thread. More... | |
| void | signalUpdateThread () |
| Signal update thread of change of state. More... | |
| void | blockWait () |
| Blocked timed wait. More... | |
| void | debugPrintTransferBuf (const std::string &strPreface, struct libusb_transfer *transfer) |
| Debug print USB transfer buffer contents. More... | |
| void | debugPrintTransferBuf (const std::string &strPreface, byte_t buf[], ssize_t n, const std::string &strEoR="\n") |
| Debug print USB transfer buffer contents. More... | |
Protected Member Functions inherited from rnr::HIDInput | |
| virtual void | setConnectionState (bool bNewState) |
| Set connection state. More... | |
Static Protected Member Functions | |
| static void | transferCallbackInput (struct libusb_transfer *transfer) |
| Input transfer function callback. More... | |
| static void | transferCallbackRumble (struct libusb_transfer *transfer) |
| Write rumble motor values transfer function callback. More... | |
| static void | transferCallbackLED (struct libusb_transfer *transfer) |
| Write LED pattern transfer function callback. More... | |
| static void | transferCallbackGoad (struct libusb_transfer *transfer) |
| Write packet to force a response packet from the Xbox360. More... | |
| static void * | updateThread (void *pArg) |
| The update thread. More... | |
Protected Attributes | |
| int | m_nProdId |
| Xbox USB product id. More... | |
| std::string | m_strProdName |
| product name More... | |
| std::string | m_strSerialNum |
| serial number More... | |
| int | m_nBatteryStatus |
| batter status More... | |
| int | m_nStatus |
| raw status byte More... | |
| int | m_nOffset |
| start offset in message More... | |
| int | m_nLeftJoyDeadZone |
| left joystick deadzone More... | |
| float | m_fLeftJoyM |
| left joystick slope More... | |
| float | m_fLeftJoyB |
| left joystick y intercept More... | |
| int | m_nRightJoyDeadZone |
| right joystick deadzone More... | |
| float | m_fRightJoyM |
| right joystick slope More... | |
| float | m_fRightJoyB |
| right joystick y intercept More... | |
| int | m_state [Xbox360FeatIdNumOf] |
| current state More... | |
| int | m_nLEDPattern |
| target LED pattern More... | |
| int | m_nLeftRumble |
| target left rumble intensity More... | |
| int | m_nRightRumble |
| target right rumble intensity More... | |
| int | m_nErrorRcv |
| consecutive rcv error count More... | |
| int | m_nErrorRcvTh |
| consec rcv error threshold More... | |
| int | m_nErrorRcvTimeout |
| consec rcv timeout error cnt More... | |
| int | m_nErrorRcvTimeoutTh |
| consec rcv timeout error th More... | |
| int | m_nErrorSend |
| consec send error count More... | |
| int | m_nErrorTotal |
| total error count More... | |
| int | m_nErrorTotalTh |
| total error threshold More... | |
| struct libusb_context * | m_usbContext |
| libusb session context More... | |
| struct libusb_device_handle * | m_usbHandle |
| USB open handle. More... | |
| UsbPkt_T | m_usbPkt [UsbPktIdNumOf] |
| USB transfer packets. More... | |
| ThreadState | m_eThreadState |
| update thread state More... | |
| struct timespec | m_tsThread |
| update thread period More... | |
| pthread_mutex_t | m_mutexUpdate |
| mutex More... | |
| pthread_cond_t | m_condUpdate |
| condition More... | |
| pthread_t | m_threadId |
| update pthread identifier More... | |
Protected Attributes inherited from rnr::HIDInput | |
| HIDClass | m_eHIDClass |
| actual HID class More... | |
| std::string | m_strProdName |
| product name More... | |
| bool | m_bIsConnected |
| HID is [not] physically connected. More... | |
| bool | m_bIsLinked |
| HID is [not] linked and communicating. More... | |
| int | m_nError |
| last error number (HID specific) More... | |
| bool | m_bFatal |
| HID is [not] in a fatal condition. More... | |
| FeatMap_T | m_featMap |
| feature-userid association map More... | |
Xbox360 controller HID input class.
Definition at line 651 of file HIDXbox360.h.
Update thread states.
| Enumerator | |
|---|---|
| ThreadStateNone |
no thread |
| ThreadStateRunning |
thread running |
| ThreadStateExit |
thread to exit |
Definition at line 669 of file HIDXbox360.h.
USB transfer packet purpose.
Definition at line 679 of file HIDXbox360.h.
| HIDXbox360::HIDXbox360 | ( | int | usbDebugLevel = 0 | ) |
Default initialization constructor.
Definition at line 80 of file HIDXbox360.cxx.
References calibrateJoySticks(), clearErrorCnts(), rnr::HIDXbox360::UsbPkt_T::m_bCancel, rnr::HIDInput::m_bFatal, rnr::HIDXbox360::UsbPkt_T::m_bHasSubmitted, m_condUpdate, m_eThreadState, rnr::HIDInput::m_featMap, m_mutexUpdate, m_nBatteryStatus, rnr::HIDInput::m_nError, m_nLEDPattern, m_nLeftRumble, m_nOffset, m_nProdId, m_nRightRumble, m_nStatus, m_usbContext, m_usbHandle, m_usbPkt, rnr::HIDXbox360::UsbPkt_T::m_usbTransfer, setErrorThresholds(), ThreadStateNone, UsbPktIdNumOf, XBOX360_LED_PAT_ALL_BLINK, XBOX360_LEFT_DEAD_ZONE, XBOX360_NO_PROD_ID, XBOX360_RIGHT_DEAD_ZONE, rnr::Xbox360FeatIdNumOf, rnr::Xbox360FeatIdPadUp, and zeroState().
| HIDXbox360::~HIDXbox360 | ( | ) |
Destructor.
Definition at line 141 of file HIDXbox360.cxx.
References close(), rnr::HIDInput::m_bIsConnected, m_condUpdate, m_mutexUpdate, and m_usbContext.
|
protected |
Blocked timed wait.
Definition at line 1860 of file HIDXbox360.cxx.
References lock(), m_condUpdate, m_mutexUpdate, m_tsThread, and unlock().
Referenced by unlock(), and updateThread().
| void HIDXbox360::calibrateJoySticks | ( | int | nLeftDeadZone, |
| int | nRightDeadZone | ||
| ) |
Set joysticks calibration.
For each joystick, there exist a deadzone near the center that should be treated as zero due to hardware induced noise. Each stick output is calibrated as illustrated:
* * Uncalibrated DeadZone Calibrated * | | * max - . max - . * | . | . * | . | . * | . ==> | . * | . | . * |. | . * 0 +----------|-- 0 +....------|-- * max dz max * * *
Definition at line 741 of file HIDXbox360.cxx.
References m_fLeftJoyB, m_fLeftJoyM, m_fRightJoyB, m_fRightJoyM, m_nLeftJoyDeadZone, and m_nRightJoyDeadZone.
Referenced by getStrError(), and HIDXbox360().
|
protected |
Cancel all pending USB transfers.
Definition at line 1340 of file HIDXbox360.cxx.
References rnr::HIDXbox360::UsbPkt_T::m_bCancel, m_usbPkt, update(), and UsbPktIdNumOf.
Referenced by close().
|
protected |
Cancel (destroy) USB update thread.
Definition at line 1845 of file HIDXbox360.cxx.
References m_eThreadState, m_threadId, signalUpdateThread(), and ThreadStateExit.
Referenced by stop(), and updown().
|
protected |
Check errors against thresholds.
If any of the error counts exceed their respective thresholds, then the connection state is automatically transitioned to the 'no link' state.
Definition at line 1787 of file HIDXbox360.cxx.
References rnr::HIDInput::m_bIsLinked, m_nErrorRcv, m_nErrorRcvTh, m_nErrorRcvTimeout, m_nErrorRcvTimeoutTh, m_nErrorTotal, m_nErrorTotalTh, and setLinkState().
Referenced by clearErrorCnts(), and transferCallbackInput().
|
protected |
Claim all Xbox USB interfaces.
Any any kernel claimed drivers will be detached.
On error, the appropriate < 0 negated MIRE.MIRECore error code is returned.
Definition at line 861 of file HIDXbox360.cxx.
References rnr::HIDInput::m_nError, m_nProdId, m_usbHandle, XBOX360_NUM_OF_INTERFACES, XBOX360_TETHERED_PROD_ID, and XBOX360_WIRED_PROD_ID.
Referenced by openXbox().
|
inlineprotected |
Clear error counts.
Definition at line 1133 of file HIDXbox360.h.
References checkErrorThresholds().
Referenced by HIDXbox360(), and open().
|
virtual |
Close connection to an opened USB Xbox360 controller.
All interface will be released.
On error, the appropriate < 0 negated MIRE.MIRECore error code is returned.
Implements rnr::HIDInput.
Definition at line 230 of file HIDXbox360.cxx.
References cancelTransfers(), freeTransferPkts(), rnr::HIDInput::m_bFatal, rnr::HIDInput::m_nError, m_nProdId, m_nStatus, m_state, m_strProdName, m_strSerialNum, m_usbContext, m_usbHandle, rnr::HIDInput::setConnectionState(), setLinkState(), stop(), XBOX360_NO_PROD_ID, XBOX360_NUM_OF_INTERFACES, rnr::Xbox360FeatIdLeftRumble, rnr::Xbox360FeatIdRightRumble, and zeroState().
Referenced by getStrError(), main(), open(), openXbox(), testXboxSanity(), and ~HIDXbox360().
|
protected |
Convert two bytes to signed integer.
| lsb | Least significant byte. |
| msb | Most significant byte. |
Definition at line 1773 of file HIDXbox360.cxx.
Referenced by updateButtonState(), updateRumbleState(), and updown().
|
protected |
Create USB update thread.
Definition at line 1829 of file HIDXbox360.cxx.
References m_eThreadState, m_threadId, ThreadStateRunning, and updateThread().
Referenced by run(), and updown().
| void HIDXbox360::debugPrintHdr | ( | ) |
Simple debug print header.
Definition at line 1928 of file HIDXbox360.cxx.
References m_nProdId, and m_strProdName.
Referenced by isWireless(), main(), testXboxInput(), testXboxLED(), and testXboxRumble().
| void HIDXbox360::debugPrintState | ( | ) |
Simple debug print state.
Definition at line 1940 of file HIDXbox360.cxx.
References rnr::HIDInput::m_bIsLinked, m_nBatteryStatus, m_nErrorRcv, m_nErrorRcvTimeout, m_nErrorSend, m_nErrorTotal, m_nStatus, m_state, rnr::Xbox360FeatIdAButton, rnr::Xbox360FeatIdBack, rnr::Xbox360FeatIdBButton, rnr::Xbox360FeatIdCenterX, rnr::Xbox360FeatIdLEDPat, rnr::Xbox360FeatIdLeftBump, rnr::Xbox360FeatIdLeftJoyX, rnr::Xbox360FeatIdLeftJoyY, rnr::Xbox360FeatIdLeftRumble, rnr::Xbox360FeatIdLeftStickClick, rnr::Xbox360FeatIdLeftTrigger, rnr::Xbox360FeatIdPadDown, rnr::Xbox360FeatIdPadLeft, rnr::Xbox360FeatIdPadRight, rnr::Xbox360FeatIdPadUp, rnr::Xbox360FeatIdRightBump, rnr::Xbox360FeatIdRightJoyX, rnr::Xbox360FeatIdRightJoyY, rnr::Xbox360FeatIdRightRumble, rnr::Xbox360FeatIdRightStickClick, rnr::Xbox360FeatIdRightTrigger, rnr::Xbox360FeatIdStart, rnr::Xbox360FeatIdXButton, and rnr::Xbox360FeatIdYButton.
Referenced by isWireless(), main(), testXboxInput(), testXboxLED(), and testXboxRumble().
|
inlineprotected |
Debug print USB transfer buffer contents.
| strPreface | User identifying preface string. |
| tranfer | Pointer to USB transfer buffer. |
Definition at line 1256 of file HIDXbox360.h.
|
protected |
Debug print USB transfer buffer contents.
| strPreface | User identifying preface string. |
| buf | USB data buffer. |
| n | USB data buffer length |
Definition at line 1987 of file HIDXbox360.cxx.
|
protected |
Flush any pending input transfer buffers.
Definition at line 1371 of file HIDXbox360.cxx.
References update().
Referenced by open().
|
protected |
Free all USB transfer packets.
On error, the appropriate < 0 negated MIRE.MIRECore error code is returned.
Definition at line 999 of file HIDXbox360.cxx.
References m_usbPkt, rnr::HIDXbox360::UsbPkt_T::m_usbTransfer, and UsbPktIdNumOf.
Referenced by close().
|
inlinevirtual |
Get the current full state of the device.
Reimplemented from rnr::HIDInput.
Definition at line 770 of file HIDXbox360.h.
References m_state, and ping().
|
virtual |
Get the feature properties.
| iMnem | User-specific mnemonic. | |
| [out] | eFeatType | Feature property type. |
| [out] | nDir | Feature is an input (HID_FEAT_INPUT) to host and/or an output (HID_FEAT_OUTPUT) to device. |
| [out] | nMin | Feature minimum value. |
| [out] | nMax | Feature maximum value. |
| [out] | nStep | Feature step size between [min,max] |
On error, the appropriate < 0 negated MIRE.MIRECore error code is returned.
Implements rnr::HIDInput.
Definition at line 353 of file HIDXbox360.cxx.
References HID_BTTN_DOWN, HID_BTTN_UP, HID_FEAT_INPUT, HID_FEAT_OUTPUT, rnr::HIDFeatTypeBiState, rnr::HIDFeatTypeEnum, rnr::HIDFeatTypeRange, rnr::HIDInput::m_featMap, XBOX360_LED_PAT_ALL_BLINK, XBOX360_LED_PAT_ALL_OFF, rnr::Xbox360FeatIdLEDPat, rnr::Xbox360FeatIdLeftJoyX, rnr::Xbox360FeatIdLeftJoyY, rnr::Xbox360FeatIdLeftRumble, rnr::Xbox360FeatIdLeftTrigger, rnr::Xbox360FeatIdRightJoyX, rnr::Xbox360FeatIdRightJoyY, rnr::Xbox360FeatIdRightRumble, and rnr::Xbox360FeatIdRightTrigger.
Referenced by getFeatureVal().
|
inlinevirtual |
Get the value associated with the mapped user mnemonic.
| iMnem | User-specific mnemonic. |
Implements rnr::HIDInput.
Definition at line 720 of file HIDXbox360.h.
References getFeatureProp(), rnr::HIDInput::m_featMap, m_state, and setFeatureVal().
Referenced by main(), testXboxInput(), testXboxLED(), and testXboxRumble().
|
inlinevirtual |
Get the string associated with the error number.
| nError | HID-specific error number. |
Reimplemented from rnr::HIDInput.
Definition at line 791 of file HIDXbox360.h.
References calibrateJoySticks(), close(), open(), run(), setLED(), setRumble(), stop(), rnr::HIDInput::T_UPDATE_DFT, and update().
|
protected |
Goad the Xbox360 to send a message.
Are you still linked?
Definition at line 420 of file HIDXbox360.cxx.
References rnr::HIDXbox360::UsbPkt_T::m_bHasSubmitted, rnr::HIDXbox360::UsbPkt_T::m_bufData, m_nLEDPattern, m_nProdId, m_usbPkt, rnr::HIDXbox360::UsbPkt_T::m_usbTransfer, UsbPktIdGoad, XBOX360_LED_MSG_LEN, XBOX360_LED_MSG_TYPE, XBOX360_LED_PAT_MASK, XBOX360_LED_PAT_POS, XBOX360_MSG_LEN_POS, XBOX360_MSG_TYPE_POS, XBOX360_WIRED_PROD_ID, XBOX360_WIRELESS_PROD_ID, XBOX360_WL_LED_MSG_LEN, XBOX360_WL_LED_PAT_1, XBOX360_WL_LED_PAT_2, XBOX360_WL_LED_PAT_3, XBOX360_WL_PKT_HDR_LEN, XBOX360_WL_PKT_TYPE_NORM, and XBOX360_WL_PKT_TYPE_POS.
|
protected |
Allocate and initialize all USB transfer packets.
On error, the appropriate < 0 negated MIRE.MIRECore error code is returned.
Definition at line 933 of file HIDXbox360.cxx.
References rnr::HIDXbox360::UsbPkt_T::m_bCancel, rnr::HIDXbox360::UsbPkt_T::m_bHasSubmitted, rnr::HIDInput::m_nError, m_usbHandle, m_usbPkt, rnr::HIDXbox360::UsbPkt_T::m_usbTransfer, transferCallbackGoad(), transferCallbackInput(), transferCallbackLED(), transferCallbackRumble(), UsbPktIdGoad, UsbPktIdInput, UsbPktIdLED, UsbPktIdNumOf, UsbPktIdRumble, XBOX360_READ_ENDPOINT, and XBOX360_WRITE_ENDPOINT.
Referenced by open().
|
inline |
Check if Xbox360 hardware is wireless.
Definition at line 926 of file HIDXbox360.h.
References debugPrintHdr(), debugPrintState(), m_nProdId, and XBOX360_WIRELESS_PROD_ID.
Referenced by transferCallbackInput().
|
inlineprotected |
Lock update thread.
The calling thread will block while waiting for the mutex to become available. Once locked, the update thread will block.
The lock()/unlock() primitives provide a safe mechanism to modify state.
Definition at line 1207 of file HIDXbox360.h.
Referenced by blockWait(), and update().
|
virtual |
Open connection to an USB Xbox360 controller.
The first Xbox found will be opened. All intefaces will be bound to this class instance.
On error, the appropriate < 0 negated MIRE.MIRECore error code is returned.
Implements rnr::HIDInput.
Definition at line 159 of file HIDXbox360.cxx.
References clearErrorCnts(), close(), flushInput(), initTransferPkts(), rnr::HIDInput::m_bFatal, rnr::HIDInput::m_nError, m_nLEDPattern, m_nLeftRumble, m_nProdId, m_nRightRumble, m_strProdName, m_usbContext, m_usbHandle, openXbox(), rnr::HIDInput::setConnectionState(), setLinkState(), submitReadTransfer(), XBOX360_LED_PAT_ALL_BLINK, XBOX360_WIRED_PROD_ID, XBOX360_WIRELESS_PROD_ID, and zeroState().
Referenced by getStrError(), main(), testXboxInput(), testXboxLED(), testXboxRumble(), and testXboxSanity().
|
protected |
Open Xbox360 connection.
Checks for all supported Xbox Controllers and opens the first for communication All interfaces are claimed.
On error, the appropriate < 0 negated MIRE.MIRECore error code is returned.
Definition at line 783 of file HIDXbox360.cxx.
References claimXboxInterfaces(), close(), rnr::HIDInput::m_nError, m_nOffset, m_nProdId, m_usbContext, m_usbHandle, MICROSOFT_VENDOR_ID, XBOX360_MSG_OFFSET_DFT, XBOX360_MSG_OFFSET_W, XBOX360_MSG_OFFSET_WL, XBOX360_NO_PROD_ID, XBOX360_TETHERED_PROD_ID, XBOX360_WIRED_PROD_ID, and XBOX360_WIRELESS_PROD_ID.
Referenced by open().
|
protected |
Parse wired Xbox360 input events.
| buf | Raw USB input buffer. |
| n | Length of data in buffer. |
Definition at line 1543 of file HIDXbox360.cxx.
References updateButtonState(), updateLEDState(), XBOX360_BTTN_MSG_LEN, XBOX360_BTTN_MSG_TYPE, XBOX360_LED_MSG_LEN, XBOX360_LED_MSG_TYPE, XBOX360_MSG_LEN_POS, and XBOX360_MSG_TYPE_POS.
Referenced by transferCallbackInput().
|
protected |
Parse wireless Xbox360 input events.
While executing, the Xbox controller can be unplugged. For a wireless connection, the dongle - Xbox controller can become unpaired, out-of-range, or wonking connection.
| buf | Raw USB input buffer. |
| n | Length of data in buffer. |
Definition at line 1381 of file HIDXbox360.cxx.
References rnr::HIDInput::m_bIsLinked, m_nBatteryStatus, m_nErrorRcv, m_nErrorRcvTimeout, m_nErrorTotal, m_nOffset, m_nStatus, m_strSerialNum, setLinkState(), updateButtonState(), XBOX360_BTTN_MSG_TYPE, XBOX360_MSG_TYPE_POS, XBOX360_WL_ANN_BATT_POS, XBOX360_WL_ANN_PAT_1, XBOX360_WL_ANN_PAT_2, XBOX360_WL_ANN_PAT_3, XBOX360_WL_ANN_SN_LEN, XBOX360_WL_ANN_SN_POS, XBOX360_WL_BATT_BATT_POS, XBOX360_WL_BATT_PAT_1, XBOX360_WL_BATT_PAT_2, XBOX360_WL_BATT_PAT_3, XBOX360_WL_BTTN_PAT_1, XBOX360_WL_BTTN_PAT_2, XBOX360_WL_BTTN_PAT_3, XBOX360_WL_F8_PAT_1, XBOX360_WL_F8_PAT_3, XBOX360_WL_LINK_PKT_LEN, XBOX360_WL_LINK_STATUS_CTLR, XBOX360_WL_LINK_STATUS_CTLR_HEADSET, XBOX360_WL_LINK_STATUS_HEADSET, XBOX360_WL_LINK_STATUS_NO_LINK, XBOX360_WL_LINK_STATUS_POS, XBOX360_WL_NORM_PKT_LEN, XBOX360_WL_NULL_PAT_1, XBOX360_WL_NULL_PAT_2, XBOX360_WL_NULL_PAT_3_ACK, XBOX360_WL_PKT_TYPE_CHG, XBOX360_WL_PKT_TYPE_NORM, and XBOX360_WL_PKT_TYPE_POS.
Referenced by transferCallbackInput().
|
virtual |
Ping device if it is connected and is responding.
Ping is not reliable. Always return true.
Reimplemented from rnr::HIDInput.
Definition at line 414 of file HIDXbox360.cxx.
References rnr::HIDInput::m_bIsLinked.
Referenced by getCurrentState(), and testXboxSanity().
|
virtual |
Create and run USB update in thread.
| hz | Update Hertz. |
Definition at line 292 of file HIDXbox360.cxx.
References createUpdateThread(), m_eThreadState, m_tsThread, and ThreadStateNone.
Referenced by getStrError(), and main().
|
inline |
Set error count thresholds.
| nErrorRcvTimeoutTh | Consecutive receive timeout error count threshold. Set to 0 to ignore. |
| nErrorRcvTh | Consecutive receive error count threshold. Set to 0 to ignore. |
| nErrorTotalTh | Total receive error count threshold. Set to 0 to ignore. |
Definition at line 912 of file HIDXbox360.h.
References m_nErrorRcvTh, m_nErrorRcvTimeoutTh, and m_nErrorTotalTh.
Referenced by HIDXbox360(), and main().
|
virtual |
Set the value associated with the mapped user mnemonic.
| iMnem | User-specific mnemonic. | |
| [in] | nVal | New input HID output value (e.g.LED). Meaning is specific to input. |
On error, the appropriate < 0 negated MIRE.MIRECore error code is returned.
Implements rnr::HIDInput.
Definition at line 331 of file HIDXbox360.cxx.
References rnr::HIDInput::m_featMap, m_state, setLED(), setRumble(), rnr::Xbox360FeatIdLEDPat, rnr::Xbox360FeatIdLeftRumble, and rnr::Xbox360FeatIdRightRumble.
Referenced by getFeatureVal().
| int HIDXbox360::setLED | ( | int | nPattern | ) |
Set the LED pattern.
| nPattern | LED pattern. See XBOX_LED_PAT_ALL_OFF ... |
On error, the appropriate < 0 negated MIRE.MIRECore error code is returned.
Definition at line 623 of file HIDXbox360.cxx.
References rnr::HIDXbox360::UsbPkt_T::m_bHasSubmitted, rnr::HIDInput::m_bIsLinked, rnr::HIDXbox360::UsbPkt_T::m_bufData, rnr::HIDInput::m_nError, m_nErrorSend, m_nErrorTotal, m_nLEDPattern, m_nProdId, m_usbPkt, rnr::HIDXbox360::UsbPkt_T::m_usbTransfer, UsbPktIdLED, XBOX360_LED_MSG_LEN, XBOX360_LED_MSG_TYPE, XBOX360_LED_PAT_MASK, XBOX360_LED_PAT_POS, XBOX360_MSG_LEN_POS, XBOX360_MSG_TYPE_POS, XBOX360_WIRED_PROD_ID, XBOX360_WIRELESS_PROD_ID, XBOX360_WL_LED_MSG_LEN, XBOX360_WL_LED_PAT_1, XBOX360_WL_LED_PAT_2, XBOX360_WL_LED_PAT_3, XBOX360_WL_PKT_HDR_LEN, XBOX360_WL_PKT_TYPE_NORM, and XBOX360_WL_PKT_TYPE_POS.
Referenced by getStrError(), main(), setFeatureVal(), setLinkState(), and testXboxLED().
|
protectedvirtual |
Set new link state.
| bNewState | New link state. |
Reimplemented from rnr::HIDInput.
Definition at line 759 of file HIDXbox360.cxx.
References rnr::HIDInput::m_bIsLinked, m_nLEDPattern, setLED(), rnr::HIDInput::setLinkState(), and zeroState().
Referenced by checkErrorThresholds(), close(), open(), parseWireless(), transferCallbackInput(), transferCallbackLED(), and transferCallbackRumble().
| int HIDXbox360::setRumble | ( | int | nLeftMot, |
| int | nRightMot | ||
| ) |
Set the rumble instensity.
| nLeftMot | Left, low-frequency motor [0-255]. |
| nRightMot | Right, high-frequency motor [0-255]. |
On error, the appropriate < 0 negated MIRE.MIRECore error code is returned.
Definition at line 492 of file HIDXbox360.cxx.
References rnr::HIDXbox360::UsbPkt_T::m_bHasSubmitted, rnr::HIDInput::m_bIsLinked, rnr::HIDXbox360::UsbPkt_T::m_bufData, rnr::HIDInput::m_nError, m_nErrorSend, m_nErrorTotal, m_nLeftRumble, m_nProdId, m_nRightRumble, m_usbPkt, rnr::HIDXbox360::UsbPkt_T::m_usbTransfer, UsbPktIdRumble, XBOX360_MSG_LEN_POS, XBOX360_MSG_TYPE_POS, XBOX360_RUMBLE_LEFT_MASK, XBOX360_RUMBLE_LEFT_POS, XBOX360_RUMBLE_MSG_LEN, XBOX360_RUMBLE_MSG_TYPE, XBOX360_RUMBLE_RIGHT_MASK, XBOX360_RUMBLE_RIGHT_POS, XBOX360_WIRED_PROD_ID, XBOX360_WIRELESS_PROD_ID, XBOX360_WL_PKT_HDR_LEN, XBOX360_WL_PKT_TYPE_NORM, XBOX360_WL_PKT_TYPE_POS, XBOX360_WL_RUMBLE_PAT_1, XBOX360_WL_RUMBLE_PAT_2, and XBOX360_WL_RUMBLE_PAT_3.
Referenced by getStrError(), main(), setFeatureVal(), and testXboxRumble().
|
protected |
Signal update thread of change of state.
Definition at line 1855 of file HIDXbox360.cxx.
References m_condUpdate.
Referenced by cancelUpdateThread(), and unlock().
|
virtual |
Stop and destroy USB update thread.
Definition at line 322 of file HIDXbox360.cxx.
References cancelUpdateThread(), m_eThreadState, ThreadStateNone, and unlock().
Referenced by close(), and getStrError().
|
protected |
Submit read Xbox input asynchronous transfer.
On error, the appropriate < 0 negated MIRE.MIRECore error code is returned.
Definition at line 1019 of file HIDXbox360.cxx.
References rnr::HIDXbox360::UsbPkt_T::m_bHasSubmitted, rnr::HIDInput::m_nError, m_usbPkt, and UsbPktIdInput.
Referenced by open(), and transferCallbackInput().
|
staticprotected |
Write packet to force a response packet from the Xbox360.
Note that the response is captured in the input transfer.
| transfer | USB transfer block structure. |
Definition at line 1315 of file HIDXbox360.cxx.
References rnr::HIDXbox360::UsbPkt_T::m_bHasSubmitted, m_usbPkt, and UsbPktIdGoad.
Referenced by initTransferPkts().
|
staticprotected |
Input transfer function callback.
| transfer | USB transfer block structure. |
Definition at line 1047 of file HIDXbox360.cxx.
References checkErrorThresholds(), isWireless(), rnr::HIDXbox360::UsbPkt_T::m_bHasSubmitted, rnr::HIDInput::m_bIsLinked, m_nErrorRcv, m_nErrorRcvTimeout, m_nErrorTotal, m_nProdId, m_usbPkt, parseWired(), parseWireless(), rnr::HIDInput::setConnectionState(), setLinkState(), submitReadTransfer(), UsbPktIdInput, XBOX360_WIRED_PROD_ID, and XBOX360_WIRELESS_PROD_ID.
Referenced by initTransferPkts().
|
staticprotected |
Write LED pattern transfer function callback.
| transfer | USB transfer block structure. |
Definition at line 1253 of file HIDXbox360.cxx.
References rnr::HIDXbox360::UsbPkt_T::m_bHasSubmitted, m_nErrorRcv, m_nErrorRcvTimeout, m_nErrorSend, m_nErrorTotal, m_nLEDPattern, m_state, m_usbPkt, rnr::HIDInput::setConnectionState(), setLinkState(), UsbPktIdLED, and rnr::Xbox360FeatIdLEDPat.
Referenced by initTransferPkts().
|
staticprotected |
Write rumble motor values transfer function callback.
| transfer | USB transfer block structure. |
Definition at line 1190 of file HIDXbox360.cxx.
References rnr::HIDXbox360::UsbPkt_T::m_bHasSubmitted, m_nErrorRcv, m_nErrorRcvTimeout, m_nErrorSend, m_nErrorTotal, m_nLeftRumble, m_nRightRumble, m_state, m_usbPkt, rnr::HIDInput::setConnectionState(), setLinkState(), UsbPktIdRumble, rnr::Xbox360FeatIdLeftRumble, and rnr::Xbox360FeatIdRightRumble.
Referenced by initTransferPkts().
|
inlineprotected |
Unlock the update thread.
The update() will be available to execute.
Definition at line 1220 of file HIDXbox360.h.
References blockWait(), signalUpdateThread(), and updateThread().
Referenced by blockWait(), stop(), and update().
|
virtual |
Read device and update HID state.
| uMSec | Block wait at most the given milliseconds for events. If zero, then update() will handle any already-pending events and then immediately return (non-blocking). Otherwise, if no events are currently pending, update() will block waiting for events for up to the specified timeout. If an event arrives update() will return early. |
Implements rnr::HIDInput.
Definition at line 1867 of file HIDXbox360.cxx.
References lock(), rnr::HIDInput::m_bIsConnected, rnr::HIDInput::m_nError, m_usbContext, and unlock().
Referenced by cancelTransfers(), flushInput(), getStrError(), testXboxInput(), testXboxLED(), testXboxRumble(), and updateThread().
|
protected |
Update the controller input button state.
| msg | Message containing raw controller state data. |
| n | Length of data in message. |
Definition at line 1577 of file HIDXbox360.cxx.
References convertToInt(), m_fLeftJoyB, m_fLeftJoyM, m_fRightJoyB, m_fRightJoyM, m_nLeftJoyDeadZone, m_nRightJoyDeadZone, m_state, updown(), XBOX360_BTTN_A_BUTTON_MASK, XBOX360_BTTN_A_BUTTON_POS, XBOX360_BTTN_B_BUTTON_MASK, XBOX360_BTTN_B_BUTTON_POS, XBOX360_BTTN_BACK_MASK, XBOX360_BTTN_BACK_POS, XBOX360_BTTN_CENTER_X_MASK, XBOX360_BTTN_CENTER_X_POS, XBOX360_BTTN_LEFT_BUMP_MASK, XBOX360_BTTN_LEFT_BUMP_POS, XBOX360_BTTN_LEFT_STICK_CLICK_MASK, XBOX360_BTTN_LEFT_STICK_CLICK_POS, XBOX360_BTTN_LEFT_TRIGGER_POS, XBOX360_BTTN_LEFT_X_POS_H, XBOX360_BTTN_LEFT_X_POS_L, XBOX360_BTTN_LEFT_Y_POS_H, XBOX360_BTTN_LEFT_Y_POS_L, XBOX360_BTTN_PAD_DOWN_MASK, XBOX360_BTTN_PAD_DOWN_POS, XBOX360_BTTN_PAD_LEFT_MASK, XBOX360_BTTN_PAD_LEFT_POS, XBOX360_BTTN_PAD_RIGHT_MASK, XBOX360_BTTN_PAD_RIGHT_POS, XBOX360_BTTN_PAD_UP_MASK, XBOX360_BTTN_PAD_UP_POS, XBOX360_BTTN_RIGHT_BUMP_MASK, XBOX360_BTTN_RIGHT_BUMP_POS, XBOX360_BTTN_RIGHT_STICK_CLICK_MASK, XBOX360_BTTN_RIGHT_STICK_CLICK_POS, XBOX360_BTTN_RIGHT_TRIGGER_POS, XBOX360_BTTN_RIGHT_X_POS_H, XBOX360_BTTN_RIGHT_X_POS_L, XBOX360_BTTN_RIGHT_Y_POS_H, XBOX360_BTTN_RIGHT_Y_POS_L, XBOX360_BTTN_START_MASK, XBOX360_BTTN_START_POS, XBOX360_BTTN_X_BUTTON_MASK, XBOX360_BTTN_X_BUTTON_POS, XBOX360_BTTN_Y_BUTTON_MASK, XBOX360_BTTN_Y_BUTTON_POS, XBOX360_MSG_LEN_POS, rnr::Xbox360FeatIdAButton, rnr::Xbox360FeatIdBack, rnr::Xbox360FeatIdBButton, rnr::Xbox360FeatIdCenterX, rnr::Xbox360FeatIdLeftBump, rnr::Xbox360FeatIdLeftJoyX, rnr::Xbox360FeatIdLeftJoyY, rnr::Xbox360FeatIdLeftStickClick, rnr::Xbox360FeatIdLeftTrigger, rnr::Xbox360FeatIdPadDown, rnr::Xbox360FeatIdPadLeft, rnr::Xbox360FeatIdPadRight, rnr::Xbox360FeatIdPadUp, rnr::Xbox360FeatIdRightBump, rnr::Xbox360FeatIdRightJoyX, rnr::Xbox360FeatIdRightJoyY, rnr::Xbox360FeatIdRightStickClick, rnr::Xbox360FeatIdRightTrigger, rnr::Xbox360FeatIdStart, rnr::Xbox360FeatIdXButton, and rnr::Xbox360FeatIdYButton.
Referenced by parseWired(), and parseWireless().
|
protected |
Update the LED pattern state.
| buf | Raw USB input buffer. |
| n | Length of data in buffer. |
Definition at line 1749 of file HIDXbox360.cxx.
References m_nProdId, m_state, XBOX360_LED_MSG_LEN, XBOX360_LED_PAT_MASK, XBOX360_LED_PAT_POS, XBOX360_MSG_OFFSET_WL, XBOX360_WIRED_PROD_ID, XBOX360_WIRELESS_PROD_ID, XBOX360_WL_LED_PAT_POS, and rnr::Xbox360FeatIdLEDPat.
Referenced by parseWired().
|
protected |
Update the rumble motors state.
| msg | Message containing raw controller status data. |
| n | Length of data in message. |
Definition at line 1726 of file HIDXbox360.cxx.
References convertToInt(), m_nProdId, m_state, XBOX360_RUMBLE_LEFT_POS, XBOX360_RUMBLE_MSG_LEN, XBOX360_RUMBLE_RIGHT_POS, XBOX360_WIRED_PROD_ID, XBOX360_WIRELESS_PROD_ID, rnr::Xbox360FeatIdLeftRumble, and rnr::Xbox360FeatIdRightRumble.
|
staticprotected |
The update thread.
| pArg | Point to this class instance. |
Definition at line 1895 of file HIDXbox360.cxx.
References blockWait(), rnr::HIDInput::isConnected(), m_eThreadState, ThreadStateExit, ThreadStateNone, ThreadStateRunning, and update().
Referenced by createUpdateThread(), and unlock().
|
inlineprotected |
Convert bit value to button up/down state.
| nBit | Bit value. |
Definition at line 1167 of file HIDXbox360.h.
References cancelUpdateThread(), convertToInt(), createUpdateThread(), HID_BTTN_DOWN, and HID_BTTN_UP.
Referenced by updateButtonState().
|
inlineprotected |
Zero controller shadowed state.
Definition at line 1155 of file HIDXbox360.h.
Referenced by close(), HIDXbox360(), open(), and setLinkState().
|
protected |
condition
Definition at line 983 of file HIDXbox360.h.
Referenced by blockWait(), HIDXbox360(), signalUpdateThread(), and ~HIDXbox360().
|
protected |
update thread state
Definition at line 980 of file HIDXbox360.h.
Referenced by cancelUpdateThread(), createUpdateThread(), HIDXbox360(), run(), stop(), and updateThread().
|
protected |
left joystick y intercept
Definition at line 954 of file HIDXbox360.h.
Referenced by calibrateJoySticks(), and updateButtonState().
|
protected |
left joystick slope
Definition at line 953 of file HIDXbox360.h.
Referenced by calibrateJoySticks(), and updateButtonState().
|
protected |
right joystick y intercept
Definition at line 957 of file HIDXbox360.h.
Referenced by calibrateJoySticks(), and updateButtonState().
|
protected |
right joystick slope
Definition at line 956 of file HIDXbox360.h.
Referenced by calibrateJoySticks(), and updateButtonState().
|
protected |
mutex
Definition at line 982 of file HIDXbox360.h.
Referenced by blockWait(), HIDXbox360(), and ~HIDXbox360().
|
protected |
batter status
Definition at line 947 of file HIDXbox360.h.
Referenced by debugPrintState(), HIDXbox360(), and parseWireless().
|
protected |
consecutive rcv error count
Definition at line 966 of file HIDXbox360.h.
Referenced by checkErrorThresholds(), debugPrintState(), parseWireless(), transferCallbackInput(), transferCallbackLED(), and transferCallbackRumble().
|
protected |
consec rcv error threshold
Definition at line 967 of file HIDXbox360.h.
Referenced by checkErrorThresholds(), and setErrorThresholds().
|
protected |
consec rcv timeout error cnt
Definition at line 968 of file HIDXbox360.h.
Referenced by checkErrorThresholds(), debugPrintState(), parseWireless(), transferCallbackInput(), transferCallbackLED(), and transferCallbackRumble().
|
protected |
consec rcv timeout error th
Definition at line 969 of file HIDXbox360.h.
Referenced by checkErrorThresholds(), and setErrorThresholds().
|
protected |
consec send error count
Definition at line 970 of file HIDXbox360.h.
Referenced by debugPrintState(), setLED(), setRumble(), transferCallbackLED(), and transferCallbackRumble().
|
protected |
total error count
Definition at line 971 of file HIDXbox360.h.
Referenced by checkErrorThresholds(), debugPrintState(), parseWireless(), setLED(), setRumble(), transferCallbackInput(), transferCallbackLED(), and transferCallbackRumble().
|
protected |
total error threshold
Definition at line 972 of file HIDXbox360.h.
Referenced by checkErrorThresholds(), and setErrorThresholds().
|
protected |
target LED pattern
Definition at line 961 of file HIDXbox360.h.
Referenced by goad(), HIDXbox360(), open(), setLED(), setLinkState(), and transferCallbackLED().
|
protected |
left joystick deadzone
Definition at line 952 of file HIDXbox360.h.
Referenced by calibrateJoySticks(), and updateButtonState().
|
protected |
target left rumble intensity
Definition at line 962 of file HIDXbox360.h.
Referenced by HIDXbox360(), open(), setRumble(), and transferCallbackRumble().
|
protected |
start offset in message
Definition at line 949 of file HIDXbox360.h.
Referenced by HIDXbox360(), openXbox(), and parseWireless().
|
protected |
Xbox USB product id.
Definition at line 944 of file HIDXbox360.h.
Referenced by claimXboxInterfaces(), close(), debugPrintHdr(), goad(), HIDXbox360(), isWireless(), open(), openXbox(), setLED(), setRumble(), transferCallbackInput(), updateLEDState(), and updateRumbleState().
|
protected |
right joystick deadzone
Definition at line 955 of file HIDXbox360.h.
Referenced by calibrateJoySticks(), and updateButtonState().
|
protected |
target right rumble intensity
Definition at line 963 of file HIDXbox360.h.
Referenced by HIDXbox360(), open(), setRumble(), and transferCallbackRumble().
|
protected |
raw status byte
Definition at line 948 of file HIDXbox360.h.
Referenced by close(), debugPrintState(), HIDXbox360(), and parseWireless().
|
protected |
current state
Definition at line 960 of file HIDXbox360.h.
Referenced by close(), debugPrintState(), getCurrentState(), getFeatureVal(), setFeatureVal(), transferCallbackLED(), transferCallbackRumble(), updateButtonState(), updateLEDState(), and updateRumbleState().
|
protected |
product name
Definition at line 945 of file HIDXbox360.h.
Referenced by close(), debugPrintHdr(), and open().
|
protected |
serial number
Definition at line 946 of file HIDXbox360.h.
Referenced by close(), and parseWireless().
|
protected |
update pthread identifier
Definition at line 984 of file HIDXbox360.h.
Referenced by cancelUpdateThread(), and createUpdateThread().
|
protected |
update thread period
Definition at line 981 of file HIDXbox360.h.
Referenced by blockWait(), and run().
|
protected |
libusb session context
Definition at line 975 of file HIDXbox360.h.
Referenced by close(), HIDXbox360(), open(), openXbox(), update(), and ~HIDXbox360().
|
protected |
USB open handle.
Definition at line 976 of file HIDXbox360.h.
Referenced by claimXboxInterfaces(), close(), HIDXbox360(), initTransferPkts(), open(), and openXbox().
|
protected |
USB transfer packets.
Definition at line 977 of file HIDXbox360.h.
Referenced by cancelTransfers(), freeTransferPkts(), goad(), HIDXbox360(), initTransferPkts(), setLED(), setRumble(), submitReadTransfer(), transferCallbackGoad(), transferCallbackInput(), transferCallbackLED(), and transferCallbackRumble().
|
static |
Consecutive receive errors threshold default.
Definition at line 661 of file HIDXbox360.h.
|
static |
Consecutive receive timeouts threshold default.
Definition at line 658 of file HIDXbox360.h.
|
static |
Total receive errors threshold default.
Definition at line 664 of file HIDXbox360.h.
|
static |
Transfer buffer maximum byte size.
Definition at line 655 of file HIDXbox360.h.