-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Add USB Joystick / Game Controller library to Arduino Leonardo and Arduino Micro #2843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Added a USB joystick to the Arduino Leonardo & Micro. Currently class is very simple, but I plan on enhancing it in future versions.
Added button, throttle, rudder, x, y, and z axis methods. Still need to do x, y, and z axis rotation and hat values.
Added the setHatSwitch function.
Added X, Y, and Z axis rotation methods.
Added a setButton method to make it easier to set the button state in some situations.
Added the ability to automatically update the state of the joystick whenever anything changes. This is the new default mode.
+1 !!!! |
I guess this will add Problems on some OS. See this issue: If you want a better USB-Core use the HID Project I suggest. Feel free to help me. |
Made a minor change to the layout of the Joystick HID report to simplify the X, Y, and Z axis values.
Update to match Version 1.6.5.
This reverts commit b66e707.
Closed with #1803 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Architecture: AVR
Applies only to the AVR microcontrollers (Uno, etc.)
Component: USB Device
Opposed to USB Host. Related to the USB subsystem (SerialUSB, HID, ...)
feature request
A request to make an enhancement (not a bug fix)
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The changes in this pull request add a Joystick library to the Arduino Leonardo and Arduino Micro. I attempted to model the methods in this library after the existing Mouse and Keyboard library. These code changes cause the Arduino Leonardo and Arduino Micro to appear as a generic Game Controller (as well as a generic keyboard and mouse) to the host computer.
The generic Game Controller provides the following:
The following is a summary of the methods provided by the Joystick library.
Joystick.begin(bool AutoSendState)
Starts emulating a game controller connected to a computer. By default all methods update the game controller state immediately. If AutoSendState is set to false, the Joystick.sendState method must be called to update the game controller state.
Joystick.end()
Stops the game controller emulation to a connected computer.
Joystick.setXAxis(byte value)
Sets the X axis value. Range -127 to 127 (0 is center).
Joystick.setYAxis(byte value)
Sets the Y axis value. Range -127 to 127 (0 is center).
Joystick.setZAxis(byte value)
Sets the Z axis value. Range -127 to 127 (0 is center).
Joystick.setXAxisRotation(int value)
Sets the X axis rotation value. Range 0° to 360°.
Joystick.setyAxisRotation(int value)
Sets the Y axis rotation value. Range 0° to 360°.
Joystick.setZAxisRotation(int value)
Sets the Z axis rotation value. Range 0° to 360°.
Joystick.setButton(byte button, byte value)
Sets the state of the specified button. The button is the 0-based button number (i.e. button '1' is 0, button '2' is 1, etc.). The value is 1 if the button is pressed and 0 if the button is released.
Joystick.pressButton(byte button)
Press the indicated button. The button is the 0-based button number (i.e. button '1' is 0, button '2' is 1, etc.).
Joystick.releaseButton(byte button)
Release the indicated button. The button is the 0-based button number (i.e. button '1' is 0, button '2' is 1, etc.).
Joystick.setThrottle(byte value)
Sets the throttle value. Range 0 to 255.
Joystick.setRudder(byte value)
Sets the rudder value. Range 0 to 255.
Joystick.setHatSwitch(byte hatSwitch, int value)
Sets the value of the specified hat switch. The hatSwitch is 0-based (i.e. hat switch '1' is 0 and hat switch '2' is 1). The value is from 0° to 360°, but in 45° increments. Any value less than 45° will be rounded down (i.e. 44° is rounded down to 0°, 89° is rounded down to 45°, etc.).
Joystick.sendState()
Sends the updated joystick state to the host computer. Only needs to be called if AutoSendState is false (see Joystick.begin for more details).
Please feel free to incorporate these additions into a future release of the Arduio software. Let me know if there is anything you think should be changed in this library.