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);
145 goto FailSetDevTblEntry;
206 goto FailSetDevTblEntry;
212 goto FailSetConfDescr;
214 #ifdef DEBUG_USB_HOST
215 Notify(PSTR(
"\r\nXbox Wireless Receiver Connected\r\n"), 0x80);
223 #ifdef DEBUG_USB_HOST
229 #ifdef DEBUG_USB_HOST
235 #ifdef DEBUG_USB_HOST
241 #ifdef DEBUG_USB_HOST
247 #ifdef DEBUG_USB_HOST
248 Notify(PSTR(
"\r\nXbox 360 Init Failed, error code: "), 0x80);
258 for (uint8_t i = 0; i < 4; i++)
269 if (!timer || ((millis() - timer) > 3000)) {
275 for (uint8_t i = 0; i < 4; i++) {
288 if (bufferSize > 0) {
290 Notify(PSTR(
"Bytes Received: "), 0x80);
291 D_PrintHex<uint16_t > (bufferSize, 0x80);
292 Notify(PSTR(
"\r\n"), 0x80);
296 printReport(i, bufferSize);
303 void XBOXRECV::readReport(uint8_t controller) {
309 #ifdef DEBUG_USB_HOST
310 Notify(PSTR(
"Controller "), 0x80);
314 #ifdef DEBUG_USB_HOST
316 switch (readBuf[1]) {
317 case 0x80: str = PSTR(
" as controller\r\n");
319 case 0x40: str = PSTR(
" as headset\r\n");
321 case 0xC0: str = PSTR(
" as controller+headset\r\n");
324 Notify(PSTR(
": connected"), 0x80);
329 #ifdef DEBUG_USB_HOST
331 Notify(PSTR(
": disconnected\r\n"), 0x80);
336 if (readBuf[1] == 0x00 && readBuf[3] & 0x13 && readBuf[4] >= 0x22) {
337 controllerStatus[controller] = ((uint16_t)readBuf[3] << 8) | readBuf[4];
340 if (readBuf[1] != 0x01)
347 ButtonState[controller] = (uint32_t)(readBuf[9] | ((uint16_t)readBuf[8] << 8) | ((uint32_t)readBuf[7] << 16) | ((uint32_t)readBuf[6] << 24));
349 hatValue[controller][
LeftHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
350 hatValue[controller][
LeftHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
351 hatValue[controller][
RightHatX] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]);
352 hatValue[controller][
RightHatY] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]);
357 if (ButtonState[controller] != OldButtonState[controller]) {
358 buttonStateChanged[controller] =
true;
359 ButtonClickState[controller] = (ButtonState[controller] >> 16) & ((~OldButtonState[controller]) >> 16);
360 if (((uint8_t)OldButtonState[controller]) == 0 && ((uint8_t)ButtonState[controller]) != 0)
361 R2Clicked[controller] =
true;
362 if ((uint8_t)(OldButtonState[controller] >> 8) == 0 && (uint8_t)(ButtonState[controller] >> 8) != 0)
363 L2Clicked[controller] =
true;
364 OldButtonState[controller] = ButtonState[controller];
368 void XBOXRECV::printReport(uint8_t controller, uint8_t nBytes) {
372 Notify(PSTR(
"Controller "), 0x80);
375 for (uint8_t i = 0; i < nBytes; i++) {
376 D_PrintHex<uint8_t > (readBuf[i], 0x80);
379 Notify(PSTR(
"\r\n"), 0x80);
385 return (uint8_t)(ButtonState[controller] >> 8);
387 return (uint8_t)ButtonState[controller];
388 return (
bool)(ButtonState[controller] & ((uint32_t)pgm_read_word(&
XBOXBUTTONS[(uint8_t)b]) << 16));
393 if (L2Clicked[controller]) {
394 L2Clicked[controller] =
false;
398 }
else if (b ==
R2) {
399 if (R2Clicked[controller]) {
400 R2Clicked[controller] =
false;
405 uint16_t button = pgm_read_word(&
XBOXBUTTONS[(uint8_t)b]);
406 bool click = (ButtonClickState[controller] & button);
407 ButtonClickState[controller] &= ~button;
412 return hatValue[controller][a];
416 bool state = buttonStateChanged[controller];
417 buttonStateChanged[controller] =
false;
441 return ((controllerStatus[controller] & 0x00C0) >> 6);
444 void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) {
447 switch (controller) {
460 Notify(PSTR(
"Error sending Xbox message\r\n"), 0x80);
468 writeBuf[3] = value | 0x40;
470 XboxCommand(controller, writeBuf, 4);
490 void XBOXRECV::checkStatus() {
498 for (uint8_t i = 0; i < 4; i++) {
499 XboxCommand(i, writeBuf, 4);
506 for (uint8_t i = 0; i < 4; i++) {
508 XboxCommand(i, writeBuf, 4);
518 writeBuf[5] = lValue;
519 writeBuf[6] = rValue;
521 XboxCommand(controller, writeBuf, 7);
524 void XBOXRECV::onInit(uint8_t controller) {
531 else if (controller == 1)
533 else if (controller == 2)