51 Notify(PSTR(
"\r\nXBOXRECV Init"), 0x80);
56 Notify(PSTR(
"\r\nAddress in use"), 0x80);
66 Notify(PSTR(
"\r\nAddress not found"), 0x80);
73 Notify(PSTR(
"\r\nepinfo is null"), 0x80);
98 goto FailUnknownDevice;
100 #ifdef DEBUG_USB_HOST
101 Notify(PSTR(
"\r\nYou'll need a wireless receiver for this libary to work"), 0x80);
103 goto FailUnknownDevice;
121 #ifdef DEBUG_USB_HOST
122 Notify(PSTR(
"\r\nsetAddr: "), 0x80);
123 D_PrintHex<uint8_t > (rcode, 0x80);
128 Notify(PSTR(
"\r\nAddr: "), 0x80);
129 D_PrintHex<uint8_t > (
bAddress, 0x80);
143 goto FailSetDevTblEntry;
204 goto FailSetDevTblEntry;
210 goto FailSetConfDescr;
212 #ifdef DEBUG_USB_HOST
213 Notify(PSTR(
"\r\nXbox Wireless Receiver Connected\r\n"), 0x80);
221 #ifdef DEBUG_USB_HOST
227 #ifdef DEBUG_USB_HOST
233 #ifdef DEBUG_USB_HOST
239 #ifdef DEBUG_USB_HOST
245 #ifdef DEBUG_USB_HOST
246 Notify(PSTR(
"\r\nXbox 360 Init Failed, error code: "), 0x80);
256 for (uint8_t i = 0; i < 4; i++)
267 if (!timer || ((millis() - timer) > 3000)) {
273 for (uint8_t i = 0; i < 4; i++) {
286 if (bufferSize > 0) {
288 Notify(PSTR(
"Bytes Received: "), 0x80);
289 D_PrintHex<uint16_t > (bufferSize, 0x80);
290 Notify(PSTR(
"\r\n"), 0x80);
294 printReport(i, bufferSize);
301 void XBOXRECV::readReport(uint8_t controller) {
307 #ifdef DEBUG_USB_HOST
308 Notify(PSTR(
"Controller "), 0x80);
312 #ifdef DEBUG_USB_HOST
314 switch (readBuf[1]) {
315 case 0x80: str = PSTR(
" as controller\r\n");
317 case 0x40: str = PSTR(
" as headset\r\n");
319 case 0xC0: str = PSTR(
" as controller+headset\r\n");
322 Notify(PSTR(
": connected"), 0x80);
326 switch (controller) {
338 #ifdef DEBUG_USB_HOST
340 Notify(PSTR(
": disconnected\r\n"), 0x80);
345 if (readBuf[1] == 0x00 && readBuf[3] & 0x13 && readBuf[4] >= 0x22) {
346 controllerStatus[controller] = ((uint16_t)readBuf[3] << 8) | readBuf[4];
349 if (readBuf[1] != 0x01)
356 ButtonState[controller] = (uint32_t)(readBuf[9] | ((uint16_t)readBuf[8] << 8) | ((uint32_t)readBuf[7] << 16) | ((uint32_t)readBuf[6] << 24));
358 hatValue[controller][
LeftHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
359 hatValue[controller][
LeftHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
360 hatValue[controller][
RightHatX] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]);
361 hatValue[controller][
RightHatY] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]);
366 if (ButtonState[controller] != OldButtonState[controller]) {
367 buttonStateChanged[controller] =
true;
368 ButtonClickState[controller] = (ButtonState[controller] >> 16) & ((~OldButtonState[controller]) >> 16);
369 if (((uint8_t)OldButtonState[controller]) == 0 && ((uint8_t)ButtonState[controller]) != 0)
370 R2Clicked[controller] =
true;
371 if ((uint8_t)(OldButtonState[controller] >> 8) == 0 && (uint8_t)(ButtonState[controller] >> 8) != 0)
372 L2Clicked[controller] =
true;
373 OldButtonState[controller] = ButtonState[controller];
377 void XBOXRECV::printReport(uint8_t controller, uint8_t nBytes) {
381 Notify(PSTR(
"Controller "), 0x80);
384 for (uint8_t i = 0; i < nBytes; i++) {
385 D_PrintHex<uint8_t > (readBuf[i], 0x80);
388 Notify(PSTR(
"\r\n"), 0x80);
394 return (uint8_t)(ButtonState[controller] >> 8);
396 return (uint8_t)ButtonState[controller];
397 return (
bool)(ButtonState[controller] & ((uint32_t)pgm_read_word(&
XBOXBUTTONS[(uint8_t)b]) << 16));
402 if (L2Clicked[controller]) {
403 L2Clicked[controller] =
false;
407 }
else if (b ==
R2) {
408 if (R2Clicked[controller]) {
409 R2Clicked[controller] =
false;
414 uint16_t button = pgm_read_word(&
XBOXBUTTONS[(uint8_t)b]);
415 bool click = (ButtonClickState[controller] & button);
416 ButtonClickState[controller] &= ~button;
421 return hatValue[controller][a];
425 bool state = buttonStateChanged[controller];
426 buttonStateChanged[controller] =
false;
450 return ((controllerStatus[controller] & 0x00C0) >> 6);
453 void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) {
456 switch (controller) {
469 Notify(PSTR(
"Error sending Xbox message\r\n"), 0x80);
477 writeBuf[3] = value | 0x40;
479 XboxCommand(controller, writeBuf, 4);
499 void XBOXRECV::checkStatus() {
507 for (uint8_t i = 0; i < 4; i++) {
508 XboxCommand(i, writeBuf, 4);
515 for (uint8_t i = 0; i < 4; i++) {
517 XboxCommand(i, writeBuf, 4);
527 writeBuf[5] = lValue;
528 writeBuf[6] = rValue;
530 XboxCommand(controller, writeBuf, 7);