Skip to content

Commit 8203ec8

Browse files
committed
Added Joystick Type
Added Joystick Type to constructor [Issue MHeironimus#16]. Need to update examples to use new constructor parameter.
1 parent 7f1b0bc commit 8203ec8

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

Joystick/src/Joystick.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
Joystick_::Joystick_(
4545
uint8_t hidReportId,
46+
uint8_t joystickType,
4647
uint8_t buttonCount,
4748
uint8_t hatSwitchCount,
4849
bool includeXAxis,
@@ -108,9 +109,9 @@ Joystick_::Joystick_(
108109
tempHidReportDescriptor[hidReportDescriptorSize++] = 0x05;
109110
tempHidReportDescriptor[hidReportDescriptorSize++] = 0x01;
110111

111-
// USAGE (Joystick)
112+
// USAGE (Joystick - 0x04; Gamepad - 0x05; Multi-axis Controller - 0x08)
112113
tempHidReportDescriptor[hidReportDescriptorSize++] = 0x09;
113-
tempHidReportDescriptor[hidReportDescriptorSize++] = 0x04;
114+
tempHidReportDescriptor[hidReportDescriptorSize++] = joystickType;
114115

115116
// COLLECTION (Application)
116117
tempHidReportDescriptor[hidReportDescriptorSize++] = 0xa1;

Joystick/src/Joystick.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
#define JOYSTICK_DEFAULT_HATSWITCH_COUNT 2
5050
#define JOYSTICK_HATSWITCH_COUNT_MAXIMUM 2
5151
#define JOYSTICK_HATSWITCH_RELEASE -1
52+
#define JOYSTICK_TYPE_JOYSTICK 0x04
53+
#define JOYSTICK_TYPE_GAMEPAD 0x05
54+
#define JOYSTICK_TYPE_MULTI_AXIS 0x08
5255

5356
class Joystick_
5457
{
@@ -110,6 +113,7 @@ class Joystick_
110113
public:
111114
Joystick_(
112115
uint8_t hidReportId = JOYSTICK_DEFAULT_REPORT_ID,
116+
uint8_t joystickType = JOYSTICK_TYPE_JOYSTICK,
113117
uint8_t buttonCount = JOYSTICK_DEFAULT_BUTTON_COUNT,
114118
uint8_t hatSwitchCount = JOYSTICK_DEFAULT_HATSWITCH_COUNT,
115119
bool includeXAxis = true,

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### BETA Testing: This branch is currently being tested. All functions have been implemented and optimized. Feel free to try it out and let me know if you have any issues. The examples are not 100% up-to-date yet.
22

33
# Arduino Joystick Library
4-
#### Version 2.0.0 (in Beta Testing)
4+
#### Version 2.0.1 (in Beta Testing)
55
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 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
##Installation Instructions
@@ -58,7 +58,8 @@ The following API is available if the Joystick library in included in a sketch f
5858
### Joystick\_(...)
5959
Constructor used to initialize and setup the Joystick. The following optional parameters are available:
6060

61-
- `uint8_t hidReportId` - Default: `0x03` - Indicates what the joystick's HID report ID should be. This value must be unique if you are creating multiple instances of Joystick. Do not use `0x01` or `0x02` as they are used by the built-in Arduino Keyboard and Mouse libraries.
61+
- `uint8_t hidReportId` - Default: `0x03` - Indicates the joystick's HID report ID. This value must be unique if you are creating multiple instances of Joystick. Do not use `0x01` or `0x02` as they are used by the built-in Arduino Keyboard and Mouse libraries.
62+
- `uint8_t joystickType` - Default: `0x04` - Indicates they HID input device type. Supported values: 0x04 - Joystick; 0x05 - Gamepad; 0x08 - Multi-axis Controller
6263
- `uint8_t buttonCount` - Default: `32` - Indicates how many buttons will be available on the joystick.
6364
- `uint8_t hatSwitchCount` - Default: `2` - Indicates how many hat switches will be available on the joystick. Range: `0` - `2`
6465
- `bool includeXAxis` - Default: `true` - Indicates if the X Axis is available on the joystick.
@@ -78,7 +79,10 @@ The following constants define the default values for the constructor parameter'
7879
- `JOYSTICK_DEFAULT_REPORT_ID` is set to `0x03`
7980
- `JOYSTICK_DEFAULT_BUTTON_COUNT` is set to `32`
8081
- `JOYSTICK_DEFAULT_HATSWITCH_COUNT` is set to `2`
81-
82+
- `JOYSTICK_TYPE_JOYSTICK` is set to `0x04`
83+
- `JOYSTICK_TYPE_GAMEPAD` is set to `0x05`
84+
- `JOYSTICK_TYPE_MULTI_AXIS` is set to `0x08`
85+
8286
### Joystick.begin(bool initAutoSendState)
8387
Starts emulating a game controller connected to a computer. By default all methods update the game controller state immediately. If `initAutoSendState` is set to `false`, the `Joystick.sendState` method must be called to update the game controller state.
8488

@@ -174,7 +178,9 @@ I have used this library to make an Arduino appear as the following:
174178
- 3 joysticks / gamepads
175179
- 4 joysticks / gamepads
176180

177-
I have tested with 1 - 32 buttons.
181+
I have tested with 1 - 32 buttons. I have also tested this with 1 - 64 buttons.
182+
The standard Microsoft Windows Game Controller Test dialog only supports 32 buttons.
183+
To test a joystick with over 32 buttons, a third-party testing tool will need to be used (e.g. http://www.planetpointy.co.uk/joystick-test-application/).
178184

179185
I have tested with 0, 1, and 2 hat switches.
180186

@@ -199,4 +205,4 @@ Other board notes:
199205
- [Arduino UNO](https://www.arduino.cc/en/Main/ArduinoBoardUno) - NOT Supported - However, it might work with the [NicoHood/HoodLoader2](https://github.com/NicoHood/HoodLoader2) library, but I have not had a chance to try this out yet.
200206
- [Arduino MEGA](https://www.arduino.cc/en/Main/ArduinoBoardMega2560) - NOT Supported - However, it might work with the [NicoHood/HoodLoader2](https://github.com/NicoHood/HoodLoader2) library, but I have not had a chance to try this out yet.
201207

202-
(as of 2016-08-09)
208+
(as of 2016-09-12)

0 commit comments

Comments
 (0)