42 uint8_t buf[constBufSize];
50 Notify(PSTR(
"\r\nXBOXRECV Init"), 0x80);
55 Notify(PSTR(
"\r\nAddress in use"), 0x80);
64 Notify(PSTR(
"\r\nAddress not found"), 0x80);
71 Notify(PSTR(
"\r\nepinfo is null"), 0x80);
92 Notify(PSTR(
"\r\nYou'll need a wireless receiver for this libary to work"), 0x80);
94 goto FailUnknownDevice;
100 #ifdef DEBUG_USB_HOST
101 Notify(PSTR(
"\r\nOut of address space"), 0x80);
115 #ifdef DEBUG_USB_HOST
123 #ifdef DEBUG_USB_HOST
129 #ifdef DEBUG_USB_HOST
130 Notify(PSTR(
"\r\nXbox 360 Init Failed, error code: "), 0x80);
144 Notify(PSTR(
"\r\nBTD Init"), 0x80);
149 #ifdef DEBUG_USB_HOST
150 Notify(PSTR(
"\r\nAddress not found"), 0x80);
159 #ifdef DEBUG_USB_HOST
160 Notify(PSTR(
"\r\nsetAddr: "), 0x80);
161 D_PrintHex<uint8_t > (rcode, 0x80);
167 Notify(PSTR(
"\r\nAddr: "), 0x80);
168 D_PrintHex<uint8_t > (
bAddress, 0x80);
175 #ifdef DEBUG_USB_HOST
176 Notify(PSTR(
"\r\nAddress not found"), 0x80);
185 goto FailSetDevTblEntry;
246 goto FailSetDevTblEntry;
252 goto FailSetConfDescr;
254 #ifdef DEBUG_USB_HOST
255 Notify(PSTR(
"\r\nXbox Wireless Receiver Connected\r\n"), 0x80);
259 checkStatusTimer = 0;
264 #ifdef DEBUG_USB_HOST
270 #ifdef DEBUG_USB_HOST
276 #ifdef DEBUG_USB_HOST
282 #ifdef DEBUG_USB_HOST
283 Notify(PSTR(
"\r\nXbox 360 Init Failed, error code: "), 0x80);
293 for (uint8_t i = 0; i < 4; i++)
304 if (!checkStatusTimer || ((millis() - checkStatusTimer) > 3000)) {
305 checkStatusTimer = millis();
311 for (uint8_t i = 0; i < 4; i++) {
323 if (bufferSize > 0) {
325 Notify(PSTR(
"Bytes Received: "), 0x80);
326 D_PrintHex<uint16_t > (bufferSize, 0x80);
327 Notify(PSTR(
"\r\n"), 0x80);
331 printReport(i, bufferSize);
338 void XBOXRECV::readReport(uint8_t controller) {
344 #ifdef DEBUG_USB_HOST
345 Notify(PSTR(
"Controller "), 0x80);
349 #ifdef DEBUG_USB_HOST
351 switch (readBuf[1]) {
352 case 0x80: str = PSTR(
" as controller\r\n");
354 case 0x40: str = PSTR(
" as headset\r\n");
356 case 0xC0: str = PSTR(
" as controller+headset\r\n");
359 Notify(PSTR(
": connected"), 0x80);
364 #ifdef DEBUG_USB_HOST
366 Notify(PSTR(
": disconnected\r\n"), 0x80);
371 if (readBuf[1] == 0x00 && readBuf[3] & 0x13 && readBuf[4] >= 0x22) {
372 controllerStatus[controller] = ((uint16_t)readBuf[3] << 8) | readBuf[4];
375 if (readBuf[1] != 0x01)
382 ButtonState[controller] = (uint32_t)(readBuf[9] | ((uint16_t)readBuf[8] << 8) | ((uint32_t)readBuf[7] << 16) | ((uint32_t)readBuf[6] << 24));
384 hatValue[controller][
LeftHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
385 hatValue[controller][
LeftHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
386 hatValue[controller][
RightHatX] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]);
387 hatValue[controller][
RightHatY] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]);
392 if (ButtonState[controller] != OldButtonState[controller]) {
393 buttonStateChanged[controller] =
true;
394 ButtonClickState[controller] = (ButtonState[controller] >> 16) & ((~OldButtonState[controller]) >> 16);
395 if (((uint8_t)OldButtonState[controller]) == 0 && ((uint8_t)ButtonState[controller]) != 0)
396 R2Clicked[controller] =
true;
397 if ((uint8_t)(OldButtonState[controller] >> 8) == 0 && (uint8_t)(ButtonState[controller] >> 8) != 0)
398 L2Clicked[controller] =
true;
399 OldButtonState[controller] = ButtonState[controller];
403 void XBOXRECV::printReport(uint8_t controller, uint8_t nBytes) {
407 Notify(PSTR(
"Controller "), 0x80);
410 for (uint8_t i = 0; i < nBytes; i++) {
411 D_PrintHex<uint8_t > (readBuf[i], 0x80);
414 Notify(PSTR(
"\r\n"), 0x80);
420 return (uint8_t)(ButtonState[controller] >> 8);
422 return (uint8_t)ButtonState[controller];
423 return (
bool)(ButtonState[controller] & ((uint32_t)pgm_read_word(&
XBOXBUTTONS[(uint8_t)b]) << 16));
428 if (L2Clicked[controller]) {
429 L2Clicked[controller] =
false;
433 }
else if (b ==
R2) {
434 if (R2Clicked[controller]) {
435 R2Clicked[controller] =
false;
440 uint16_t button = pgm_read_word(&
XBOXBUTTONS[(uint8_t)b]);
441 bool click = (ButtonClickState[controller] & button);
442 ButtonClickState[controller] &= ~button;
447 return hatValue[controller][a];
451 bool state = buttonStateChanged[controller];
452 buttonStateChanged[controller] =
false;
476 return ((controllerStatus[controller] & 0x00C0) >> 6);
479 void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) {
483 else if (controller == 1)
485 else if (controller == 2)
493 Notify(PSTR(
"Error sending Xbox message\r\n"), 0x80);
503 XboxCommand(controller, writeBuf, 4);
510 writeBuf[3] = value | 0x40;
512 XboxCommand(controller, writeBuf, 4);
532 void XBOXRECV::checkStatus() {
540 for (uint8_t i = 0; i < 4; i++) {
541 XboxCommand(i, writeBuf, 4);
548 for (uint8_t i = 0; i < 4; i++) {
550 XboxCommand(i, writeBuf, 4);
560 writeBuf[5] = lValue;
561 writeBuf[6] = rValue;
563 XboxCommand(controller, writeBuf, 7);
566 void XBOXRECV::onInit(uint8_t controller) {
573 else if (controller == 1)
575 else if (controller == 2)
#define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID
bool getButtonClick(Button b, uint8_t controller=0)
#define USB_ERROR_EPINFO_IS_NULL
void setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller=0)
#define XBOX_WIRELESS_RECEIVER_PID
uint8_t Xbox360Connected[4]
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
bool buttonChanged(uint8_t controller=0)
#define XBOX_OUTPUT_PIPE_3
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
#define USB_ERROR_FailGetDevDescr
#define NotifyFailGetDevDescr(...)
const uint16_t XBOXBUTTONS[]
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
virtual void FreeAddress(uint8_t addr)=0
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
#define XBOX_INPUT_PIPE_2
#define NotifyFailUnknownDevice(...)
#define USB_NAK_MAX_POWER
virtual uint8_t Release()
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
bool XboxReceiverConnected
void setLedBlink(LED l, uint8_t controller=0)
void setLedOn(LED l, uint8_t controller=0)
uint8_t getBatteryLevel(uint8_t controller=0)
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
#define XBOX_OUTPUT_PIPE_1
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define XBOX_INPUT_PIPE_1
void setLedMode(LEDMode lm, uint8_t controller=0)
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
void setLedRaw(uint8_t value, uint8_t controller=0)
#define XBOX_MAX_ENDPOINTS
int16_t getAnalogHat(AnalogHat a, uint8_t controller=0)
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
AddressPool & GetAddressPool()
#define XBOX_INPUT_PIPE_3
#define XBOX_CONTROL_PIPE
uint8_t getButtonPress(Button b, uint8_t controller=0)
#define XBOX_INPUT_PIPE_4
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
#define NotifyFailSetConfDescr(...)
void disconnect(uint8_t controller=0)
#define XBOX_OUTPUT_PIPE_4
#define XBOX_OUTPUT_PIPE_2
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
#define NotifyFailSetDevTblEntry(...)
#define USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET