diff --git a/libraries/ArduinoJoystickLibrary/.gitignore b/libraries/ArduinoJoystickLibrary/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/libraries/ArduinoJoystickLibrary/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/libraries/ArduinoJoystickLibrary/CONTRIBUTING.md b/libraries/ArduinoJoystickLibrary/CONTRIBUTING.md new file mode 100644 index 0000000..f0e8c9d --- /dev/null +++ b/libraries/ArduinoJoystickLibrary/CONTRIBUTING.md @@ -0,0 +1,28 @@ +## How to contribute to the Arduino Joystick Library + +### Report a bug + +* **Check to see if the bug has already reported** by searching on GitHub under [Issues](https://github.com/MHeironimus/ArduinoJoystickLibrary/issues). + +* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/MHeironimus/ArduinoJoystickLibrary/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible (e.g. host OS, Arduino IDE version, etc.), any important hardware information (e.g. name of Arduino board being used, specific pin wirings if they are relevant, etc.), and a **sample sketch** file demonstrating the issue. + +### Fix a bug + +* Open a new GitHub pull request with the fix. + +* Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable. + +### Whitespace, format code, or cosmetic updates + +* Changes that are cosmetic in nature and do not add anything substantial to the stability, functionality, or testability will generally not be accepted. + +### Adding a new feature + +* Feel free to [create a new issue](https://github.com/MHeironimus/ArduinoJoystickLibrary/issues/new) to document the feature you are planning to add. This will allow others to see and comment on what you would plan to add to the library. + +### Questions about the library + +* Be sure to check the [FAQ](https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki/FAQ) in the [Wiki](https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki) to see if your question has already been answered. +* Another good place to look for general Arduino questions is the [Arduino]() website. + +The Arduino Joystick Library is a volunteer effort done in volunteer's spare time. Please be patient as it may take some time for bugs to be fixed, features to be added, and questions to be answered. diff --git a/libraries/ArduinoJoystickLibrary/LICENSE b/libraries/ArduinoJoystickLibrary/LICENSE new file mode 100644 index 0000000..65c5ca8 --- /dev/null +++ b/libraries/ArduinoJoystickLibrary/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/libraries/ArduinoJoystickLibrary/README.md b/libraries/ArduinoJoystickLibrary/README.md new file mode 100644 index 0000000..7801179 --- /dev/null +++ b/libraries/ArduinoJoystickLibrary/README.md @@ -0,0 +1,234 @@ +# Arduino Joystick Library + +#### Version 2.1.1 + +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.). + +## Features + +The joystick or gamepad can have the following features: +- Buttons (default: 32) +- Up to 2 Hat Switches +- X, Y, and/or Z Axis (up to 16-bit precision) +- X, Y, and/or Z Axis Rotation (up to 16-bit precision) +- Rudder (up to 16-bit precision) +- Throttle (up to 16-bit precision) +- Accelerator (up to 16-bit precision) +- Brake (up to 16-bit precision) +- Steering (up to 16-bit precision) + +## Installation Instructions + +The following instructions can be used to install the latest version of the library in the Arduino IDE (thanks to [@per1234](https://github.com/per1234) for this update): + +1. Download https://github.com/MHeironimus/ArduinoJoystickLibrary/archive/master.zip +2. In the Arduino IDE, select `Sketch` > `Include Library` > `Add .ZIP Library...`. Browse to where the downloaded ZIP file is located and click `Open`. The Joystick library's examples will now appear under `File` > `Examples` > `Joystick`. + +## Examples + +### Simple example + +```C++ +#include + +// Create the Joystick +Joystick_ Joystick; + +// Constant that maps the physical pin to the joystick button. +const int pinToButtonMap = 9; + +void setup() { + // Initialize Button Pins + pinMode(pinToButtonMap, INPUT_PULLUP); + + // Initialize Joystick Library + Joystick.begin(); +} + +// Last state of the button +int lastButtonState = 0; + +void loop() { + + // Read pin values + int currentButtonState = !digitalRead(pinToButtonMap); + if (currentButtonState != lastButtonState) + { + Joystick.setButton(0, currentButtonState); + lastButtonState = currentButtonState; + } + + delay(50); +} +``` + +### Included Examples + +The following example Arduino sketch files are included in this library: + +#### Simple Samples + +- `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. +- `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. +- `GamepadExample` - Creates a simple Gamepad with an Up, Down, Left, Right, and Fire button. +- `FunduinoJoystickShield` - Creates a simple Gamepad using a Funduino Joystick Shield (https://protosupplies.com/product/funduino-joystick-shield-v1-a/). +- `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. + +#### Used for Testing + +- `JoystickTest` - Simple test of the Joystick library. It exercises many of the Joystick library’s functions when pin A0 is grounded. +- `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. +- `FlightControllerTest` - Creates a Flight Controller and tests 32 buttons, the X and Y axis, the Throttle, and the Rudder when pin A0 is grounded. +- `HatSwitchTest` - Creates a joystick with two hat switches. Grounding pins 4 - 11 cause the hat switches to change position. +- `DrivingControllerTest` - Creates a Driving Controller and tests 4 buttons, the Steering, Brake, and Accelerator when pin A0 is grounded. + +## Joystick Library API + +The following API is available if the Joystick library in included in a sketch file. + +### Joystick\_(...) + +Constructor used to initialize and setup the Joystick. The following optional parameters are available: + +- `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. +- `uint8_t joystickType` - Default: `JOYSTICK_TYPE_JOYSTICK` or `0x04` - Indicates the HID input device type. Supported values: + - `JOYSTICK_TYPE_JOYSTICK` or `0x04` - Joystick + - `JOYSTICK_TYPE_GAMEPAD` or `0x05` - Gamepad + - `JOYSTICK_TYPE_MULTI_AXIS` or `0x08` - Multi-axis Controller +- `uint8_t buttonCount` - Default: `32` - Indicates how many buttons will be available on the joystick. +- `uint8_t hatSwitchCount` - Default: `2` - Indicates how many hat switches will be available on the joystick. Range: `0` - `2` +- `bool includeXAxis` - Default: `true` - Indicates if the X Axis is available on the joystick. +- `bool includeYAxis` - Default: `true` - Indicates if the Y Axis is available on the joystick. +- `bool includeZAxis` - Default: `true` - Indicates if the Z Axis (in some situations this is the right X Axis) is available on the joystick. +- `bool includeRxAxis` - Default: `true` - Indicates if the X Axis Rotation (in some situations this is the right Y Axis) is available on the joystick. +- `bool includeRyAxis` - Default: `true` - Indicates if the Y Axis Rotation is available on the joystick. +- `bool includeRzAxis` - Default: `true` - Indicates if the Z Axis Rotation is available on the joystick. +- `bool includeRudder` - Default: `true` - Indicates if the Rudder is available on the joystick. +- `bool includeThrottle` - Default: `true` - Indicates if the Throttle is available on the joystick. +- `bool includeAccelerator` - Default: `true` - Indicates if the Accelerator is available on the joystick. +- `bool includeBrake` - Default: `true` - Indicates if the Brake is available on the joystick. +- `bool includeSteering` - Default: `true` - Indicates if the Steering is available on the joystick. + +The following constants define the default values for the constructor parameters listed above: + +- `JOYSTICK_DEFAULT_REPORT_ID` is set to `0x03` +- `JOYSTICK_DEFAULT_BUTTON_COUNT` is set to `32` +- `JOYSTICK_DEFAULT_HATSWITCH_COUNT` is set to `2` + +### Joystick.begin(bool initAutoSendState) + +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. + +### Joystick.end() + +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). + +### Joystick.setXAxisRange(int32_t minimum, int32_t maximum) + +Sets the range of values that will be used for the X axis. Default: `0` to `1023` + +### Joystick.setXAxis(int32_t value) + +Sets the X axis value. See `setXAxisRange` for the range. + +### Joystick.setYAxisRange(int32_t minimum, int32_t maximum) + +Sets the range of values that will be used for the Y axis. Default: `0` to `1023` + +### Joystick.setYAxis(int32_t value) + +Sets the Y axis value. See `setYAxisRange` for the range. + +### Joystick.setZAxisRange(int32_t minimum, int32_t maximum) + +Sets the range of values that will be used for the Z axis. Default: `0` to `1023` + +### Joystick.setZAxis(int32_t value) + +Sets the Z axis value. See `setZAxisRange` for the range. + +### Joystick.setRxAxisRange(int32_t minimum, int32_t maximum) + +Sets the range of values that will be used for the X axis rotation. Default: `0` to `1023` + +### Joystick.setRxAxis(int32_t value) + +Sets the X axis rotation value. See `setRxAxisRange` for the range. + +### Joystick.setRyAxisRange(int32_t minimum, int32_t maximum) + +Sets the range of values that will be used for the Y axis rotation. Default: `0` to `1023` + +### Joystick.setRyAxis(int32_t value) + +Sets the Y axis rotation value. See `setRyAxisRange` for the range. + +### Joystick.setRzAxisRange(int32_t minimum, int32_t maximum) + +Sets the range of values that will be used for the Z axis rotation. Default: `0` to `1023` + +### Joystick.setRzAxis(int32_t value) + +Sets the Z axis rotation value. See `setRzAxisRange` for the range. + +### Joystick.setRudderRange(int32_t minimum, int32_t maximum) + +Sets the range of values that will be used for the Rudder. Default: `0` to `1023` + +### Joystick.setRudder(int32_t value) + +Sets the Rudder value. See `setRudderRange` for the range. + +### Joystick.setThrottleRange(int32_t minimum, int32_t maximum) + +Sets the range of values that will be used for the Throttle. Default: `0` to `1023` + +### Joystick.setThrottle(int32_t value) + +Sets the Throttle value. See `setThrottleRange` for the range. + +### Joystick.setAcceleratorRange(int32_t minimum, int32_t maximum) + +Sets the range of values that will be used for the Accelerator. Default: `0` to `1023` + +### Joystick.setAccelerator(int32_t value) + +Sets the Accelerator value. See `setAcceleratorRange` for the range. + +### Joystick.setBrakeRange(int32_t minimum, int32_t maximum) + +Sets the range of values that will be used for the Brake. Default: `0` to `1023` + +### Joystick.setBrake(int32_t value) + +Sets the Brake value. See `setBrakeRange` for the range. + +### Joystick.setSteeringRange(int32_t minimum, int32_t maximum) + +Sets the range of values that will be used for the Steering. Default: `0` to `1023` + +### Joystick.setSteering(int32_t value) + +Sets the Steering value. See `setSteeringRange` for the range. + +### Joystick.setButton(uint8_t button, uint8_t value) + +Sets the state (`0` or `1`) of the specified button (range: `0` - (`buttonCount - 1`)). 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(uint8_t button) + +Press the indicated button (range: `0` - (`buttonCount - 1`)). The button is the 0-based button number (i.e. button #1 is `0`, button #2 is `1`, etc.). + +### Joystick.releaseButton(uint8_t button) + +Release the indicated button (range: `0` - (`buttonCount - 1`)). The button is the 0-based button number (i.e. button #1 is `0`, button #2 is `1`, etc.). + +### Joystick.setHatSwitch(int8_t hatSwitch, int16_t 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.). Set the value to `JOYSTICK_HATSWITCH_RELEASE` or `-1` to release the hat switch. + +### 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). + +See the [Wiki](https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki) for more details on things like FAQ, supported boards, testing, etc. diff --git a/libraries/ArduinoJoystickLibrary/library.properties b/libraries/ArduinoJoystickLibrary/library.properties new file mode 100644 index 0000000..3e3fe88 --- /dev/null +++ b/libraries/ArduinoJoystickLibrary/library.properties @@ -0,0 +1,9 @@ +name=Joystick +version=2.1.1 +author=Matthew Heironimus +maintainer=Matthew Heironimus +sentence=Allows an Arduino board with USB capabilities (e.g. Leonardo, Arduino Micro, Arudino Due, etc.) to appear as a Joystick or Gamepad. +paragraph=This library is built on the PluggableUSB library. It can be used with or without other HID-based libraries (Mouse, Keyboard, etc.). +category=Device Control +url=https://github.com/MHeironimus/ArduinoJoystickLibrary +architectures=avr,sam