Skip to content

Commit dabdcd4

Browse files
authored
Merge pull request MHeironimus#238 from MHeironimus/unity-fix
Version 2.1.0 - Unity Fix
2 parents e800604 + 3144b33 commit dabdcd4

File tree

6 files changed

+261
-236
lines changed

6 files changed

+261
-236
lines changed

README.md

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Arduino Joystick Library
22

3-
#### Version 2.0.8
3+
#### Version 2.1.0
44

5-
This library can be used with Arduino IDE 1.6.6 (or above) to add one or more joysticks (or gamepads) to the list of HID devices an [Arduino Leonardo](https://www.arduino.cc/en/Main/ArduinoBoardLeonardo) or [Arduino Micro](https://www.arduino.cc/en/Main/ArduinoBoardMicro) (or any Arduino clone that is based on the ATmega32u4) can support. This library will also work with the [Arduino Due](https://www.arduino.cc/en/Main/ArduinoBoardDue), thanks to [@Palakis](https://github.com/Palakis). A complete list of supported boards can be found in the [Wiki](https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki/Supported-Boards). This will not work with Arduino IDE 1.6.5 (or below) or with non-32u4 based Arduino devices (e.g. Arduino UNO, Arduino MEGA, etc.).
5+
This library can be used with Arduino IDE 1.6.6 or above (see [Wiki - Testing Details](https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki/Testing-Details) for more information) to add one or more joysticks (or gamepads) to the list of HID devices an [Arduino Leonardo](https://www.arduino.cc/en/Main/ArduinoBoardLeonardo) or [Arduino Micro](https://www.arduino.cc/en/Main/ArduinoBoardMicro) (or any Arduino clone that is based on the ATmega32u4) can support. This library will also work with the [Arduino Due](https://www.arduino.cc/en/Main/ArduinoBoardDue), thanks to [@Palakis](https://github.com/Palakis). A complete list of supported boards can be found in the [Wiki - Supported Boards](https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki/Supported-Boards). This will not work with Arduino IDE 1.6.5 (or below) or with non-32u4 based Arduino devices (e.g. Arduino UNO, Arduino MEGA, etc.).
66

77
## Features
88

@@ -26,18 +26,6 @@ The following instructions can be used to install the latest version of the libr
2626

2727
## Examples
2828

29-
The following example Arduino sketch files are included in this library:
30-
31-
- `JoystickTest` - Simple test of the Joystick library. It exercises many of the Joystick library’s functions when pin A0 is grounded.
32-
- `MultipleJoystickTest` - Creates 4 Joysticks using the library and exercises the first 16 buttons, the X axis, and the Y axis of each joystick when pin A0 is grounded.
33-
- `JoystickButton` - Creates a Joystick and maps pin 9 to button 0 of the joystick, pin 10 to button 1, pin 11 to button 2, and pin 12 to button 3.
34-
- `JoystickKeyboard` - Creates a Joystick and a Keyboard. Maps pin 9 to Joystick Button 0, pin 10 to Joystick Button 1, pin 11 to Keyboard key 1, and pin 12 to Keyboard key 2.
35-
- `GamepadExample` - Creates a simple Gamepad with an Up, Down, Left, Right, and Fire button.
36-
- `DrivingControllerTest` - Creates a Driving Controller and tests 4 buttons, the Steering, Brake, and Accelerator when pin A0 is grounded.
37-
- `FlightControllerTest` - Creates a Flight Controller and tests 32 buttons, the X and Y axis, the Throttle, and the Rudder when pin A0 is grounded.
38-
- `HatSwitchTest` - Creates a joystick with two hat switches. Grounding pins 4 - 11 cause the hat switches to change position.
39-
- `ArcadeStickExample` - Simple arcade stick example that demonstrates how to read twelve Arduino Pro Micro digital pins and map them to the library (thanks to [@nebhead](https://github.com/nebhead) for this example). NOTE: This sketch is for the Arduino Pro Micro only.
40-
4129
### Simple example
4230

4331
```C++
@@ -74,6 +62,25 @@ void loop() {
7462
}
7563
```
7664

65+
### Included Examples
66+
67+
The following example Arduino sketch files are included in this library:
68+
69+
#### Simple Samples
70+
71+
- `JoystickButton` - Creates a Joystick and maps pin 9 to button 0 of the joystick, pin 10 to button 1, pin 11 to button 2, and pin 12 to button 3.
72+
- `JoystickKeyboard` - Creates a Joystick and a Keyboard. Maps pin 9 to Joystick Button 0, pin 10 to Joystick Button 1, pin 11 to Keyboard key 1, and pin 12 to Keyboard key 2.
73+
- `GamepadExample` - Creates a simple Gamepad with an Up, Down, Left, Right, and Fire button.
74+
- `ArcadeStickExample` - Simple arcade stick example that demonstrates how to read twelve Arduino Pro Micro digital pins and map them to the library (thanks to [@nebhead](https://github.com/nebhead) for this example). NOTE: This sketch is for the Arduino Pro Micro only.
75+
76+
#### Used for Testing
77+
78+
- `JoystickTest` - Simple test of the Joystick library. It exercises many of the Joystick library’s functions when pin A0 is grounded.
79+
- `MultipleJoystickTest` - Creates 4 Joysticks using the library (each with a slightly different configuration) and exercises the first 16 buttons (if present), the X axis, and the Y axis of each joystick when pin A0 is grounded.
80+
- `FlightControllerTest` - Creates a Flight Controller and tests 32 buttons, the X and Y axis, the Throttle, and the Rudder when pin A0 is grounded.
81+
- `HatSwitchTest` - Creates a joystick with two hat switches. Grounding pins 4 - 11 cause the hat switches to change position.
82+
- `DrivingControllerTest` - Creates a Driving Controller and tests 4 buttons, the Steering, Brake, and Accelerator when pin A0 is grounded.
83+
7784
## Joystick Library API
7885

7986
The following API is available if the Joystick library in included in a sketch file.
@@ -113,93 +120,93 @@ Starts emulating a game controller connected to a computer. By default, all meth
113120

114121
### Joystick.end()
115122

116-
Stops the game controller emulation to a connected computer.
123+
Stops the game controller emulation to a connected computer (Note: just like the Arduino `Keyboard.h` and `Mouse.h` libraries, the `end()` function does not actually do anything).
117124

118-
### Joystick.setXAxisRange(int16_t minimum, int16_t maximum)
125+
### Joystick.setXAxisRange(int32_t minimum, int32_t maximum)
119126

120127
Sets the range of values that will be used for the X axis. Default: `0` to `1023`
121128

122-
### Joystick.setXAxis(int16_t value)
129+
### Joystick.setXAxis(int32_t value)
123130

124131
Sets the X axis value. See `setXAxisRange` for the range.
125132

126-
### Joystick.setYAxisRange(int16_t minimum, int16_t maximum)
133+
### Joystick.setYAxisRange(int32_t minimum, int32_t maximum)
127134

128135
Sets the range of values that will be used for the Y axis. Default: `0` to `1023`
129136

130-
### Joystick.setYAxis(int16_t value)
137+
### Joystick.setYAxis(int32_t value)
131138

132139
Sets the Y axis value. See `setYAxisRange` for the range.
133140

134-
### Joystick.setZAxisRange(int16_t minimum, int16_t maximum)
141+
### Joystick.setZAxisRange(int32_t minimum, int32_t maximum)
135142

136143
Sets the range of values that will be used for the Z axis. Default: `0` to `1023`
137144

138-
### Joystick.setZAxis(int16_t value)
145+
### Joystick.setZAxis(int32_t value)
139146

140147
Sets the Z axis value. See `setZAxisRange` for the range.
141148

142-
### Joystick.setRxAxisRange(int16_t minimum, int16_t maximum)
149+
### Joystick.setRxAxisRange(int32_t minimum, int32_t maximum)
143150

144151
Sets the range of values that will be used for the X axis rotation. Default: `0` to `1023`
145152

146-
### Joystick.setRxAxis(int16_t value)
153+
### Joystick.setRxAxis(int32_t value)
147154

148155
Sets the X axis rotation value. See `setRxAxisRange` for the range.
149156

150-
### Joystick.setRyAxisRange(int16_t minimum, int16_t maximum)
157+
### Joystick.setRyAxisRange(int32_t minimum, int32_t maximum)
151158

152159
Sets the range of values that will be used for the Y axis rotation. Default: `0` to `1023`
153160

154-
### Joystick.setRyAxis(int16_t value)
161+
### Joystick.setRyAxis(int32_t value)
155162

156163
Sets the Y axis rotation value. See `setRyAxisRange` for the range.
157164

158-
### Joystick.setRzAxisRange(int16_t minimum, int16_t maximum)
165+
### Joystick.setRzAxisRange(int32_t minimum, int32_t maximum)
159166

160167
Sets the range of values that will be used for the Z axis rotation. Default: `0` to `1023`
161168

162-
### Joystick.setRzAxis(int16_t value)
169+
### Joystick.setRzAxis(int32_t value)
163170

164171
Sets the Z axis rotation value. See `setRzAxisRange` for the range.
165172

166-
### Joystick.setRudderRange(int16_t minimum, int16_t maximum)
173+
### Joystick.setRudderRange(int32_t minimum, int32_t maximum)
167174

168175
Sets the range of values that will be used for the Rudder. Default: `0` to `1023`
169176

170-
### Joystick.setRudder(int16_t value)
177+
### Joystick.setRudder(int32_t value)
171178

172179
Sets the Rudder value. See `setRudderRange` for the range.
173180

174-
### Joystick.setThrottleRange(int16_t minimum, int16_t maximum)
181+
### Joystick.setThrottleRange(int32_t minimum, int32_t maximum)
175182

176183
Sets the range of values that will be used for the Throttle. Default: `0` to `1023`
177184

178-
### Joystick.setThrottle(int16_t value)
185+
### Joystick.setThrottle(int32_t value)
179186

180187
Sets the Throttle value. See `setThrottleRange` for the range.
181188

182-
### Joystick.setAcceleratorRange(int16_t minimum, int16_t maximum)
189+
### Joystick.setAcceleratorRange(int32_t minimum, int32_t maximum)
183190

184191
Sets the range of values that will be used for the Accelerator. Default: `0` to `1023`
185192

186-
### Joystick.setAccelerator(int16_t value)
193+
### Joystick.setAccelerator(int32_t value)
187194

188195
Sets the Accelerator value. See `setAcceleratorRange` for the range.
189196

190-
### Joystick.setBrakeRange(int16_t minimum, int16_t maximum)
197+
### Joystick.setBrakeRange(int32_t minimum, int32_t maximum)
191198

192199
Sets the range of values that will be used for the Brake. Default: `0` to `1023`
193200

194-
### Joystick.setBrake(int16_t value)
201+
### Joystick.setBrake(int32_t value)
195202

196203
Sets the Brake value. See `setBrakeRange` for the range.
197204

198-
### Joystick.setSteeringRange(int16_t minimum, int16_t maximum)
205+
### Joystick.setSteeringRange(int32_t minimum, int32_t maximum)
199206

200207
Sets the range of values that will be used for the Steering. Default: `0` to `1023`
201208

202-
### Joystick.setSteering(int16_t value)
209+
### Joystick.setSteering(int32_t value)
203210

204211
Sets the Steering value. See `setSteeringRange` for the range.
205212

examples/JoystickTest/JoystickTest.ino

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// above.
99
// 2016-05-13 Updated to use new dynamic Joystick library
1010
// that can be customized.
11+
// 2022-03-29 Updated to work with version 2.1.0 of the
12+
// Joystick library.
1113
//------------------------------------------------------------
1214

1315
#include "Joystick.h"
@@ -105,18 +107,22 @@ void testXYAxis(unsigned int currentStep)
105107

106108
void testZAxis(unsigned int currentStep)
107109
{
110+
int z;
111+
108112
if (currentStep < 128)
109113
{
110-
Joystick.setZAxis(-currentStep);
114+
z = -currentStep;
111115
}
112116
else if (currentStep < 256 + 128)
113117
{
114-
Joystick.setZAxis(currentStep - 128 - 127);
118+
z = currentStep - 128 - 127;
115119
}
116120
else if (currentStep < 256 + 128 + 127)
117121
{
118-
Joystick.setZAxis(127 - (currentStep - 383));
122+
z = 127 - (currentStep - 383);
119123
}
124+
125+
Joystick.setZAxis(z);
120126
}
121127

122128
void testHatSwitch(unsigned int currentStep)

examples/MultipleJoystickTest/MultipleJoystickTest.ino

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
// Each joystick has a unique configuration.
66
//
77
// Matthew Heironimus
8-
// 2016-05-13
8+
// 2016-05-13 - Original Version
9+
// 2022-03-29 - Updated to work with Joystick Library v2.1.0
910
//------------------------------------------------------------
1011
#include <Joystick.h>
1112

1213
#define JOYSTICK_COUNT 4
1314

1415
Joystick_ Joystick[JOYSTICK_COUNT] = {
15-
Joystick_(0x03, JOYSTICK_TYPE_GAMEPAD, 4, 2, true, true, false, false, false, false, false, false, false, false, false),
16-
Joystick_(0x04, JOYSTICK_TYPE_JOYSTICK, 8, 1, true, true, true, true, false, false, false, false, false, false, false),
17-
Joystick_(0x05, JOYSTICK_TYPE_MULTI_AXIS, 16, 0, false, true, false, true, false, false, true, true, false, false, false),
18-
Joystick_(0x06, JOYSTICK_TYPE_MULTI_AXIS, 32, 1, true, true, false, true, true, false, false, false, true, true, true)
16+
Joystick_(0x03, JOYSTICK_TYPE_JOYSTICK, 4, 2, true, true, false, false, false, false, false, false, false, false, false),
17+
Joystick_(0x04, JOYSTICK_TYPE_JOYSTICK, 8, 1, true, true, true, true, false, false, false, false, false, false, false),
18+
Joystick_(0x05, JOYSTICK_TYPE_JOYSTICK, 16, 0, false, true, false, true, false, false, true, true, false, false, false),
19+
Joystick_(0x06, JOYSTICK_TYPE_JOYSTICK, 32, 1, true, true, false, true, true, false, false, false, false, false, false)
1920
};
2021

2122
// Set to true to test "Auto Send" mode or false to test "Manual Send" mode.
@@ -74,28 +75,37 @@ void testMultiButtonPush(int joystickId, unsigned int currentStep)
7475

7576
void testXYAxis(int joystickId, unsigned int currentStep)
7677
{
78+
int x;
79+
int y;
80+
7781
if (currentStep < 255)
7882
{
79-
Joystick[joystickId].setXAxis(currentStep - 127);
80-
Joystick[joystickId].setYAxis(-127);
83+
x = currentStep - 127;
84+
y = -127;
8185
}
8286
else if (currentStep < 510)
8387
{
84-
Joystick[joystickId].setYAxis(currentStep - 255 - 127);
88+
x = 127;
89+
y = currentStep - 255 - 127;
8590
}
8691
else if (currentStep < 765)
8792
{
88-
Joystick[joystickId].setXAxis(127 - (currentStep - 510));
93+
x = 127 - (currentStep - 510);
94+
y = 127;
8995
}
9096
else if (currentStep < 1020)
9197
{
92-
Joystick[joystickId].setYAxis(127 - (currentStep - 765));
98+
x = -127;
99+
y = 127 - (currentStep - 765);
93100
}
94101
else if (currentStep <= 1020 + 127)
95102
{
96-
Joystick[joystickId].setXAxis(currentStep - 1020 - 127);
97-
Joystick[joystickId].setYAxis(currentStep - 1020 - 127);
103+
x = currentStep - 1020 - 127;
104+
y = currentStep - 1020 - 127;
98105
}
106+
107+
Joystick[joystickId].setXAxis(x);
108+
Joystick[joystickId].setYAxis(y);
99109
}
100110

101111
void setup() {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Joystick
2-
version=2.0.8
2+
version=2.1.0
33
author=Matthew Heironimus
44
maintainer=Matthew Heironimus <[email protected]>
55
sentence=Allows an Arduino board with USB capabilities (e.g. Leonardo, Arduino Micro, Arudino Due, etc.) to appear as a Joystick or Gamepad.

0 commit comments

Comments
 (0)