42 uint8_t buf[constBufSize];
51 Notify(PSTR(
"\r\nXBOXRECV Init"), 0x80);
56 Notify(PSTR(
"\r\nAddress in use"), 0x80);
65 Notify(PSTR(
"\r\nAddress not found"), 0x80);
72 Notify(PSTR(
"\r\nepinfo is null"), 0x80);
93 Notify(PSTR(
"\r\nYou'll need a wireless receiver for this libary to work"), 0x80);
95 goto FailUnknownDevice;
101 #ifdef DEBUG_USB_HOST
102 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);
142 Notify(PSTR(
"\r\nBTD Init"), 0x80);
147 #ifdef DEBUG_USB_HOST
148 Notify(PSTR(
"\r\nAddress not found"), 0x80);
157 #ifdef DEBUG_USB_HOST
158 Notify(PSTR(
"\r\nsetAddr: "), 0x80);
159 D_PrintHex<uint8_t > (rcode, 0x80);
165 Notify(PSTR(
"\r\nAddr: "), 0x80);
166 D_PrintHex<uint8_t > (
bAddress, 0x80);
173 #ifdef DEBUG_USB_HOST
174 Notify(PSTR(
"\r\nAddress not found"), 0x80);
183 goto FailSetDevTblEntry;
244 goto FailSetDevTblEntry;
250 goto FailSetConfDescr;
252 #ifdef DEBUG_USB_HOST
253 Notify(PSTR(
"\r\nXbox Wireless Receiver Connected\r\n"), 0x80);
257 checkStatusTimer = 0;
262 #ifdef DEBUG_USB_HOST
268 #ifdef DEBUG_USB_HOST
273 #ifdef DEBUG_USB_HOST
274 Notify(PSTR(
"\r\nXbox 360 Init Failed, error code: "), 0x80);
284 for(uint8_t i = 0; i < 4; i++)
295 if(!checkStatusTimer || ((millis() - checkStatusTimer) > 3000)) {
296 checkStatusTimer = millis();
302 for(uint8_t i = 0; i < 4; i++) {
316 Notify(PSTR(
"Bytes Received: "), 0x80);
317 D_PrintHex<uint16_t > (bufferSize, 0x80);
318 Notify(PSTR(
"\r\n"), 0x80);
322 printReport(i, bufferSize);
329 void XBOXRECV::readReport(uint8_t controller) {
335 #ifdef DEBUG_USB_HOST
336 Notify(PSTR(
"Controller "), 0x80);
340 #ifdef DEBUG_USB_HOST
343 case 0x80: str = PSTR(
" as controller\r\n");
345 case 0x40: str = PSTR(
" as headset\r\n");
347 case 0xC0: str = PSTR(
" as controller+headset\r\n");
350 Notify(PSTR(
": connected"), 0x80);
355 #ifdef DEBUG_USB_HOST
357 Notify(PSTR(
": disconnected\r\n"), 0x80);
362 if(readBuf[1] == 0x00 && readBuf[3] & 0x13 && readBuf[4] >= 0x22) {
363 controllerStatus[controller] = ((uint16_t)readBuf[3] << 8) | readBuf[4];
366 if(readBuf[1] != 0x01)
373 ButtonState[controller] = (uint32_t)(readBuf[9] | ((uint16_t)readBuf[8] << 8) | ((uint32_t)readBuf[7] << 16) | ((uint32_t)readBuf[6] << 24));
375 hatValue[controller][
LeftHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
376 hatValue[controller][
LeftHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
377 hatValue[controller][
RightHatX] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]);
378 hatValue[controller][
RightHatY] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]);
383 if(ButtonState[controller] != OldButtonState[controller]) {
384 buttonStateChanged[controller] =
true;
385 ButtonClickState[controller] = (ButtonState[controller] >> 16) & ((~OldButtonState[controller]) >> 16);
386 if(((uint8_t)OldButtonState[controller]) == 0 && ((uint8_t)ButtonState[controller]) != 0)
387 R2Clicked[controller] =
true;
388 if((uint8_t)(OldButtonState[controller] >> 8) == 0 && (uint8_t)(ButtonState[controller] >> 8) != 0)
389 L2Clicked[controller] =
true;
390 OldButtonState[controller] = ButtonState[controller];
394 void XBOXRECV::printReport(uint8_t controller, uint8_t nBytes) {
398 Notify(PSTR(
"Controller "), 0x80);
401 for(uint8_t i = 0; i < nBytes; i++) {
402 D_PrintHex<uint8_t > (readBuf[i], 0x80);
405 Notify(PSTR(
"\r\n"), 0x80);
411 return (uint8_t)(ButtonState[controller] >> 8);
413 return (uint8_t)ButtonState[controller];
414 return (
bool)(ButtonState[controller] & ((uint32_t)pgm_read_word(&
XBOX_BUTTONS[(uint8_t)b]) << 16));
419 if(L2Clicked[controller]) {
420 L2Clicked[controller] =
false;
425 if(R2Clicked[controller]) {
426 R2Clicked[controller] =
false;
431 uint16_t button = pgm_read_word(&
XBOX_BUTTONS[(uint8_t)b]);
432 bool click = (ButtonClickState[controller] & button);
433 ButtonClickState[controller] &= ~button;
438 return hatValue[controller][a];
442 bool state = buttonStateChanged[controller];
443 buttonStateChanged[controller] =
false;
467 return ((controllerStatus[controller] & 0x00C0) >> 6);
470 void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) {
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);
534 void XBOXRECV::checkStatus() {
542 for(uint8_t i = 0; i < 4; i++) {
543 XboxCommand(i, writeBuf, 4);
550 for(uint8_t i = 0; i < 4; i++) {
552 XboxCommand(i, writeBuf, 4);
562 writeBuf[5] = lValue;
563 writeBuf[6] = rValue;
565 XboxCommand(controller, writeBuf, 7);
568 void XBOXRECV::onInit(uint8_t controller) {
575 else if(controller == 1)
577 else if(controller == 2)
#define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID
#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]
void setLedMode(LEDModeEnum lm, uint8_t controller=0)
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(...)
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()
bool getButtonClick(ButtonEnum b, uint8_t controller=0)
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
void setLedOn(LEDEnum l, uint8_t controller=0)
uint8_t getButtonPress(ButtonEnum b, uint8_t controller=0)
bool XboxReceiverConnected
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
int16_t getAnalogHat(AnalogHatEnum a, uint8_t controller=0)
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define XBOX_INPUT_PIPE_1
void setLedBlink(LEDEnum l, 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)
const uint8_t XBOX_LEDS[]
#define XBOX_MAX_ENDPOINTS
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
AddressPool & GetAddressPool()
#define XBOX_INPUT_PIPE_3
#define XBOX_CONTROL_PIPE
#define XBOX_INPUT_PIPE_4
const uint16_t XBOX_BUTTONS[]
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