Added error check for wireless controllers and wireless receivers

This commit is contained in:
Kristian Lauszus 2012-07-18 19:27:26 +02:00
parent 9d49f803fa
commit 3c14815f9b
2 changed files with 20 additions and 4 deletions

View file

@ -40,6 +40,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
uint8_t rcode; uint8_t rcode;
UsbDevice *p = NULL; UsbDevice *p = NULL;
EpInfo *oldep_ptr = NULL; EpInfo *oldep_ptr = NULL;
uint16_t PID;
uint16_t VID; uint16_t VID;
// get memory address of USB device address pool // get memory address of USB device address pool
@ -133,8 +134,22 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
goto FailSetDevTblEntry; goto FailSetDevTblEntry;
VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor; VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor;
PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
if(VID == XBOX_VID) { // We just check if it's a xbox controller using the Vendor ID if(VID == XBOX_VID) { // We just check if it's a xbox controller using the Vendor ID
if(PID == XBOX_WIRELESS_PID) {
#ifdef DEBUG
Notify(PSTR("\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication"));
#endif
return 0;
}
else if(PID == XBOX_WIRELESS_RECEIVER_PID || PID == XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) {
#ifdef DEBUG
Notify(PSTR("\r\nThis library only supports Xbox 360 controllers via USB"));
#endif
return 0;
}
/* The application will work in reduced host mode, so we can save program and data /* The application will work in reduced host mode, so we can save program and data
memory space. After verifying the VID we will use known values for the memory space. After verifying the VID we will use known values for the
configuration values for device, interface, endpoints and HID for the XBOX360 Controllers */ configuration values for device, interface, endpoints and HID for the XBOX360 Controllers */
@ -199,7 +214,7 @@ FailUnknownDevice:
Notify(PSTR("\r\nUnknown Device Connected - VID: ")); Notify(PSTR("\r\nUnknown Device Connected - VID: "));
PrintHex<uint16_t>(VID); PrintHex<uint16_t>(VID);
Notify(PSTR(" PID: ")); Notify(PSTR(" PID: "));
PrintHex<uint16_t>(((USB_DEVICE_DESCRIPTOR*)buf)->idProduct); PrintHex<uint16_t>(PID);
#endif #endif
goto Fail; goto Fail;
Fail: Fail:
@ -235,8 +250,6 @@ void XBOXUSB::readReport() {
if (readBuf == NULL) if (readBuf == NULL)
return; return;
if(readBuf[0] != 0x00 || readBuf[1] != 0x14) { // Check if it's the correct report - the controller also sends different status reports if(readBuf[0] != 0x00 || readBuf[1] != 0x14) { // Check if it's the correct report - the controller also sends different status reports
/*for(int i = 0; i < EP_MAXPKTSIZE; i++)
readBuf[i] = 0;*/
return; return;
} }

View file

@ -38,7 +38,10 @@
#define XBOX_OUTPUT_PIPE 2 #define XBOX_OUTPUT_PIPE 2
//PID and VID of the different devices //PID and VID of the different devices
#define XBOX_VID 0x045E // Microsoft Corporation #define XBOX_VID 0x045E // Microsoft Corporation
#define XBOX_WIRELESS_PID 0x028F // Wireless controller only support charging
#define XBOX_WIRELESS_RECEIVER_PID 0x0719 // Microsoft Wireless Gaming Receiver
#define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID 0x0291 // Third party Wireless Gaming Receiver
#define XBOX_REPORT_BUFFER_SIZE 14 // Size of the input report buffer #define XBOX_REPORT_BUFFER_SIZE 14 // Size of the input report buffer