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)
#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
#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(...)
#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(...)