19 #define DEBUG // Uncomment to print data for debugging
49 Notify(PSTR(
"\r\nXBOXUSB Init"));
54 Notify(PSTR(
"\r\nAddress in use"));
64 Notify(PSTR(
"\r\nAddress not found"));
71 Notify(PSTR(
"\r\nepinfo is null"));
96 goto FailUnknownDevice;
99 Notify(PSTR(
"\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication"));
101 goto FailUnknownDevice;
105 Notify(PSTR(
"\r\nThis library only supports Xbox 360 controllers via USB"));
107 goto FailUnknownDevice;
126 Notify(PSTR(
"\r\nsetAddr: "));
128 PrintHex<uint8_t>(rcode);
132 Notify(PSTR(
"\r\nAddr: "));
147 goto FailSetDevTblEntry;
169 goto FailSetDevTblEntry;
178 Notify(PSTR(
"\r\nXbox 360 Controller Connected\r\n"));
188 Notify(PSTR(
"\r\ngetDevDescr:"));
193 Notify(PSTR(
"\r\nsetDevTblEn:"));
198 Notify(PSTR(
"\r\nsetConf:"));
203 Notify(PSTR(
"\r\nUnknown Device Connected - VID: "));
204 PrintHex<uint16_t>(VID);
206 PrintHex<uint16_t>(PID);
212 Notify(PSTR(
"\r\nXbox 360 Init Failed, error code: "));
213 Serial.print(rcode,HEX);
239 void XBOXUSB::readReport() {
242 if(readBuf[0] != 0x00 || readBuf[1] != 0x14) {
246 ButtonState = (uint32_t)(readBuf[5] | ((uint16_t)readBuf[4] << 8) | ((uint32_t)readBuf[3] << 16) | ((uint32_t)readBuf[2] << 24));
248 hatValue[
LeftHatX] = (int16_t)(((uint16_t)readBuf[7] << 8) | readBuf[6]);
249 hatValue[
LeftHatY] = (int16_t)(((uint16_t)readBuf[9] << 8) | readBuf[8]);
250 hatValue[
RightHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
251 hatValue[
RightHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
256 if(ButtonState != OldButtonState) {
257 ButtonClickState = (ButtonState >> 16) & ((~OldButtonState) >> 16);
258 if(((uint8_t)OldButtonState) == 0 && ((uint8_t)ButtonState) != 0)
260 if((uint8_t)(OldButtonState >> 8) == 0 && (uint8_t)(ButtonState >> 8) != 0)
262 OldButtonState = ButtonState;
266 void XBOXUSB::printReport() {
271 PrintHex<uint8_t>(readBuf[i]);
280 return (uint8_t)(ButtonState >> 8);
282 return (uint8_t)ButtonState;
283 return (ButtonState & ((uint32_t)pgm_read_word(&BUTTONS[(uint8_t)b]) << 16));
300 uint16_t button = pgm_read_word(&BUTTONS[(uint8_t)b]);
301 bool click = (ButtonClickState & button);
302 ButtonClickState &= ~button;
310 void XBOXUSB::XboxCommand(uint8_t* data, uint16_t nbytes) {
312 pUsb->
ctrlReq(
bAddress,
epInfo[
XBOX_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL);
319 XboxCommand(writeBuf, 3);
323 setLedRaw((pgm_read_byte(&LEDS[(uint8_t)led]))+4);
326 setLedRaw(pgm_read_byte(&LEDS[(uint8_t)led]));
335 writeBuf[3] = lValue;
336 writeBuf[4] = rValue;
341 XboxCommand(writeBuf, 8);