116 goto FailGetDevDescr;
119 PID = udd->idProduct;
122 goto FailUnknownDevice;
139 #ifdef DEBUG_USB_HOST
141 D_PrintHex<uint8_t > (rcode, 0x80);
147 D_PrintHex<uint8_t > (
bAddress, 0x80);
163 goto FailSetDevTblEntry;
185 goto FailSetDevTblEntry;
191 goto FailSetConfDescr;
193 #ifdef DEBUG_USB_HOST
194 Notify(
PSTR(
"\r\nXbox Controller Connected\r\n"), 0x80);
204 #ifdef DEBUG_USB_HOST
210 #ifdef DEBUG_USB_HOST
216 #ifdef DEBUG_USB_HOST
222 #ifdef DEBUG_USB_HOST
228 #ifdef DEBUG_USB_HOST
229 Notify(
PSTR(
"\r\nXbox Init Failed, error code: "), 0x80);
252 printReport(BUFFER_SIZE);
257 void XBOXOLD::readReport() {
258 ButtonState = readBuf[2];
260 for(uint8_t i = 0; i <
sizeof (buttonValues); i++)
261 buttonValues[i] = readBuf[i + 4];
263 hatValue[
LeftHatX] = (int16_t)(((uint16_t)readBuf[12] << 8) | readBuf[13]);
264 hatValue[
LeftHatY] = (int16_t)(((uint16_t)readBuf[14] << 8) | readBuf[15]);
265 hatValue[
RightHatX] = (int16_t)(((uint16_t)readBuf[16] << 8) | readBuf[17]);
266 hatValue[
RightHatY] = (int16_t)(((uint16_t)readBuf[18] << 8) | readBuf[19]);
271 if(ButtonState != OldButtonState || memcmp(buttonValues, oldButtonValues,
sizeof (buttonValues)) != 0) {
272 ButtonClickState = ButtonState & ~OldButtonState;
273 OldButtonState = ButtonState;
275 for(uint8_t i = 0; i <
sizeof (buttonValues); i++) {
276 if(oldButtonValues[i] == 0 && buttonValues[i] != 0)
277 buttonClicked[i] =
true;
278 oldButtonValues[i] = buttonValues[i];
283 void XBOXOLD::printReport(uint16_t length __attribute__((unused))) {
287 for(uint8_t i = 0; i < length; i++) {
288 D_PrintHex<uint8_t > (readBuf[i], 0x80);
295 int8_t XBOXOLD::getAnalogIndex(
ButtonEnum b) {
315 int8_t XBOXOLD::getDigitalIndex(
ButtonEnum b) {
336 const int8_t analogIndex = getAnalogIndex(b);
337 if (analogIndex >= 0) {
339 return buttonValues[buttonIndex];
341 const int8_t digitalIndex = getDigitalIndex(b);
342 if (digitalIndex >= 0) {
344 return (ButtonState & buttonMask);
350 const int8_t analogIndex = getAnalogIndex(b);
351 if (analogIndex >= 0) {
353 if (buttonClicked[buttonIndex]) {
354 buttonClicked[buttonIndex] =
false;
359 const int8_t digitalIndex = getDigitalIndex(b);
360 if (digitalIndex >= 0) {
362 const bool click = (ButtonClickState & mask);
363 ButtonClickState &= ~mask;
374 void XBOXOLD::XboxCommand(uint8_t* data, uint16_t nbytes) {
376 pUsb->
ctrlReq(
bAddress,
epInfo[
XBOX_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL);
385 writeBuf[3] = rValue;
387 writeBuf[5] = lValue;
389 XboxCommand(writeBuf, 6);