]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/Xbox/XBOXUSB/XBOXUSB.ino
lufa: usb-usb: Use LUFA startup instead of cusotom
[max/tmk_keyboard.git] / tmk_core / protocol / usb_hid / USB_Host_Shield_2.0 / examples / Xbox / XBOXUSB / XBOXUSB.ino
1 /*
2  Example sketch for the Xbox 360 USB library - developed by Kristian Lauszus
3  For more information visit my blog: http://blog.tkjelectronics.dk/ or
4  send me an e-mail:  kristianl@tkjelectronics.com
5  */
6
7 #include <XBOXUSB.h>
8
9 // Satisfy the IDE, which needs to see the include statment in the ino too.
10 #ifdef dobogusinclude
11 #include <spi4teensy3.h>
12 #include <SPI.h>
13 #endif
14
15 USB Usb;
16 XBOXUSB Xbox(&Usb);
17
18 void setup() {
19   Serial.begin(115200);
20 #if !defined(__MIPSEL__)
21   while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
22 #endif
23   if (Usb.Init() == -1) {
24     Serial.print(F("\r\nOSC did not start"));
25     while (1); //halt
26   }
27   Serial.print(F("\r\nXBOX USB Library Started"));
28 }
29 void loop() {
30   Usb.Task();
31   if (Xbox.Xbox360Connected) {
32     if (Xbox.getButtonPress(L2) || Xbox.getButtonPress(R2)) {
33       Serial.print("L2: ");
34       Serial.print(Xbox.getButtonPress(L2));
35       Serial.print("\tR2: ");
36       Serial.println(Xbox.getButtonPress(R2));
37       Xbox.setRumbleOn(Xbox.getButtonPress(L2), Xbox.getButtonPress(R2));
38     } else
39       Xbox.setRumbleOn(0, 0);
40
41     if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500 || Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500 || Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500 || Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) {
42       if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500) {
43         Serial.print(F("LeftHatX: "));
44         Serial.print(Xbox.getAnalogHat(LeftHatX));
45         Serial.print("\t");
46       }
47       if (Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) {
48         Serial.print(F("LeftHatY: "));
49         Serial.print(Xbox.getAnalogHat(LeftHatY));
50         Serial.print("\t");
51       }
52       if (Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) {
53         Serial.print(F("RightHatX: "));
54         Serial.print(Xbox.getAnalogHat(RightHatX));
55         Serial.print("\t");
56       }
57       if (Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) {
58         Serial.print(F("RightHatY: "));
59         Serial.print(Xbox.getAnalogHat(RightHatY));
60       }
61       Serial.println();
62     }
63
64     if (Xbox.getButtonClick(UP)) {
65       Xbox.setLedOn(LED1);
66       Serial.println(F("Up"));
67     }
68     if (Xbox.getButtonClick(DOWN)) {
69       Xbox.setLedOn(LED4);
70       Serial.println(F("Down"));
71     }
72     if (Xbox.getButtonClick(LEFT)) {
73       Xbox.setLedOn(LED3);
74       Serial.println(F("Left"));
75     }
76     if (Xbox.getButtonClick(RIGHT)) {
77       Xbox.setLedOn(LED2);
78       Serial.println(F("Right"));
79     }
80
81     if (Xbox.getButtonClick(START)) {
82       Xbox.setLedMode(ALTERNATING);
83       Serial.println(F("Start"));
84     }
85     if (Xbox.getButtonClick(BACK)) {
86       Xbox.setLedBlink(ALL);
87       Serial.println(F("Back"));
88     }
89     if (Xbox.getButtonClick(L3))
90       Serial.println(F("L3"));
91     if (Xbox.getButtonClick(R3))
92       Serial.println(F("R3"));
93
94     if (Xbox.getButtonClick(L1))
95       Serial.println(F("L1"));
96     if (Xbox.getButtonClick(R1))
97       Serial.println(F("R1"));
98     if (Xbox.getButtonClick(XBOX)) {
99       Xbox.setLedMode(ROTATING);
100       Serial.println(F("Xbox"));
101     }
102
103     if (Xbox.getButtonClick(A))
104       Serial.println(F("A"));
105     if (Xbox.getButtonClick(B))
106       Serial.println(F("B"));
107     if (Xbox.getButtonClick(X))
108       Serial.println(F("X"));
109     if (Xbox.getButtonClick(Y))
110       Serial.println(F("Y"));
111   }
112   delay(1);
113 }