forked from felis/USB_Host_Shield_2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SRWS1.ino
180 lines (165 loc) · 5.75 KB
/
SRWS1.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
Example sketch for the SteelSeries SRW-S1 Steering Wheel - developed by Kristian Lauszus
For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: [email protected]
*/
#include <SPI.h>
#include "SRWS1.h"
USB Usb;
SRWS1 srw1(&Usb);
bool printTilt;
void setup() {
Serial.begin(115200);
#if !defined(__MIPSEL__)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while (1); // Halt
}
Serial.println(F("\r\nSteelSeries SRW-S1 Steering Wheel example started"));
}
void loop() {
Usb.Task();
if (srw1.connected()) {
if (printTilt) { // Show tilt angle using the LEDs
srw1.setLeds(1 << map(srw1.srws1Data.tilt, -1800, 1800, 0, 14)); // Turn on a LED according to tilt value
Serial.println(srw1.srws1Data.tilt);
} else { // Show strobe light effect
static uint32_t timer;
if ((int32_t)((uint32_t)millis() - timer) > 12) {
timer = (uint32_t)millis(); // Reset timer
static uint16_t leds = 0;
//PrintHex<uint16_t > (leds, 0x80); Serial.println();
srw1.setLeds(leds); // Update LEDs
static bool dirUp = true;
if (dirUp) {
leds <<= 1;
if (leds == 0x8000) // All are actually turned off, as there is only 15 LEDs
dirUp = false; // If we have reached the end i.e. all LEDs are off, then change direction
else if (!(leds & 0x8000)) // If last bit is not set, then set the lowest bit
leds |= 1; // Set lowest bit
} else {
leds >>= 1;
if (leds == 0) // Check if all LEDs are off
dirUp = true; // If all LEDs are off, then repeat the sequence
else if (!(leds & 0x1)) // If last bit is not set, then set the top bit
leds |= 1 << 15; // Set top bit
}
}
}
if (srw1.srws1Data.leftTrigger) {
Serial.print(F("L2: "));
Serial.println(srw1.srws1Data.leftTrigger);
}
if (srw1.srws1Data.rightTrigger) {
Serial.print(F("R2: "));
Serial.println(srw1.srws1Data.rightTrigger);
}
if (srw1.buttonClickState.select) {
srw1.buttonClickState.select = 0; // Clear event
Serial.println(F("Select"));
printTilt = !printTilt; // Print tilt value & show it using the LEDs as well
}
if (srw1.buttonClickState.back) {
srw1.buttonClickState.back = 0; // Clear event
Serial.println(F("Back"));
}
if (srw1.buttonClickState.lookLeft) {
srw1.buttonClickState.lookLeft = 0; // Clear event
Serial.println(F("Look Left"));
}
if (srw1.buttonClickState.lights) {
srw1.buttonClickState.lights = 0; // Clear event
Serial.println(F("Lights"));
}
if (srw1.buttonClickState.lookBack) {
srw1.buttonClickState.lookBack = 0; // Clear event
Serial.println(F("Look Back"));
}
if (srw1.buttonClickState.rearBrakeBalance) {
srw1.buttonClickState.rearBrakeBalance = 0; // Clear event
Serial.println(F("R. Brake Balance"));
}
if (srw1.buttonClickState.frontBrakeBalance) {
srw1.buttonClickState.frontBrakeBalance = 0; // Clear event
Serial.println(F("F. Brake Balance"));
}
if (srw1.buttonClickState.requestPit) {
srw1.buttonClickState.requestPit = 0; // Clear event
Serial.println(F("Request Pit"));
}
if (srw1.buttonClickState.leftGear) {
srw1.buttonClickState.leftGear = 0; // Clear event
Serial.println(F("Left Gear"));
}
if (srw1.buttonClickState.camera) {
srw1.buttonClickState.camera = 0; // Clear event
Serial.println(F("Camera"));
}
if (srw1.buttonClickState.lookRight) {
srw1.buttonClickState.lookRight = 0; // Clear event
Serial.println(F("Look right"));
}
if (srw1.buttonClickState.boost) {
srw1.buttonClickState.boost = 0; // Clear event
Serial.println(F("Boost"));
}
if (srw1.buttonClickState.horn) {
srw1.buttonClickState.horn = 0; // Clear event
Serial.println(F("Horn"));
}
if (srw1.buttonClickState.hud) {
srw1.buttonClickState.hud = 0; // Clear event
Serial.println(F("HUD"));
}
if (srw1.buttonClickState.launchControl) {
srw1.buttonClickState.launchControl = 0; // Clear event
Serial.println(F("Launch Control"));
}
if (srw1.buttonClickState.speedLimiter) {
srw1.buttonClickState.speedLimiter = 0; // Clear event
Serial.println(F("Speed Limiter"));
}
if (srw1.buttonClickState.rightGear) {
srw1.buttonClickState.rightGear = 0; // Clear event
Serial.println(F("Right gear"));
}
if (srw1.srws1Data.assists) Serial.println(srw1.srws1Data.assists);
if (srw1.srws1Data.steeringSensitivity) Serial.println(srw1.srws1Data.steeringSensitivity);
if (srw1.srws1Data.assistValues) Serial.println(srw1.srws1Data.assistValues);
switch (srw1.srws1Data.btn.dpad) {
case DPAD_UP:
Serial.println(F("Up"));
break;
case DPAD_UP_RIGHT:
Serial.println(F("UP & right"));
break;
case DPAD_RIGHT:
Serial.println(F("Right"));
break;
case DPAD_RIGHT_DOWN:
Serial.println(F("Right & down"));
break;
case DPAD_DOWN:
Serial.println(F("Down"));
break;
case DPAD_DOWN_LEFT:
Serial.println(F("Down & left"));
break;
case DPAD_LEFT:
Serial.println(F("Left"));
break;
case DPAD_LEFT_UP:
Serial.println(F("Left & up"));
break;
case DPAD_OFF:
break;
default:
Serial.print(F("Unknown state: "));
PrintHex<uint8_t > (srw1.srws1Data.btn.dpad, 0x80);
Serial.println();
break;
}
}
}