Skip to content

Commit 60fc9b5

Browse files
committed
Began work on making the X, Y, Z, X Rotation, Y Rotation, and Z Rotation configurable and 16-bit.
1 parent 1fc3f5b commit 60fc9b5

File tree

6 files changed

+378
-92
lines changed

6 files changed

+378
-92
lines changed

Joystick/examples/JoystickTest/JoystickTest.ino

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,36 @@ void testMultiButtonPush(unsigned int currentStep)
6969

7070
void testXYAxis(unsigned int currentStep)
7171
{
72+
int xAxis;
73+
int yAxis;
74+
7275
if (currentStep < 256)
7376
{
74-
Joystick.setXAxis(currentStep - 127);
75-
Joystick.setYAxis(-127);
77+
xAxis = currentStep - 127;
78+
yAxis = -127;
79+
Joystick.setXAxis(xAxis);
80+
Joystick.setYAxis(yAxis);
7681
}
7782
else if (currentStep < 512)
7883
{
79-
Joystick.setYAxis(currentStep - 256 - 127);
84+
yAxis = currentStep - 256 - 127;
85+
Joystick.setYAxis(yAxis);
8086
}
8187
else if (currentStep < 768)
8288
{
83-
Joystick.setXAxis(128 - (currentStep - 512));
89+
xAxis = 128 - (currentStep - 512);
90+
Joystick.setXAxis(xAxis);
8491
}
8592
else if (currentStep < 1024)
8693
{
87-
Joystick.setYAxis(128 - (currentStep - 768));
94+
yAxis = 128 - (currentStep - 768);
95+
Joystick.setYAxis(yAxis);
8896
}
8997
else if (currentStep < 1024 + 128)
9098
{
91-
Joystick.setXAxis(currentStep - 1024 - 127);
92-
Joystick.setYAxis(currentStep - 1024 - 127);
99+
xAxis = currentStep - 1024 - 127;
100+
Joystick.setXAxis(xAxis);
101+
Joystick.setYAxis(xAxis);
93102
}
94103
}
95104

@@ -150,13 +159,30 @@ void testThrottleRudder(unsigned int value)
150159
Joystick.setRudder(255 - value);
151160
}
152161

153-
void testXYAxisRotation(unsigned int degree)
162+
void testXYZAxisRotation(unsigned int degree)
154163
{
155-
Joystick.setXAxisRotation(degree);
156-
Joystick.setYAxisRotation(360 - degree);
164+
Joystick.setRxAxis(degree);
165+
Joystick.setRyAxis(360 - degree);
166+
Joystick.setRzAxis(degree * 2);
157167
}
158168

159169
void setup() {
170+
171+
/*
172+
* Uncomment this out for debugging...
173+
Serial.begin(9600);
174+
while (!Serial) {
175+
; // wait for serial port to connect. Needed for native USB
176+
}
177+
*/
178+
179+
Joystick.setXAxisRange(-127, 127);
180+
Joystick.setYAxisRange(-127, 127);
181+
Joystick.setZAxisRange(-127, 127);
182+
Joystick.setRxAxisRange(0, 360);
183+
Joystick.setRyAxisRange(0, 360);
184+
Joystick.setRzAxisRange(0, 720);
185+
160186
if (testAutoSendMode)
161187
{
162188
Joystick.begin();
@@ -175,6 +201,7 @@ void loop() {
175201
// System Disabled
176202
if (digitalRead(A0) != 0)
177203
{
204+
// Turn indicator light off.
178205
digitalWrite(13, 0);
179206
return;
180207
}
@@ -218,7 +245,7 @@ void loop() {
218245
else if (gCurrentStep < (37 + 256 + 1024 + 128 + 510 + 28 + 360))
219246
{
220247
gNextTime = millis() + gcAnalogDelta;
221-
testXYAxisRotation(gCurrentStep - (37 + 256 + 1024 + 128 + 510 + 28));
248+
testXYZAxisRotation(gCurrentStep - (37 + 256 + 1024 + 128 + 510 + 28));
222249
}
223250

224251
if (testAutoSendMode == false)

Joystick/examples/MultipleJoystickTest/MultipleJoystickTest.ino

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Program used to test the Arduino Joystick Library to create
2-
// multiple Joystick objects on a single Arduino Leonardo or
3-
// Arduino Micro.
1+
// Program used to test using the Arduino Joystick Library
2+
// to create multiple Joystick objects on a single Arduino
3+
// Leonardo or Arduino Micro.
44
//
55
// Matthew Heironimus
66
// 2016-05-13
@@ -10,9 +10,9 @@
1010
#define JOYSTICK_COUNT 4
1111

1212
Joystick_ Joystick[JOYSTICK_COUNT] = {
13-
Joystick_(0x03, 4),
14-
Joystick_(0x04, 8),
15-
Joystick_(0x05, 16),
13+
Joystick_(0x03, 4, true, true, false, false, false, false),
14+
Joystick_(0x04, 8, true, true, true, true, false, false),
15+
Joystick_(0x05, 16, false, true, false, true, false, false),
1616
Joystick_(0x06, 32)
1717
};
1818

@@ -97,9 +97,18 @@ void testXYAxis(int joystickId, unsigned int currentStep)
9797
}
9898

9999
void setup() {
100+
101+
/* Uncomment this out for debugging...
102+
Serial.begin(9600);
103+
while (!Serial) {
104+
; // wait for serial port to connect. Needed for native USB
105+
}
106+
*/
100107

101108
for (int index = 0; index < JOYSTICK_COUNT; index++)
102109
{
110+
Joystick[index].setXAxisRange(-127, 127);
111+
103112
if (testAutoSendMode)
104113
{
105114
Joystick[index].begin();

0 commit comments

Comments
 (0)