19 #define DEBUG // Uncomment to print data for debugging
49 Notify(PSTR(
"\r\nXBOXUSB Init"), 0x80);
54 Notify(PSTR(
"\r\nAddress in use"), 0x80);
64 Notify(PSTR(
"\r\nAddress not found"), 0x80);
71 Notify(PSTR(
"\r\nepinfo is null"), 0x80);
96 goto FailUnknownDevice;
99 Notify(PSTR(
"\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication"), 0x80);
101 goto FailUnknownDevice;
104 Notify(PSTR(
"\r\nThis library only supports Xbox 360 controllers via USB"), 0x80);
106 goto FailUnknownDevice;
125 Notify(PSTR(
"\r\nsetAddr: "), 0x80);
127 PrintHex<uint8_t > (rcode, 0x80);
131 Notify(PSTR(
"\r\nAddr: "), 0x80);
132 PrintHex<uint8_t > (
bAddress, 0x80);
146 goto FailSetDevTblEntry;
168 goto FailSetDevTblEntry;
174 goto FailSetConfDescr;
177 Notify(PSTR(
"\r\nXbox 360 Controller Connected\r\n"), 0x80);
202 Notify(PSTR(
"\r\nXbox 360 Init Failed, error code: "), 0x80);
230 void XBOXUSB::readReport() {
233 if (readBuf[0] != 0x00 || readBuf[1] != 0x14) {
237 ButtonState = (uint32_t)(readBuf[5] | ((uint16_t)readBuf[4] << 8) | ((uint32_t)readBuf[3] << 16) | ((uint32_t)readBuf[2] << 24));
239 hatValue[
LeftHatX] = (int16_t)(((uint16_t)readBuf[7] << 8) | readBuf[6]);
240 hatValue[
LeftHatY] = (int16_t)(((uint16_t)readBuf[9] << 8) | readBuf[8]);
241 hatValue[
RightHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
242 hatValue[
RightHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
247 if (ButtonState != OldButtonState) {
248 ButtonClickState = (ButtonState >> 16) & ((~OldButtonState) >> 16);
249 if (((uint8_t)OldButtonState) == 0 && ((uint8_t)ButtonState) != 0)
251 if ((uint8_t)(OldButtonState >> 8) == 0 && (uint8_t)(ButtonState >> 8) != 0)
253 OldButtonState = ButtonState;
257 void XBOXUSB::printReport() {
262 PrintHex<uint8_t > (readBuf[i], 0x80);
265 Notify(PSTR(
"\r\n"), 0x80);
271 return (uint8_t)(ButtonState >> 8);
273 return (uint8_t)ButtonState;
274 return (ButtonState & ((uint32_t)pgm_read_word(&
XBOXBUTTONS[(uint8_t)b]) << 16));
284 }
else if (b ==
R2) {
291 uint16_t button = pgm_read_word(&
XBOXBUTTONS[(uint8_t)b]);
292 bool click = (ButtonClickState & button);
293 ButtonClickState &= ~button;
302 void XBOXUSB::XboxCommand(uint8_t* data, uint16_t nbytes) {
304 pUsb->
ctrlReq(
bAddress,
epInfo[
XBOX_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL);
312 XboxCommand(writeBuf, 3);
332 writeBuf[3] = lValue;
333 writeBuf[4] = rValue;
338 XboxCommand(writeBuf, 8);