43 uint8_t buf[constBufSize];
94 Notify(
PSTR(
"\r\nYou'll need a wireless receiver for this libary to work"), 0x80);
96 goto FailUnknownDevice;
102 #ifdef DEBUG_USB_HOST
103 Notify(
PSTR(
"\r\nOut of address space"), 0x80);
116 #ifdef DEBUG_USB_HOST
124 #ifdef DEBUG_USB_HOST
130 #ifdef DEBUG_USB_HOST
131 Notify(
PSTR(
"\r\nXbox 360 Init Failed, error code: "), 0x80);
138 uint8_t
XBOXRECV::Init(uint8_t parent __attribute__((unused)), uint8_t port __attribute__((unused)),
bool lowspeed) {
148 #ifdef DEBUG_USB_HOST
158 #ifdef DEBUG_USB_HOST
160 D_PrintHex<uint8_t > (rcode, 0x80);
167 D_PrintHex<uint8_t > (
bAddress, 0x80);
174 #ifdef DEBUG_USB_HOST
184 goto FailSetDevTblEntry;
245 goto FailSetDevTblEntry;
251 goto FailSetConfDescr;
253 #ifdef DEBUG_USB_HOST
254 Notify(
PSTR(
"\r\nXbox Wireless Receiver Connected\r\n"), 0x80);
258 checkStatusTimer = 0;
263 #ifdef DEBUG_USB_HOST
269 #ifdef DEBUG_USB_HOST
274 #ifdef DEBUG_USB_HOST
275 Notify(
PSTR(
"\r\nXbox 360 Init Failed, error code: "), 0x80);
285 for(uint8_t i = 0; i < 4; i++)
296 if(!checkStatusTimer || ((int32_t)((uint32_t)millis() - checkStatusTimer) > 3000)) {
297 checkStatusTimer = (uint32_t)millis();
303 for(uint8_t i = 0; i < 4; i++) {
318 D_PrintHex<uint16_t > (bufferSize, 0x80);
323 printReport(i, bufferSize);
330 void XBOXRECV::readReport(uint8_t controller) {
336 #ifdef DEBUG_USB_HOST
341 #ifdef DEBUG_USB_HOST
344 case 0x80: str =
PSTR(
" as controller\r\n");
346 case 0x40: str =
PSTR(
" as headset\r\n");
348 case 0xC0: str =
PSTR(
" as controller+headset\r\n");
356 #ifdef DEBUG_USB_HOST
363 if(readBuf[1] == 0x00 && readBuf[3] & 0x13 && readBuf[4] >= 0x22) {
364 controllerStatus[controller] = ((uint16_t)readBuf[3] << 8) | readBuf[4];
367 if(readBuf[1] != 0x01)
374 ButtonState[controller] = (uint32_t)(readBuf[9] | ((uint16_t)readBuf[8] << 8) | ((uint32_t)readBuf[7] << 16) | ((uint32_t)readBuf[6] << 24));
376 hatValue[controller][
LeftHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
377 hatValue[controller][
LeftHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
378 hatValue[controller][
RightHatX] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]);
379 hatValue[controller][
RightHatY] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]);
384 if(ButtonState[controller] != OldButtonState[controller]) {
385 buttonStateChanged[controller] =
true;
386 ButtonClickState[controller] = (ButtonState[controller] >> 16) & ((~OldButtonState[controller]) >> 16);
387 if(((uint8_t)OldButtonState[controller]) == 0 && ((uint8_t)ButtonState[controller]) != 0)
388 R2Clicked[controller] =
true;
389 if((uint8_t)(OldButtonState[controller] >> 8) == 0 && (uint8_t)(ButtonState[controller] >> 8) != 0)
390 L2Clicked[controller] =
true;
391 OldButtonState[controller] = ButtonState[controller];
395 void XBOXRECV::printReport(uint8_t controller __attribute__((unused)), uint8_t nBytes __attribute__((unused))) {
402 for(uint8_t i = 0; i < nBytes; i++) {
403 D_PrintHex<uint8_t > (readBuf[i], 0x80);
413 return (uint8_t)(ButtonState[controller] >> 8);
415 return (uint8_t)ButtonState[controller];
422 if(L2Clicked[controller]) {
423 L2Clicked[controller] =
false;
428 if(R2Clicked[controller]) {
429 R2Clicked[controller] =
false;
435 bool click = (ButtonClickState[controller] & button);
436 ButtonClickState[controller] &= ~button;
441 return hatValue[controller][a];
445 bool state = buttonStateChanged[controller];
446 buttonStateChanged[controller] =
false;
470 return ((controllerStatus[controller] & 0x00C0) >> 6);
473 void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) {
496 Notify(
PSTR(
"Error sending Xbox message\r\n"), 0x80);
506 XboxCommand(controller, writeBuf, 4);
513 writeBuf[3] = value | 0x40;
515 XboxCommand(controller, writeBuf, 4);
537 void XBOXRECV::checkStatus() {
545 for(uint8_t i = 0; i < 4; i++) {
546 XboxCommand(i, writeBuf, 4);
553 for(uint8_t i = 0; i < 4; i++) {
555 XboxCommand(i, writeBuf, 4);
565 writeBuf[5] = lValue;
566 writeBuf[6] = rValue;
568 XboxCommand(controller, writeBuf, 7);
571 void XBOXRECV::onInit(uint8_t controller) {
578 else if(controller == 1)
580 else if(controller == 2)